def test_notparallel_twice(cli, datafiles): project = str(datafiles) # # Explicitly configure default max-jobs using user configuration # cli.configure({"build": {"max-jobs": 2}}) # Fetch the variables and environment of both elements, where parallel.bst depends on notparallel.bst result = cli.run( project=project, args=["show", "--format", "%{vars}%{env}", "parallel.bst"]) result.assert_success() # Split on the empty line, which separates elements in bst show output groups = result.output.split("\n\n") assert len(groups) >= 2 notparallel_vars = _yaml.load_data(groups[0]) parallel_vars = _yaml.load_data(groups[1]) # Test the first group for the expected notparallel state assert notparallel_vars.get_str("element-name") == "notparallel.bst" assert notparallel_vars.get_str("max-jobs") == "1" assert notparallel_vars.get_str("MAKEFLAGS") == "-j1" # Test the second group for the expected !notparallel state assert parallel_vars.get_str("element-name") == "parallel.bst" assert parallel_vars.get_str("max-jobs") == "2" assert parallel_vars.get_str("MAKEFLAGS") == "-j2"
def test_max_jobs(cli, datafiles, cli_value, config_value): project = str(datafiles) target = "target.bst" # Specify `--max-jobs` if this test sets it args = [] if cli_value is not None: args += ["--max-jobs", cli_value] args += ["show", "--deps", "none", "--format", "%{vars}", target] # Specify `max-jobs` in user configuration if this test sets it if config_value is not None: cli.configure({"build": {"max-jobs": config_value}}) result = cli.run(project=project, silent=True, args=args) result.assert_success() loaded = _yaml.load_data(result.output) loaded_value = loaded.get_int("max-jobs") # We expect the value provided on the command line to take # precedence over the configuration file value, if specified. # # If neither are specified then we expect the default expected_value = cli_value or config_value or "0" if expected_value == "0": # If we are expecting the automatic behavior of using the maximum # number of cores available, just check that it is a value > 0 assert loaded_value > 0, "Automatic setting of max-jobs didnt work" else: # Check that we got the explicitly set value assert loaded_value == int(expected_value)
def test_option_from_deep_junction(cli, tmpdir, datafiles): project = os.path.join(str(datafiles), "junction_options_deep") junction_repo_a = os.path.join(tmpdir, "a") junction_repo_b = os.path.join(tmpdir, "b") generate_junction( junction_repo_a, os.path.join(project, "subproject-2"), os.path.join(project, "subproject-1", "junction-2.bst"), store_ref=True, options={"local_option": "set"}, ) generate_junction( junction_repo_b, os.path.join(project, "subproject-1"), os.path.join(project, "junction-1.bst"), store_ref=True, ) result = cli.run( project=project, args=["show", "--deps", "none", "--format", "%{vars}", "element.bst"]) result.assert_success() loaded = _yaml.load_data(result.output) assert not loaded.get_bool("is-default")
def test_compound_or_conditional(cli, datafiles, debug, logging, expected): project = os.path.join(datafiles.dirname, datafiles.basename, "compound-or-condition") # Test with the opt option set result = cli.run( project=project, silent=True, args=[ "--option", "debug", debug, "--option", "logging", logging, "show", "--deps", "none", "--format", "%{vars}", "element.bst", ], ) result.assert_success() loaded = _yaml.load_data(result.output) assert loaded.get_str("logging") == expected
def test_deep_references(cli, datafiles, maxvars): project = str(datafiles) # Generate an element with very, very many variables to resolve, # each which expand to the value of the previous variable. # # The bottom variable defines a test value which we check for # in the top variable in `bst show` output. # topvar = "var{}".format(maxvars) bottomvar = "var0" testvalue = "testvalue {}".format(maxvars) # Generate variables = { "var{}".format(idx + 1): "%{var" + str(idx) + "}" for idx in range(maxvars) } variables[bottomvar] = testvalue element = {"kind": "manual", "variables": variables} _yaml.roundtrip_dump(element, os.path.join(project, "test.bst")) # Run `bst show` result = cli.run(project=project, args=["show", "--format", "%{vars}", "test.bst"]) result.assert_success() # Test results result_vars = _yaml.load_data(result.output) assert result_vars.get_str(topvar) == testvalue
def test_include_project_file(cli, datafiles): project = os.path.join(str(datafiles), "file") result = cli.run( project=project, args=["show", "--deps", "none", "--format", "%{vars}", "element.bst"]) result.assert_success() loaded = _yaml.load_data(result.output) assert loaded.get_bool("included")
def test_partial_context_junctions(cli, datafiles): project = str(datafiles) result = cli.run(project=project, args=["show", "--format", "%{vars}", "test.bst"]) result.assert_success() result_vars = _yaml.load_data(result.output) assert result_vars.get_str("eltvar") == "/bar/foo/baz"
def test_override_project_path(cli, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename, "overridepath") result = cli.run(project=project, args=["show", "--format", "%{env}", "manual.bst"]) result.assert_success() # Read back the overridden path env = _yaml.load_data(result.output) assert env.get_str("PATH") == "/bin:/sbin"
def test_conditional_config(cli, datafiles, target, value, expected): project = os.path.join(datafiles.dirname, datafiles.basename, "option-element-mask") cli.configure({"projects": {"test": {"options": {"debug_elements": value}}}}) result = cli.run(project=project, silent=True, args=["show", "--deps", "none", "--format", "%{vars}", target]) result.assert_success() loaded = _yaml.load_data(result.output) assert loaded.get_str("debug") == expected
def test_include_element_overrides_sub_include(cli, datafiles): project = os.path.join(str(datafiles), "sub-include") result = cli.run( project=project, args=["show", "--deps", "none", "--format", "%{vars}", "element.bst"]) result.assert_success() loaded = _yaml.load_data(result.output) assert loaded.get_str("included", default=None) is not None
def test_load_default_project(cli, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename, "default") result = cli.run(project=project, args=["show", "--format", "%{env}", "manual.bst"]) result.assert_success() # Read back some of our project defaults from the env env = _yaml.load_data(result.output) assert env.get_str("USER") == "tomjon" assert env.get_str("TERM") == "dumb"
def test_overrides(cli, datafiles, target, varname, expected): project = str(datafiles) result = cli.run( project=project, silent=True, args=["show", "--deps", "none", "--format", "%{vars}", target]) result.assert_success() result_vars = _yaml.load_data(result.output) assert result_vars.get_str(varname) == expected
def test_include_full_path(cli, tmpdir, datafiles): project = os.path.join(str(datafiles), "full_path") result = cli.run( project=project, args=["show", "--deps", "none", "--format", "%{vars}", "element.bst"]) result.assert_success() loaded = _yaml.load_data(result.output) assert loaded.get_str("bar") == "red" assert loaded.get_str("foo") == "blue"
def test_cross_link_junction_include(cli, tmpdir, datafiles): project = os.path.join(str(datafiles), "cross-link-junction-include") # Show the variables and parse our test variable from the subsubproject result = cli.run(project=project, args=["show", "--format", "%{vars}", "target.bst"]) result.assert_success() # Read back some of our project defaults from the env variables = _yaml.load_data(result.output) assert variables.get_str("test") == "the test"
def test_variables_are_resolved_in_public_section(cli, datafiles): project = str(datafiles) result = cli.run(project=project, args=["show", "--format", "%{public}", "public.bst"]) result.assert_success() output = _yaml.load_data(result.output).strip_node_info() expected = {"integration-commands": ["echo expanded"], "test": "expanded"} assert {k: v for k, v in output.items() if k in expected} == expected
def test_prepend_configure_commands(cli, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename, "prepend-configure-commands") result = cli.run( project=project, silent=True, args=["show", "--deps", "none", "--format", "%{config}", "element.bst"] ) result.assert_success() loaded = _yaml.load_data(result.output) config_commands = loaded.get_str_list("configure-commands") assert len(config_commands) == 3 assert config_commands[0] == 'echo "Hello World!"'
def test_conditional_cli(cli, datafiles, target, option, expected): project = os.path.join(datafiles.dirname, datafiles.basename, "option-bool") result = cli.run( project=project, silent=True, args=["--option", "pony", option, "show", "--deps", "none", "--format", "%{vars}", target], ) result.assert_success() loaded = _yaml.load_data(result.output) assert loaded.get_str("thepony") == expected
def test_include_element_overrides_composition(cli, datafiles): project = os.path.join(str(datafiles), "overrides") result = cli.run(project=project, args=[ "show", "--deps", "none", "--format", "%{config}", "element.bst" ]) result.assert_success() loaded = _yaml.load_data(result.output) assert loaded.get_str_list("build-commands") == ["first", "second"]
def run_project_config(self, *, project_config=None, **kwargs): # First load the project.conf and substitute {project_dir} # # Save the original project.conf, because we will run more than # once in the same temp directory # project_directory = kwargs["project"] project_filename = os.path.join(project_directory, "project.conf") project_backup = os.path.join(project_directory, "project.conf.backup") project_load_filename = project_filename if not os.path.exists(project_backup): shutil.copy(project_filename, project_backup) else: project_load_filename = project_backup with open(project_load_filename) as f: config = f.read() config = config.format(project_dir=project_directory) if project_config is not None: # If a custom project configuration dictionary was # specified, composite it on top of the already # substituted base project configuration # base_config = _yaml.load_data(config) # In order to leverage _yaml.composite_dict(), both # dictionaries need to be loaded via _yaml.load_data() first # with tempfile.TemporaryDirectory( dir=project_directory) as scratchdir: temp_project = os.path.join(scratchdir, "project.conf") with open(temp_project, "w") as f: yaml.safe_dump(project_config, f) project_config = _yaml.load(temp_project, shortname="project.conf") project_config._composite(base_config) _yaml.roundtrip_dump(base_config, project_filename) else: # Otherwise, just dump it as is with open(project_filename, "w") as f: f.write(config) return super().run(**kwargs)
def test_notparallel(cli, datafiles): project = str(datafiles) # Test the vars result = cli.run( project=project, args=["show", "--format", "%{vars}%{env}", "notparallel.bst"]) result.assert_success() result_vars = _yaml.load_data(result.output) assert result_vars.get_str("element-name") == "notparallel.bst" assert result_vars.get_str("max-jobs") == "1" assert result_vars.get_str("MAKEFLAGS") == "-j1"
def test_inner(cli, datafiles): project = os.path.join(str(datafiles), "inner") result = cli.run( project=project, args=[ "-o", "build_arch", "x86_64", "show", "--deps", "none", "--format", "%{vars}", "element.bst" ], ) result.assert_success() loaded = _yaml.load_data(result.output) assert loaded.get_str("build_arch") == "x86_64"
def test_override(cli, datafiles, arch): project = os.path.join(datafiles.dirname, datafiles.basename, "option-overrides") bst_args = ["--option", "arch", arch] bst_args += ["show", "--deps", "none", "--format", "%{vars}", "element.bst"] result = cli.run(project=project, silent=True, args=bst_args) result.assert_success() # See the associated project.conf for the expected values expected_value = "--host={}-unknown-linux-gnu".format(arch) loaded = _yaml.load_data(result.output) assert loaded.get_str("conf-global") == expected_value
def test_conditionals(cli, datafiles, system, value, expected): with override_platform_uname(system=system): project = os.path.join(datafiles.dirname, datafiles.basename, "option-os") bst_args = [] if value is not None: bst_args += ["--option", "machine_os", value] bst_args += ["show", "--deps", "none", "--format", "%{vars}", "element.bst"] result = cli.run(project=project, silent=True, args=bst_args) result.assert_success() loaded = _yaml.load_data(result.output) assert loaded.get_str("result") == expected
def test_preserve_conditionals(cli, datafiles, project_dir): project = os.path.join(str(datafiles), project_dir) result = cli.run( project=project, args=[ "-o", "build_arch", "i586", "show", "--deps", "none", "--format", "%{vars}", "element.bst" ], ) result.assert_success() loaded = _yaml.load_data(result.output) assert loaded.get_str("enable-work-around") == "true" assert loaded.get_str("size") == "4"
def test_include_junction_file(cli, tmpdir, datafiles): project = os.path.join(str(datafiles), "junction") generate_junction(tmpdir, os.path.join(project, "subproject"), os.path.join(project, "junction.bst"), store_ref=True) result = cli.run( project=project, args=["show", "--deps", "none", "--format", "%{vars}", "element.bst"]) result.assert_success() loaded = _yaml.load_data(result.output) assert loaded.get_bool("included")
def test_list_overide_does_not_fail_upon_first_composition(cli, datafiles): project = os.path.join(str(datafiles), "eventual_overrides") result = cli.run(project=project, args=[ "show", "--deps", "none", "--format", "%{public}", "element.bst" ]) result.assert_success() loaded = _yaml.load_data(result.output) # Assert that the explicitly overwritten public data is present bst = loaded.get_mapping("bst") assert "foo-commands" in bst assert bst.get_str_list("foo-commands") == ["need", "this"]
def test_junction_do_not_use_included_overrides(cli, tmpdir, datafiles): project = os.path.join(str(datafiles), "overrides-junction") generate_junction(tmpdir, os.path.join(project, "subproject"), os.path.join(project, "junction.bst"), store_ref=True) result = cli.run( project=project, args=["show", "--deps", "none", "--format", "%{vars}", "junction.bst"]) result.assert_success() loaded = _yaml.load_data(result.output) assert loaded.get_str("main_override", default=None) is not None assert loaded.get_str("included_override", default=None) is None
def test_export(cli, datafiles, option_name, option_value, var_name, var_value): project = os.path.join(datafiles.dirname, datafiles.basename, "option-exports") result = cli.run( project=project, silent=True, args=[ "--option", option_name, option_value, "show", "--deps", "none", "--format", "%{vars}", "element.bst" ], ) result.assert_success() loaded = _yaml.load_data(result.output) assert loaded.get_str(var_name) == var_value
def test_list_cross_junction(cli, tmpdir): project, _ = open_cross_junction(cli, tmpdir) element = "sub.bst:data.bst" args = ["workspace", "list"] result = cli.run(project=project, args=args) result.assert_success() loaded = _yaml.load_data(result.output) workspaces = loaded.get_sequence("workspaces") assert len(workspaces) == 1 first_workspace = workspaces.mapping_at(0) assert "element" in first_workspace assert first_workspace.get_str("element") == element
def test_close_all_cross_junction(cli, tmpdir): project, workspace = open_cross_junction(cli, tmpdir) args = ["workspace", "close", "--remove-dir", "--all"] result = cli.run(project=project, args=args) result.assert_success() assert not os.path.exists(str(workspace)) args = ["workspace", "list"] result = cli.run(project=project, args=args) result.assert_success() loaded = _yaml.load_data(result.output) workspaces = loaded.get_sequence("workspaces") assert not workspaces