Loading apex/apex.go +3 −18 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package apex import ( "fmt" "path" "path/filepath" "sort" "strings" Loading Loading @@ -1242,7 +1241,7 @@ type apexBundle struct { container_certificate_file android.Path container_private_key_file android.Path fileContexts android.Path fileContexts android.WritablePath // list of files to be included in this apex filesInfo []apexFile Loading Loading @@ -2195,22 +2194,6 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.installDir = android.PathForModuleInstall(ctx, "apex") a.filesInfo = filesInfo if a.properties.ApexType != zipApex { if a.properties.File_contexts == nil { a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts") } else { a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts) if a.Platform() { if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched { ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts) } } } if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() { ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts) return } } // Optimization. If we are building bundled APEX, for the files that are gathered due to the // transitive dependencies, don't place them inside the APEX, but place a symlink pointing // the same library in the system partition, thus effectively sharing the same libraries Loading @@ -2234,6 +2217,8 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { // prepare apex_manifest.json a.buildManifest(ctx, provideNativeLibs, requireNativeLibs) a.buildFileContexts(ctx) a.setCertificateAndPrivateKey(ctx) if a.properties.ApexType == flattenedApex { a.buildFlattenedApex(ctx) Loading apex/apex_test.go +73 −79 Original line number Diff line number Diff line Loading @@ -3480,7 +3480,7 @@ func TestApexInVariousPartition(t *testing.T) { } } func TestFileContexts(t *testing.T) { func TestFileContexts_FindInDefaultLocationIfNotSet(t *testing.T) { ctx, _ := testApex(t, ` apex { name: "myapex", Loading @@ -3494,13 +3494,11 @@ func TestFileContexts(t *testing.T) { } `) module := ctx.ModuleForTests("myapex", "android_common_myapex_image") apexRule := module.Rule("apexRule") actual := apexRule.Args["file_contexts"] expected := "system/sepolicy/apex/myapex-file_contexts" if actual != expected { t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) rule := module.Output("file_contexts") ensureContains(t, rule.RuleParams.Command, "cat system/sepolicy/apex/myapex-file_contexts") } func TestFileContexts_ShouldBeUnderSystemSepolicyForSystemApexes(t *testing.T) { testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` apex { name: "myapex", Loading @@ -3516,7 +3514,9 @@ func TestFileContexts(t *testing.T) { `, withFiles(map[string][]byte{ "my_own_file_contexts": nil, })) } func TestFileContexts_ProductSpecificApexes(t *testing.T) { testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` apex { name: "myapex", Loading @@ -3532,7 +3532,7 @@ func TestFileContexts(t *testing.T) { } `) ctx, _ = testApex(t, ` ctx, _ := testApex(t, ` apex { name: "myapex", key: "myapex.key", Loading @@ -3548,15 +3548,13 @@ func TestFileContexts(t *testing.T) { `, withFiles(map[string][]byte{ "product_specific_file_contexts": nil, })) module = ctx.ModuleForTests("myapex", "android_common_myapex_image") apexRule = module.Rule("apexRule") actual = apexRule.Args["file_contexts"] expected = "product_specific_file_contexts" if actual != expected { t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) module := ctx.ModuleForTests("myapex", "android_common_myapex_image") rule := module.Output("file_contexts") ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") } ctx, _ = testApex(t, ` func TestFileContexts_SetViaFileGroup(t *testing.T) { ctx, _ := testApex(t, ` apex { name: "myapex", key: "myapex.key", Loading @@ -3577,13 +3575,9 @@ func TestFileContexts(t *testing.T) { `, withFiles(map[string][]byte{ "product_specific_file_contexts": nil, })) module = ctx.ModuleForTests("myapex", "android_common_myapex_image") apexRule = module.Rule("apexRule") actual = apexRule.Args["file_contexts"] expected = "product_specific_file_contexts" if actual != expected { t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) } module := ctx.ModuleForTests("myapex", "android_common_myapex_image") rule := module.Output("file_contexts") ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") } func TestApexKeyFromOtherModule(t *testing.T) { Loading apex/builder.go +33 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package apex import ( "encoding/json" "fmt" "path" "path/filepath" "runtime" "sort" Loading Loading @@ -231,6 +232,38 @@ func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, }) } func (a *apexBundle) buildFileContexts(ctx android.ModuleContext) { if a.properties.ApexType == zipApex { return } var fileContexts android.Path if a.properties.File_contexts == nil { fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts") } else { fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts) } if a.Platform() { if matched, err := path.Match("system/sepolicy/**/*", fileContexts.String()); err != nil || !matched { ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", fileContexts) return } } if !android.ExistentPathForSource(ctx, fileContexts.String()).Valid() { ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts) return } output := android.PathForModuleOut(ctx, "file_contexts") rule := android.NewRuleBuilder() rule.Command().Text("rm").FlagWithOutput("-f ", output) rule.Command().Text("cat").Input(fileContexts).Text(">>").Output(output) rule.Command().Text("echo").Text(">>").Output(output) rule.Command().Text("echo").Flag("/apex_manifest\\\\.pb u:object_r:system_file:s0").Text(">>").Output(output) rule.Build(pctx, ctx, "file_contexts."+a.Name(), "Generate file_contexts") a.fileContexts = output.OutputPath } func (a *apexBundle) buildNoticeFiles(ctx android.ModuleContext, apexFileName string) android.NoticeOutputs { var noticeFiles android.Paths Loading Loading
apex/apex.go +3 −18 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package apex import ( "fmt" "path" "path/filepath" "sort" "strings" Loading Loading @@ -1242,7 +1241,7 @@ type apexBundle struct { container_certificate_file android.Path container_private_key_file android.Path fileContexts android.Path fileContexts android.WritablePath // list of files to be included in this apex filesInfo []apexFile Loading Loading @@ -2195,22 +2194,6 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.installDir = android.PathForModuleInstall(ctx, "apex") a.filesInfo = filesInfo if a.properties.ApexType != zipApex { if a.properties.File_contexts == nil { a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts") } else { a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts) if a.Platform() { if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched { ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts) } } } if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() { ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts) return } } // Optimization. If we are building bundled APEX, for the files that are gathered due to the // transitive dependencies, don't place them inside the APEX, but place a symlink pointing // the same library in the system partition, thus effectively sharing the same libraries Loading @@ -2234,6 +2217,8 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { // prepare apex_manifest.json a.buildManifest(ctx, provideNativeLibs, requireNativeLibs) a.buildFileContexts(ctx) a.setCertificateAndPrivateKey(ctx) if a.properties.ApexType == flattenedApex { a.buildFlattenedApex(ctx) Loading
apex/apex_test.go +73 −79 Original line number Diff line number Diff line Loading @@ -3480,7 +3480,7 @@ func TestApexInVariousPartition(t *testing.T) { } } func TestFileContexts(t *testing.T) { func TestFileContexts_FindInDefaultLocationIfNotSet(t *testing.T) { ctx, _ := testApex(t, ` apex { name: "myapex", Loading @@ -3494,13 +3494,11 @@ func TestFileContexts(t *testing.T) { } `) module := ctx.ModuleForTests("myapex", "android_common_myapex_image") apexRule := module.Rule("apexRule") actual := apexRule.Args["file_contexts"] expected := "system/sepolicy/apex/myapex-file_contexts" if actual != expected { t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) rule := module.Output("file_contexts") ensureContains(t, rule.RuleParams.Command, "cat system/sepolicy/apex/myapex-file_contexts") } func TestFileContexts_ShouldBeUnderSystemSepolicyForSystemApexes(t *testing.T) { testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` apex { name: "myapex", Loading @@ -3516,7 +3514,9 @@ func TestFileContexts(t *testing.T) { `, withFiles(map[string][]byte{ "my_own_file_contexts": nil, })) } func TestFileContexts_ProductSpecificApexes(t *testing.T) { testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` apex { name: "myapex", Loading @@ -3532,7 +3532,7 @@ func TestFileContexts(t *testing.T) { } `) ctx, _ = testApex(t, ` ctx, _ := testApex(t, ` apex { name: "myapex", key: "myapex.key", Loading @@ -3548,15 +3548,13 @@ func TestFileContexts(t *testing.T) { `, withFiles(map[string][]byte{ "product_specific_file_contexts": nil, })) module = ctx.ModuleForTests("myapex", "android_common_myapex_image") apexRule = module.Rule("apexRule") actual = apexRule.Args["file_contexts"] expected = "product_specific_file_contexts" if actual != expected { t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) module := ctx.ModuleForTests("myapex", "android_common_myapex_image") rule := module.Output("file_contexts") ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") } ctx, _ = testApex(t, ` func TestFileContexts_SetViaFileGroup(t *testing.T) { ctx, _ := testApex(t, ` apex { name: "myapex", key: "myapex.key", Loading @@ -3577,13 +3575,9 @@ func TestFileContexts(t *testing.T) { `, withFiles(map[string][]byte{ "product_specific_file_contexts": nil, })) module = ctx.ModuleForTests("myapex", "android_common_myapex_image") apexRule = module.Rule("apexRule") actual = apexRule.Args["file_contexts"] expected = "product_specific_file_contexts" if actual != expected { t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) } module := ctx.ModuleForTests("myapex", "android_common_myapex_image") rule := module.Output("file_contexts") ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") } func TestApexKeyFromOtherModule(t *testing.T) { Loading
apex/builder.go +33 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package apex import ( "encoding/json" "fmt" "path" "path/filepath" "runtime" "sort" Loading Loading @@ -231,6 +232,38 @@ func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, }) } func (a *apexBundle) buildFileContexts(ctx android.ModuleContext) { if a.properties.ApexType == zipApex { return } var fileContexts android.Path if a.properties.File_contexts == nil { fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts") } else { fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts) } if a.Platform() { if matched, err := path.Match("system/sepolicy/**/*", fileContexts.String()); err != nil || !matched { ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", fileContexts) return } } if !android.ExistentPathForSource(ctx, fileContexts.String()).Valid() { ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts) return } output := android.PathForModuleOut(ctx, "file_contexts") rule := android.NewRuleBuilder() rule.Command().Text("rm").FlagWithOutput("-f ", output) rule.Command().Text("cat").Input(fileContexts).Text(">>").Output(output) rule.Command().Text("echo").Text(">>").Output(output) rule.Command().Text("echo").Flag("/apex_manifest\\\\.pb u:object_r:system_file:s0").Text(">>").Output(output) rule.Build(pctx, ctx, "file_contexts."+a.Name(), "Generate file_contexts") a.fileContexts = output.OutputPath } func (a *apexBundle) buildNoticeFiles(ctx android.ModuleContext, apexFileName string) android.NoticeOutputs { var noticeFiles android.Paths Loading