Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2acff670 authored by LaMont Jones's avatar LaMont Jones Committed by Gerrit Code Review
Browse files

Merge "find_input_delta: allow inspection of sharded jars" into main

parents 8729b733 56853003
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ import (
	"errors"
	"fmt"
	"io/fs"
	"path/filepath"
	"regexp"
	"slices"

	fid_proto "android/soong/cmd/find_input_delta/find_input_delta_proto_internal"
@@ -73,15 +73,16 @@ func CreateState(inputs []string, inspect_contents bool, fsys StatReadFileFS) (*
	return ret, nil
}

// We ignore any suffix digit caused by sharding.
var InspectExtsZipRegexp = regexp.MustCompile("\\.(jar|apex|apk)[0-9]*$")

// Inspect the file and extract the state of the elements in the archive.
// If this is not an archive of some sort, nil is returned.
func InspectFileContents(name string) ([]*fid_proto.PartialCompileInput, error) {
	switch filepath.Ext(name) {
	case ".jar", ".apex", ".apk":
	if InspectExtsZipRegexp.Match([]byte(name)) {
		return inspectZipFileContents(name)
	default:
		return nil, nil
	}
	return nil, nil
}

func inspectZipFileContents(name string) ([]*fid_proto.PartialCompileInput, error) {
+22 −0
Original line number Diff line number Diff line
@@ -259,3 +259,25 @@ func TestCompareInternalState(t *testing.T) {
		}
	}
}

func TestCompareInspectExtsZipRegexp(t *testing.T) {
	testCases := []struct {
		Name     string
		Expected bool
	}{
		{Name: ".jar", Expected: true},
		{Name: ".jar5", Expected: true},
		{Name: ".apex", Expected: true},
		{Name: ".apex9", Expected: true},
		{Name: ".apexx", Expected: false},
		{Name: ".apk", Expected: true},
		{Name: ".apk3", Expected: true},
		{Name: ".go", Expected: false},
	}
	for _, tc := range testCases {
		actual := InspectExtsZipRegexp.Match([]byte(tc.Name))
		if tc.Expected != actual {
			t.Errorf("%s: expected %v, actual %v", tc.Name, tc.Expected, actual)
		}
	}
}