diff options
Diffstat (limited to 'java')
| -rw-r--r-- | java/aar.go | 8 | ||||
| -rw-r--r-- | java/app_builder.go | 4 | ||||
| -rw-r--r-- | java/config/kotlin.go | 6 | ||||
| -rw-r--r-- | java/dex.go | 5 | ||||
| -rw-r--r-- | java/droiddoc.go | 21 | ||||
| -rw-r--r-- | java/java.go | 46 | ||||
| -rw-r--r-- | java/java_test.go | 61 | ||||
| -rw-r--r-- | java/sdk_library.go | 6 |
8 files changed, 138 insertions, 19 deletions
diff --git a/java/aar.go b/java/aar.go index a49aef0a2..99e9136d8 100644 --- a/java/aar.go +++ b/java/aar.go @@ -157,11 +157,9 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, mani } func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkContext sdkContext) { - if !ctx.Config().UnbundledBuild() { - sdkDep := decodeSdkDep(ctx, sdkContext) - if sdkDep.frameworkResModule != "" { - ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule) - } + sdkDep := decodeSdkDep(ctx, sdkContext) + if sdkDep.frameworkResModule != "" { + ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule) } } diff --git a/java/app_builder.go b/java/app_builder.go index b0983bde3..28fc4c490 100644 --- a/java/app_builder.go +++ b/java/app_builder.go @@ -32,10 +32,10 @@ var ( Signapk = pctx.AndroidStaticRule("signapk", blueprint.RuleParams{ Command: `${config.JavaCmd} -Djava.library.path=$$(dirname $signapkJniLibrary) ` + - `-jar $signapkCmd $certificates $in $out`, + `-jar $signapkCmd $flags $certificates $in $out`, CommandDeps: []string{"$signapkCmd", "$signapkJniLibrary"}, }, - "certificates") + "flags", "certificates") androidManifestMerger = pctx.AndroidStaticRule("androidManifestMerger", blueprint.RuleParams{ diff --git a/java/config/kotlin.go b/java/config/kotlin.go index 35f9e9d72..432840e55 100644 --- a/java/config/kotlin.go +++ b/java/config/kotlin.go @@ -15,7 +15,11 @@ package config var ( - KotlinStdlibJar = "external/kotlinc/lib/kotlin-stdlib.jar" + KotlinStdlibJar = "external/kotlinc/lib/kotlin-stdlib.jar" + KotlincIllegalFlags = []string{ + "-no-jdk", + "-no-stdlib", + } ) func init() { diff --git a/java/dex.go b/java/dex.go index 5cec3252e..a6d486ab5 100644 --- a/java/dex.go +++ b/java/dex.go @@ -160,6 +160,11 @@ func (j *Module) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8F // 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. + // Don't strip out debug information for eng builds. + if ctx.Config().Eng() { + r8Flags = append(r8Flags, "--debug") + } + return r8Flags, r8Deps } diff --git a/java/droiddoc.go b/java/droiddoc.go index 9dadb30e5..9cde18987 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -360,6 +360,9 @@ type DroidstubsProperties struct { // a list of top-level directories containing Java stub files to merge show/hide annotations from. Merge_inclusion_annotations_dirs []string + // a file containing a list of classes to do nullability validation for. + Validate_nullability_from_list *string + // a file containing expected warnings produced by validation of nullability annotations. Check_nullability_warnings *string @@ -1126,9 +1129,9 @@ func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.P Inputs: d.Javadoc.srcFiles, Implicits: implicits, Args: map[string]string{ - "outDir": android.PathForModuleOut(ctx, "out").String(), - "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(), - "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(), + "outDir": android.PathForModuleOut(ctx, "dokka-out").String(), + "srcJarDir": android.PathForModuleOut(ctx, "dokka-srcjars").String(), + "stubsDir": android.PathForModuleOut(ctx, "dokka-stubsDir").String(), "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "), "classpathArgs": classpathArgs, "opts": opts, @@ -1302,6 +1305,9 @@ func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) { } } + if String(d.properties.Validate_nullability_from_list) != "" { + android.ExtractSourceDeps(ctx, d.properties.Validate_nullability_from_list) + } if String(d.properties.Check_nullability_warnings) != "" { android.ExtractSourceDeps(ctx, d.properties.Check_nullability_warnings) } @@ -1411,7 +1417,9 @@ func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext, var flags string if Bool(d.properties.Annotations_enabled) { flags += " --include-annotations" - validatingNullability := strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") + validatingNullability := + strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") || + String(d.properties.Validate_nullability_from_list) != "" migratingNullability := String(d.properties.Previous_api) != "" if !(migratingNullability || validatingNullability) { ctx.PropertyErrorf("previous_api", @@ -1422,6 +1430,9 @@ func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext, *implicits = append(*implicits, previousApi) flags += " --migrate-nullness " + previousApi.String() } + if s := String(d.properties.Validate_nullability_from_list); s != "" { + flags += " --validate-nullability-from-list " + ctx.ExpandSource(s, "validate_nullability_from_list").String() + } if validatingNullability { d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt") *implicitOutputs = append(*implicitOutputs, d.nullabilityWarningsFile) @@ -1574,7 +1585,7 @@ func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext, Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile}, implicits...), Args: map[string]string{ - "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(), + "srcJarDir": android.PathForModuleOut(ctx, "apicheck-srcjars").String(), "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "), "javaVersion": javaVersion, "bootclasspathArgs": bootclasspathArgs, diff --git a/java/java.go b/java/java.go index 50c284a94..5ed99f7e8 100644 --- a/java/java.go +++ b/java/java.go @@ -89,6 +89,9 @@ type CompilerProperties struct { // list of module-specific flags that will be used for javac compiles Javacflags []string `android:"arch_variant"` + // list of module-specific flags that will be used for kotlinc compiles + Kotlincflags []string `android:"arch_variant"` + // list of of java libraries that will be in the classpath Libs []string `android:"arch_variant"` @@ -330,6 +333,10 @@ func (j *Module) Srcs() android.Paths { return android.Paths{j.outputFile} } +func (j *Module) DexJarFile() android.Path { + return j.dexJarFile +} + var _ android.SourceFileProducer = (*Module)(nil) type Dependency interface { @@ -1083,13 +1090,21 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path var kotlinJars android.Paths if srcFiles.HasExt(".kt") { + // user defined kotlin flags. + kotlincFlags := j.properties.Kotlincflags + CheckKotlincFlags(ctx, kotlincFlags) + // If there are kotlin files, compile them first but pass all the kotlin and java files // kotlinc will use the java files to resolve types referenced by the kotlin files, but // won't emit any classes for them. - - flags.kotlincFlags = "-no-stdlib" + kotlincFlags = append(kotlincFlags, "-no-stdlib") if ctx.Device() { - flags.kotlincFlags += " -no-jdk" + kotlincFlags = append(kotlincFlags, "-no-jdk") + } + if len(kotlincFlags) > 0 { + // optimization. + ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " ")) + flags.kotlincFlags += "$kotlincFlags" } var kotlinSrcFiles android.Paths @@ -1328,6 +1343,31 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path j.outputFile = outputFile.WithoutRel() } +// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user, +// since some of these flags may be used internally. +func CheckKotlincFlags(ctx android.ModuleContext, flags []string) { + for _, flag := range flags { + flag = strings.TrimSpace(flag) + + if !strings.HasPrefix(flag, "-") { + ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag) + } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") { + ctx.PropertyErrorf("kotlincflags", + "Bad flag: `%s`, only use internal compiler for consistency.", flag) + } else if inList(flag, config.KotlincIllegalFlags) { + ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag) + } else if flag == "-include-runtime" { + ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag) + } else { + args := strings.Split(flag, " ") + if args[0] == "-kotlin-home" { + ctx.PropertyErrorf("kotlincflags", + "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag) + } + } + } +} + func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths, deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path { diff --git a/java/java_test.go b/java/java_test.go index 86349fe67..4d4b83618 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1124,3 +1124,64 @@ func TestJavaSdkLibrary(t *testing.T) { } } } + +var compilerFlagsTestCases = []struct { + in string + out bool +}{ + { + in: "a", + out: false, + }, + { + in: "-a", + out: true, + }, + { + in: "-no-jdk", + out: false, + }, + { + in: "-no-stdlib", + out: false, + }, + { + in: "-kotlin-home", + out: false, + }, + { + in: "-kotlin-home /some/path", + out: false, + }, + { + in: "-include-runtime", + out: false, + }, + { + in: "-Xintellij-plugin-root", + out: false, + }, +} + +type mockContext struct { + android.ModuleContext + result bool +} + +func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) { + // CheckBadCompilerFlags calls this function when the flag should be rejected + ctx.result = false +} + +func TestCompilerFlags(t *testing.T) { + for _, testCase := range compilerFlagsTestCases { + ctx := &mockContext{result: true} + CheckKotlincFlags(ctx, []string{testCase.in}) + if ctx.result != testCase.out { + t.Errorf("incorrect output:") + t.Errorf(" input: %#v", testCase.in) + t.Errorf(" expected: %#v", testCase.out) + t.Errorf(" got: %#v", ctx.result) + } + } +} diff --git a/java/sdk_library.go b/java/sdk_library.go index e513a59aa..573fc8ef5 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -229,19 +229,19 @@ func (module *sdkLibrary) AndroidMk() android.AndroidMkData { // Create dist rules to install the stubs libs to the dist dir if len(module.publicApiStubsPath) == 1 { fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ - module.publicApiStubsPath.Strings()[0]+ + module.publicApiStubsImplPath.Strings()[0]+ ":"+path.Join("apistubs", owner, "public", module.BaseModuleName()+".jar")+")") } if len(module.systemApiStubsPath) == 1 { fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ - module.systemApiStubsPath.Strings()[0]+ + module.systemApiStubsImplPath.Strings()[0]+ ":"+path.Join("apistubs", owner, "system", module.BaseModuleName()+".jar")+")") } if len(module.testApiStubsPath) == 1 { fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ - module.testApiStubsPath.Strings()[0]+ + module.testApiStubsImplPath.Strings()[0]+ ":"+path.Join("apistubs", owner, "test", module.BaseModuleName()+".jar")+")") } |