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()...)
|
||||||
}
|
}
|
||||||
|
|
133
java/app_test.go
133
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 {
|
// If the overlay is compiled as part of this module (i.e. a .arsc.flat file),
|
||||||
for _, o := range overlayFile.Inputs.Strings() {
|
// verify the inputs to the .arsc.flat rule.
|
||||||
overlayOutput := module.MaybeOutput(o)
|
files = append(files, res.Inputs.Strings()...)
|
||||||
if overlayOutput.Rule != nil {
|
} else {
|
||||||
// If the overlay is compiled as part of this module (i.e. a .arsc.flat file),
|
// Otherwise, verify the full path to the output of the other module
|
||||||
// verify the inputs to the .arsc.flat rule.
|
files = append(files, o)
|
||||||
overlayFiles = append(overlayFiles, overlayOutput.Inputs.Strings()...)
|
|
||||||
} else {
|
|
||||||
// Otherwise, verify the full path to the output of the other module
|
|
||||||
overlayFiles = append(overlayFiles, o)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return files
|
||||||
rroDirs := module.Module().(*AndroidApp).rroDirs.Strings()
|
|
||||||
|
|
||||||
return overlayFiles, rroDirs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
apps := []string{"foo", "bar"}
|
getResources := func(moduleName string) (resourceFiles, overlayFiles, rroDirs []string) {
|
||||||
for _, app := range apps {
|
module := ctx.ModuleForTests(moduleName, "android_common")
|
||||||
overlayFiles, rroDirs := getOverlays(app)
|
resourceList := module.MaybeOutput("aapt2/res.list")
|
||||||
|
if resourceList.Rule != nil {
|
||||||
if !reflect.DeepEqual(overlayFiles, testCase.overlayFiles[app]) {
|
resourceFiles = resourceListToFiles(module, resourceList.Inputs.Strings())
|
||||||
t.Errorf("expected %s overlay files:\n %#v\n got:\n %#v",
|
|
||||||
app, testCase.overlayFiles[app], overlayFiles)
|
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(rroDirs, testCase.rroDirs[app]) {
|
overlayList := module.MaybeOutput("aapt2/overlay.list")
|
||||||
|
if overlayList.Rule != nil {
|
||||||
|
overlayFiles = resourceListToFiles(module, overlayList.Inputs.Strings())
|
||||||
|
}
|
||||||
|
|
||||||
|
rroDirs = module.Module().(AndroidLibraryDependency).ExportedRRODirs().Strings()
|
||||||
|
|
||||||
|
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",
|
||||||
|
module, testCase.overlayFiles[module], overlayFiles)
|
||||||
|
}
|
||||||
|
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