Merge "Fix resource overlay order for static libraries"
am: 0653d6d464
Change-Id: Ibe193ed1291d83cb685b2ad75c33f1c4ddea540e
This commit is contained in:
commit
2a1f4b2bda
2 changed files with 102 additions and 45 deletions
14
java/aar.go
14
java/aar.go
|
@ -215,17 +215,17 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
|
|||
|
||||
compiledOverlay = append(compiledOverlay, transitiveStaticLibs...)
|
||||
|
||||
if a.isLibrary {
|
||||
// For a static library we treat all the resources equally with no overlay.
|
||||
for _, compiledResDir := range compiledResDirs {
|
||||
compiledRes = append(compiledRes, compiledResDir...)
|
||||
}
|
||||
} else if len(transitiveStaticLibs) > 0 {
|
||||
if len(transitiveStaticLibs) > 0 {
|
||||
// If we are using static android libraries, every source file becomes an overlay.
|
||||
// This is to emulate old AAPT behavior which simulated library support.
|
||||
for _, compiledResDir := range compiledResDirs {
|
||||
compiledOverlay = append(compiledOverlay, compiledResDir...)
|
||||
}
|
||||
} else if a.isLibrary {
|
||||
// Otherwise, for a static library we treat all the resources equally with no overlay.
|
||||
for _, compiledResDir := range compiledResDirs {
|
||||
compiledRes = append(compiledRes, compiledResDir...)
|
||||
}
|
||||
} else if len(compiledResDirs) > 0 {
|
||||
// Without static libraries, the first directory is our directory, which can then be
|
||||
// overlaid by the rest.
|
||||
|
@ -278,8 +278,8 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
|
|||
}
|
||||
case staticLibTag:
|
||||
if exportPackage != nil {
|
||||
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
|
||||
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
|
||||
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
|
||||
staticLibManifests = append(staticLibManifests, aarDep.ExportedManifest())
|
||||
staticRRODirs = append(staticRRODirs, aarDep.ExportedRRODirs()...)
|
||||
}
|
||||
|
|
117
java/app_test.go
117
java/app_test.go
|
@ -164,11 +164,12 @@ func TestResourceDirs(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestEnforceRRO(t *testing.T) {
|
||||
func TestAndroidResources(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
enforceRROTargets []string
|
||||
enforceRROExcludedOverlays []string
|
||||
resourceFiles map[string][]string
|
||||
overlayFiles map[string][]string
|
||||
rroDirs map[string][]string
|
||||
}{
|
||||
|
@ -176,17 +177,29 @@ func TestEnforceRRO(t *testing.T) {
|
|||
name: "no RRO",
|
||||
enforceRROTargets: nil,
|
||||
enforceRROExcludedOverlays: nil,
|
||||
resourceFiles: map[string][]string{
|
||||
"foo": nil,
|
||||
"bar": {"bar/res/res/values/strings.xml"},
|
||||
"lib": nil,
|
||||
"lib2": {"lib2/res/res/values/strings.xml"},
|
||||
},
|
||||
overlayFiles: map[string][]string{
|
||||
"foo": []string{
|
||||
"foo": {
|
||||
buildDir + "/.intermediates/lib2/android_common/package-res.apk",
|
||||
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/overlay/foo/res/values/strings.xml",
|
||||
},
|
||||
"bar": []string{
|
||||
"bar": {
|
||||
"device/vendor/blah/static_overlay/bar/res/values/strings.xml",
|
||||
"device/vendor/blah/overlay/bar/res/values/strings.xml",
|
||||
},
|
||||
"lib": {
|
||||
buildDir + "/.intermediates/lib2/android_common/package-res.apk",
|
||||
"lib/res/res/values/strings.xml",
|
||||
"device/vendor/blah/overlay/lib/res/values/strings.xml",
|
||||
},
|
||||
},
|
||||
rroDirs: map[string][]string{
|
||||
"foo": nil,
|
||||
|
@ -197,25 +210,38 @@ func TestEnforceRRO(t *testing.T) {
|
|||
name: "enforce RRO on foo",
|
||||
enforceRROTargets: []string{"foo"},
|
||||
enforceRROExcludedOverlays: []string{"device/vendor/blah/static_overlay"},
|
||||
resourceFiles: map[string][]string{
|
||||
"foo": nil,
|
||||
"bar": {"bar/res/res/values/strings.xml"},
|
||||
"lib": nil,
|
||||
"lib2": {"lib2/res/res/values/strings.xml"},
|
||||
},
|
||||
overlayFiles: map[string][]string{
|
||||
"foo": []string{
|
||||
"foo": {
|
||||
buildDir + "/.intermediates/lib2/android_common/package-res.apk",
|
||||
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": {
|
||||
"device/vendor/blah/static_overlay/bar/res/values/strings.xml",
|
||||
"device/vendor/blah/overlay/bar/res/values/strings.xml",
|
||||
},
|
||||
"lib": {
|
||||
buildDir + "/.intermediates/lib2/android_common/package-res.apk",
|
||||
"lib/res/res/values/strings.xml",
|
||||
"device/vendor/blah/overlay/lib/res/values/strings.xml",
|
||||
},
|
||||
},
|
||||
|
||||
rroDirs: map[string][]string{
|
||||
"foo": []string{
|
||||
"foo": {
|
||||
"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,
|
||||
"lib": nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -226,20 +252,32 @@ func TestEnforceRRO(t *testing.T) {
|
|||
"device/vendor/blah/static_overlay/foo",
|
||||
"device/vendor/blah/static_overlay/bar/res",
|
||||
},
|
||||
resourceFiles: map[string][]string{
|
||||
"foo": nil,
|
||||
"bar": {"bar/res/res/values/strings.xml"},
|
||||
"lib": nil,
|
||||
"lib2": {"lib2/res/res/values/strings.xml"},
|
||||
},
|
||||
overlayFiles: map[string][]string{
|
||||
"foo": []string{
|
||||
"foo": {
|
||||
buildDir + "/.intermediates/lib2/android_common/package-res.apk",
|
||||
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": {"device/vendor/blah/static_overlay/bar/res/values/strings.xml"},
|
||||
"lib": {
|
||||
buildDir + "/.intermediates/lib2/android_common/package-res.apk",
|
||||
"lib/res/res/values/strings.xml",
|
||||
},
|
||||
},
|
||||
rroDirs: map[string][]string{
|
||||
"foo": []string{
|
||||
"foo": {
|
||||
"device/vendor/blah/overlay/foo/res",
|
||||
"device/vendor/blah/overlay/lib/res",
|
||||
},
|
||||
"bar": []string{"device/vendor/blah/overlay/bar/res"},
|
||||
"bar": {"device/vendor/blah/overlay/bar/res"},
|
||||
"lib": {"device/vendor/blah/overlay/lib/res"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -254,6 +292,7 @@ func TestEnforceRRO(t *testing.T) {
|
|||
"foo/res/res/values/strings.xml": nil,
|
||||
"bar/res/res/values/strings.xml": nil,
|
||||
"lib/res/res/values/strings.xml": nil,
|
||||
"lib2/res/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/lib/res/values/strings.xml": nil,
|
||||
|
@ -277,6 +316,12 @@ func TestEnforceRRO(t *testing.T) {
|
|||
android_library {
|
||||
name: "lib",
|
||||
resource_dirs: ["lib/res"],
|
||||
static_libs: ["lib2"],
|
||||
}
|
||||
|
||||
android_library {
|
||||
name: "lib2",
|
||||
resource_dirs: ["lib2/res"],
|
||||
}
|
||||
`
|
||||
|
||||
|
@ -294,40 +339,52 @@ func TestEnforceRRO(t *testing.T) {
|
|||
ctx := testAppContext(config, bp, fs)
|
||||
run(t, ctx, config)
|
||||
|
||||
getOverlays := func(moduleName string) ([]string, []string) {
|
||||
module := ctx.ModuleForTests(moduleName, "android_common")
|
||||
overlayFile := module.MaybeOutput("aapt2/overlay.list")
|
||||
var overlayFiles []string
|
||||
if overlayFile.Rule != nil {
|
||||
for _, o := range overlayFile.Inputs.Strings() {
|
||||
overlayOutput := module.MaybeOutput(o)
|
||||
if overlayOutput.Rule != nil {
|
||||
resourceListToFiles := func(module android.TestingModule, list []string) (files []string) {
|
||||
for _, o := range list {
|
||||
res := module.MaybeOutput(o)
|
||||
if res.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()...)
|
||||
files = append(files, res.Inputs.Strings()...)
|
||||
} else {
|
||||
// Otherwise, verify the full path to the output of the other module
|
||||
overlayFiles = append(overlayFiles, o)
|
||||
files = append(files, o)
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
rroDirs := module.Module().(*AndroidApp).rroDirs.Strings()
|
||||
|
||||
return overlayFiles, rroDirs
|
||||
getResources := func(moduleName string) (resourceFiles, overlayFiles, rroDirs []string) {
|
||||
module := ctx.ModuleForTests(moduleName, "android_common")
|
||||
resourceList := module.MaybeOutput("aapt2/res.list")
|
||||
if resourceList.Rule != nil {
|
||||
resourceFiles = resourceListToFiles(module, resourceList.Inputs.Strings())
|
||||
}
|
||||
overlayList := module.MaybeOutput("aapt2/overlay.list")
|
||||
if overlayList.Rule != nil {
|
||||
overlayFiles = resourceListToFiles(module, overlayList.Inputs.Strings())
|
||||
}
|
||||
|
||||
apps := []string{"foo", "bar"}
|
||||
for _, app := range apps {
|
||||
overlayFiles, rroDirs := getOverlays(app)
|
||||
rroDirs = module.Module().(AndroidLibraryDependency).ExportedRRODirs().Strings()
|
||||
|
||||
if !reflect.DeepEqual(overlayFiles, testCase.overlayFiles[app]) {
|
||||
return resourceFiles, overlayFiles, rroDirs
|
||||
}
|
||||
|
||||
modules := []string{"foo", "bar", "lib", "lib2"}
|
||||
for _, module := range modules {
|
||||
resourceFiles, overlayFiles, rroDirs := getResources(module)
|
||||
|
||||
if !reflect.DeepEqual(resourceFiles, testCase.resourceFiles[module]) {
|
||||
t.Errorf("expected %s resource files:\n %#v\n got:\n %#v",
|
||||
module, testCase.resourceFiles[module], resourceFiles)
|
||||
}
|
||||
if !reflect.DeepEqual(overlayFiles, testCase.overlayFiles[module]) {
|
||||
t.Errorf("expected %s overlay files:\n %#v\n got:\n %#v",
|
||||
app, testCase.overlayFiles[app], overlayFiles)
|
||||
module, testCase.overlayFiles[module], overlayFiles)
|
||||
}
|
||||
if !reflect.DeepEqual(rroDirs, testCase.rroDirs[app]) {
|
||||
if !reflect.DeepEqual(rroDirs, testCase.rroDirs[module]) {
|
||||
t.Errorf("expected %s rroDirs: %#v\n got:\n %#v",
|
||||
app, testCase.rroDirs[app], rroDirs)
|
||||
module, testCase.rroDirs[module], rroDirs)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue