def test_track_deps(cli, datafiles, deps, expected_states): project = str(datafiles) generate_project(project, {"aliases": { "project-root": "file:///" + project }}) target = "bananas.bst" build_dep = "apples.bst" runtime_dep = "oranges.bst" # Assert that none of the sources have a reference states = cli.get_element_states(project, [target, build_dep, runtime_dep]) assert all([state == "no reference" for state in states.values()]) # Now track the specified sources result = cli.run(project=project, args=["source", "track", "--deps", deps, target]) result.assert_success() # Finally assert that we have tracked _only_ the desired sources states = cli.get_element_states(project, [target, build_dep, runtime_dep]) states_flattened = (states[target], states[build_dep], states[runtime_dep]) assert states_flattened == expected_states
def test_stage_explicit_basedir(cli, tmpdir, datafiles, srcdir): project = str(datafiles) generate_project(project, config={"aliases": {"tmpdir": "file:///" + str(tmpdir)}}) checkoutdir = os.path.join(str(tmpdir), "checkout") # Create a local tar src_tar = os.path.join(str(tmpdir), "a.tar.gz") _assemble_tar(os.path.join(str(datafiles), "content"), srcdir, src_tar) # Track, fetch, build, checkout result = cli.run(project=project, args=["source", "track", "target.bst"]) result.assert_success() result = cli.run(project=project, args=["source", "fetch", "target.bst"]) result.assert_success() result = cli.run(project=project, args=["build", "target.bst"]) result.assert_success() result = cli.run(project=project, args=["artifact", "checkout", "target.bst", "--directory", checkoutdir]) result.assert_success() # Check that the content of the first directory is checked out (base-dir: '*') original_dir = os.path.join(str(datafiles), "content", "a") original_contents = list_dir_contents(original_dir) checkout_contents = list_dir_contents(checkoutdir) assert checkout_contents == original_contents
def test_simple_file_build(cli, tmpdir, datafiles): project = str(datafiles) generate_project(project, {"aliases": { "tmpdir": "file:///" + str(tmpdir) }}) checkoutdir = os.path.join(str(tmpdir), "checkout") # Try to fetch it result = cli.run(project=project, args=["source", "fetch", "target.bst"]) result.assert_success() result = cli.run(project=project, args=["build", "target.bst"]) result.assert_success() result = cli.run(project=project, args=[ "artifact", "checkout", "target.bst", "--directory", checkoutdir ]) result.assert_success() # Note that the url of the file in target.bst is actually /dir/file # but this tests confirms we take the basename checkout_file = os.path.join(checkoutdir, "file") assert os.path.exists(checkout_file) mode = os.stat(checkout_file).st_mode # Assert not executable by anyone assert not mode & (stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH) # Assert not writeable by anyone other than me (unless umask allows it) if utils.get_umask() & stat.S_IWGRP: assert not mode & stat.S_IWGRP if utils.get_umask() & stat.S_IWOTH: assert not mode & stat.S_IWOTH
def test_executable(cli, tmpdir, datafiles): """This test confirms that the 'ecxecutable' parameter is honoured. """ project = str(datafiles) generate_project(project, {"aliases": { "tmpdir": "file:///" + str(tmpdir) }}) checkoutdir = os.path.join(str(tmpdir), "checkout") assert cli.get_element_state( project, "target-custom-executable.bst") == "fetch needed" # Try to fetch it cli.run(project=project, args=["build", "target-custom-executable.bst"]) cli.run(project=project, args=[ "artifact", "checkout", "target-custom-executable.bst", "--directory", checkoutdir ]) mode = os.stat(os.path.join(checkoutdir, "some-custom-file")).st_mode assert mode & stat.S_IEXEC # Assert executable by anyone assert mode & (stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)
def test_simple_file_custom_name_build(cli, tmpdir, datafiles): project = str(datafiles) generate_project(project, {"aliases": { "tmpdir": "file:///" + str(tmpdir) }}) checkoutdir = os.path.join(str(tmpdir), "checkout") # Try to fetch it result = cli.run(project=project, args=["source", "fetch", "target.bst"]) result.assert_success() result = cli.run(project=project, args=["build", "target.bst"]) result.assert_success() result = cli.run(project=project, args=[ "artifact", "checkout", "target.bst", "--directory", checkoutdir ]) result.assert_success() assert not os.path.exists(os.path.join(checkoutdir, "file")) assert os.path.exists(os.path.join(checkoutdir, "custom-file"))
def test_no_ref(cli, tmpdir, datafiles): project = str(datafiles) generate_project(project, config={"aliases": {"tmpdir": "file:///" + str(tmpdir)}}) assert cli.get_element_state(project, "target.bst") == "no reference"
def test_no_packages(cli, datafiles): project = str(datafiles) generate_project(project) result = cli.run(project=project, args=["show", "target.bst"]) result.assert_main_error(ErrorDomain.SOURCE, None)
def test_first_source(cli, datafiles): project = str(datafiles) generate_project(project) result = cli.run(project=project, args=["show", "target.bst"]) result.assert_main_error(ErrorDomain.ELEMENT, None)
def test_no_ref(cli, datafiles): project = str(datafiles) generate_project(project) assert cli.get_element_state(project, "target.bst") == "no reference"
def test_git_describe_head_is_tagged(cli, tmpdir, datafiles, ref_storage, tag_type): project = str(datafiles) project_config = load_yaml(os.path.join(project, "project.conf")) project_config["ref-storage"] = ref_storage generate_project(project, config=project_config) repofiles = os.path.join(str(tmpdir), "repofiles") os.makedirs(repofiles, exist_ok=True) file0 = os.path.join(repofiles, "file0") with open(file0, "w", encoding="utf-8") as f: f.write("test\n") repo = create_repo("git", str(tmpdir)) def tag(name): if tag_type == "annotated": repo.add_annotated_tag(name, name) else: repo.add_tag(name) repo.create(repofiles) tag("uselesstag") file1 = os.path.join(str(tmpdir), "file1") with open(file1, "w", encoding="utf-8") as f: f.write("test\n") repo.add_file(file1) file2 = os.path.join(str(tmpdir), "file2") with open(file2, "w", encoding="utf-8") as f: f.write("test\n") repo.branch("branch2") repo.add_file(file2) repo.checkout("master") file3 = os.path.join(str(tmpdir), "file3") with open(file3, "w", encoding="utf-8") as f: f.write("test\n") repo.add_file(file3) tagged_ref = repo.merge("branch2") tag("tag") config = repo.source_config() config["track"] = repo.latest_commit() config["track-tags"] = True # Write out our test target element = { "kind": "import", "sources": [config], } generate_element(project, "target.bst", element) element_path = os.path.join(project, "target.bst") if ref_storage == "inline": result = cli.run(project=project, args=["source", "track", "target.bst"]) result.assert_success() else: result = cli.run( project=project, args=["source", "track", "target.bst", "--deps", "all"]) result.assert_success() if ref_storage == "inline": element = load_yaml(element_path) source = element.get_sequence("sources").mapping_at(0) tags = source.get_sequence("tags") assert len(tags) == 1 tag = source.get_sequence("tags").mapping_at(0) assert "tag" in tag assert "commit" in tag assert "annotated" in tag assert tag.get_bool("annotated") == (tag_type == "annotated") tag_name = tag.get_str("tag") commit = tag.get_str("commit") assert (tag_name, commit) == ("tag", repo.rev_parse("tag^{commit}")) checkout = os.path.join(str(tmpdir), "checkout") result = cli.run(project=project, args=["build", "target.bst"]) result.assert_success() result = cli.run( project=project, args=["artifact", "checkout", "target.bst", "--directory", checkout]) result.assert_success() if tag_type == "annotated": options = [] else: options = ["--tags"] describe = subprocess.check_output(["git", "describe", *options], cwd=checkout, universal_newlines=True) assert describe.startswith("tag") tags = subprocess.check_output(["git", "tag"], cwd=checkout, universal_newlines=True) tags = set(tags.splitlines()) assert tags == set(["tag"]) rev_list = subprocess.check_output(["git", "rev-list", "--all"], cwd=checkout, universal_newlines=True) assert set(rev_list.splitlines()) == set([tagged_ref]) with pytest.raises(subprocess.CalledProcessError): subprocess.run( ["git", "log", repo.rev_parse("uselesstag")], cwd=checkout, check=True)
def test_overwrite_rogue_tag_multiple_remotes(cli, tmpdir, datafiles): """When using multiple remotes in cache (i.e. when using aliases), we need to make sure we override tags. This is not allowed to fetch tags that were present from different origins """ project = str(datafiles) repofiles = os.path.join(str(tmpdir), "repofiles") os.makedirs(repofiles, exist_ok=True) file0 = os.path.join(repofiles, "file0") with open(file0, "w", encoding="utf-8") as f: f.write("test\n") repo = create_repo("git", str(tmpdir)) top_commit = repo.create(repofiles) repodir, reponame = os.path.split(repo.repo) project_config = load_yaml(os.path.join(project, "project.conf")) project_config["aliases"] = Node.from_dict({"repo": "http://example.com/"}) project_config["mirrors"] = [{ "name": "middle-earth", "aliases": { "repo": ["file://{}/".format(repodir)] } }] generate_project(project, config=project_config) repo.add_annotated_tag("tag", "tag") file1 = os.path.join(repofiles, "file1") with open(file1, "w", encoding="utf-8") as f: f.write("test\n") ref = repo.add_file(file1) config = repo.source_config(ref=ref) del config["track"] config["url"] = "repo:{}".format(reponame) # Write out our test target element = { "kind": "import", "sources": [config], } generate_element(project, "target.bst", element) result = cli.run(project=project, args=["build", "target.bst"]) result.assert_success() repo.checkout(top_commit) file2 = os.path.join(repofiles, "file2") with open(file2, "w", encoding="utf-8") as f: f.write("test\n") new_ref = repo.add_file(file2) repo.delete_tag("tag") repo.add_annotated_tag("tag", "tag") repo.checkout("master") otherpath = os.path.join(str(tmpdir), "other_path") shutil.copytree(repo.repo, os.path.join(otherpath, "repo")) create_repo("git", otherpath) repodir, reponame = os.path.split(repo.repo) generate_project(project, config=project_config) config = repo.source_config(ref=new_ref) del config["track"] config["url"] = "repo:{}".format(reponame) element = { "kind": "import", "sources": [config], } generate_element(project, "target.bst", element) result = cli.run(project=project, args=["build", "target.bst"]) result.assert_success()
def test_git_describe_relevant_history(cli, tmpdir, datafiles): project = str(datafiles) project_config = load_yaml(os.path.join(project, "project.conf")) project_config["ref-storage"] = "project.refs" generate_project(project, config=project_config) repofiles = os.path.join(str(tmpdir), "repofiles") os.makedirs(repofiles, exist_ok=True) file0 = os.path.join(repofiles, "file0") with open(file0, "w", encoding="utf-8") as f: f.write("test\n") repo = create_repo("git", str(tmpdir)) repo.create(repofiles) file1 = os.path.join(str(tmpdir), "file1") with open(file1, "w", encoding="utf-8") as f: f.write("test\n") repo.add_file(file1) repo.branch("branch") repo.checkout("master") file2 = os.path.join(str(tmpdir), "file2") with open(file2, "w", encoding="utf-8") as f: f.write("test\n") repo.add_file(file2) file3 = os.path.join(str(tmpdir), "file3") with open(file3, "w", encoding="utf-8") as f: f.write("test\n") branch_boundary = repo.add_file(file3) repo.checkout("branch") file4 = os.path.join(str(tmpdir), "file4") with open(file4, "w", encoding="utf-8") as f: f.write("test\n") tagged_ref = repo.add_file(file4) repo.add_annotated_tag("tag1", "tag1") head = repo.merge("master") config = repo.source_config() config["track"] = head config["track-tags"] = True # Write out our test target element = { "kind": "import", "sources": [config], } generate_element(project, "target.bst", element) result = cli.run(project=project, args=["source", "track", "target.bst", "--deps", "all"]) result.assert_success() checkout = os.path.join(str(tmpdir), "checkout") result = cli.run(project=project, args=["build", "target.bst"]) result.assert_success() result = cli.run( project=project, args=["artifact", "checkout", "target.bst", "--directory", checkout]) result.assert_success() describe = subprocess.check_output(["git", "describe"], cwd=checkout, universal_newlines=True) assert describe.startswith("tag1-2-") rev_list = subprocess.check_output(["git", "rev-list", "--all"], cwd=checkout, universal_newlines=True) assert set(rev_list.splitlines()) == set( [head, tagged_ref, branch_boundary])