diff --git a/changelog.d/+variant-other-command.bugfix.md b/changelog.d/+variant-other-command.bugfix.md new file mode 100644 index 0000000..df80d55 --- /dev/null +++ b/changelog.d/+variant-other-command.bugfix.md @@ -0,0 +1 @@ +`--variant` now works only with a recipe build or `submit`. Other commands refuse it instead of running as if it were absent. diff --git a/docs/orgmode/reference/cli.org b/docs/orgmode/reference/cli.org index aa5e222..8ccedb2 100644 --- a/docs/orgmode/reference/cli.org +++ b/docs/orgmode/reference/cli.org @@ -295,6 +295,7 @@ The flags reach the C, C++ and Fortran compilers through EasyBuild's toolchain; An easyconfig with the =SYSTEM= toolchain keeps its options and gets only the suffix. Dependencies build as usual. =--explain= shows the variant as =EB_LOCAL_VARIANT= and =EB_LOCAL_VARIANT_BLOCK=, the lines appended. +With another command, including =eb=, =env=, =config=, =profiles= and =dev=, it is refused: those would otherwise run as if it were not there, and =eb= would install the optimised module. =submit= keeps it and puts it on the batch command. [[file:../howto/build-for-profiling.org][Build software to profile or debug]] uses both. ** eb diff --git a/docs/reference/cli.md b/docs/reference/cli.md index c3cc1a5..2549cec 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -297,6 +297,7 @@ The flags reach the C, C++ and Fortran compilers through EasyBuild's toolchain; An easyconfig with the `SYSTEM` toolchain keeps its options and gets only the suffix. Dependencies build as usual. `--explain` shows the variant as `EB_LOCAL_VARIANT` and `EB_LOCAL_VARIANT_BLOCK`, the lines appended. +With another command, including `eb`, `env`, `config`, `profiles` and `dev`, it is refused: those would otherwise run as if it were not there, and `eb` would install the optimised module. `submit` keeps it and puts it on the batch command. [Build software to profile or debug](../howto/build-for-profiling.md) uses both. ### eb diff --git a/src/main.zig b/src/main.zig index 9185222..4957cf4 100644 --- a/src/main.zig +++ b/src/main.zig @@ -7820,6 +7820,11 @@ fn runMain(init: std.process.Init) u8 { // would run as if it were not there. if (g.explain and command != .build and command != .eb) die("--explain goes with a recipe or with eb, not with {s}", .{@tagName(command)}); + // --variant changes the easyconfig a recipe build compiles, and submit + // puts that option on the batch command. Another command would run as + // if it were not there, and eb would install the optimised module. + if (g.variant != null and command != .build and command != .submit) + die("--variant goes with a recipe or with submit, not with {s}", .{@tagName(command)}); // The cache is a pair of files. It does not read the site file. if (command == .@"lmod-cache") return lmodcache.run(init.io, a, c.env, cache); if (command == .overlay) { diff --git a/tests/test_extend_cli.py b/tests/test_extend_cli.py index 92c8df0..77fe368 100644 --- a/tests/test_extend_cli.py +++ b/tests/test_extend_cli.py @@ -196,6 +196,56 @@ def test_explain_with_a_command_it_does_not_explain_is_refused(self): self.assertIn(f"--explain goes with a recipe or with eb, not with {args[0]}", run.stderr) self.assertTrue(old.exists()) + def test_variant_before_another_command_is_refused(self): + # Parsed while the command is still a recipe build, then left set. + # eb would install the optimised module; env, config and profiles + # would succeed as if --variant were not there. + cases = ( + (["--variant", "perf", "eb", "x.eb"], "eb"), + (["--variant=debug", "eb", "x.eb"], "eb"), + (["--variant", "perf", "--explain", "eb", "x.eb"], "eb"), + (["--variant", "perf", "env"], "env"), + (["--variant", "perf", "config"], "config"), + (["--variant", "perf", "profiles"], "profiles"), + (["--variant", "perf", "dev"], "dev"), + ) + for args, command in cases: + with self.subTest(args=args): + ran = self.root / "eb-ran" + ran.unlink(missing_ok=True) + run = self.run_tool(args) + self.assertEqual(run.returncode, 2, run.stdout + run.stderr) + self.assertEqual(run.stdout, "") + self.assertIn(f"--variant goes with a recipe or with submit, not with {command}", run.stderr) + self.assertFalse(ran.exists()) + + def test_variant_stays_on_a_recipe_and_on_submit(self): + prefix = self.root / "gpu" + site = self.root / "site.toml" + site.write_text( + '[storage]\nnode_local_root = "/local"\n' + '[build.node_types]\nmilan = "--constraint=milan"\n' + f'[profile.gpu]\nprefix = "{prefix}"\n', + encoding="utf-8", + ) + site.chmod(0o600) + explained = self.run_tool( + ["--config", str(site), "--profile", "gpu", "--explain", "--variant", "perf", "pigz.eb", "--robot"], + EB_LOCAL_CONFIG=str(site), + ) + self.assertEqual(explained.returncode, 0, explained.stderr) + self.assertIn("export EB_LOCAL_VARIANT=perf\n", explained.stdout) + self.assertIn("--variant perf", explained.stdout) + submitted = self.run_tool( + ["--config", str(site), "--profile", "gpu", "--variant", "perf", "submit", "--print", "pigz.eb"], + EB_LOCAL_CONFIG=str(site), + ) + self.assertEqual(submitted.returncode, 0, submitted.stdout + submitted.stderr) + self.assertIn("--profile gpu", submitted.stdout) + self.assertIn("--variant perf", submitted.stdout) + self.assertIn("exec ", submitted.stdout) + self.assertFalse((self.root / "eb-ran").exists()) + def test_eb_accepts_trailing_slash_in_install_variable(self): mine = self.root / "mine" run = self.run_tool(