From 094054ab0761903626f27d32781dc64b67534219 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 17 Oct 2018 15:10:48 -0700 Subject: Support main_class property in java_binary modules Add a main_class property that will be used to generate a manifest containing a Main-Class entry. Test: m checkbuild Change-Id: I0a59bb2b93cad915afd82fba708fa0f7eda2fe7a --- java/java.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index e5218bb76..c15a62b24 100644 --- a/java/java.go +++ b/java/java.go @@ -309,6 +309,9 @@ type Module struct { // list of extra progurad flag files extraProguardFlagFiles android.Paths + // manifest file to use instead of properties.Manifest + overrideManifest android.OptionalPath + // list of SDK lib names that this java moudule is exporting exportedSdkLibs []string @@ -1193,8 +1196,8 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path jars = append(jars, deps.staticJars...) jars = append(jars, deps.staticResourceJars...) - var manifest android.OptionalPath - if j.properties.Manifest != nil { + manifest := j.overrideManifest + if !manifest.Valid() && j.properties.Manifest != nil { manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest")) } @@ -1536,6 +1539,9 @@ func TestHostFactory() android.Module { type binaryProperties struct { // installable script to execute the resulting jar Wrapper *string + + // Name of the class containing main to be inserted into the manifest as Main-Class. + Main_class *string } type Binary struct { @@ -1556,6 +1562,15 @@ func (j *Binary) HostToolPath() android.OptionalPath { func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { if ctx.Arch().ArchType == android.Common { // Compile the jar + if j.binaryProperties.Main_class != nil { + if j.properties.Manifest != nil { + ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set") + } + manifestFile := android.PathForModuleOut(ctx, "manifest.txt") + GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class)) + j.overrideManifest = android.OptionalPathForPath(manifestFile) + } + j.Library.GenerateAndroidBuildActions(ctx) } else { // Handle the binary wrapper -- cgit v1.2.3-59-g8ed1b From 4b964c00a6f114a85cf13ef825e72df25985f8e6 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 15 Oct 2018 16:18:06 -0700 Subject: Fix instrumentation_for to match LOCAL_INSTRUMENTATION_FOR The value from instrumentation_for should not go to aapt2 link --rename-instrumentation-target-package, that should be the equivalent of LOCAL_MANIFEST_INSTRUMENTATION_FOR. That property is never used in Make, so it is left unimplemented in Soong. Add the module listed in instrumentation_for as a shared library for javac, but don't import its resources. Bug: 117804211 Test: m checkbuild Change-Id: I7f035dc0ecb964a3ca391ae1ca2b87cb0f6a7cec --- java/aar.go | 2 ++ java/app.go | 12 ++++++------ java/dex.go | 4 ++-- java/java.go | 23 ++++++++++++----------- 4 files changed, 22 insertions(+), 19 deletions(-) (limited to 'java/java.go') diff --git a/java/aar.go b/java/aar.go index 35fb96f78..a06d19164 100644 --- a/java/aar.go +++ b/java/aar.go @@ -250,6 +250,8 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati } switch ctx.OtherModuleDependencyTag(module) { + case instrumentationForTag: + // Nothing, instrumentationForTag is treated as libTag for javac but not for aapt2. case libTag, frameworkResTag: if exportPackage != nil { sharedLibs = append(sharedLibs, exportPackage) diff --git a/java/app.go b/java/app.go index d21b62aec..5d25dcf17 100644 --- a/java/app.go +++ b/java/app.go @@ -318,12 +318,6 @@ type AndroidTest struct { } func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { - if String(a.appTestProperties.Instrumentation_for) != "" { - a.AndroidApp.extraLinkFlags = append(a.AndroidApp.extraLinkFlags, - "--rename-instrumentation-target-package", - String(a.appTestProperties.Instrumentation_for)) - } - a.generateAndroidBuildActions(ctx) a.testConfig = tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config, a.testProperties.Test_config_template, a.manifestPath) @@ -335,6 +329,12 @@ func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) { android.ExtractSourceDeps(ctx, a.testProperties.Test_config_template) android.ExtractSourcesDeps(ctx, a.testProperties.Data) a.AndroidApp.DepsMutator(ctx) + if a.appTestProperties.Instrumentation_for != nil { + // The android_app dependency listed in instrumentation_for needs to be added to the classpath for javac, + // but not added to the aapt2 link includes like a normal android_app or android_library dependency, so + // use instrumentationForTag instead of libTag. + ctx.AddVariationDependencies(nil, instrumentationForTag, String(a.appTestProperties.Instrumentation_for)) + } } func AndroidTestFactory() android.Module { diff --git a/java/dex.go b/java/dex.go index ce0c18e66..625fb83cc 100644 --- a/java/dex.go +++ b/java/dex.go @@ -157,6 +157,8 @@ func (j *Module) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8F if !Bool(opt.Obfuscate) { r8Flags = append(r8Flags, "-dontobfuscate") } + // TODO(ccross): if this is an instrumentation test of an obfuscated app, use the + // dictionary of the app and move the app from libraryjars to injars. return r8Flags, r8Deps } @@ -171,8 +173,6 @@ func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, outDir := android.PathForModuleOut(ctx, "dex") if useR8 { - // TODO(ccross): if this is an instrumentation test of an obfuscated app, use the - // dictionary of the app and move the app from libraryjars to injars. proguardDictionary := android.PathForModuleOut(ctx, "proguard_dictionary") j.proguardDictionary = proguardDictionary r8Flags, r8Deps := j.r8Flags(ctx, flags) diff --git a/java/java.go b/java/java.go index c15a62b24..d7068c6d9 100644 --- a/java/java.go +++ b/java/java.go @@ -371,16 +371,17 @@ type jniDependencyTag struct { } var ( - staticLibTag = dependencyTag{name: "staticlib"} - libTag = dependencyTag{name: "javalib"} - annoTag = dependencyTag{name: "annotation processor"} - bootClasspathTag = dependencyTag{name: "bootclasspath"} - systemModulesTag = dependencyTag{name: "system modules"} - frameworkResTag = dependencyTag{name: "framework-res"} - frameworkApkTag = dependencyTag{name: "framework-apk"} - kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"} - proguardRaiseTag = dependencyTag{name: "proguard-raise"} - certificateTag = dependencyTag{name: "certificate"} + staticLibTag = dependencyTag{name: "staticlib"} + libTag = dependencyTag{name: "javalib"} + annoTag = dependencyTag{name: "annotation processor"} + bootClasspathTag = dependencyTag{name: "bootclasspath"} + systemModulesTag = dependencyTag{name: "system modules"} + frameworkResTag = dependencyTag{name: "framework-res"} + frameworkApkTag = dependencyTag{name: "framework-apk"} + kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"} + proguardRaiseTag = dependencyTag{name: "proguard-raise"} + certificateTag = dependencyTag{name: "certificate"} + instrumentationForTag = dependencyTag{name: "instrumentation_for"} ) type sdkDep struct { @@ -820,7 +821,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { switch tag { case bootClasspathTag: deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...) - case libTag: + case libTag, instrumentationForTag: deps.classpath = append(deps.classpath, dep.HeaderJars()...) // sdk lib names from dependencies are re-exported j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...) -- cgit v1.2.3-59-g8ed1b