예제 #1
0
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"
예제 #2
0
파일: show.py 프로젝트: wjt/buildstream
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)
예제 #3
0
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")
예제 #4
0
파일: options.py 프로젝트: wjt/buildstream
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
예제 #5
0
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
예제 #6
0
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")
예제 #7
0
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"
예제 #8
0
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"
예제 #9
0
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
예제 #10
0
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
예제 #11
0
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"
예제 #12
0
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
예제 #13
0
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"
예제 #14
0
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"
예제 #15
0
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
예제 #16
0
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!"'
예제 #17
0
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
예제 #18
0
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"]
예제 #19
0
    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)
예제 #20
0
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"
예제 #21
0
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"
예제 #22
0
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
예제 #23
0
파일: optionos.py 프로젝트: wjt/buildstream
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
예제 #24
0
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"
예제 #25
0
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")
예제 #26
0
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"]
예제 #27
0
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
예제 #28
0
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
예제 #29
0
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
예제 #30
0
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