Merge "Touch up manifest if there's no source code." am: 96eac767df

am: c831a0a895

Change-Id: I19cba0c3017eff6f309dae04aacdb7e0aee1613d
This commit is contained in:
Jaewoong Jung
2019-06-06 07:18:38 -07:00
committed by android-build-merger
7 changed files with 156 additions and 9 deletions

View File

@@ -85,6 +85,7 @@ type aapt struct {
useEmbeddedDex bool
usesNonSdkApis bool
sdkLibraries []string
hasNoCode bool
splitNames []string
splits []split
@@ -204,7 +205,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
manifestPath := manifestFixer(ctx, manifestSrcPath, sdkContext, sdkLibraries,
a.isLibrary, a.useEmbeddedNativeLibs, a.usesNonSdkApis, a.useEmbeddedDex)
a.isLibrary, a.useEmbeddedNativeLibs, a.usesNonSdkApis, a.useEmbeddedDex, a.hasNoCode)
a.transitiveManifestPaths = append(android.Paths{manifestPath}, transitiveStaticLibManifests...)

View File

@@ -53,7 +53,7 @@ var optionalUsesLibs = []string{
// Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml
func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext, sdkLibraries []string,
isLibrary, useEmbeddedNativeLibs, usesNonSdkApis, useEmbeddedDex bool) android.Path {
isLibrary, useEmbeddedNativeLibs, usesNonSdkApis, useEmbeddedDex, hasNoCode bool) android.Path {
var args []string
if isLibrary {
@@ -87,6 +87,10 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext
}
}
if hasNoCode {
args = append(args, "--has-no-code")
}
var deps android.Paths
targetSdkVersion := sdkVersionOrDefault(ctx, sdkContext.targetSdkVersion())
if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&

View File

@@ -243,6 +243,9 @@ func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool {
func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
a.aapt.usesNonSdkApis = Bool(a.Module.deviceProperties.Platform_apis)
// Ask manifest_fixer to add or update the application element indicating this app has no code.
a.aapt.hasNoCode = !a.hasCode(ctx)
aaptLinkFlags := []string{}
// Add TARGET_AAPT_CHARACTERISTICS values to AAPT link flags if they exist and --product flags were not provided.

View File

@@ -1327,3 +1327,73 @@ func TestUsesLibraries(t *testing.T) {
t.Errorf("wanted %q in %q", w, cmd)
}
}
func TestCodelessApp(t *testing.T) {
testCases := []struct {
name string
bp string
noCode bool
}{
{
name: "normal",
bp: `
android_app {
name: "foo",
srcs: ["a.java"],
}
`,
noCode: false,
},
{
name: "app without sources",
bp: `
android_app {
name: "foo",
}
`,
noCode: true,
},
{
name: "app with libraries",
bp: `
android_app {
name: "foo",
static_libs: ["lib"],
}
java_library {
name: "lib",
srcs: ["a.java"],
}
`,
noCode: false,
},
{
name: "app with sourceless libraries",
bp: `
android_app {
name: "foo",
static_libs: ["lib"],
}
java_library {
name: "lib",
}
`,
// TODO(jungjw): this should probably be true
noCode: false,
},
}
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
ctx := testApp(t, test.bp)
foo := ctx.ModuleForTests("foo", "android_common")
manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"]
if strings.Contains(manifestFixerArgs, "--has-no-code") != test.noCode {
t.Errorf("unexpected manifest_fixer args: %q", manifestFixerArgs)
}
})
}
}

View File

@@ -969,8 +969,6 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
hasSrcs := false
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
deps := j.collectDeps(ctx)
@@ -985,9 +983,6 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
}
srcFiles = j.genSources(ctx, srcFiles, flags)
if len(srcFiles) > 0 {
hasSrcs = true
}
srcJars := srcFiles.FilterByExt(".srcjar")
srcJars = append(srcJars, deps.srcJars...)
@@ -1184,7 +1179,6 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
if len(deps.staticJars) > 0 {
jars = append(jars, deps.staticJars...)
hasSrcs = true
}
manifest := j.overrideManifest
@@ -1296,7 +1290,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
j.implementationAndResourcesJar = implementationAndResourcesJar
if ctx.Device() && hasSrcs &&
if ctx.Device() && j.hasCode(ctx) &&
(Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
// Dex compilation
var dexOutputFile android.ModuleOutPath
@@ -1501,6 +1495,11 @@ func (j *Module) CompilerDeps() []string {
return jdeps
}
func (j *Module) hasCode(ctx android.ModuleContext) bool {
srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0
}
//
// Java libraries (.jar file)
//