Fix non-deterministic output for merge_zips

A map iteration was causing a non-deterministic order
in output entries. The default behaviour is to preserve
the same order of the input zips, which is necessary
to ensure a deterministic output for deterministic inputs.

Bug: b/322788229
Test: Ran a couple of builds and confirmed no cache misses from
the output of merge_zips.

Change-Id: I3217e6887ab108d213a290b59da5b33d51b8241f
This commit is contained in:
Anas Sulaiman
2024-02-09 21:06:49 +00:00
parent b129b7cba2
commit 437e9470c0
2 changed files with 36 additions and 5 deletions

View File

@@ -342,7 +342,8 @@ func (oz *OutputZip) writeEntries(entries []string) error {
func (oz *OutputZip) getUninitializedPythonPackages(inputZips []InputZip) ([]string, error) {
// the runfiles packages needs to be populated with "__init__.py".
// the runfiles dirs have been treated as packages.
allPackages := make(map[string]bool)
var allPackages []string // Using a slice to preserve input order.
seenPkgs := make(map[string]bool)
initedPackages := make(map[string]bool)
getPackage := func(path string) string {
ret := filepath.Dir(path)
@@ -369,16 +370,17 @@ func (oz *OutputZip) getUninitializedPythonPackages(inputZips []InputZip) ([]str
initedPackages[pyPkg] = true
}
for pyPkg != "" {
if _, found := allPackages[pyPkg]; found {
if _, found := seenPkgs[pyPkg]; found {
break
}
allPackages[pyPkg] = true
seenPkgs[pyPkg] = true
allPackages = append(allPackages, pyPkg)
pyPkg = getPackage(pyPkg)
}
}
}
noInitPackages := make([]string, 0)
for pyPkg := range allPackages {
for _, pyPkg := range allPackages {
if _, found := initedPackages[pyPkg]; !found {
noInitPackages = append(noInitPackages, pyPkg)
}