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

feat(): macros nodejs_binary_toolchains nodejs_test_toolchains input … #3132

Merged
merged 1 commit into from
Dec 14, 2021

Conversation

dymart
Copy link
Contributor

@dymart dymart commented Dec 10, 2021

…multiple toolchains nodejs_binary or nodejs_test

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Could only pass one toolchain to a rule

What is the new behavior?

can pass multiple toolchains to a rule and it will create a new target for each toolchain

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@dymart dymart force-pushed the 5.tool branch 2 times, most recently from 736e685 to d1352a2 Compare December 10, 2021 07:45
@@ -250,8 +250,10 @@ fi
# when building the image as that will reflect the selected --platform.
node_tool_files = ctx.files.node[:]

# this should be resolved the same as above
node_tool_files.extend(ctx.toolchains["@build_bazel_rules_nodejs//toolchains/node:toolchain_type"].nodeinfo.tool_files)
if ctx.attr.toolchain:
Copy link
Collaborator

Choose a reason for hiding this comment

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

can reduce duplication by assigning to a local variable that holds either ctx.attr.toolchain or ctx.toolchains[default]

@@ -658,6 +661,27 @@ def nodejs_binary_macro(name, **kwargs):
**kwargs
)

def nodejs_binary_toolchain_macro(name, toolchains = [], **kwargs):
"""This extens nodejs binary and allows for multiple toolchains to be passed as a list and
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: extends

maybe get a spell checker into your editor?

@@ -658,6 +661,27 @@ def nodejs_binary_macro(name, **kwargs):
**kwargs
)

def nodejs_binary_toolchain_macro(name, toolchains = [], **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if this is holding it's weight and worth putting in rules_nodejs code, rather than just put it in an example and let users maintain a little macro for this purpose. In all the life of the project I think we only heard of two users who want it

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'm not sure what the outcome here should be. Should it switch to adding nodejs_binary to rules_nodejs then have an example there? Or just remove this macro and create an example that that shows users how to do it?

My only push back on not many users requesting it is, has there been many build tools that can make it this easy to run different toolchains on the same machine in parallel. Could be useful during upgrades to different node versions and allow better gradual migrations.

# bazel build //internal/node/test:main_multiple_0
# bazel build //internal/node/test:main_multiple_1
# the numbers are based on the order that the toolchains are passed to the rule
nodejs_binary_toolchains(
Copy link
Collaborator

Choose a reason for hiding this comment

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

it might even be better to show it with a comprehension rather than a macro

[
  nodejs_binary(name = "x" + tc, ...)
  for tc in [...]
]

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 this would be in the case we decide to remove the macro mentioned in the above comment?
Is that the preferred outcome?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We want to keep our maintenance burden in the upstream repo minimal, since it's not really funded. So any code maintained here ought to be broadly applicable. If only a couple users need it, then my instinct is it should live in their repo (we can have an example to help them).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds Good! thanks for the clarification

"@bazel_tools//src/conditions:darwin": "@node15_darwin_amd64//:node_toolchain",
"@bazel_tools//src/conditions:windows": "@node15_windows_amd64//:node_toolchain",
}),
select({
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems like the two select's have the same content?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I wasn't sure about the best way to check that the correct version of two different toolchain versions was being used from one test. So both toolchains are the same. I could also just run a normal test that doesn't check the version with two different toolchains. I'm open to suggestions

@dymart dymart force-pushed the 5.tool branch 7 times, most recently from 9804727 to 906f3ad Compare December 13, 2021 15:57
@dymart dymart requested a review from alexeagle December 13, 2021 16:16
# bazel build //internal/node/test:main_multiple_loop_1
# the numbers are based on the order that the toolchains are passed to the rule
[
nodejs_binary(
Copy link
Collaborator

Choose a reason for hiding this comment

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

duplicate targets to what is stamped out below?

//internal/node/test:main_multiple_loop_node16
//internal/node/test:main_multiple_loop_node15

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes they would be the same. Added to show different ways of doing the same thing. If there is a preferred way I can remove the other

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the for id, tc in zip( example with the clearer named targets is a better one so you can remove the enumerate one.

nodejs_binary(
name = "main_multiple_loop_" + id,
entry_point = "binary_version.js",
node = tc,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you aiming to collapse node & toolchain into just one attr?

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 was hoping to get the use of toolchains added and then go back and clean this up. Originally it was behind a macro as well so a change collapsing the two wouldn't have been visible. But if we want to combine them now we could do that as well

Copy link
Collaborator

Choose a reason for hiding this comment

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

A follow-up of removing node in favor toolchain sounds good to me. Seems easier to do it that way and the downstream effects will be easier to see.

Copy link
Collaborator

@gregmagolan gregmagolan left a comment

Choose a reason for hiding this comment

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

Looks great. Can you add a nodejs_test (like the one done in e2e/core) that the node version at runtime is what you expect. Can be done as a follow up to this.

…multiple toolchains nodejs_binary or nodejs_test
@dymart dymart merged commit 55a7521 into bazel-contrib:5.x Dec 14, 2021
@dymart
Copy link
Contributor Author

dymart commented Dec 14, 2021

Added test to verify node version to this pr for multiple versions

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