Loading pkgs/development/python-modules/craft-parts/bash-path.patch +74 −16 Original line number Diff line number Diff line diff --git a/craft_parts/executor/step_handler.py b/craft_parts/executor/step_handler.py index 404df69..f90e2ac 100644 index 5eab915..bc26252 100644 --- a/craft_parts/executor/step_handler.py +++ b/craft_parts/executor/step_handler.py @@ -243,8 +243,9 @@ class StepHandler: print(script, file=script_file) script_file.flush() script_file.seek(0) + import shutil process = subprocess.Popen( # pylint: disable=consider-using-with - ["/bin/bash"], + [shutil.which("bash")], stdin=script_file, cwd=work_dir, stdout=self._stdout, @@ -394,7 +395,8 @@ def _create_and_run_script( @@ -445,7 +445,8 @@ def _create_and_run_script( ) -> None: """Create a script with step-specific commands and execute it.""" with script_path.open("w") as run_file: Loading @@ -22,12 +11,28 @@ index 404df69..f90e2ac 100644 + print(f"#!{shutil.which('bash')}", file=run_file) print("set -euo pipefail", file=run_file) if build_environment_script_path: if environment_script_path: diff --git a/craft_parts/plugins/java_plugin.py b/craft_parts/plugins/java_plugin.py index f2b4064..cb4e9e8 100644 --- a/craft_parts/plugins/java_plugin.py +++ b/craft_parts/plugins/java_plugin.py @@ -71,9 +71,8 @@ class JavaPlugin(Plugin): return None, "" def _find_javac(self) -> list[str]: - cmd = ["find", "/usr/lib/jvm", "-path", "*/bin/javac", "-print"] - output = subprocess.check_output(cmd, text=True) - return [x for x in output.split("\n") if len(x) > 0] + import shutil + return [shutil.which("javac")] @override def get_build_environment(self) -> dict[str, str]: diff --git a/craft_parts/plugins/validator.py b/craft_parts/plugins/validator.py index b8d8f11..fce0e72 100644 index 5b4c735..8ff30c2 100644 --- a/craft_parts/plugins/validator.py +++ b/craft_parts/plugins/validator.py @@ -142,9 +142,9 @@ class PluginEnvironmentValidator: @@ -141,9 +141,9 @@ class PluginEnvironmentValidator: print(self._env, file=env_file) print(cmd, file=env_file) env_file.flush() Loading @@ -39,3 +44,56 @@ index b8d8f11..fce0e72 100644 check=True, capture_output=True, text=True, diff --git a/tests/unit/executor/test_step_handler.py b/tests/unit/executor/test_step_handler.py index 4e73c2b..b762fb8 100644 --- a/tests/unit/executor/test_step_handler.py +++ b/tests/unit/executor/test_step_handler.py @@ -209,9 +209,10 @@ class TestStepHandlerBuiltins: assert get_mode(build_script_path) == 0o755 with open(build_script_path) as file: + import shutil assert file.read() == dedent( f"""\ - #!/bin/bash + #!{shutil.which('bash')} set -euo pipefail source {environment_script_path} set -x diff --git a/tests/unit/utils/test_process.py b/tests/unit/utils/test_process.py index 84b29ad..dc2d772 100644 --- a/tests/unit/utils/test_process.py +++ b/tests/unit/utils/test_process.py @@ -33,7 +33,8 @@ _RUN_TEST_CASES = [ @pytest.mark.parametrize(("out", "err"), _RUN_TEST_CASES) def test_run(out, err): - result = process.run(["/usr/bin/sh", "-c", f"echo {out};sleep 0;echo {err} >&2"]) + import shutil + result = process.run([shutil.which("sh"), "-c", f"echo {out};sleep 0;echo {err} >&2"]) assert result.returncode == 0 assert result.stdout == (out + "\n").encode() assert result.stderr == (err + "\n").encode() @@ -42,8 +43,9 @@ def test_run(out, err): @pytest.mark.parametrize(("out", "err"), _RUN_TEST_CASES) def test_run_devnull(out, err): + import shutil result = process.run( - ["/usr/bin/sh", "-c", f"echo {out};echo {err} >&2"], + [shutil.which("sh"), "-c", f"echo {out};echo {err} >&2"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ) @@ -78,9 +80,10 @@ def test_run_selector(out, err, new_dir): selector.register(sock, selectors.EVENT_READ, accept) + import shutil result = process.run( [ - "/usr/bin/sh", + shutil.which("sh"), "-c", f"echo {out};sleep 0;echo {err} >&2; echo -n {out}|socat - UNIX-CONNECT:{new_dir}/test.socket", ], pkgs/development/python-modules/craft-parts/default.nix +12 −2 Original line number Diff line number Diff line Loading @@ -18,13 +18,17 @@ jsonschema, git, squashfsTools, socat, setuptools-scm, stdenv, ant, maven, jdk, }: buildPythonPackage rec { pname = "craft-parts"; version = "2.2.2"; version = "2.6.0"; pyproject = true; Loading @@ -32,7 +36,7 @@ buildPythonPackage rec { owner = "canonical"; repo = "craft-parts"; tag = version; hash = "sha256-6ufcay1C2Qv3nnG0augnPWzwBVDMj1ypRwzHRAhHARA="; hash = "sha256-SybDzprUrKeL+Jl7Gm4XYLlvmy056D1OtJB7v/W2flY="; }; patches = [ ./bash-path.patch ]; Loading @@ -57,14 +61,18 @@ buildPythonPackage rec { pythonImportsCheck = [ "craft_parts" ]; nativeCheckInputs = [ ant git hypothesis jdk jsonschema maven pytest-check pytest-mock pytest-subprocess pytestCheckHook requests-mock socat squashfsTools ]; Loading @@ -80,6 +88,8 @@ buildPythonPackage rec { "test_run_prime" "test_get_build_packages_with_source_type" "test_get_build_packages" # Relies upon certain paths being present that don't make sense on Nix. "test_java_plugin_jre_not_17" ]; disabledTestPaths = Loading Loading
pkgs/development/python-modules/craft-parts/bash-path.patch +74 −16 Original line number Diff line number Diff line diff --git a/craft_parts/executor/step_handler.py b/craft_parts/executor/step_handler.py index 404df69..f90e2ac 100644 index 5eab915..bc26252 100644 --- a/craft_parts/executor/step_handler.py +++ b/craft_parts/executor/step_handler.py @@ -243,8 +243,9 @@ class StepHandler: print(script, file=script_file) script_file.flush() script_file.seek(0) + import shutil process = subprocess.Popen( # pylint: disable=consider-using-with - ["/bin/bash"], + [shutil.which("bash")], stdin=script_file, cwd=work_dir, stdout=self._stdout, @@ -394,7 +395,8 @@ def _create_and_run_script( @@ -445,7 +445,8 @@ def _create_and_run_script( ) -> None: """Create a script with step-specific commands and execute it.""" with script_path.open("w") as run_file: Loading @@ -22,12 +11,28 @@ index 404df69..f90e2ac 100644 + print(f"#!{shutil.which('bash')}", file=run_file) print("set -euo pipefail", file=run_file) if build_environment_script_path: if environment_script_path: diff --git a/craft_parts/plugins/java_plugin.py b/craft_parts/plugins/java_plugin.py index f2b4064..cb4e9e8 100644 --- a/craft_parts/plugins/java_plugin.py +++ b/craft_parts/plugins/java_plugin.py @@ -71,9 +71,8 @@ class JavaPlugin(Plugin): return None, "" def _find_javac(self) -> list[str]: - cmd = ["find", "/usr/lib/jvm", "-path", "*/bin/javac", "-print"] - output = subprocess.check_output(cmd, text=True) - return [x for x in output.split("\n") if len(x) > 0] + import shutil + return [shutil.which("javac")] @override def get_build_environment(self) -> dict[str, str]: diff --git a/craft_parts/plugins/validator.py b/craft_parts/plugins/validator.py index b8d8f11..fce0e72 100644 index 5b4c735..8ff30c2 100644 --- a/craft_parts/plugins/validator.py +++ b/craft_parts/plugins/validator.py @@ -142,9 +142,9 @@ class PluginEnvironmentValidator: @@ -141,9 +141,9 @@ class PluginEnvironmentValidator: print(self._env, file=env_file) print(cmd, file=env_file) env_file.flush() Loading @@ -39,3 +44,56 @@ index b8d8f11..fce0e72 100644 check=True, capture_output=True, text=True, diff --git a/tests/unit/executor/test_step_handler.py b/tests/unit/executor/test_step_handler.py index 4e73c2b..b762fb8 100644 --- a/tests/unit/executor/test_step_handler.py +++ b/tests/unit/executor/test_step_handler.py @@ -209,9 +209,10 @@ class TestStepHandlerBuiltins: assert get_mode(build_script_path) == 0o755 with open(build_script_path) as file: + import shutil assert file.read() == dedent( f"""\ - #!/bin/bash + #!{shutil.which('bash')} set -euo pipefail source {environment_script_path} set -x diff --git a/tests/unit/utils/test_process.py b/tests/unit/utils/test_process.py index 84b29ad..dc2d772 100644 --- a/tests/unit/utils/test_process.py +++ b/tests/unit/utils/test_process.py @@ -33,7 +33,8 @@ _RUN_TEST_CASES = [ @pytest.mark.parametrize(("out", "err"), _RUN_TEST_CASES) def test_run(out, err): - result = process.run(["/usr/bin/sh", "-c", f"echo {out};sleep 0;echo {err} >&2"]) + import shutil + result = process.run([shutil.which("sh"), "-c", f"echo {out};sleep 0;echo {err} >&2"]) assert result.returncode == 0 assert result.stdout == (out + "\n").encode() assert result.stderr == (err + "\n").encode() @@ -42,8 +43,9 @@ def test_run(out, err): @pytest.mark.parametrize(("out", "err"), _RUN_TEST_CASES) def test_run_devnull(out, err): + import shutil result = process.run( - ["/usr/bin/sh", "-c", f"echo {out};echo {err} >&2"], + [shutil.which("sh"), "-c", f"echo {out};echo {err} >&2"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ) @@ -78,9 +80,10 @@ def test_run_selector(out, err, new_dir): selector.register(sock, selectors.EVENT_READ, accept) + import shutil result = process.run( [ - "/usr/bin/sh", + shutil.which("sh"), "-c", f"echo {out};sleep 0;echo {err} >&2; echo -n {out}|socat - UNIX-CONNECT:{new_dir}/test.socket", ],
pkgs/development/python-modules/craft-parts/default.nix +12 −2 Original line number Diff line number Diff line Loading @@ -18,13 +18,17 @@ jsonschema, git, squashfsTools, socat, setuptools-scm, stdenv, ant, maven, jdk, }: buildPythonPackage rec { pname = "craft-parts"; version = "2.2.2"; version = "2.6.0"; pyproject = true; Loading @@ -32,7 +36,7 @@ buildPythonPackage rec { owner = "canonical"; repo = "craft-parts"; tag = version; hash = "sha256-6ufcay1C2Qv3nnG0augnPWzwBVDMj1ypRwzHRAhHARA="; hash = "sha256-SybDzprUrKeL+Jl7Gm4XYLlvmy056D1OtJB7v/W2flY="; }; patches = [ ./bash-path.patch ]; Loading @@ -57,14 +61,18 @@ buildPythonPackage rec { pythonImportsCheck = [ "craft_parts" ]; nativeCheckInputs = [ ant git hypothesis jdk jsonschema maven pytest-check pytest-mock pytest-subprocess pytestCheckHook requests-mock socat squashfsTools ]; Loading @@ -80,6 +88,8 @@ buildPythonPackage rec { "test_run_prime" "test_get_build_packages_with_source_type" "test_get_build_packages" # Relies upon certain paths being present that don't make sense on Nix. "test_java_plugin_jre_not_17" ]; disabledTestPaths = Loading