Loading java/app_import.go +30 −23 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package java // This file contains the module implementations for android_app_import and android_test_import. import ( "github.com/google/blueprint" "reflect" "github.com/google/blueprint/proptools" Loading @@ -31,6 +32,24 @@ func init() { initAndroidAppImportVariantGroupTypes() } var ( uncompressEmbeddedJniLibsRule = pctx.AndroidStaticRule("uncompress-embedded-jni-libs", blueprint.RuleParams{ Command: `if (zipinfo $in 'lib/*.so' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then ` + `${config.Zip2ZipCmd} -i $in -o $out -0 'lib/**/*.so'` + `; else cp -f $in $out; fi`, CommandDeps: []string{"${config.Zip2ZipCmd}"}, Description: "Uncompress embedded JNI libs", }) uncompressDexRule = pctx.AndroidStaticRule("uncompress-dex", blueprint.RuleParams{ Command: `if (zipinfo $in '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then ` + `${config.Zip2ZipCmd} -i $in -o $out -0 'classes*.dex'` + `; else cp -f $in $out; fi`, CommandDeps: []string{"${config.Zip2ZipCmd}"}, Description: "Uncompress dex files", }) ) func RegisterAppImportBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("android_app_import", AndroidAppImportFactory) ctx.RegisterModuleType("android_test_import", AndroidTestImportFactory) Loading Loading @@ -193,15 +212,12 @@ func (a *AndroidAppImport) uncompressEmbeddedJniLibs( }) return } rule := android.NewRuleBuilder(pctx, ctx) rule.Command(). Textf(`if (zipinfo %s 'lib/*.so' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, inputPath). BuiltTool("zip2zip"). FlagWithInput("-i ", inputPath). FlagWithOutput("-o ", outputPath). FlagWithArg("-0 ", "'lib/**/*.so'"). Textf(`; else cp -f %s %s; fi`, inputPath, outputPath) rule.Build("uncompress-embedded-jni-libs", "Uncompress embedded JIN libs") ctx.Build(pctx, android.BuildParams{ Rule: uncompressEmbeddedJniLibsRule, Input: inputPath, Output: outputPath, }) } // Returns whether this module should have the dex file stored uncompressed in the APK. Loading @@ -218,19 +234,6 @@ func (a *AndroidAppImport) shouldUncompressDex(ctx android.ModuleContext) bool { return shouldUncompressDex(ctx, &a.dexpreopter) } func (a *AndroidAppImport) uncompressDex( ctx android.ModuleContext, inputPath android.Path, outputPath android.OutputPath) { rule := android.NewRuleBuilder(pctx, ctx) rule.Command(). Textf(`if (zipinfo %s '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, inputPath). BuiltTool("zip2zip"). FlagWithInput("-i ", inputPath). FlagWithOutput("-o ", outputPath). FlagWithArg("-0 ", "'classes*.dex'"). Textf(`; else cp -f %s %s; fi`, inputPath, outputPath) rule.Build("uncompress-dex", "Uncompress dex files") } func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.generateAndroidBuildActions(ctx) } Loading Loading @@ -306,7 +309,11 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext a.dexpreopter.dexpreopt(ctx, jnisUncompressed) if a.dexpreopter.uncompressedDex { dexUncompressed := android.PathForModuleOut(ctx, "dex-uncompressed", ctx.ModuleName()+".apk") a.uncompressDex(ctx, jnisUncompressed, dexUncompressed.OutputPath) ctx.Build(pctx, android.BuildParams{ Rule: uncompressDexRule, Input: jnisUncompressed, Output: dexUncompressed, }) jnisUncompressed = dexUncompressed } Loading java/app_import_test.go +8 −19 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ package java import ( "fmt" "reflect" "regexp" "strings" "testing" Loading Loading @@ -294,7 +293,6 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) { }, } jniRuleRe := regexp.MustCompile("^if \\(zipinfo (\\S+)") for _, test := range testCases { result := android.GroupFixturePreparers( PrepareForTestWithJavaDefaultModules, Loading @@ -305,13 +303,9 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) { ).RunTestWithBp(t, bp) variant := result.ModuleForTests("foo", "android_common") jniRuleCommand := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command matches := jniRuleRe.FindStringSubmatch(jniRuleCommand) if len(matches) != 2 { t.Errorf("failed to extract the src apk path from %q", jniRuleCommand) } if strings.HasSuffix(matches[1], test.expected) { t.Errorf("wrong src apk, expected: %q got: %q", test.expected, matches[1]) input := variant.Output("jnis-uncompressed/foo.apk").Input.String() if strings.HasSuffix(input, test.expected) { t.Errorf("wrong src apk, expected: %q got: %q", test.expected, input) } provenanceMetaDataRule := variant.Rule("genProvenanceMetaData") Loading Loading @@ -456,7 +450,6 @@ func TestAndroidAppImport_ArchVariants(t *testing.T) { }, } jniRuleRe := regexp.MustCompile("^if \\(zipinfo (\\S+)") for _, test := range testCases { ctx, _ := testJava(t, test.bp) Loading @@ -469,13 +462,9 @@ func TestAndroidAppImport_ArchVariants(t *testing.T) { android.AssertDeepEquals(t, "Provenance metadata is not empty", android.TestingBuildParams{}, rule) continue } jniRuleCommand := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command matches := jniRuleRe.FindStringSubmatch(jniRuleCommand) if len(matches) != 2 { t.Errorf("failed to extract the src apk path from %q", jniRuleCommand) } if strings.HasSuffix(matches[1], test.expected) { t.Errorf("wrong src apk, expected: %q got: %q", test.expected, matches[1]) input := variant.Output("jnis-uncompressed/foo.apk").Input.String() if strings.HasSuffix(input, test.expected) { t.Errorf("wrong src apk, expected: %q got: %q", test.expected, input) } rule := variant.Rule("genProvenanceMetaData") android.AssertStringEquals(t, "Invalid input", test.artifactPath, rule.Inputs[0].String()) Loading Loading @@ -686,8 +675,8 @@ func TestAndroidTestImport_NoJinUncompressForPresigned(t *testing.T) { `) variant := ctx.ModuleForTests("foo", "android_common") jniRule := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command if !strings.HasPrefix(jniRule, "if (zipinfo") { jniRule := variant.Output("jnis-uncompressed/foo.apk").BuildParams.Rule.String() if jniRule == android.Cp.String() { t.Errorf("Unexpected JNI uncompress rule command: " + jniRule) } Loading Loading
java/app_import.go +30 −23 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package java // This file contains the module implementations for android_app_import and android_test_import. import ( "github.com/google/blueprint" "reflect" "github.com/google/blueprint/proptools" Loading @@ -31,6 +32,24 @@ func init() { initAndroidAppImportVariantGroupTypes() } var ( uncompressEmbeddedJniLibsRule = pctx.AndroidStaticRule("uncompress-embedded-jni-libs", blueprint.RuleParams{ Command: `if (zipinfo $in 'lib/*.so' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then ` + `${config.Zip2ZipCmd} -i $in -o $out -0 'lib/**/*.so'` + `; else cp -f $in $out; fi`, CommandDeps: []string{"${config.Zip2ZipCmd}"}, Description: "Uncompress embedded JNI libs", }) uncompressDexRule = pctx.AndroidStaticRule("uncompress-dex", blueprint.RuleParams{ Command: `if (zipinfo $in '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then ` + `${config.Zip2ZipCmd} -i $in -o $out -0 'classes*.dex'` + `; else cp -f $in $out; fi`, CommandDeps: []string{"${config.Zip2ZipCmd}"}, Description: "Uncompress dex files", }) ) func RegisterAppImportBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("android_app_import", AndroidAppImportFactory) ctx.RegisterModuleType("android_test_import", AndroidTestImportFactory) Loading Loading @@ -193,15 +212,12 @@ func (a *AndroidAppImport) uncompressEmbeddedJniLibs( }) return } rule := android.NewRuleBuilder(pctx, ctx) rule.Command(). Textf(`if (zipinfo %s 'lib/*.so' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, inputPath). BuiltTool("zip2zip"). FlagWithInput("-i ", inputPath). FlagWithOutput("-o ", outputPath). FlagWithArg("-0 ", "'lib/**/*.so'"). Textf(`; else cp -f %s %s; fi`, inputPath, outputPath) rule.Build("uncompress-embedded-jni-libs", "Uncompress embedded JIN libs") ctx.Build(pctx, android.BuildParams{ Rule: uncompressEmbeddedJniLibsRule, Input: inputPath, Output: outputPath, }) } // Returns whether this module should have the dex file stored uncompressed in the APK. Loading @@ -218,19 +234,6 @@ func (a *AndroidAppImport) shouldUncompressDex(ctx android.ModuleContext) bool { return shouldUncompressDex(ctx, &a.dexpreopter) } func (a *AndroidAppImport) uncompressDex( ctx android.ModuleContext, inputPath android.Path, outputPath android.OutputPath) { rule := android.NewRuleBuilder(pctx, ctx) rule.Command(). Textf(`if (zipinfo %s '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, inputPath). BuiltTool("zip2zip"). FlagWithInput("-i ", inputPath). FlagWithOutput("-o ", outputPath). FlagWithArg("-0 ", "'classes*.dex'"). Textf(`; else cp -f %s %s; fi`, inputPath, outputPath) rule.Build("uncompress-dex", "Uncompress dex files") } func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.generateAndroidBuildActions(ctx) } Loading Loading @@ -306,7 +309,11 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext a.dexpreopter.dexpreopt(ctx, jnisUncompressed) if a.dexpreopter.uncompressedDex { dexUncompressed := android.PathForModuleOut(ctx, "dex-uncompressed", ctx.ModuleName()+".apk") a.uncompressDex(ctx, jnisUncompressed, dexUncompressed.OutputPath) ctx.Build(pctx, android.BuildParams{ Rule: uncompressDexRule, Input: jnisUncompressed, Output: dexUncompressed, }) jnisUncompressed = dexUncompressed } Loading
java/app_import_test.go +8 −19 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ package java import ( "fmt" "reflect" "regexp" "strings" "testing" Loading Loading @@ -294,7 +293,6 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) { }, } jniRuleRe := regexp.MustCompile("^if \\(zipinfo (\\S+)") for _, test := range testCases { result := android.GroupFixturePreparers( PrepareForTestWithJavaDefaultModules, Loading @@ -305,13 +303,9 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) { ).RunTestWithBp(t, bp) variant := result.ModuleForTests("foo", "android_common") jniRuleCommand := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command matches := jniRuleRe.FindStringSubmatch(jniRuleCommand) if len(matches) != 2 { t.Errorf("failed to extract the src apk path from %q", jniRuleCommand) } if strings.HasSuffix(matches[1], test.expected) { t.Errorf("wrong src apk, expected: %q got: %q", test.expected, matches[1]) input := variant.Output("jnis-uncompressed/foo.apk").Input.String() if strings.HasSuffix(input, test.expected) { t.Errorf("wrong src apk, expected: %q got: %q", test.expected, input) } provenanceMetaDataRule := variant.Rule("genProvenanceMetaData") Loading Loading @@ -456,7 +450,6 @@ func TestAndroidAppImport_ArchVariants(t *testing.T) { }, } jniRuleRe := regexp.MustCompile("^if \\(zipinfo (\\S+)") for _, test := range testCases { ctx, _ := testJava(t, test.bp) Loading @@ -469,13 +462,9 @@ func TestAndroidAppImport_ArchVariants(t *testing.T) { android.AssertDeepEquals(t, "Provenance metadata is not empty", android.TestingBuildParams{}, rule) continue } jniRuleCommand := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command matches := jniRuleRe.FindStringSubmatch(jniRuleCommand) if len(matches) != 2 { t.Errorf("failed to extract the src apk path from %q", jniRuleCommand) } if strings.HasSuffix(matches[1], test.expected) { t.Errorf("wrong src apk, expected: %q got: %q", test.expected, matches[1]) input := variant.Output("jnis-uncompressed/foo.apk").Input.String() if strings.HasSuffix(input, test.expected) { t.Errorf("wrong src apk, expected: %q got: %q", test.expected, input) } rule := variant.Rule("genProvenanceMetaData") android.AssertStringEquals(t, "Invalid input", test.artifactPath, rule.Inputs[0].String()) Loading Loading @@ -686,8 +675,8 @@ func TestAndroidTestImport_NoJinUncompressForPresigned(t *testing.T) { `) variant := ctx.ModuleForTests("foo", "android_common") jniRule := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command if !strings.HasPrefix(jniRule, "if (zipinfo") { jniRule := variant.Output("jnis-uncompressed/foo.apk").BuildParams.Rule.String() if jniRule == android.Cp.String() { t.Errorf("Unexpected JNI uncompress rule command: " + jniRule) } Loading