Revert "Improve error reporting when depending on prebuilt implementation jar"

This reverts commit c61783b20d.

Bug: 257969510
Reason for revert: b/255275437 - breaks checkbuild target

Change-Id: I01f88053cc24dbc1a4eb5c009f15473bdff3d565
This commit is contained in:
Paul Duffin 2022-11-21 10:57:30 +00:00 committed by Gerrit Code Review
parent c61783b20d
commit 7ed6ff8c76
7 changed files with 72 additions and 256 deletions

View file

@ -232,6 +232,12 @@ type SnapshotBuilder interface {
// relative path) and add the dest to the zip.
CopyToSnapshot(src Path, dest string)
// EmptyFile returns the path to an empty file.
//
// This can be used by sdk member types that need to create an empty file in the snapshot, simply
// pass the value returned from this to the CopyToSnapshot() method.
EmptyFile() Path
// UnzipToSnapshot generates a rule that will unzip the supplied zip into the snapshot relative
// directory destDir.
UnzipToSnapshot(zipPath Path, destDir string)
@ -258,14 +264,6 @@ type SnapshotBuilder interface {
// See sdk/update.go for more information.
AddPrebuiltModule(member SdkMember, moduleType string) BpModule
// AddInternalModule creates a new module in the generated Android.bp file that can only be
// referenced by one of the other modules in the snapshot.
//
// The created module's name is constructed by concatenating the name of this member and the
// nameSuffix, separated by "-". It also has the visibility property set to "//visibility:private"
// to prevent it from being inadvertently accessed from outside the snapshot.
AddInternalModule(properties SdkMemberProperties, moduleType string, nameSuffix string) BpModule
// SdkMemberReferencePropertyTag returns a property tag to use when adding a property to a
// BpModule that contains references to other sdk members.
//
@ -924,12 +922,6 @@ func RegisterSdkMemberType(memberType SdkMemberType) {
//
// Contains common properties that apply across many different member types.
type SdkMemberPropertiesBase struct {
// The name of the member.
//
// Ignore this property during optimization. This is needed because this property is the same for
// all variants of a member and so would be optimized away if it was not ignored.
MemberName string `sdk:"ignore"`
// The number of unique os types supported by the member variants.
//
// If a member has a variant with more than one os type then it will need to differentiate
@ -953,10 +945,6 @@ type SdkMemberPropertiesBase struct {
Compile_multilib string `android:"arch_variant"`
}
func (b *SdkMemberPropertiesBase) Name() string {
return b.MemberName
}
// OsPrefix returns the os prefix to use for any file paths in the sdk.
//
// Is an empty string if the member only provides variants for a single os type, otherwise
@ -982,8 +970,6 @@ type SdkMemberProperties interface {
// Base returns the base structure.
Base() *SdkMemberPropertiesBase
Name() string
// PopulateFromVariant populates this structure with information from a module variant.
//
// It will typically be called once for each variant of a member module that the SDK depends upon.

View file

@ -1,61 +0,0 @@
#!/bin/bash
# Copyright 2022 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.
# Script to detect and report an attempt to access an invalid implementation
# jar.
MOD=$1
cat <<EOF
$MOD is a java_library that generates a jar file which must not be accessed
from outside the mainline module that provides it. If you are seeing this
message it means that you are incorrectly attempting to use the jar file
from a java_import prebuilt of $MOD.
This is most likely due to an incorrect dependency on $MOD in an Android.mk
or Android.bp file. Please remove that dependency and replace with
something more appropriate, e.g. a dependency on an API provided by the
module.
If you do not know where the extraneous dependency was added then you can
run the following command to find a list of all the paths from the target
which you are trying to build to the target which produced this error.
prebuilts/build-tools/linux-x86/bin/ninja -f out/combined-\${TARGET_PRODUCT}.ninja -t path <target> <invalid-jar>
Where <target> is the build target you specified on the command line which
produces this error and <invalid-jar> is the rule that failed with this
message. If you are specifying multiple build targets then you will need to
run the above command for every target until you find the cause.
The command will output one (of the possibly many) dependency paths from
<target> to <invalid-jar>, one file/phony target per line. e.g. it may
output something like this:
....
out/soong/.intermediates/acme/broken/android_common/combined/broken.jar
out/soong/.intermediates/prebuilts/module_sdk/art/current/sdk/prebuilt_core-libart/android_common/combined/core-libart.jar
out/soong/.intermediates/prebuilts/module_sdk/art/current/sdk/art-module-sdk_core-libart-error/gen/this-file-will-never-be-created.jar
The last line is the failing target, the second to last line is a dependency
from the core-libart java_import onto the failing target, the third to last
line is the source of the dependency so you should look in acme/Android.bp
file for the "broken" module.
EOF
exit 1

View file

@ -86,11 +86,11 @@ func RegisterJavaSdkMemberTypes() {
var (
// Supports adding java header libraries to module_exports and sdk.
javaHeaderLibsSdkMemberType = &librarySdkMemberType{
SdkMemberTypeBase: android.SdkMemberTypeBase{
android.SdkMemberTypeBase{
PropertyName: "java_header_libs",
SupportsSdk: true,
},
jarToExportGetter: func(_ android.SdkMemberContext, j *Library) android.Path {
func(_ android.SdkMemberContext, j *Library) android.Path {
headerJars := j.HeaderJars()
if len(headerJars) != 1 {
panic(fmt.Errorf("there must be only one header jar from %q", j.Name()))
@ -98,8 +98,8 @@ var (
return headerJars[0]
},
snapshotPathGetter: sdkSnapshotFilePathForJar,
onlyCopyJarToSnapshot: copyEverythingToSnapshot,
sdkSnapshotFilePathForJar,
copyEverythingToSnapshot,
}
// Export implementation classes jar as part of the sdk.
@ -113,12 +113,12 @@ var (
// Supports adding java implementation libraries to module_exports but not sdk.
javaLibsSdkMemberType = &librarySdkMemberType{
SdkMemberTypeBase: android.SdkMemberTypeBase{
android.SdkMemberTypeBase{
PropertyName: "java_libs",
},
jarToExportGetter: exportImplementationClassesJar,
snapshotPathGetter: sdkSnapshotFilePathForJar,
onlyCopyJarToSnapshot: copyEverythingToSnapshot,
exportImplementationClassesJar,
sdkSnapshotFilePathForJar,
copyEverythingToSnapshot,
}
snapshotRequiresImplementationJar = func(ctx android.SdkMemberContext) bool {
@ -143,11 +143,11 @@ var (
// necessary. The java_boot_libs property to allow those modules to be exported as part of the
// sdk/module_exports without exposing any unnecessary information.
javaBootLibsSdkMemberType = &librarySdkMemberType{
SdkMemberTypeBase: android.SdkMemberTypeBase{
android.SdkMemberTypeBase{
PropertyName: "java_boot_libs",
SupportsSdk: true,
},
jarToExportGetter: func(ctx android.SdkMemberContext, j *Library) android.Path {
func(ctx android.SdkMemberContext, j *Library) android.Path {
if snapshotRequiresImplementationJar(ctx) {
return exportImplementationClassesJar(ctx, j)
}
@ -156,9 +156,9 @@ var (
// jar for use by dexpreopting and boot jars package check. They do not need to provide an
// actual implementation jar but the java_import will need a file that exists so just copy an
// empty file. Any attempt to use that file as a jar will cause a build error.
return nil
return ctx.SnapshotBuilder().EmptyFile()
},
snapshotPathGetter: func(ctx android.SdkMemberContext, osPrefix, name string) string {
func(ctx android.SdkMemberContext, osPrefix, name string) string {
if snapshotRequiresImplementationJar(ctx) {
return sdkSnapshotFilePathForJar(ctx, osPrefix, name)
}
@ -168,7 +168,7 @@ var (
// TODO(b/175714559): Provide a proper error message in Soong not ninja.
return filepath.Join(osPrefix, "java_boot_libs", "snapshot", "jars", "are", "invalid", name+jarFileSuffix)
},
onlyCopyJarToSnapshot: onlyCopyJarToSnapshot,
onlyCopyJarToSnapshot,
}
// Supports adding java systemserver libraries to module_exports and sdk.
@ -182,27 +182,27 @@ var (
// necessary. The java_systemserver_libs property to allow those modules to be exported as part of
// the sdk/module_exports without exposing any unnecessary information.
javaSystemserverLibsSdkMemberType = &librarySdkMemberType{
SdkMemberTypeBase: android.SdkMemberTypeBase{
android.SdkMemberTypeBase{
PropertyName: "java_systemserver_libs",
SupportsSdk: true,
// This was only added in Tiramisu.
SupportedBuildReleaseSpecification: "Tiramisu+",
},
jarToExportGetter: func(ctx android.SdkMemberContext, j *Library) android.Path {
func(ctx android.SdkMemberContext, j *Library) android.Path {
// Java systemserver libs are only provided in the SDK to provide access to their dex
// implementation jar for use by dexpreopting. They do not need to provide an actual
// implementation jar but the java_import will need a file that exists so just copy an empty
// file. Any attempt to use that file as a jar will cause a build error.
return nil
return ctx.SnapshotBuilder().EmptyFile()
},
snapshotPathGetter: func(_ android.SdkMemberContext, osPrefix, name string) string {
func(_ android.SdkMemberContext, osPrefix, name string) string {
// Create a special name for the implementation jar to try and provide some useful information
// to a developer that attempts to compile against this.
// TODO(b/175714559): Provide a proper error message in Soong not ninja.
return filepath.Join(osPrefix, "java_systemserver_libs", "snapshot", "jars", "are", "invalid", name+jarFileSuffix)
},
onlyCopyJarToSnapshot: onlyCopyJarToSnapshot,
onlyCopyJarToSnapshot,
}
// Supports adding java test libraries to module_exports but not sdk.
@ -232,7 +232,7 @@ type JavaInfo struct {
ImplementationAndResourcesJars android.Paths
// ImplementationJars is a list of jars that contain the implementations of classes in the
// module.
//module.
ImplementationJars android.Paths
// ResourceJars is a list of jars that contain the resources included in the module.
@ -718,8 +718,7 @@ type librarySdkMemberType struct {
android.SdkMemberTypeBase
// Function to retrieve the appropriate output jar (implementation or header) from
// the library, if this returns nil then it is assumed that the snapshot must not provide access
// to the jar.
// the library.
jarToExportGetter func(ctx android.SdkMemberContext, j *Library) android.Path
// Function to compute the snapshot relative path to which the named library's
@ -756,11 +755,7 @@ func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMembe
type librarySdkMemberProperties struct {
android.SdkMemberPropertiesBase
JarToExport android.Path `android:"arch_variant"`
// The path to a script to use when the jar is invalid.
InvalidJarScript android.Path
JarToExport android.Path `android:"arch_variant"`
AidlIncludeDirs android.Paths
// The list of permitted packages that need to be passed to the prebuilts as they are used to
@ -771,15 +766,7 @@ type librarySdkMemberProperties struct {
func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
j := variant.(*Library)
memberType := ctx.MemberType().(*librarySdkMemberType)
p.JarToExport = memberType.jarToExportGetter(ctx, j)
// If no jar was provided for export then disallow access to it completely.
if p.JarToExport == nil {
// Copy the script to prevent access to the jar into the snapshot.
p.InvalidJarScript = android.PathForSource(ctx.SdkModuleContext(),
"build/soong/java/invalid_implementation_jar.sh")
}
p.JarToExport = ctx.MemberType().(*librarySdkMemberType).jarToExportGetter(ctx, j)
p.AidlIncludeDirs = j.AidlIncludeDirs()
@ -802,21 +789,6 @@ func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberConte
propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
}
if scriptSrc := p.InvalidJarScript; scriptSrc != nil {
// Copy the script to prevent access to the jar into the snapshot.
scriptDest := filepath.Join("scripts", scriptSrc.Base())
builder.CopyToSnapshot(scriptSrc, scriptDest)
// Generate a genrule module that will invoke the script passing in the module name.
genrule := builder.AddInternalModule(p, "genrule", "error")
genRuleName := genrule.Name()
genrule.AddProperty("out", []string{"this-file-will-never-be-created.jar"})
genrule.AddProperty("tool_files", []string{scriptDest})
genrule.AddProperty("cmd", fmt.Sprintf("$(location %s) %s", scriptDest, p.Name()))
propertySet.AddPropertyWithTag("jars", []string{":" + genRuleName}, builder.SdkMemberReferencePropertyTag(true))
}
if len(p.PermittedPackages) > 0 {
propertySet.AddProperty("permitted_packages", p.PermittedPackages)
}
@ -1678,7 +1650,7 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
}
func (j *Import) commonBuildActions(ctx android.ModuleContext) {
// TODO(b/231322772) these should come from Bazel once available
//TODO(b/231322772) these should come from Bazel once available
j.sdkVersion = j.SdkVersion(ctx)
j.minSdkVersion = j.MinSdkVersion(ctx)
@ -2281,7 +2253,7 @@ func (m *Library) convertJavaResourcesAttributes(ctx android.TopDownMutatorConte
resources.Append(android.BazelLabelForModuleSrc(ctx, m.properties.Java_resources))
}
// TODO(b/179889880) handle case where glob includes files outside package
//TODO(b/179889880) handle case where glob includes files outside package
resDeps := ResourceDirsToFiles(
ctx,
m.properties.Java_resource_dirs,
@ -2429,7 +2401,7 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
}
epEnabled := m.properties.Errorprone.Enabled
// TODO(b/227504307) add configuration that depends on RUN_ERROR_PRONE environment variable
//TODO(b/227504307) add configuration that depends on RUN_ERROR_PRONE environment variable
if Bool(epEnabled) {
javacopts = append(javacopts, m.properties.Errorprone.Javacflags...)
}
@ -2665,7 +2637,7 @@ func (i *Import) ProcessBazelQueryResponse(ctx android.ModuleContext) {
HeaderJars: android.PathsIfNonNil(i.combinedClasspathFile),
ImplementationAndResourcesJars: android.PathsIfNonNil(i.combinedClasspathFile),
ImplementationJars: android.PathsIfNonNil(i.combinedClasspathFile),
// TODO(b/240308299) include AIDL information from Bazel
//TODO(b/240308299) include AIDL information from Bazel
})
i.maybeInstall(ctx, jarName, outputFile)

View file

@ -169,15 +169,7 @@ java_import {
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["com.android.art"],
jars: [":mysdk_core1-error"],
}
genrule {
name: "mysdk_core1-error",
visibility: ["//visibility:private"],
out: ["this-file-will-never-be-created.jar"],
tool_files: ["scripts/invalid_implementation_jar.sh"],
cmd: "$(location scripts/invalid_implementation_jar.sh) core1",
jars: ["java_boot_libs/snapshot/jars/are/invalid/core1.jar"],
}
java_import {
@ -185,15 +177,7 @@ java_import {
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["com.android.art"],
jars: [":mysdk_core2-error"],
}
genrule {
name: "mysdk_core2-error",
visibility: ["//visibility:private"],
out: ["this-file-will-never-be-created.jar"],
tool_files: ["scripts/invalid_implementation_jar.sh"],
cmd: "$(location scripts/invalid_implementation_jar.sh) core2",
jars: ["java_boot_libs/snapshot/jars/are/invalid/core2.jar"],
}
`),
checkAllCopyRules(`
@ -203,7 +187,8 @@ genrule {
.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv
.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv
.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv
build/soong/java/invalid_implementation_jar.sh -> scripts/invalid_implementation_jar.sh
.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/core1.jar
.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/core2.jar
`),
snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot),
@ -372,18 +357,10 @@ java_import {
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["myapex"],
jars: [":mysdk_mybootlib-error"],
jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"],
permitted_packages: ["mybootlib"],
}
genrule {
name: "mysdk_mybootlib-error",
visibility: ["//visibility:private"],
out: ["this-file-will-never-be-created.jar"],
tool_files: ["scripts/invalid_implementation_jar.sh"],
cmd: "$(location scripts/invalid_implementation_jar.sh) mybootlib",
}
java_sdk_library_import {
name: "myothersdklibrary",
prefer: false,
@ -490,7 +467,7 @@ func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) {
.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv
.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv
.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv
build/soong/java/invalid_implementation_jar.sh -> scripts/invalid_implementation_jar.sh
.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar
.intermediates/myothersdklibrary.stubs/android_common/javac/myothersdklibrary.stubs.jar -> sdk_library/public/myothersdklibrary-stubs.jar
.intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_api.txt -> sdk_library/public/myothersdklibrary.txt
.intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_removed.txt -> sdk_library/public/myothersdklibrary-removed.txt
@ -510,7 +487,7 @@ build/soong/java/invalid_implementation_jar.sh -> scripts/invalid_implementation
.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv
.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv
.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv
build/soong/java/invalid_implementation_jar.sh -> scripts/invalid_implementation_jar.sh
.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar
.intermediates/myothersdklibrary.stubs/android_common/javac/myothersdklibrary.stubs.jar -> sdk_library/public/myothersdklibrary-stubs.jar
.intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_api.txt -> sdk_library/public/myothersdklibrary.txt
.intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_removed.txt -> sdk_library/public/myothersdklibrary-removed.txt
@ -899,18 +876,10 @@ java_import {
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["myapex"],
jars: [":mysdk_mybootlib-error"],
jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"],
permitted_packages: ["mybootlib"],
}
genrule {
name: "mysdk_mybootlib-error",
visibility: ["//visibility:private"],
out: ["this-file-will-never-be-created.jar"],
tool_files: ["scripts/invalid_implementation_jar.sh"],
cmd: "$(location scripts/invalid_implementation_jar.sh) mybootlib",
}
java_sdk_library_import {
name: "mynewlibrary",
prefer: false,
@ -961,7 +930,7 @@ my-unsupported-packages.txt -> hiddenapi/my-unsupported-packages.txt
.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv
.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv
.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv
build/soong/java/invalid_implementation_jar.sh -> scripts/invalid_implementation_jar.sh
.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar
.intermediates/mynewlibrary.stubs/android_common/javac/mynewlibrary.stubs.jar -> sdk_library/public/mynewlibrary-stubs.jar
.intermediates/mynewlibrary.stubs.source/android_common/metalava/mynewlibrary.stubs.source_api.txt -> sdk_library/public/mynewlibrary.txt
.intermediates/mynewlibrary.stubs.source/android_common/metalava/mynewlibrary.stubs.source_removed.txt -> sdk_library/public/mynewlibrary-removed.txt

View file

@ -19,13 +19,11 @@ import (
"testing"
"android/soong/android"
"android/soong/genrule"
"android/soong/java"
)
var prepareForSdkTestWithJava = android.GroupFixturePreparers(
java.PrepareForTestWithJavaBuildComponents,
genrule.PrepareForTestWithGenRuleBuildComponents,
PrepareForTestWithSdkBuildComponents,
// Ensure that all source paths are provided. This helps ensure that the snapshot generation is
@ -36,7 +34,6 @@ var prepareForSdkTestWithJava = android.GroupFixturePreparers(
// Files needs by most of the tests.
android.MockFS{
"Test.java": nil,
"build/soong/java/invalid_implementation_jar.sh": nil,
}.AddToFixture(),
)
@ -291,26 +288,18 @@ java_import {
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
jars: [":mysdk_myjavalib-error"],
jars: ["java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar"],
permitted_packages: ["pkg.myjavalib"],
}
genrule {
name: "mysdk_myjavalib-error",
visibility: ["//visibility:private"],
out: ["this-file-will-never-be-created.jar"],
tool_files: ["scripts/invalid_implementation_jar.sh"],
cmd: "$(location scripts/invalid_implementation_jar.sh) myjavalib",
}
`),
checkAllCopyRules(`
build/soong/java/invalid_implementation_jar.sh -> scripts/invalid_implementation_jar.sh
.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar
`),
)
}
func TestSnapshotWithJavaBootLibrary_UpdatableMedia(t *testing.T) {
runTest := func(t *testing.T, targetBuildRelease, expectedJarPath, expectedGenRule, expectedCopyRule string) {
runTest := func(t *testing.T, targetBuildRelease, expectedJarPath, expectedCopyRule string) {
result := android.GroupFixturePreparers(
prepareForSdkTestWithJava,
android.FixtureMergeEnv(map[string]string{
@ -345,27 +334,20 @@ java_import {
jars: ["%s"],
permitted_packages: ["pkg.media"],
}
%s`, expectedJarPath, expectedGenRule)),
`, expectedJarPath)),
checkAllCopyRules(expectedCopyRule),
)
}
t.Run("updatable-media in S", func(t *testing.T) {
runTest(t, "S", "java/updatable-media.jar", "", `
runTest(t, "S", "java/updatable-media.jar", `
.intermediates/updatable-media/android_common/package-check/updatable-media.jar -> java/updatable-media.jar
`)
})
t.Run("updatable-media in T", func(t *testing.T) {
runTest(t, "Tiramisu", ":mysdk_updatable-media-error", `
genrule {
name: "mysdk_updatable-media-error",
visibility: ["//visibility:private"],
out: ["this-file-will-never-be-created.jar"],
tool_files: ["scripts/invalid_implementation_jar.sh"],
cmd: "$(location scripts/invalid_implementation_jar.sh) updatable-media",
}`, `
build/soong/java/invalid_implementation_jar.sh -> scripts/invalid_implementation_jar.sh
runTest(t, "Tiramisu", "java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar", `
.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar
`)
})
}
@ -407,20 +389,12 @@ java_import {
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
jars: [":myexports_myjavalib-error"],
jars: ["java_systemserver_libs/snapshot/jars/are/invalid/myjavalib.jar"],
permitted_packages: ["pkg.myjavalib"],
}
genrule {
name: "myexports_myjavalib-error",
visibility: ["//visibility:private"],
out: ["this-file-will-never-be-created.jar"],
tool_files: ["scripts/invalid_implementation_jar.sh"],
cmd: "$(location scripts/invalid_implementation_jar.sh) myjavalib",
}
`),
checkAllCopyRules(`
build/soong/java/invalid_implementation_jar.sh -> scripts/invalid_implementation_jar.sh
.intermediates/myexports/common_os/empty -> java_systemserver_libs/snapshot/jars/are/invalid/myjavalib.jar
`),
)
}

View file

@ -119,18 +119,10 @@ java_import {
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["myapex"],
jars: [":mysdk_mylib-error"],
jars: ["java_systemserver_libs/snapshot/jars/are/invalid/mylib.jar"],
permitted_packages: ["mylib"],
}
genrule {
name: "mysdk_mylib-error",
visibility: ["//visibility:private"],
out: ["this-file-will-never-be-created.jar"],
tool_files: ["scripts/invalid_implementation_jar.sh"],
cmd: "$(location scripts/invalid_implementation_jar.sh) mylib",
}
prebuilt_systemserverclasspath_fragment {
name: "mysystemserverclasspathfragment",
prefer: false,
@ -188,18 +180,10 @@ java_import {
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["myapex"],
jars: [":mysdk_mylib-error"],
jars: ["java_systemserver_libs/snapshot/jars/are/invalid/mylib.jar"],
permitted_packages: ["mylib"],
}
genrule {
name: "mysdk_mylib-error",
visibility: ["//visibility:private"],
out: ["this-file-will-never-be-created.jar"],
tool_files: ["scripts/invalid_implementation_jar.sh"],
cmd: "$(location scripts/invalid_implementation_jar.sh) mylib",
}
prebuilt_systemserverclasspath_fragment {
name: "mysystemserverclasspathfragment",
prefer: false,

View file

@ -1049,6 +1049,9 @@ type snapshotBuilder struct {
filesToZip android.Paths
zipsToMerge android.Paths
// The path to an empty file.
emptyFile android.WritablePath
prebuiltModules map[string]*bpModule
prebuiltOrder []*bpModule
@ -1108,6 +1111,19 @@ 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 {
@ -1184,24 +1200,6 @@ 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.
@ -1232,23 +1230,18 @@ 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(reference string, required bool) string {
prefix := ""
name := strings.TrimPrefix(reference, ":")
if name != reference {
prefix = ":"
}
func (s *snapshotBuilder) snapshotSdkMemberName(name string, required bool) string {
if _, ok := s.allMembersByName[name]; !ok {
if required {
s.ctx.ModuleErrorf("Required member reference %s is not a member of the sdk", name)
}
return reference
return name
}
if s.isInternalMember(name) {
return prefix + s.ctx.ModuleName() + "_" + name
return s.ctx.ModuleName() + "_" + name
} else {
return reference
return name
}
}
@ -2064,7 +2057,6 @@ 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
}