Merge changes I28c45e13,I9754ebf0,I0dda0184
* changes: Export RRO resource dirs from static android_library dependencies Add a static lib to TestEnforceRRO Move TestEnforceRRO test cases into test function
This commit is contained in:
30
java/aar.go
30
java/aar.go
@@ -26,6 +26,7 @@ type AndroidLibraryDependency interface {
|
|||||||
Dependency
|
Dependency
|
||||||
ExportPackage() android.Path
|
ExportPackage() android.Path
|
||||||
ExportedProguardFlagFiles() android.Paths
|
ExportedProguardFlagFiles() android.Paths
|
||||||
|
ExportedRRODirs() android.Paths
|
||||||
ExportedStaticPackages() android.Paths
|
ExportedStaticPackages() android.Paths
|
||||||
ExportedManifest() android.Path
|
ExportedManifest() android.Path
|
||||||
}
|
}
|
||||||
@@ -80,6 +81,14 @@ func (a *aapt) ExportPackage() android.Path {
|
|||||||
return a.exportPackage
|
return a.exportPackage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *aapt) ExportedRRODirs() android.Paths {
|
||||||
|
return a.rroDirs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *aapt) ExportedManifest() android.Path {
|
||||||
|
return a.manifestPath
|
||||||
|
}
|
||||||
|
|
||||||
func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, manifestPath android.Path) (flags []string,
|
func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, manifestPath android.Path) (flags []string,
|
||||||
deps android.Paths, resDirs, overlayDirs []globbedResourceDir, rroDirs android.Paths) {
|
deps android.Paths, resDirs, overlayDirs []globbedResourceDir, rroDirs android.Paths) {
|
||||||
|
|
||||||
@@ -164,7 +173,7 @@ func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkContext sdkContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, extraLinkFlags ...string) {
|
func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, extraLinkFlags ...string) {
|
||||||
transitiveStaticLibs, staticLibManifests, libDeps, libFlags := aaptLibs(ctx, sdkContext)
|
transitiveStaticLibs, staticLibManifests, staticRRODirs, libDeps, libFlags := aaptLibs(ctx, sdkContext)
|
||||||
|
|
||||||
// App manifest file
|
// App manifest file
|
||||||
manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
|
manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
|
||||||
@@ -174,6 +183,8 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
|
|||||||
|
|
||||||
linkFlags, linkDeps, resDirs, overlayDirs, rroDirs := a.aapt2Flags(ctx, sdkContext, manifestPath)
|
linkFlags, linkDeps, resDirs, overlayDirs, rroDirs := a.aapt2Flags(ctx, sdkContext, manifestPath)
|
||||||
|
|
||||||
|
rroDirs = append(rroDirs, staticRRODirs...)
|
||||||
|
|
||||||
linkFlags = append(linkFlags, libFlags...)
|
linkFlags = append(linkFlags, libFlags...)
|
||||||
linkDeps = append(linkDeps, libDeps...)
|
linkDeps = append(linkDeps, libDeps...)
|
||||||
linkFlags = append(linkFlags, extraLinkFlags...)
|
linkFlags = append(linkFlags, extraLinkFlags...)
|
||||||
@@ -235,7 +246,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
|
|||||||
|
|
||||||
// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
|
// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
|
||||||
func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStaticLibs, staticLibManifests,
|
func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStaticLibs, staticLibManifests,
|
||||||
deps android.Paths, flags []string) {
|
staticRRODirs, deps android.Paths, flags []string) {
|
||||||
|
|
||||||
var sharedLibs android.Paths
|
var sharedLibs android.Paths
|
||||||
|
|
||||||
@@ -263,6 +274,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
|
|||||||
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
|
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
|
||||||
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
|
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
|
||||||
staticLibManifests = append(staticLibManifests, aarDep.ExportedManifest())
|
staticLibManifests = append(staticLibManifests, aarDep.ExportedManifest())
|
||||||
|
staticRRODirs = append(staticRRODirs, aarDep.ExportedRRODirs()...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -279,8 +291,9 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
|
|||||||
}
|
}
|
||||||
|
|
||||||
transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs)
|
transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs)
|
||||||
|
staticRRODirs = android.FirstUniquePaths(staticRRODirs)
|
||||||
|
|
||||||
return transitiveStaticLibs, staticLibManifests, deps, flags
|
return transitiveStaticLibs, staticLibManifests, staticRRODirs, deps, flags
|
||||||
}
|
}
|
||||||
|
|
||||||
type AndroidLibrary struct {
|
type AndroidLibrary struct {
|
||||||
@@ -303,10 +316,6 @@ func (a *AndroidLibrary) ExportedStaticPackages() android.Paths {
|
|||||||
return a.exportedStaticPackages
|
return a.exportedStaticPackages
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AndroidLibrary) ExportedManifest() android.Path {
|
|
||||||
return a.manifestPath
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ AndroidLibraryDependency = (*AndroidLibrary)(nil)
|
var _ AndroidLibraryDependency = (*AndroidLibrary)(nil)
|
||||||
|
|
||||||
func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
@@ -426,6 +435,10 @@ func (a *AARImport) ExportedProguardFlagFiles() android.Paths {
|
|||||||
return android.Paths{a.proguardFlags}
|
return android.Paths{a.proguardFlags}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *AARImport) ExportedRRODirs() android.Paths {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *AARImport) ExportedStaticPackages() android.Paths {
|
func (a *AARImport) ExportedStaticPackages() android.Paths {
|
||||||
return a.exportedStaticPackages
|
return a.exportedStaticPackages
|
||||||
}
|
}
|
||||||
@@ -518,9 +531,10 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
linkFlags = append(linkFlags, "--manifest "+a.manifest.String())
|
linkFlags = append(linkFlags, "--manifest "+a.manifest.String())
|
||||||
linkDeps = append(linkDeps, a.manifest)
|
linkDeps = append(linkDeps, a.manifest)
|
||||||
|
|
||||||
transitiveStaticLibs, staticLibManifests, libDeps, libFlags := aaptLibs(ctx, sdkContext(a))
|
transitiveStaticLibs, staticLibManifests, staticRRODirs, libDeps, libFlags := aaptLibs(ctx, sdkContext(a))
|
||||||
|
|
||||||
_ = staticLibManifests
|
_ = staticLibManifests
|
||||||
|
_ = staticRRODirs
|
||||||
|
|
||||||
linkDeps = append(linkDeps, libDeps...)
|
linkDeps = append(linkDeps, libDeps...)
|
||||||
linkFlags = append(linkFlags, libFlags...)
|
linkFlags = append(linkFlags, libFlags...)
|
||||||
|
@@ -95,10 +95,6 @@ func (a *AndroidApp) ExportedStaticPackages() android.Paths {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AndroidApp) ExportedManifest() android.Path {
|
|
||||||
return a.manifestPath
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ AndroidLibraryDependency = (*AndroidApp)(nil)
|
var _ AndroidLibraryDependency = (*AndroidApp)(nil)
|
||||||
|
|
||||||
type Certificate struct {
|
type Certificate struct {
|
||||||
|
@@ -106,7 +106,8 @@ func TestApp(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var testEnforceRROTests = []struct {
|
func TestEnforceRRO(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
enforceRROTargets []string
|
enforceRROTargets []string
|
||||||
enforceRROExcludedOverlays []string
|
enforceRROExcludedOverlays []string
|
||||||
@@ -119,6 +120,8 @@ var testEnforceRROTests = []struct {
|
|||||||
enforceRROExcludedOverlays: nil,
|
enforceRROExcludedOverlays: nil,
|
||||||
overlayFiles: map[string][]string{
|
overlayFiles: map[string][]string{
|
||||||
"foo": []string{
|
"foo": []string{
|
||||||
|
buildDir + "/.intermediates/lib/android_common/package-res.apk",
|
||||||
|
"foo/res/res/values/strings.xml",
|
||||||
"device/vendor/blah/static_overlay/foo/res/values/strings.xml",
|
"device/vendor/blah/static_overlay/foo/res/values/strings.xml",
|
||||||
"device/vendor/blah/overlay/foo/res/values/strings.xml",
|
"device/vendor/blah/overlay/foo/res/values/strings.xml",
|
||||||
},
|
},
|
||||||
@@ -137,14 +140,23 @@ var testEnforceRROTests = []struct {
|
|||||||
enforceRROTargets: []string{"foo"},
|
enforceRROTargets: []string{"foo"},
|
||||||
enforceRROExcludedOverlays: []string{"device/vendor/blah/static_overlay"},
|
enforceRROExcludedOverlays: []string{"device/vendor/blah/static_overlay"},
|
||||||
overlayFiles: map[string][]string{
|
overlayFiles: map[string][]string{
|
||||||
"foo": []string{"device/vendor/blah/static_overlay/foo/res/values/strings.xml"},
|
"foo": []string{
|
||||||
|
buildDir + "/.intermediates/lib/android_common/package-res.apk",
|
||||||
|
"foo/res/res/values/strings.xml",
|
||||||
|
"device/vendor/blah/static_overlay/foo/res/values/strings.xml",
|
||||||
|
},
|
||||||
"bar": []string{
|
"bar": []string{
|
||||||
"device/vendor/blah/static_overlay/bar/res/values/strings.xml",
|
"device/vendor/blah/static_overlay/bar/res/values/strings.xml",
|
||||||
"device/vendor/blah/overlay/bar/res/values/strings.xml",
|
"device/vendor/blah/overlay/bar/res/values/strings.xml",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
rroDirs: map[string][]string{
|
rroDirs: map[string][]string{
|
||||||
"foo": []string{"device/vendor/blah/overlay/foo/res"},
|
"foo": []string{
|
||||||
|
"device/vendor/blah/overlay/foo/res",
|
||||||
|
// Enforce RRO on "foo" could imply RRO on static dependencies, but for now it doesn't.
|
||||||
|
// "device/vendor/blah/overlay/lib/res",
|
||||||
|
},
|
||||||
"bar": nil,
|
"bar": nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -157,17 +169,23 @@ var testEnforceRROTests = []struct {
|
|||||||
"device/vendor/blah/static_overlay/bar/res",
|
"device/vendor/blah/static_overlay/bar/res",
|
||||||
},
|
},
|
||||||
overlayFiles: map[string][]string{
|
overlayFiles: map[string][]string{
|
||||||
"foo": []string{"device/vendor/blah/static_overlay/foo/res/values/strings.xml"},
|
"foo": []string{
|
||||||
|
buildDir + "/.intermediates/lib/android_common/package-res.apk",
|
||||||
|
"foo/res/res/values/strings.xml",
|
||||||
|
"device/vendor/blah/static_overlay/foo/res/values/strings.xml",
|
||||||
|
},
|
||||||
"bar": []string{"device/vendor/blah/static_overlay/bar/res/values/strings.xml"},
|
"bar": []string{"device/vendor/blah/static_overlay/bar/res/values/strings.xml"},
|
||||||
},
|
},
|
||||||
rroDirs: map[string][]string{
|
rroDirs: map[string][]string{
|
||||||
"foo": []string{"device/vendor/blah/overlay/foo/res"},
|
"foo": []string{
|
||||||
|
"device/vendor/blah/overlay/foo/res",
|
||||||
|
"device/vendor/blah/overlay/lib/res",
|
||||||
|
},
|
||||||
"bar": []string{"device/vendor/blah/overlay/bar/res"},
|
"bar": []string{"device/vendor/blah/overlay/bar/res"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnforceRRO(t *testing.T) {
|
|
||||||
resourceOverlays := []string{
|
resourceOverlays := []string{
|
||||||
"device/vendor/blah/overlay",
|
"device/vendor/blah/overlay",
|
||||||
"device/vendor/blah/overlay2",
|
"device/vendor/blah/overlay2",
|
||||||
@@ -177,8 +195,10 @@ func TestEnforceRRO(t *testing.T) {
|
|||||||
fs := map[string][]byte{
|
fs := map[string][]byte{
|
||||||
"foo/res/res/values/strings.xml": nil,
|
"foo/res/res/values/strings.xml": nil,
|
||||||
"bar/res/res/values/strings.xml": nil,
|
"bar/res/res/values/strings.xml": nil,
|
||||||
|
"lib/res/res/values/strings.xml": nil,
|
||||||
"device/vendor/blah/overlay/foo/res/values/strings.xml": nil,
|
"device/vendor/blah/overlay/foo/res/values/strings.xml": nil,
|
||||||
"device/vendor/blah/overlay/bar/res/values/strings.xml": nil,
|
"device/vendor/blah/overlay/bar/res/values/strings.xml": nil,
|
||||||
|
"device/vendor/blah/overlay/lib/res/values/strings.xml": nil,
|
||||||
"device/vendor/blah/static_overlay/foo/res/values/strings.xml": nil,
|
"device/vendor/blah/static_overlay/foo/res/values/strings.xml": nil,
|
||||||
"device/vendor/blah/static_overlay/bar/res/values/strings.xml": nil,
|
"device/vendor/blah/static_overlay/bar/res/values/strings.xml": nil,
|
||||||
"device/vendor/blah/overlay2/res/values/strings.xml": nil,
|
"device/vendor/blah/overlay2/res/values/strings.xml": nil,
|
||||||
@@ -188,15 +208,21 @@ func TestEnforceRRO(t *testing.T) {
|
|||||||
android_app {
|
android_app {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
resource_dirs: ["foo/res"],
|
resource_dirs: ["foo/res"],
|
||||||
|
static_libs: ["lib"],
|
||||||
}
|
}
|
||||||
|
|
||||||
android_app {
|
android_app {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
resource_dirs: ["bar/res"],
|
resource_dirs: ["bar/res"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
android_library {
|
||||||
|
name: "lib",
|
||||||
|
resource_dirs: ["lib/res"],
|
||||||
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
for _, testCase := range testEnforceRROTests {
|
for _, testCase := range testCases {
|
||||||
t.Run(testCase.name, func(t *testing.T) {
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
config := testConfig(nil)
|
config := testConfig(nil)
|
||||||
config.TestProductVariables.ResourceOverlays = resourceOverlays
|
config.TestProductVariables.ResourceOverlays = resourceOverlays
|
||||||
@@ -216,7 +242,15 @@ func TestEnforceRRO(t *testing.T) {
|
|||||||
var overlayFiles []string
|
var overlayFiles []string
|
||||||
if overlayFile.Rule != nil {
|
if overlayFile.Rule != nil {
|
||||||
for _, o := range overlayFile.Inputs.Strings() {
|
for _, o := range overlayFile.Inputs.Strings() {
|
||||||
overlayFiles = append(overlayFiles, module.Output(o).Inputs.Strings()...)
|
overlayOutput := module.MaybeOutput(o)
|
||||||
|
if overlayOutput.Rule != nil {
|
||||||
|
// If the overlay is compiled as part of this module (i.e. a .arsc.flat file),
|
||||||
|
// verify the inputs to the .arsc.flat rule.
|
||||||
|
overlayFiles = append(overlayFiles, overlayOutput.Inputs.Strings()...)
|
||||||
|
} else {
|
||||||
|
// Otherwise, verify the full path to the output of the other module
|
||||||
|
overlayFiles = append(overlayFiles, o)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user