From a47df7fe25d1f2e3a0ea5ed4895c1aa266150784 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 6 Oct 2022 11:01:59 +0100 Subject: [PATCH] Add Config,RunningInsideUnitTest Sometimes it is necessary for some functionality to be disabled while running in unit tests, e.g. functionality that requires external information such as error prone tools and configuration. Sometimes it is necessary for some functionality to be enabled while running in unit tests, e.g. functionality that makes state available for testing but which is not necessary at runtime. Previously, that was done by checking to see if TestProductVariables was nil. This change adds a method to abstract that. Bug: 245956352 Test: m nothing Change-Id: I7845b79328e7180623161a9bf897568089da4e4f (cherry picked from commit 741355826fc314796b3e5ca4cb89e4d196e96b20) Merged-In: I7845b79328e7180623161a9bf897568089da4e4f --- android/config.go | 5 +++++ java/base.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/android/config.go b/android/config.go index ddae886e5..0bca7210b 100644 --- a/android/config.go +++ b/android/config.go @@ -93,6 +93,11 @@ func (c Config) PrimaryBuilderInvocations() []bootstrap.PrimaryBuilderInvocation return []bootstrap.PrimaryBuilderInvocation{} } +// RunningInsideUnitTest returns true if this code is being run as part of a Soong unit test. +func (c Config) RunningInsideUnitTest() bool { + return c.config.TestProductVariables != nil +} + // A DeviceConfig object represents the configuration for a particular device // being built. For now there will only be one of these, but in the future there // may be multiple devices being built. diff --git a/java/base.go b/java/base.go index b629f0f19..4e7b18c46 100644 --- a/java/base.go +++ b/java/base.go @@ -881,7 +881,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB epEnabled := j.properties.Errorprone.Enabled if (ctx.Config().RunErrorProne() && epEnabled == nil) || Bool(epEnabled) { - if config.ErrorProneClasspath == nil && ctx.Config().TestProductVariables == nil { + if config.ErrorProneClasspath == nil && !ctx.Config().RunningInsideUnitTest() { ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?") }