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