summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
author LaMont Jones <lamontjones@google.com> 2024-11-14 14:37:02 -0800
committer LaMont Jones <lamontjones@google.com> 2024-11-14 16:44:01 -0800
commit5685300333fa8a1c6626e66907454ce507191977 (patch)
tree3902dd1177cce61e064daea82e73402fb19dfbd9 /cmd
parentc26262eb5e881ffdb822cc3c6cabe7f666d899db (diff)
find_input_delta: allow inspection of sharded jars
Bug: b/376287012 Test: TH, unit tests Change-Id: I4b8a6cbb6df24efa327433e4b42f23b5e10ea59a
Diffstat (limited to 'cmd')
-rw-r--r--cmd/find_input_delta/find_input_delta_lib/internal_state.go11
-rw-r--r--cmd/find_input_delta/find_input_delta_lib/internal_state_test.go22
2 files changed, 28 insertions, 5 deletions
diff --git a/cmd/find_input_delta/find_input_delta_lib/internal_state.go b/cmd/find_input_delta/find_input_delta_lib/internal_state.go
index f0242b724..2b8c39527 100644
--- a/cmd/find_input_delta/find_input_delta_lib/internal_state.go
+++ b/cmd/find_input_delta/find_input_delta_lib/internal_state.go
@@ -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) {
diff --git a/cmd/find_input_delta/find_input_delta_lib/internal_state_test.go b/cmd/find_input_delta/find_input_delta_lib/internal_state_test.go
index e69424c54..c168d5a6b 100644
--- a/cmd/find_input_delta/find_input_delta_lib/internal_state_test.go
+++ b/cmd/find_input_delta/find_input_delta_lib/internal_state_test.go
@@ -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)
+ }
+ }
+}