Improve error reporting when depending on prebuilt implementation jar

The sdk snapshot must not be including implementation code for boot
libraries, the implementation is provided by dex jars within the
corresponding APEX. However, the snapshot does need a module for each
boot library so that the build can seamlessly access the dex files from
the APEX.

A java_library boot library (like core-oj) is represented in the
snapshot by a java_import module which requires a jar file to be
provided, otherwise it is disabled. However, that is provided purely
to keep Soong happy and should never be used.

Previously, the snapshot would contain an empty file for the jar. As
an empty file is an invalid jar any tool (like compiler) that tried
to consume it would fail which was the correct behavior. Unfortunately,
the error message that was produced was not very helpful, it was just
some variant on `invalid file` which lead to a lot of bugs being
raised.

This change replaces that empty file with a reference to the output
from a genrule which runs a script which produces a more useful error
message, with information on how to fix the issue, and fails the build.

It also adds a Name() method to the SdkMemberProperties type as that is
needed in AddInternalModule() to construct the name of the additional
module.

Tested as follows:

In AOSP/master make the following changes:
1. Temporarily set visibility on core-oj and core-libart to
   //visibility:public.
2. Run packages/modules/common/build/mainline_modules_sdks.py to create
   the snapshots.

For each of the S, T and latest snapshots I did the following in the
s-aml-prebuilt-test, t-aml-prebuilt-test and aosp/master branches:

1. Created an Android.bp file containing the following:
  java_library {
    name: "broken",
    static_libs: [
      "prebuilt_core-libart",
      "prebuilt_core-oj",
    ],
  }

2. Fix the visibility issues and run `m broken` where it fails with an
   invalid file.

3. Delete the contents of the prebuilts/module_sdk/art/current/sdk
   directory.

4. Unpack the relevant version of the art-module-sdk snapshot into the
   directory.

5. Run `m broken` where it fails with the helpful message.

6. Test the instructions on how to use the ninja -t path tool to
   identify the cause of the problem and fix it.

Bug: 257969510
Test: See above.
Change-Id: I125bde2d7202afff84c97daebcef37e21c548a3a
This commit is contained in:
Paul Duffin
2022-10-20 17:21:40 +01:00
parent 7cc632d3d6
commit c61783b20d
7 changed files with 256 additions and 72 deletions

View File

@@ -1049,9 +1049,6 @@ type snapshotBuilder struct {
filesToZip android.Paths
zipsToMerge android.Paths
// The path to an empty file.
emptyFile android.WritablePath
prebuiltModules map[string]*bpModule
prebuiltOrder []*bpModule
@@ -1111,19 +1108,6 @@ func (s *snapshotBuilder) UnzipToSnapshot(zipPath android.Path, destDir string)
s.zipsToMerge = append(s.zipsToMerge, tmpZipPath)
}
func (s *snapshotBuilder) EmptyFile() android.Path {
if s.emptyFile == nil {
ctx := s.ctx
s.emptyFile = android.PathForModuleOut(ctx, "empty")
s.ctx.Build(pctx, android.BuildParams{
Rule: android.Touch,
Output: s.emptyFile,
})
}
return s.emptyFile
}
func (s *snapshotBuilder) AddPrebuiltModule(member android.SdkMember, moduleType string) android.BpModule {
name := member.Name()
if s.prebuiltModules[name] != nil {
@@ -1200,6 +1184,24 @@ func (s *snapshotBuilder) AddPrebuiltModule(member android.SdkMember, moduleType
return m
}
func (s *snapshotBuilder) AddInternalModule(properties android.SdkMemberProperties, moduleType string, nameSuffix string) android.BpModule {
name := properties.Name() + "-" + nameSuffix
if s.prebuiltModules[name] != nil {
panic(fmt.Sprintf("Duplicate module detected, module %s has already been added", name))
}
m := s.bpFile.newModule(moduleType)
m.AddProperty("name", name)
m.AddProperty("visibility", []string{"//visibility:private"})
s.prebuiltModules[name] = m
s.prebuiltOrder = append(s.prebuiltOrder, m)
s.allMembersByName[name] = struct{}{}
return m
}
func addHostDeviceSupportedProperties(deviceSupported bool, hostSupported bool, bpModule *bpModule) {
// If neither device or host is supported then this module does not support either so will not
// recognize the properties.
@@ -1230,18 +1232,23 @@ func (s *snapshotBuilder) OptionalSdkMemberReferencePropertyTag() android.BpProp
// Get a name for sdk snapshot member. If the member is private then generate a snapshot specific
// name. As part of the processing this checks to make sure that any required members are part of
// the snapshot.
func (s *snapshotBuilder) snapshotSdkMemberName(name string, required bool) string {
func (s *snapshotBuilder) snapshotSdkMemberName(reference string, required bool) string {
prefix := ""
name := strings.TrimPrefix(reference, ":")
if name != reference {
prefix = ":"
}
if _, ok := s.allMembersByName[name]; !ok {
if required {
s.ctx.ModuleErrorf("Required member reference %s is not a member of the sdk", name)
}
return name
return reference
}
if s.isInternalMember(name) {
return s.ctx.ModuleName() + "_" + name
return prefix + s.ctx.ModuleName() + "_" + name
} else {
return name
return reference
}
}
@@ -2057,6 +2064,7 @@ func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModu
variantPropertiesFactory := func() android.SdkMemberProperties {
properties := memberType.CreateVariantPropertiesStruct()
base := properties.Base()
base.MemberName = member.Name()
base.Os_count = osCount
return properties
}