Support multiple filters in zipsync

Also applied this feature to kotlinc since it needs both java and kt files.

Test: local test and presubmits

Bug: 287071909
Change-Id: I28c725b03115aef47055448cb75412980015da15
This commit is contained in:
Zi Wang 2023-06-13 10:40:52 -07:00
parent 722a2b50c6
commit 6a66e3d01e
2 changed files with 35 additions and 4 deletions

View file

@ -29,10 +29,14 @@ import (
var (
outputDir = flag.String("d", "", "output dir")
outputFile = flag.String("l", "", "output list file")
filter = flag.String("f", "", "optional filter pattern")
zipPrefix = flag.String("zip-prefix", "", "optional prefix within the zip file to extract, stripping the prefix")
filter multiFlag
)
func init() {
flag.Var(&filter, "f", "optional filter pattern")
}
func must(err error) {
if err != nil {
log.Fatal(err)
@ -107,13 +111,15 @@ func main() {
}
name = strings.TrimPrefix(name, *zipPrefix)
}
if *filter != "" {
if match, err := filepath.Match(*filter, filepath.Base(name)); err != nil {
if filter != nil {
if match, err := filter.Match(filepath.Base(name)); err != nil {
log.Fatal(err)
} else if !match {
continue
}
}
if filepath.IsAbs(name) {
log.Fatalf("%q in %q is an absolute path", name, input)
}
@ -151,3 +157,28 @@ func main() {
must(ioutil.WriteFile(*outputFile, []byte(data), 0666))
}
}
type multiFlag []string
func (m *multiFlag) String() string {
return strings.Join(*m, " ")
}
func (m *multiFlag) Set(s string) error {
*m = append(*m, s)
return nil
}
func (m *multiFlag) Match(s string) (bool, error) {
if m == nil {
return false, nil
}
for _, f := range *m {
if match, err := filepath.Match(f, s); err != nil {
return false, err
} else if match {
return true, nil
}
}
return false, nil
}

View file

@ -30,7 +30,7 @@ var kotlinc = pctx.AndroidRemoteStaticRule("kotlinc", android.RemoteRuleSupports
blueprint.RuleParams{
Command: `rm -rf "$classesDir" "$headerClassesDir" "$srcJarDir" "$kotlinBuildFile" "$emptyDir" && ` +
`mkdir -p "$classesDir" "$headerClassesDir" "$srcJarDir" "$emptyDir" && ` +
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" -f "*.kt" $srcJars && ` +
`${config.GenKotlinBuildFileCmd} --classpath "$classpath" --name "$name"` +
` --out_dir "$classesDir" --srcs "$out.rsp" --srcs "$srcJarDir/list"` +
` $commonSrcFilesArg --out "$kotlinBuildFile" && ` +