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

Fix directory matching if string doesn’t start with bazel-out/ or external/ #639

Merged
merged 6 commits into from
Jul 4, 2022

Conversation

BalestraPatrick
Copy link
Contributor

Fixes #638. This correctly matches and replaces file paths independently from where they are in the flag. This fixes building with BwX when using something like rules_apple_linker that passes the custom linker via the --ld-path flag.

opt = "$(BUILD_DIR)/" + opt
elif opt.startswith("external/"):
opt = "$(LINKS_DIR)/" + opt
if "bazel-out/" in opt:
Copy link
Contributor

@brentleyjones brentleyjones Jul 4, 2022

Choose a reason for hiding this comment

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

We need this to be startswith to not over replace. Instead we need to split the flag better so we know what the start of the path is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would splitting on = be sufficient? Or what else were you thinking?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe so. Basically match the logic in opts.bzl more completely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So for example -Wl,-add_ast_path,bazel-out/darwin_x86_64-dbg-ST-5534cb307cb8/ would still be handled as before, but for flags that don't use -Wl but are instead passed directly as --ld-path=external/..., we would handle them differently? Not sure what other cases there could be.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's the only two cases we have to worry about.

@brentleyjones
Copy link
Contributor

brentleyjones commented Jul 4, 2022

Can you add an example for this as well?

@BalestraPatrick
Copy link
Contributor Author

Looking into adding an example with rules_apple_linker now.

@@ -366,6 +366,13 @@ def _process_linkopt(linkopt, *, triple):
if opt.endswith(".swiftmodule"):
opt = opt + "/{}.swiftmodule".format(triple)

# Process paths in the --flag=value format
flag, sep, value = opt.partition("=")
if value:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can move this up and only do the path prepend logic once?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if how I changed it is like you meant it, but I couldn't find a way to make it more readable. Let me know how it looks!

@brentleyjones brentleyjones enabled auto-merge (squash) July 4, 2022 23:34
@brentleyjones brentleyjones merged commit 8695f68 into main Jul 4, 2022
@brentleyjones brentleyjones deleted the pb/replace-linker-inputs-paths branch July 4, 2022 23:34
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.

Bug: Linker inputs aren't expanded with correct filepaths in some cases
2 participants