From fa58eadc615c9133c962a0425272c33cd6bbf673 Mon Sep 17 00:00:00 2001 From: aldersondrive Date: Tue, 17 Dec 2019 10:28:03 -0500 Subject: [PATCH 1/4] Fix the path to the Python executable on OpenBSD. --- .../build/lib/bazel/rules/python/BazelPythonSemantics.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java index 7beb82367b36aa..b39bff54ae3c5b 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java @@ -235,13 +235,14 @@ public void createExecutable( if (OS.getCurrent() != OS.WINDOWS) { PathFragment shExecutable = ShToolchain.getPathOrError(ruleContext); + String pythonExecutableName = OS.getCurrent() == OS.OPENBSD ? "python3" : "python"; ruleContext.registerAction( new SpawnAction.Builder() .addInput(zipFile) .addOutput(executable) .setShellCommand( shExecutable, - "echo '#!/usr/bin/env python' | cat - " + "echo '#!/usr/bin/env " + pythonExecutableName + "' | cat - " + zipFile.getExecPathString() + " > " + executable.getExecPathString()) From 11df97d2fc9e98266e81a3ebec7d346c471cdfaf Mon Sep 17 00:00:00 2001 From: aldersondrive Date: Wed, 8 Jan 2020 07:05:06 -0500 Subject: [PATCH 2/4] Change the Python executable name from `python` to `python3`. As discussed here: https://github.com/bazelbuild/bazel/pull/10432#issuecomment-571746342 --- .../build/lib/bazel/rules/python/BazelPythonSemantics.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java index b39bff54ae3c5b..116c06bd1d92f6 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java @@ -235,14 +235,13 @@ public void createExecutable( if (OS.getCurrent() != OS.WINDOWS) { PathFragment shExecutable = ShToolchain.getPathOrError(ruleContext); - String pythonExecutableName = OS.getCurrent() == OS.OPENBSD ? "python3" : "python"; ruleContext.registerAction( new SpawnAction.Builder() .addInput(zipFile) .addOutput(executable) .setShellCommand( shExecutable, - "echo '#!/usr/bin/env " + pythonExecutableName + "' | cat - " + "echo '#!/usr/bin/env python3' | cat - " + zipFile.getExecPathString() + " > " + executable.getExecPathString()) From a1db6b24421da36a1a9ac44e663b2c9d8cfb3bb5 Mon Sep 17 00:00:00 2001 From: aldersondrive Date: Tue, 4 Feb 2020 13:21:49 -0500 Subject: [PATCH 3/4] Revert "Change the Python executable name from `python` to `python3`." This reverts commit 11df97d2fc9e98266e81a3ebec7d346c471cdfaf. --- .../build/lib/bazel/rules/python/BazelPythonSemantics.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java index 116c06bd1d92f6..b39bff54ae3c5b 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java @@ -235,13 +235,14 @@ public void createExecutable( if (OS.getCurrent() != OS.WINDOWS) { PathFragment shExecutable = ShToolchain.getPathOrError(ruleContext); + String pythonExecutableName = OS.getCurrent() == OS.OPENBSD ? "python3" : "python"; ruleContext.registerAction( new SpawnAction.Builder() .addInput(zipFile) .addOutput(executable) .setShellCommand( shExecutable, - "echo '#!/usr/bin/env python3' | cat - " + "echo '#!/usr/bin/env " + pythonExecutableName + "' | cat - " + zipFile.getExecPathString() + " > " + executable.getExecPathString()) From 54a93144e7843db6e23aaa57a2412d278d59f7e1 Mon Sep 17 00:00:00 2001 From: aldersondrive Date: Tue, 4 Feb 2020 13:25:06 -0500 Subject: [PATCH 4/4] Add a TODO, as discussed in code review. --- .../build/lib/bazel/rules/python/BazelPythonSemantics.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java index b39bff54ae3c5b..a54d5705df332b 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java @@ -235,6 +235,8 @@ public void createExecutable( if (OS.getCurrent() != OS.WINDOWS) { PathFragment shExecutable = ShToolchain.getPathOrError(ruleContext); + // TODO(#8685): Remove this special-case handling as part of making the proper shebang a + // property of the Python toolchain configuration. String pythonExecutableName = OS.getCurrent() == OS.OPENBSD ? "python3" : "python"; ruleContext.registerAction( new SpawnAction.Builder()