Export: trimming enhancements#3530
Conversation
setting subincludes at package level instead of at target level
- register subinclude statements in the package metadata - filter subincludes label - export all non build_target related statements
…dary build def with sources the updated test uses non-standard child naming to validate new trimming logic
previous implementation was append only meaning that it would mark a subinclude as required if it was visited before even if not exported.
f6fbf1a to
7152109
Compare
…a to also avoid tracking inside subincludes
…Parser is set. This wasn't an issue before since we would force close all the channels and fail during the first parse, but now we will attempt to wait for parsed package during an export.
…ents (including non-target generators). The reason for pivoting is that the previous implementation failed to identify necessary subincludes for variable declarations or other builtin methods (string join)
…ls to interpretStatements with the package level scope (e.g. for loop)
…y if blocks that have interpreted stmts (var redeclaration)
… they were interpreted oir not
toastwaffle
left a comment
There was a problem hiding this comment.
Nearly there!
As ever, comments phrased as questions probably imply a need for code comments
| keys = append(keys, k) | ||
| size += len(vals) | ||
| } | ||
| sort.Strings(keys) |
There was a problem hiding this comment.
Non-actionable: Why do we sort here?
|
|
||
| func (target *BuildTarget) allBuildInputs(unnamed []BuildInput, named map[string][]BuildInput) []BuildInput { | ||
| ret := unnamed | ||
| func (target *BuildTarget) selectBuildInputs(unnamed []BuildInput, named map[string][]BuildInput) []BuildInput { |
There was a problem hiding this comment.
- Given you've touched it and presumably understand why this exists, could you add a doc comment here?
- I'm not sure "select" is the right word, maybe "combined"?
- Why is this even a method on BuildTarget? I think this can be a plain func
| return int64(bs.Start) | ||
| } | ||
|
|
||
| // hashBuildStatement mixes the Start and End byte coordinates to produce a unique 64-bit hash. |
There was a problem hiding this comment.
I feel like for amusement we should state that "This does introduce a 4,294,967,296 byte size limit on BUILD files processed by Please"
Also, is it at all concerning that our hash is not uniformly distributed? What's worse - a non-uniform distribution, or doing more work to make it uniform?
| // dependencies. Dependencies identify the subincluded targets required for a successful | ||
| // interpretation of the statement, i.e. targets that provide the required symbols (variables or | ||
| // methods). The files argument identify the files required when interpreting that statement, for | ||
| // example using glob(), |
There was a problem hiding this comment.
I don't follow "for example using glob"
| RegisterSubincludeStatement(label BuildLabel, stmtProvider BuildStatementProvider) | ||
| RegisterStatementTarget(target BuildLabel, stmtProvider BuildStatementProvider) | ||
| // RegisterSubincludeStatement records the given build statement (provided by stmtProvider) | ||
| // as being a subincluded statement. This should only be called for statements in BUILD files. |
There was a problem hiding this comment.
subincluded -> subinclude? otherwise I don't follow
| @@ -0,0 +1,2 @@ | |||
| [parse] | |||
| BuildFileName = BUILD_FILE No newline at end of file | |||
There was a problem hiding this comment.
supernit: missing trailing newline
| custom_file( | ||
| name = "unneeded", | ||
| src = "unneeded.txt", | ||
| ) No newline at end of file |
There was a problem hiding this comment.
supernit: missing trailing newline
| @@ -0,0 +1,2 @@ | |||
| [parse] | |||
| BuildFileName = BUILD_FILE No newline at end of file | |||
There was a problem hiding this comment.
supernit: missing trailing newline
| name = "_foo#sub", | ||
| srcs = ["BUILD_FILE"], | ||
| visibility = ["PUBLIC"], | ||
| ) No newline at end of file |
There was a problem hiding this comment.
supernit: missing trailing newline
| @@ -0,0 +1,2 @@ | |||
| [parse] | |||
| BuildFileName = BUILD_FILE No newline at end of file | |||
There was a problem hiding this comment.
supernit: missing trailing newline
Enhancements to plz export, moving from a basic target-level trimming (using gc.RewriteFile) to build statement-level trimming, including only the required build rules and subincludes.
For consistency, we format all the exported BUILD files.
Changelog:
src/export/export.goto enforce better separation of the DefaultExporter (for trimming) and NoTrimExporter.