Merge "Replace panic with ModuleErrorf" into main am: ec3887ad2f
am: db7220eb70
am: 1ef21535e7
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2901513 Change-Id: I3e894707ca4a3866046de2f53d7c8c1ebd59477b Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -1286,7 +1286,7 @@ func (a *AARImport) ImplementationAndResourcesJars() android.Paths {
|
||||
return android.Paths{a.classpathFile}
|
||||
}
|
||||
|
||||
func (a *AARImport) DexJarBuildPath() android.Path {
|
||||
func (a *AARImport) DexJarBuildPath(ctx android.ModuleErrorfContext) android.Path {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -1639,7 +1639,7 @@ func (u *usesLibrary) classLoaderContextForUsesLibDeps(ctx android.ModuleContext
|
||||
replaceInList(u.usesLibraryProperties.Optional_uses_libs, dep, libName)
|
||||
}
|
||||
clcMap.AddContext(ctx, tag.sdkVersion, libName, tag.optional,
|
||||
lib.DexJarBuildPath().PathOrNil(), lib.DexJarInstallPath(),
|
||||
lib.DexJarBuildPath(ctx).PathOrNil(), lib.DexJarInstallPath(),
|
||||
lib.ClassLoaderContexts())
|
||||
} else if ctx.Config().AllowMissingDependencies() {
|
||||
ctx.AddMissingDependencies([]string{dep})
|
||||
|
@@ -1929,7 +1929,7 @@ func (j *Module) ImplementationJars() android.Paths {
|
||||
return android.Paths{j.implementationJarFile}
|
||||
}
|
||||
|
||||
func (j *Module) DexJarBuildPath() OptionalDexJarPath {
|
||||
func (j *Module) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath {
|
||||
return j.dexJarFile
|
||||
}
|
||||
|
||||
|
@@ -151,7 +151,7 @@ func (d *DeviceHostConverter) ImplementationAndResourcesJars() android.Paths {
|
||||
return d.implementationAndResourceJars
|
||||
}
|
||||
|
||||
func (d *DeviceHostConverter) DexJarBuildPath() android.Path {
|
||||
func (d *DeviceHostConverter) DexJarBuildPath(ctx android.ModuleErrorfContext) android.Path {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -291,7 +291,7 @@ func hiddenAPIRetrieveDexJarBuildPath(ctx android.ModuleContext, module android.
|
||||
if sdkLibrary, ok := module.(SdkLibraryDependency); ok {
|
||||
dexJar = sdkLibrary.SdkApiStubDexJar(ctx, kind)
|
||||
} else if j, ok := module.(UsesLibraryDependency); ok {
|
||||
dexJar = j.DexJarBuildPath()
|
||||
dexJar = j.DexJarBuildPath(ctx)
|
||||
} else {
|
||||
ctx.ModuleErrorf("dependency %s of module type %s does not support providing a dex jar", module, ctx.OtherModuleType(module))
|
||||
return nil
|
||||
@@ -1457,7 +1457,9 @@ func handleMissingDexBootFile(ctx android.ModuleContext, module android.Module,
|
||||
// However, under certain conditions, e.g. errors, or special build configurations it will return
|
||||
// a path to a fake file.
|
||||
func retrieveEncodedBootDexJarFromModule(ctx android.ModuleContext, module android.Module) android.Path {
|
||||
bootDexJar := module.(interface{ DexJarBuildPath() OptionalDexJarPath }).DexJarBuildPath()
|
||||
bootDexJar := module.(interface {
|
||||
DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath
|
||||
}).DexJarBuildPath(ctx)
|
||||
if !bootDexJar.Valid() {
|
||||
fake := android.PathForModuleOut(ctx, fmt.Sprintf("fake/encoded-dex/%s.jar", module.Name()))
|
||||
handleMissingDexBootFile(ctx, module, fake, bootDexJar.InvalidReason())
|
||||
|
@@ -309,7 +309,8 @@ func TestHiddenAPIEncoding_JavaSdkLibrary(t *testing.T) {
|
||||
android.AssertStringEquals(t, "encode embedded java_library", unencodedDexJar, actualUnencodedDexJar.String())
|
||||
|
||||
// Make sure that the encoded dex jar is the exported one.
|
||||
exportedDexJar := moduleForTests.Module().(UsesLibraryDependency).DexJarBuildPath().Path()
|
||||
errCtx := moduleErrorfTestCtx{}
|
||||
exportedDexJar := moduleForTests.Module().(UsesLibraryDependency).DexJarBuildPath(errCtx).Path()
|
||||
android.AssertPathRelativeToTopEquals(t, "encode embedded java_library", encodedDexJar, exportedDexJar)
|
||||
}
|
||||
|
||||
|
12
java/java.go
12
java/java.go
@@ -316,7 +316,7 @@ type ApexDependency interface {
|
||||
|
||||
// Provides build path and install path to DEX jars.
|
||||
type UsesLibraryDependency interface {
|
||||
DexJarBuildPath() OptionalDexJarPath
|
||||
DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath
|
||||
DexJarInstallPath() android.Path
|
||||
ClassLoaderContexts() dexpreopt.ClassLoaderContextMap
|
||||
}
|
||||
@@ -2013,7 +2013,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
})
|
||||
}
|
||||
|
||||
func (al *ApiLibrary) DexJarBuildPath() OptionalDexJarPath {
|
||||
func (al *ApiLibrary) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath {
|
||||
return al.dexJarFile
|
||||
}
|
||||
|
||||
@@ -2380,9 +2380,9 @@ func (j *Import) ImplementationAndResourcesJars() android.Paths {
|
||||
return android.Paths{j.combinedClasspathFile}
|
||||
}
|
||||
|
||||
func (j *Import) DexJarBuildPath() OptionalDexJarPath {
|
||||
func (j *Import) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath {
|
||||
if j.dexJarFileErr != nil {
|
||||
panic(j.dexJarFileErr.Error())
|
||||
ctx.ModuleErrorf(j.dexJarFileErr.Error())
|
||||
}
|
||||
return j.dexJarFile
|
||||
}
|
||||
@@ -2633,7 +2633,7 @@ func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
}
|
||||
}
|
||||
|
||||
func (j *DexImport) DexJarBuildPath() OptionalDexJarPath {
|
||||
func (j *DexImport) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath {
|
||||
return j.dexJarFile
|
||||
}
|
||||
|
||||
@@ -2801,7 +2801,7 @@ func addCLCFromDep(ctx android.ModuleContext, depModule android.Module,
|
||||
// from its CLC should be added to the current CLC.
|
||||
if sdkLib != nil {
|
||||
clcMap.AddContext(ctx, dexpreopt.AnySdkVersion, *sdkLib, false,
|
||||
dep.DexJarBuildPath().PathOrNil(), dep.DexJarInstallPath(), dep.ClassLoaderContexts())
|
||||
dep.DexJarBuildPath(ctx).PathOrNil(), dep.DexJarInstallPath(), dep.ClassLoaderContexts())
|
||||
} else {
|
||||
clcMap.AddContextMap(dep.ClassLoaderContexts(), depName)
|
||||
}
|
||||
|
@@ -528,6 +528,15 @@ func TestHostBinaryNoJavaDebugInfoOverride(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A minimal context object for use with DexJarBuildPath
|
||||
type moduleErrorfTestCtx struct {
|
||||
}
|
||||
|
||||
func (ctx moduleErrorfTestCtx) ModuleErrorf(format string, args ...interface{}) {
|
||||
}
|
||||
|
||||
var _ android.ModuleErrorfContext = (*moduleErrorfTestCtx)(nil)
|
||||
|
||||
func TestPrebuilts(t *testing.T) {
|
||||
ctx, _ := testJava(t, `
|
||||
java_library {
|
||||
@@ -595,7 +604,8 @@ func TestPrebuilts(t *testing.T) {
|
||||
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barJar.String())
|
||||
}
|
||||
|
||||
barDexJar := barModule.Module().(*Import).DexJarBuildPath()
|
||||
errCtx := moduleErrorfTestCtx{}
|
||||
barDexJar := barModule.Module().(*Import).DexJarBuildPath(errCtx)
|
||||
if barDexJar.IsSet() {
|
||||
t.Errorf("bar dex jar build path expected to be set, got %s", barDexJar)
|
||||
}
|
||||
@@ -608,7 +618,7 @@ func TestPrebuilts(t *testing.T) {
|
||||
t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, bazJar.String())
|
||||
}
|
||||
|
||||
bazDexJar := bazModule.Module().(*Import).DexJarBuildPath().Path()
|
||||
bazDexJar := bazModule.Module().(*Import).DexJarBuildPath(errCtx).Path()
|
||||
expectedDexJar := "out/soong/.intermediates/baz/android_common/dex/baz.jar"
|
||||
android.AssertPathRelativeToTopEquals(t, "baz dex jar build path", expectedDexJar, bazDexJar)
|
||||
|
||||
|
@@ -694,7 +694,7 @@ func (paths *scopePaths) extractStubsLibraryInfoFromDependency(ctx android.Modul
|
||||
paths.stubsImplPath = lib.ImplementationJars
|
||||
|
||||
libDep := dep.(UsesLibraryDependency)
|
||||
paths.stubsDexJarPath = libDep.DexJarBuildPath()
|
||||
paths.stubsDexJarPath = libDep.DexJarBuildPath(ctx)
|
||||
return nil
|
||||
} else {
|
||||
return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library")
|
||||
@@ -2828,11 +2828,11 @@ func (module *SdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleCont
|
||||
}
|
||||
|
||||
// to satisfy UsesLibraryDependency interface
|
||||
func (module *SdkLibraryImport) DexJarBuildPath() OptionalDexJarPath {
|
||||
func (module *SdkLibraryImport) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath {
|
||||
// The dex implementation jar extracted from the .apex file should be used in preference to the
|
||||
// source.
|
||||
if module.dexJarFileErr != nil {
|
||||
panic(module.dexJarFileErr.Error())
|
||||
ctx.ModuleErrorf(module.dexJarFileErr.Error())
|
||||
}
|
||||
if module.dexJarFile.IsSet() {
|
||||
return module.dexJarFile
|
||||
@@ -2840,7 +2840,7 @@ func (module *SdkLibraryImport) DexJarBuildPath() OptionalDexJarPath {
|
||||
if module.implLibraryModule == nil {
|
||||
return makeUnsetDexJarPath()
|
||||
} else {
|
||||
return module.implLibraryModule.DexJarBuildPath()
|
||||
return module.implLibraryModule.DexJarBuildPath(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user