From fee57cb33e83f04f5c29b4b1a669be3b4b87264f Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 5 Sep 2017 13:16:45 -0700 Subject: [PATCH] Move error_prone config to external/error_prone The error_prone config will likely need to be updated at the same time as the error_prone prebuilts, so move the config into the same project. This requires jumping through some hoops because external/error_prone may not be present in all manifests. Bug: 64489631 Test: m -j RUN_ERROR_PRONE=true Change-Id: I2c59df1148134ffedac0e00d32ac7082a9fb5330 --- Android.bp | 2 +- java/builder.go | 10 +++- java/config/config.go | 5 +- java/config/error_prone.go | 45 +++++++++++++++++ java/config/errorprone.go | 100 ------------------------------------- 5 files changed, 56 insertions(+), 106 deletions(-) create mode 100644 java/config/error_prone.go delete mode 100644 java/config/errorprone.go diff --git a/Android.bp b/Android.bp index a2ce8a302..89bd6ea9f 100644 --- a/Android.bp +++ b/Android.bp @@ -222,7 +222,7 @@ bootstrap_go_package { ], srcs: [ "java/config/config.go", - "java/config/errorprone.go", + "java/config/error_prone.go", "java/config/makevars.go", ], } diff --git a/java/builder.go b/java/builder.go index 6912c872e..e359529a5 100644 --- a/java/builder.go +++ b/java/builder.go @@ -21,9 +21,10 @@ package java import ( "strings" - "android/soong/android" - "github.com/google/blueprint" + + "android/soong/android" + "android/soong/java/config" ) var ( @@ -166,6 +167,11 @@ func TransformJavaToClasses(ctx android.ModuleContext, srcFiles android.Paths, s func RunErrorProne(ctx android.ModuleContext, srcFiles android.Paths, srcFileLists android.Paths, flags javaBuilderFlags, deps android.Paths) android.Path { + if config.ErrorProneJar == "" { + ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?") + return nil + } + classDir := android.PathForModuleOut(ctx, "classes-errorprone") annoDir := android.PathForModuleOut(ctx, "anno-errorprone") classFileList := android.PathForModuleOut(ctx, "classes-errorprone.list") diff --git a/java/config/config.go b/java/config/config.go index 4a5a2dd07..047c4cb43 100644 --- a/java/config/config.go +++ b/java/config/config.go @@ -26,15 +26,14 @@ import ( var ( pctx = android.NewPackageContext("android/soong/java/config") - JavacHeapSize = "2048M" - DefaultLibraries = []string{"core-oj", "core-libart", "ext", "framework", "okhttp"} ) func init() { pctx.Import("github.com/google/blueprint/bootstrap") - pctx.StaticVariable("JavacHeapFlags", "-J-Xmx"+JavacHeapSize) + pctx.StaticVariable("JavacHeapSize", "2048M") + pctx.StaticVariable("JavacHeapFlags", "-J-Xmx${JavacHeapSize}") pctx.StaticVariable("CommonJdkFlags", strings.Join([]string{ `-Xmaxerrs 9999999`, diff --git a/java/config/error_prone.go b/java/config/error_prone.go new file mode 100644 index 000000000..31cbf2c9e --- /dev/null +++ b/java/config/error_prone.go @@ -0,0 +1,45 @@ +// Copyright 2017 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package config + +var ( + // These will be filled out by external/error_prone/soong/error_prone.go if it is available + ErrorProneJavacJar string + ErrorProneJar string + ErrorProneClasspath string + ErrorProneChecksError string + ErrorProneFlags string +) + +// Wrapper that grabs value of val late so it can be initialized by a later module's init function +func errorProneVar(name string, val *string) { + pctx.VariableFunc(name, func(config interface{}) (string, error) { + return *val, nil + }) +} + +func init() { + errorProneVar("ErrorProneJar", &ErrorProneJar) + errorProneVar("ErrorProneJavacJar", &ErrorProneJavacJar) + errorProneVar("ErrorProneClasspath", &ErrorProneClasspath) + errorProneVar("ErrorProneChecksError", &ErrorProneChecksError) + errorProneVar("ErrorProneFlags", &ErrorProneFlags) + + pctx.StaticVariable("ErrorProneCmd", + "${JavaCmd} -Xmx${JavacHeapSize} -Xbootclasspath/p:${ErrorProneJavacJar} "+ + "-cp ${ErrorProneJar}:${ErrorProneClasspath} "+ + "${ErrorProneFlags} ${CommonJdkFlags} ${ErrorProneChecksError}") + +} diff --git a/java/config/errorprone.go b/java/config/errorprone.go deleted file mode 100644 index ddb9902ed..000000000 --- a/java/config/errorprone.go +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2017 Google Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package config - -import ( - "strings" -) - -func init() { - pctx.SourcePathVariable("ErrorProneJavacJar", "external/error_prone/javac/javac-9-dev-r3297-4.jar") - pctx.SourcePathVariable("ErrorProneJar", "external/error_prone/error_prone/error_prone_core-2.0.19-with-dependencies.jar") - pctx.SourcePathsVariable("ErrorProneClasspath", ":", - "external/error_prone/error_prone/error_prone_annotations-2.0.19.jar", - "external/error_prone/checkerframework/dataflow-1.8.10.jar", - "external/error_prone/checkerframework/javacutil-1.8.10.jar", - "external/error_prone/jFormatString/jFormatString-3.0.0.jar") - - // The checks that are fatal to the build. - pctx.StaticVariable("ErrorProneChecksError", strings.Join([]string{ - "-Xep:AsyncCallableReturnsNull:ERROR", - "-Xep:AsyncFunctionReturnsNull:ERROR", - "-Xep:BundleDeserializationCast:ERROR", - "-Xep:CompatibleWithAnnotationMisuse:ERROR", - "-Xep:CompileTimeConstant:ERROR", - "-Xep:DaggerProvidesNull:ERROR", - "-Xep:DoNotCall:ERROR", - "-Xep:ForOverride:ERROR", - "-Xep:FunctionalInterfaceMethodChanged:ERROR", - "-Xep:FuturesGetCheckedIllegalExceptionType:ERROR", - "-Xep:GuiceAssistedInjectScoping:ERROR", - "-Xep:GuiceAssistedParameters:ERROR", - "-Xep:GuiceInjectOnFinalField:ERROR", - "-Xep:Immutable:ERROR", - "-Xep:ImmutableModification:ERROR", - "-Xep:IncompatibleArgumentType:ERROR", - "-Xep:IndexOfChar:ERROR", - "-Xep:InjectMoreThanOneScopeAnnotationOnClass:ERROR", - "-Xep:JavaxInjectOnAbstractMethod:ERROR", - "-Xep:JUnit4SetUpNotRun:ERROR", - "-Xep:JUnit4TearDownNotRun:ERROR", - "-Xep:JUnit4TestNotRun:ERROR", - "-Xep:JUnitAssertSameCheck:ERROR", - "-Xep:LiteByteStringUtf8:ERROR", - "-Xep:LoopConditionChecker:ERROR", - "-Xep:MockitoCast:ERROR", - "-Xep:MockitoUsage:ERROR", - "-Xep:MoreThanOneInjectableConstructor:ERROR", - "-Xep:MustBeClosedChecker:ERROR", - "-Xep:NonCanonicalStaticImport:ERROR", - "-Xep:NonFinalCompileTimeConstant:ERROR", - "-Xep:OptionalEquality:ERROR", - "-Xep:OverlappingQualifierAndScopeAnnotation:ERROR", - "-Xep:PackageInfo:ERROR", - "-Xep:PreconditionsCheckNotNull:ERROR", - "-Xep:PreconditionsCheckNotNullPrimitive:ERROR", - "-Xep:ProtoFieldNullComparison:ERROR", - "-Xep:ProvidesMethodOutsideOfModule:ERROR", - "-Xep:RestrictedApiChecker:ERROR", - "-Xep:SelfAssignment:ERROR", - "-Xep:StreamToString:ERROR", - "-Xep:SuppressWarningsDeprecated:ERROR", - "-Xep:ThrowIfUncheckedKnownChecked:ERROR", - "-Xep:ThrowNull:ERROR", - "-Xep:TypeParameterQualifier:ERROR", - "-Xep:UnnecessaryTypeArgument:ERROR", - "-Xep:UnusedAnonymousClass:ERROR", - }, " ")) - - pctx.StaticVariable("ErrorProneHeapFlags", "-Xmx"+JavacHeapSize) - - pctx.StaticVariable("ErrorProneFlags", strings.Join([]string{ - "com.google.errorprone.ErrorProneCompiler", - "-Xdiags:verbose", - "-XDcompilePolicy=simple", - "-XDallowBetterNullChecks=false", - "-XDusePolyAttribution=true", - "-XDuseStrictMethodClashCheck=true", - "-XDuseStructuralMostSpecificResolution=true", - "-XDuseGraphInference=true", - "-XDandroidCompatible=true", - "-XepAllErrorsAsWarnings", - }, " ")) - - pctx.StaticVariable("ErrorProneCmd", - "${JavaCmd} ${ErrorProneHeapFlags} -Xbootclasspath/p:${ErrorProneJavacJar} "+ - "-cp ${ErrorProneJar}:${ErrorProneClasspath} "+ - "${ErrorProneFlags} ${CommonJdkFlags} ${ErrorProneChecksError}") -}