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

[Bootstrap Template] Fixed bootstrap template not being passed to py_binary from py_runtime on bazel latest #18103

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,13 @@ def _expand_bootstrap_template(

if runtime:
shebang = runtime.stub_shebang
template = runtime.bootstrap_template
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like just one test is failing because bootstrap template is None, which makes sense -- the test is specifically testing a manually created PyRuntimeInfo. It's expected that PyRuntimeInfo.bootstrap_template is set; Normally this is handled by the py_runtime rule, but the test is specifically checking for a custom implementation.

This is around the line you'll need to modify:
https://cs.opensource.google/bazel/bazel/+/master:src/test/java/com/google/devtools/build/lib/rules/python/PythonStarlarkApiTest.java;l=120;drc=17827eee79808fceb6558d632c5b5594e8e9a47a

The net changes should be something like:

  • In the call to PyRuntimeInfo(), add bootstrap_template=ctx.file.bootstrap_template
  • A couple lines below, to the userruntime rule definition, add 'bootstrap_template': attr.label_list(allow_files=True)
  • A couple lines below, in the call to userruntime() add bootstrap_template='bootstrap.txt'

And bazel test //src/test/java/com/google/devtools/build/lib/rules/python:PythonStarlarkApiTest

else:
shebang = DEFAULT_STUB_SHEBANG
template = ctx.file._bootstrap_template

ctx.actions.expand_template(
template = ctx.file._bootstrap_template,
template = template,
output = output,
substitutions = {
"%shebang%": shebang,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,16 @@ public void runtimeSandwich() throws Exception {
" return [PyRuntimeInfo(",
" interpreter = ctx.file.interpreter,",
" files = depset(direct = ctx.files.files, transitive=[info.files]),",
" python_version = info.python_version)]",
" python_version = info.python_version,",
" bootstrap_template = ctx.file.bootstrap_template)]",
"",
"userruntime = rule(",
" implementation = _userruntime_impl,",
" attrs = {",
" 'runtime': attr.label(),",
" 'interpreter': attr.label(allow_single_file=True),",
" 'files': attr.label_list(allow_files=True),",
" 'bootstrap_template': attr.label(allow_single_file=True),",
" },",
")");
scratch.file(
Expand All @@ -148,6 +150,7 @@ public void runtimeSandwich() throws Exception {
" runtime = ':pyruntime',",
" interpreter = ':userintr',",
" files = ['userdata.txt'],",
" bootstrap_template = 'bootstrap.txt',",
")",
"py_runtime_pair(",
" name = 'userruntime_pair',",
Expand Down