Skip to content
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

unused_deps: Add exported dependencies before removing #1169

Merged
merged 2 commits into from
Jul 13, 2023

Conversation

vj-sc
Copy link
Contributor

@vj-sc vj-sc commented May 25, 2023

A dependency that is marked for removal might contain exports. Since exports are treated as if the parent explicitly depended on them, removal of such a dependency can cause issues since the exported dependencies will no longer be available to the parent.
This PR proposes to fix this by first adding the exports explicitly to the parent's deps before removing the dependency.

@google-cla
Copy link

google-cla bot commented May 25, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@@ -291,6 +291,8 @@ func printCommands(label string, deps map[string]bool) (anyCommandPrinted bool)
if hasRuntimeComment(str) {
fmt.Printf("buildozer 'move deps runtime_deps %s' %s\n", str.Value, label)
} else {
// add dep's exported dependencies to label before removing dep
fmt.Printf("buildozer \"add deps $(%s query 'labels(exports, %s)' | tr '\\n' ' ')\" %s\n", *buildTool, str.Value, label)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to locate a utility function for obtaining a label's attribute but was unable to find one, so I used a bazel query invocation here. It'd be better to avoid the query. I'd appreciate any pointers on this in case I missed something.

@vladmos
Copy link
Member

vladmos commented Jul 12, 2023

Do I understand correctly that you're adding deps unconditionally even if it doesn't contain exports? Or will the command be no-op if there are no exports?

@0vj00
Copy link

0vj00 commented Jul 13, 2023

Do I understand correctly that you're adding deps unconditionally even if it doesn't contain exports? Or will the command be no-op if there are no exports?

In the case where there are no exports, the command becomes buildozer "add deps " <label> and since there are no arguments to the add deps part, buildozer doesn't modify the label.

@vladmos vladmos merged commit 34721cc into bazelbuild:master Jul 13, 2023
apattidb pushed a commit to databricks/buildtools that referenced this pull request May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants