-
Notifications
You must be signed in to change notification settings - Fork 455
buildozer: support multi-file copy operations #1441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -811,7 +811,26 @@ func cmdDictListAdd(opts *Options, env CmdEnvironment) (*build.File, error) { | |||||
| } | ||||||
|
|
||||||
| func copyAttributeBetweenRules(env CmdEnvironment, attrName string, from string) (*build.File, error) { | ||||||
| fromRule := FindRuleByName(env.File, from) | ||||||
| // Check if the source rule is in another package | ||||||
| buildFile, _, _, rule := InterpretLabelForWorkspaceLocation(NewOpts().RootDir, from) | ||||||
| var fromRule *build.Rule | ||||||
|
|
||||||
| if buildFile != "" && buildFile != env.File.Path { | ||||||
| // The rule is in another file, we need to load it | ||||||
| data, _, err := file.ReadFile(buildFile) | ||||||
| if err != nil { | ||||||
| return nil, fmt.Errorf("could not read file '%s': %v", buildFile, err) | ||||||
| } | ||||||
| f, err := build.Parse(buildFile, data) | ||||||
| if err != nil { | ||||||
| return nil, fmt.Errorf("could not parse file '%s': %v", buildFile, err) | ||||||
| } | ||||||
| fromRule = FindRuleByName(f, rule) | ||||||
|
Comment on lines
+818
to
+828
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implementation reads and parses the source BUILD file every time a For example: Consider introducing a cache for parsed |
||||||
| } else { | ||||||
| // The rule is in the same file | ||||||
| fromRule = FindRuleByName(env.File, from) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the source rule is in the same file, you are calling This will cause lookups to fail for rules specified with an absolute label that are in the current file. You should use the
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| if fromRule == nil { | ||||||
| return nil, fmt.Errorf("could not find rule '%s'", from) | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to
InterpretLabelForWorkspaceLocationusesNewOpts().RootDir, which creates a newOptionsobject with a default (empty)RootDir. This ignores theRootDirthat might have been passed tobuildozervia command-line flags, which can lead to incorrect workspace root detection.To fix this,
copyAttributeBetweenRulesshould accept the*Optionsstruct (passed down fromcmdCopy/cmdCopyNoOverwrite) and useopts.RootDirhere.