-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify computation of
Package#sourceRoot
This field is initialized in `finishInit()`, but doesn't depend on anything discovered during BUILD file evaluation. So we may as well compute it during the constructor call and remove some complexity from this class. This CL should not cause a behavioral change. Structural changes: - `sourceRoot` is now final. - The existing method `computeSourceRoot()` is inlined and eliminated. A new static method by the same name is factored out of the relevant part of `finishInit()`. The effect is that the method boundary now encapsulates the actual job of determining the source root, whereas previously this work both spanned multiple methods and intermingled with unrelated tasks. - Validation of the consistency between `buildFilename` and `isRepoRulePackage` is moved from `computeSourceRoot()` down into `Metadata`'s constructor. `isWorkspaceFile()` and `isModuleDotBazelFile()` are inlined into their sole call sites. Changes to the body (hope this helps for reading the diff): - The `baseName` local var is no longer needed. - The trivial true branch of the outer `if` statement is turned into an early exit at the top of the method. - Rewrote the early `return`s from the inlined method as `if`-`else`s that initialize a local var `sourceRoot`. - The `throw` IAE statement is turned into a `Preconditions.checkArgument()`. - Renamed local var `packageDirectory` -> `pkgDirFragment`, factored some other local vars up top. - Added TODO about simplifying `current`'s initialization (didn't want to risk it in this CL). Some test cases were previously creating `Package.Builder`s with bad BUILD filenames but not actually constructing the final package. This was allowed because the validation was deferred until `finishInit()`, which didn't run. Fixed those test cases to pass, now that the validation of BUILD filenames happens up front. Work toward #19922. Drive-by simplification while doing other refactoring of `Package`'s fields. PiperOrigin-RevId: 676390008 Change-Id: I1c928924adea5c5caaa6d056de50cb98ce17b79a
- Loading branch information
1 parent
8d0e4db
commit 9a4d8cc
Showing
4 changed files
with
61 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters