Skip to content

Add support for $(location) in nodejs_binary#entry_point - #42

Closed
alexeagle wants to merge 2 commits into
bazel-contrib:masterfrom
alexeagle:issue_32
Closed

alexeagle wants to merge 2 commits into
bazel-contrib:masterfrom
alexeagle:issue_32

Conversation

@alexeagle

Copy link
Copy Markdown
Collaborator

No description provided.

@alexeagle

Copy link
Copy Markdown
Collaborator Author

@vladmos I would appreciate an opinion from the Bazel team: I'm using $(location :label) expansion in a different way than intended I think - I want these to reference output locations in the RUNFILES.
According to https://docs.bazel.build/versions/master/be/make-variables.html#location it should give paths relative to the runfiles of the _bin or _test target, but I find I have to do munging on the path.

@alexeagle
alexeagle force-pushed the issue_32 branch 4 times, most recently from 6f10738 to cdb2a1b Compare October 31, 2017 15:21
@alexeagle

Copy link
Copy Markdown
Collaborator Author

@rzhw any comments? I'm still a bit unsure if users should be exposed to the $(location) syntax as I've done here.
Another possibility would be to allow either string or label in the entry_point attr, and if the value starts with @, :, or // then treat it as requiring location expansion (and also maybe add it to data automatically)

@filipesilva filipesilva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM but would like to see what @vladmos and @rzhw have to say about those alternatives.

@rzhw rzhw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, assuming we're happy with how $(location) is currently overloaded (because of the path munging).

I hadn't thought of that being a concern previously, so echoing interest in comment from the Bazel team.

Comment thread examples/program/BUILD.bazel Outdated
py_test(
name = "bin_test",
srcs = ["bin_test.py"],
deps = ["@build_bazel_rules_nodejs//internal:runfiles"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Does using just //internal:runfiles work, since this is just an example that lives in this workspace?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Whoops, didn't realise this example was a separate workspace.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah having two workspaces in this repo is useful for learning about things like this, and also catches some bugs where the wrong context is used to create a path.

@rzhw

rzhw commented Nov 1, 2017 •

Copy link
Copy Markdown
Contributor

bazelbuild/bazel#2475 looks relevant, particularly this proposal. $(rootpath) would let expand_path_into_runfiles be deprecated. Though it still leaves the concern of exposing users to that syntax in the first place.

@alexeagle

Copy link
Copy Markdown
Collaborator Author

Awesome job tracking down that feature request. It looks like Ulf is close to introducing the $(rootpath) expansion.
Since that change would affect how users write their entry_point, I think I should hold this PR for a couple weeks to see if that lands and is released.

@rzhw

rzhw commented Jan 11, 2018

Copy link
Copy Markdown
Contributor

Looks like $(rootpath) has landed in 0.8.0.

Tests here, doesn't appear to test for e.g. $(rootpath @other_wksp//:thing)

@rzhw

rzhw commented Feb 23, 2018

Copy link
Copy Markdown
Contributor

What's currently blocking this from landing?

I've tried rebasing once but looks like I'm hitting some conflicts again 😢

@alexeagle

Copy link
Copy Markdown
Collaborator Author

Nothing blocking this other than prioritization. I haven't had time, would appreciate some help!

(Also I'm switching to Windows to force myself to make all the Bazel + Angular builds work on Windows so it's going to be slow going for a while....)

@rzhw

rzhw commented Feb 23, 2018

Copy link
Copy Markdown
Contributor

Gotcha, what's needed after resolving the merge conflicts if any? Verifying it works on Windows, design input from someone else from Bazel?

@alexeagle

Copy link
Copy Markdown
Collaborator Author

Sorry @rzhw just never prioritized this one. Dusting it off now...

BREAKING CHANGE:
This forces us to use workspace-relative paths since the rootpath helper returns this format.
Users are now exposed to the external path segment to reference other workspaces.
See discussion: bazel-contrib#84

Fixes bazel-contrib#32
@nimerritt

Copy link
Copy Markdown
Contributor

@alexeagle Any reason this can't be merged? I could help out if it's a time thing. It is confusing for others in my team who don't know the details of the rules_nodejs implementation to understand what this field should be. Using a build target instead hides the implementation details better.

@gregmagolan

gregmagolan commented Jun 26, 2018 •

Copy link
Copy Markdown
Collaborator

@nimerrit This has been collecting some dust. I've been looking at related code recently with #240. I'll discuss this PR with @alexeagle when he's back from vacation next week and to see what else needs to be done so that it can get in. It would be a good one to land for users like yourself.

return path
return expand_path_into_runfiles(ctx, path)

def expand_path_into_runfiles(ctx, path):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

expand_path_into_runfiles is used in rules_typescript so likely need to keep it around as deprecated

// or just path/to/thing with the implied local workspace
// This matches Bazel semantics for cwd of toolchain processes
// and helpers like ctx.expand_location("$(rootpath foo)")
resolveRunfiles('TEMPLATED_user_workspace_name', request),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This seems make sense. It should also continue to work with #240.

@nimerritt

Copy link
Copy Markdown
Contributor

@alexeagle @gregmagolan Any updates on this? I'm trying to calculate the entry_point in a macro and can't figure out how to do it currently. The discussion in #32 would have me believe that I can use native.respitory_name but that actually returns @ and not the required rules_nodejs. I had it hard-coded for the specific repository to work around this, but now I'm consuming my rules from another workspace, so this is now more important. Any suggestions? Do you need help with this PR?

@Globegitter

Globegitter commented Sep 15, 2018 •

Copy link
Copy Markdown

Given a discussion here: bazelbuild/bazel#6001 (and updated docs: bazelbuild/bazel@22a4994) it seems that entry_point should not be a string and not use the $(location x) syntax but rather be a label.That would also make the most sense to me and it should be able to make this work with node_modules also.

@alexeagle

Copy link
Copy Markdown
Collaborator Author

Will go with a label, thanks @Globegitter
Sorry this has been so stale...

@alexeagle alexeagle closed this Nov 30, 2018
alexeagle added a commit to alexeagle/rules_nodejs that referenced this pull request Oct 17, 2020
alexeagle added a commit to alexeagle/rules_nodejs that referenced this pull request Oct 18, 2020
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.

6 participants