Merge "Fix resource overlay order for static libraries"
This commit is contained in:
commit
0653d6d464
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...)
|
compiledOverlay = append(compiledOverlay, transitiveStaticLibs...)
|
||||||
|
|
||||||
if a.isLibrary {
|
if len(transitiveStaticLibs) > 0 {
|
||||||
// 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 we are using static android libraries, every source file becomes an overlay.
|
// If we are using static android libraries, every source file becomes an overlay.
|
||||||
// This is to emulate old AAPT behavior which simulated library support.
|
// This is to emulate old AAPT behavior which simulated library support.
|
||||||
for _, compiledResDir := range compiledResDirs {
|
for _, compiledResDir := range compiledResDirs {
|
||||||
compiledOverlay = append(compiledOverlay, compiledResDir...)
|
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 {
|
} else if len(compiledResDirs) > 0 {
|
||||||
// Without static libraries, the first directory is our directory, which can then be
|
// Without static libraries, the first directory is our directory, which can then be
|
||||||
// overlaid by the rest.
|
// overlaid by the rest.
|
||||||
|
@ -278,8 +278,8 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
|
||||||
}
|
}
|
||||||
case staticLibTag:
|
case staticLibTag:
|
||||||
if exportPackage != nil {
|
if exportPackage != nil {
|
||||||
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
|
|
||||||
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
|
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
|
||||||
|
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
|
||||||
staticLibManifests = append(staticLibManifests, aarDep.ExportedManifest())
|
staticLibManifests = append(staticLibManifests, aarDep.ExportedManifest())
|
||||||
staticRRODirs = append(staticRRODirs, aarDep.ExportedRRODirs()...)
|
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 {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
enforceRROTargets []string
|
enforceRROTargets []string
|
||||||
enforceRROExcludedOverlays []string
|
enforceRROExcludedOverlays []string
|
||||||
|
resourceFiles map[string][]string
|
||||||
overlayFiles map[string][]string
|
overlayFiles map[string][]string
|
||||||
rroDirs map[string][]string
|
rroDirs map[string][]string
|
||||||
}{
|
}{
|
||||||
|
@ -176,17 +177,29 @@ func TestEnforceRRO(t *testing.T) {
|
||||||
name: "no RRO",
|
name: "no RRO",
|
||||||
enforceRROTargets: nil,
|
enforceRROTargets: nil,
|
||||||
enforceRROExcludedOverlays: 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{
|
overlayFiles: map[string][]string{
|
||||||
"foo": []string{
|
"foo": {
|
||||||
|
buildDir + "/.intermediates/lib2/android_common/package-res.apk",
|
||||||
buildDir + "/.intermediates/lib/android_common/package-res.apk",
|
buildDir + "/.intermediates/lib/android_common/package-res.apk",
|
||||||
"foo/res/res/values/strings.xml",
|
"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",
|
||||||
},
|
},
|
||||||
"bar": []string{
|
"bar": {
|
||||||
"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",
|
||||||
},
|
},
|
||||||
|
"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{
|
rroDirs: map[string][]string{
|
||||||
"foo": nil,
|
"foo": nil,
|
||||||
|
@ -197,25 +210,38 @@ func TestEnforceRRO(t *testing.T) {
|
||||||
name: "enforce RRO on foo",
|
name: "enforce RRO on foo",
|
||||||
enforceRROTargets: []string{"foo"},
|
enforceRROTargets: []string{"foo"},
|
||||||
enforceRROExcludedOverlays: []string{"device/vendor/blah/static_overlay"},
|
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{
|
overlayFiles: map[string][]string{
|
||||||
"foo": []string{
|
"foo": {
|
||||||
|
buildDir + "/.intermediates/lib2/android_common/package-res.apk",
|
||||||
buildDir + "/.intermediates/lib/android_common/package-res.apk",
|
buildDir + "/.intermediates/lib/android_common/package-res.apk",
|
||||||
"foo/res/res/values/strings.xml",
|
"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",
|
||||||
},
|
},
|
||||||
"bar": []string{
|
"bar": {
|
||||||
"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",
|
||||||
},
|
},
|
||||||
|
"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{
|
rroDirs: map[string][]string{
|
||||||
"foo": []string{
|
"foo": {
|
||||||
"device/vendor/blah/overlay/foo/res",
|
"device/vendor/blah/overlay/foo/res",
|
||||||
// Enforce RRO on "foo" could imply RRO on static dependencies, but for now it doesn't.
|
// Enforce RRO on "foo" could imply RRO on static dependencies, but for now it doesn't.
|
||||||
// "device/vendor/blah/overlay/lib/res",
|
// "device/vendor/blah/overlay/lib/res",
|
||||||
},
|
},
|
||||||
"bar": nil,
|
"bar": nil,
|
||||||
|
"lib": nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -226,20 +252,32 @@ func TestEnforceRRO(t *testing.T) {
|
||||||
"device/vendor/blah/static_overlay/foo",
|
"device/vendor/blah/static_overlay/foo",
|
||||||
"device/vendor/blah/static_overlay/bar/res",
|
"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{
|
overlayFiles: map[string][]string{
|
||||||
"foo": []string{
|
"foo": {
|
||||||
|
buildDir + "/.intermediates/lib2/android_common/package-res.apk",
|
||||||
buildDir + "/.intermediates/lib/android_common/package-res.apk",
|
buildDir + "/.intermediates/lib/android_common/package-res.apk",
|
||||||
"foo/res/res/values/strings.xml",
|
"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",
|
||||||
},
|
},
|
||||||
"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{
|
rroDirs: map[string][]string{
|
||||||
"foo": []string{
|
"foo": {
|
||||||
"device/vendor/blah/overlay/foo/res",
|
"device/vendor/blah/overlay/foo/res",
|
||||||
"device/vendor/blah/overlay/lib/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,
|
"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,
|
"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/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/overlay/lib/res/values/strings.xml": nil,
|
||||||
|
@ -277,6 +316,12 @@ func TestEnforceRRO(t *testing.T) {
|
||||||
android_library {
|
android_library {
|
||||||
name: "lib",
|
name: "lib",
|
||||||
resource_dirs: ["lib/res"],
|
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)
|
ctx := testAppContext(config, bp, fs)
|
||||||
run(t, ctx, config)
|
run(t, ctx, config)
|
||||||
|
|
||||||
getOverlays := func(moduleName string) ([]string, []string) {
|
resourceListToFiles := func(module android.TestingModule, list []string) (files []string) {
|
||||||
module := ctx.ModuleForTests(moduleName, "android_common")
|
for _, o := range list {
|
||||||
overlayFile := module.MaybeOutput("aapt2/overlay.list")
|
res := module.MaybeOutput(o)
|
||||||
var overlayFiles []string
|
if res.Rule != nil {
|
||||||
if overlayFile.Rule != nil {
|
|
||||||
for _, o := range overlayFile.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),
|
// If the overlay is compiled as part of this module (i.e. a .arsc.flat file),
|
||||||
// verify the inputs to the .arsc.flat rule.
|
// verify the inputs to the .arsc.flat rule.
|
||||||
overlayFiles = append(overlayFiles, overlayOutput.Inputs.Strings()...)
|
files = append(files, res.Inputs.Strings()...)
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, verify the full path to the output of the other module
|
// 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()
|
getResources := func(moduleName string) (resourceFiles, overlayFiles, rroDirs []string) {
|
||||||
|
module := ctx.ModuleForTests(moduleName, "android_common")
|
||||||
return overlayFiles, rroDirs
|
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"}
|
rroDirs = module.Module().(AndroidLibraryDependency).ExportedRRODirs().Strings()
|
||||||
for _, app := range apps {
|
|
||||||
overlayFiles, rroDirs := getOverlays(app)
|
|
||||||
|
|
||||||
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",
|
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",
|
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