Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/ci/build_original_vold.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,21 @@ def verify_checkout(
path = source / relpath
if path.is_symlink() or not path.is_dir() or not path.resolve().is_relative_to(source):
raise BuildError(f"source project is missing or unsafe: {relpath}")
top = command(
["git", "rev-parse", "--show-toplevel"], path, capture_output=True, text=True,
).stdout.strip()
if Path(top).resolve() != path.resolve():
raise BuildError(f"source project is not its own Git worktree: {relpath}")
head = command(["git", "rev-parse", "HEAD"], path, capture_output=True, text=True).stdout.strip()
if head != revision:
raise BuildError(f"source revision changed: {relpath}")
# Ordinary status hides tracked modifications under these flags.
# Source provenance must cover the bytes the compiler will read.
tracked = command(
["git", "ls-files", "-v", "-z"], path, capture_output=True, text=True,
).stdout.split("\0")
if any(entry and (entry[0].islower() or entry[0] == "S") for entry in tracked):
raise BuildError(f"source project has assume-unchanged or skip-worktree entries: {relpath}")
dirt = command(
["git", "status", "--porcelain", "--untracked-files=all", "--ignored"],
path, capture_output=True, text=True,
Expand Down
30 changes: 30 additions & 0 deletions tests/vold_original_build_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,36 @@ def test_legacy_manifest_link_must_target_the_pinned_checkout_file(self):
with self.assertRaisesRegex(builder.BuildError, "link does not select"):
builder.verify_active_manifest(source, self.manifest)

def test_hidden_worktree_edits_cannot_pass_source_cleanliness_gate(self):
for flag in ("--assume-unchanged", "--skip-worktree"):
with self.subTest(flag=flag), tempfile.TemporaryDirectory() as tmp:
source = Path(tmp)
project = source / "system/vold"
project.mkdir(parents=True)
subprocess.run(["git", "init", "--quiet", str(project)], check=True)
tracked = project / "Utils.h"
tracked.write_text("reviewed source\n")
subprocess.run(["git", "add", "Utils.h"], cwd=project, check=True)
subprocess.run([
"git", "-c", "user.name=Fixture", "-c", "user.email=fixture@example.invalid",
"commit", "--quiet", "-m", "pinned source",
], cwd=project, check=True)
revision = subprocess.run([
"git", "rev-parse", "HEAD",
], cwd=project, check=True, capture_output=True, text=True).stdout.strip()
manifest = f'<manifest><project name="system/vold" revision="{revision}" /></manifest>'.encode()
self.selected_manifest(source, manifest)
with patch.object(builder.shutil, "which", return_value="/trusted/repo"):
builder.verify_checkout(source, manifest, clean=True, selected=["system/vold"])
subprocess.run(["git", "update-index", flag, "Utils.h"], cwd=project, check=True)
tracked.write_text("unreviewed hidden source\n")
status = subprocess.run([
"git", "status", "--porcelain", "--untracked-files=all", "--ignored",
], cwd=project, check=True, capture_output=True, text=True).stdout
self.assertEqual(status, "", "fixture must reproduce hidden edits")
with self.assertRaisesRegex(builder.BuildError, "assume-unchanged or skip-worktree"):
builder.verify_checkout(source, manifest, clean=True, selected=["system/vold"])

def test_omitted_manifest_path_checks_real_git_revision_and_local_content(self):
with tempfile.TemporaryDirectory() as tmp:
source = Path(tmp)
Expand Down
12 changes: 11 additions & 1 deletion tests/vold_source_closure_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,17 @@ def test_selections_are_checked_against_unchanged_manifest(self):
revisions = original.project_map(raw)

def mocked_command(argv, cwd, **kwargs):
result = revisions[cwd.relative_to(source).as_posix()][1] if argv[1] == "rev-parse" else ""
self.assertEqual(argv[0], "git")
if argv[1:] == ["rev-parse", "--show-toplevel"]:
result = str(cwd)
elif argv[1:] == ["rev-parse", "HEAD"]:
result = revisions[cwd.relative_to(source).as_posix()][1]
elif argv[1:] == ["ls-files", "-v", "-z"]:
result = "H Android.bp\0"
elif argv[1:] == ["status", "--porcelain", "--untracked-files=all", "--ignored"]:
result = ""
else:
self.fail(f"unexpected source verification command: {argv}")
return type("Result", (), {"stdout": result})()

for project in first:
Expand Down
Loading