diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-07-21 20:52:55 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-07-21 20:52:55 +0000 |
commit | f14f9d643468dfb159bac51af74dd46bfb43fc70 (patch) | |
tree | 3a3592c04e357e6cf1e86e35d55b7de66ae5ba1a | |
parent | a39a8ea83c7989e845218e79cd7715c47489ac43 (diff) | |
parent | 43d56de71af3678a8ed3e115f3b43e2e7834d0a2 (diff) | |
download | soong-android13-mainline-go-uwb-release.tar.gz |
Snap for 8857240 from 43d56de71af3678a8ed3e115f3b43e2e7834d0a2 to mainline-go-uwb-releaseaml_go_uwb_330912000android13-mainline-go-uwb-release
Change-Id: I57ef38343e6628596e8093fd88b6a60aed142afc
-rw-r--r-- | android/sdk.go | 4 | ||||
-rw-r--r-- | apex/builder.go | 41 | ||||
-rw-r--r-- | java/java.go | 30 | ||||
-rw-r--r-- | scripts/Android.bp | 10 | ||||
-rwxr-xr-x | scripts/jsonmodify.py | 24 | ||||
-rw-r--r-- | scripts/jsonmodify_test.py | 75 | ||||
-rw-r--r-- | sdk/build_release.go | 12 | ||||
-rw-r--r-- | sdk/java_sdk_test.go | 65 | ||||
-rw-r--r-- | sdk/update.go | 12 |
9 files changed, 218 insertions, 55 deletions
diff --git a/android/sdk.go b/android/sdk.go index 07b94b246..a71f7f211 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -985,6 +985,10 @@ type SdkMemberContext interface { // RequiresTrait returns true if this member is expected to provide the specified trait. RequiresTrait(trait SdkMemberTrait) bool + + // IsTargetBuildBeforeTiramisu return true if the target build release for which this snapshot is + // being generated is before Tiramisu, i.e. S. + IsTargetBuildBeforeTiramisu() bool } // ExportedComponentsInfo contains information about the components that this module exports to an diff --git a/apex/builder.go b/apex/builder.go index dda342f82..1956b4447 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -76,16 +76,12 @@ var ( Command: `rm -f $out && ${jsonmodify} $in ` + `-a provideNativeLibs ${provideNativeLibs} ` + `-a requireNativeLibs ${requireNativeLibs} ` + + `-se version 0 ${default_version} ` + `${opt} ` + `-o $out`, CommandDeps: []string{"${jsonmodify}"}, Description: "prepare ${out}", - }, "provideNativeLibs", "requireNativeLibs", "opt") - - stripCommentsApexManifestRule = pctx.StaticRule("stripCommentsApexManifestRule", blueprint.RuleParams{ - Command: `sed '/^\s*\/\//d' $in > $out`, - Description: "strip lines starting with // ${in}=>${out}", - }) + }, "provideNativeLibs", "requireNativeLibs", "default_version", "opt") stripApexManifestRule = pctx.StaticRule("stripApexManifestRule", blueprint.RuleParams{ Command: `rm -f $out && ${conv_apex_manifest} strip $in -o $out`, @@ -93,11 +89,6 @@ var ( Description: "strip ${in}=>${out}", }) - setVersionApexManifestRule = pctx.StaticRule("setVersionApexManifestRule", blueprint.RuleParams{ - Command: `sed 's/\"version\":\s*0\([^0-9]*\)$$/\"version\":\ ${default_version}\1/' $in > $out`, - Description: "Replace 'version: 0' with the correct version // ${in}=>${out}", - }, "default_version") - pbApexManifestRule = pctx.StaticRule("pbApexManifestRule", blueprint.RuleParams{ Command: `rm -f $out && ${conv_apex_manifest} proto $in -o $out`, CommandDeps: []string{"${conv_apex_manifest}"}, @@ -117,7 +108,6 @@ var ( `--canned_fs_config ${canned_fs_config} ` + `--include_build_info ` + `--payload_type image ` + - `--apex_version ${apex_version} ` + `--key ${key} ${opt_flags} ${image_dir} ${out} `, CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}", "${mke2fs}", "${resize2fs}", "${sefcontext_compile}", "${make_f2fs}", "${sload_f2fs}", "${make_erofs}", @@ -125,7 +115,7 @@ var ( Rspfile: "${out}.copy_commands", RspfileContent: "${copy_commands}", Description: "APEX ${image_dir} => ${out}", - }, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", "opt_flags", "manifest", "payload_fs_type", "apex_version") + }, "tool_path", "image_dir", "copy_commands", "file_contexts", "canned_fs_config", "key", "opt_flags", "manifest", "payload_fs_type") zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{ Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` + @@ -133,13 +123,12 @@ var ( `APEXER_TOOL_PATH=${tool_path} ` + `${apexer} --force --manifest ${manifest} ` + `--payload_type zip ` + - `--apex_version ${apex_version} ` + `${image_dir} ${out} `, CommandDeps: []string{"${apexer}", "${merge_zips}", "${soong_zip}", "${zipalign}", "${aapt2}"}, Rspfile: "${out}.copy_commands", RspfileContent: "${copy_commands}", Description: "ZipAPEX ${image_dir} => ${out}", - }, "tool_path", "image_dir", "copy_commands", "manifest", "apex_version") + }, "tool_path", "image_dir", "copy_commands", "manifest") apexProtoConvertRule = pctx.AndroidStaticRule("apexProtoConvertRule", blueprint.RuleParams{ @@ -217,31 +206,15 @@ func (a *apexBundle) buildManifest(ctx android.ModuleContext, provideNativeLibs, optCommands = append(optCommands, "-a jniLibs "+strings.Join(jniLibs, " ")) } - manifestJsonCommentsStripped := android.PathForModuleOut(ctx, "apex_manifest_comments_stripped.json") - ctx.Build(pctx, android.BuildParams{ - Rule: stripCommentsApexManifestRule, - Input: src, - Output: manifestJsonCommentsStripped, - }) - - manifestJsonVersionChanged := android.PathForModuleOut(ctx, "apex_manifest_version_changed.json") - ctx.Build(pctx, android.BuildParams{ - Rule: setVersionApexManifestRule, - Input: manifestJsonCommentsStripped, - Output: manifestJsonVersionChanged, - Args: map[string]string{ - "default_version": defaultManifestVersion, - }, - }) - manifestJsonFullOut := android.PathForModuleOut(ctx, "apex_manifest_full.json") ctx.Build(pctx, android.BuildParams{ Rule: apexManifestRule, - Input: manifestJsonVersionChanged, + Input: src, Output: manifestJsonFullOut, Args: map[string]string{ "provideNativeLibs": strings.Join(provideNativeLibs, " "), "requireNativeLibs": strings.Join(requireNativeLibs, " "), + "default_version": defaultManifestVersion, "opt": strings.Join(optCommands, " "), }, }) @@ -699,7 +672,6 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { "file_contexts": fileContexts.String(), "canned_fs_config": cannedFsConfig.String(), "key": a.privateKeyFile.String(), - "apex_version": defaultManifestVersion, "opt_flags": strings.Join(optFlags, " "), }, }) @@ -796,7 +768,6 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { "image_dir": imageDir.String(), "copy_commands": strings.Join(copyCommands, " && "), "manifest": a.manifestPbOut.String(), - "apex_version": defaultManifestVersion, }, }) } diff --git a/java/java.go b/java/java.go index 9ab77a54e..1e99aa32f 100644 --- a/java/java.go +++ b/java/java.go @@ -118,6 +118,16 @@ var ( copyEverythingToSnapshot, } + snapshotRequiresImplementationJar = func(ctx android.SdkMemberContext) bool { + // In the S build the build will break if updatable-media does not provide a full implementation + // jar. That issue was fixed in Tiramisu by b/229932396. + if ctx.IsTargetBuildBeforeTiramisu() && ctx.Name() == "updatable-media" { + return true + } + + return false + } + // Supports adding java boot libraries to module_exports and sdk. // // The build has some implicit dependencies (via the boot jars configuration) on a number of @@ -135,13 +145,21 @@ var ( SupportsSdk: true, }, func(ctx android.SdkMemberContext, j *Library) android.Path { + if snapshotRequiresImplementationJar(ctx) { + return exportImplementationClassesJar(ctx, j) + } + // Java boot libs are only provided in the SDK to provide access to their dex implementation // 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 ctx.SnapshotBuilder().EmptyFile() }, - func(osPrefix, name string) string { + func(ctx android.SdkMemberContext, osPrefix, name string) string { + if snapshotRequiresImplementationJar(ctx) { + return sdkSnapshotFilePathForJar(ctx, osPrefix, name) + } + // 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. @@ -175,7 +193,7 @@ var ( // file. Any attempt to use that file as a jar will cause a build error. return ctx.SnapshotBuilder().EmptyFile() }, - func(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. @@ -649,7 +667,7 @@ const ( ) // path to the jar file of a java library. Relative to <sdk_root>/<api_dir> -func sdkSnapshotFilePathForJar(osPrefix, name string) string { +func sdkSnapshotFilePathForJar(_ android.SdkMemberContext, osPrefix, name string) string { return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix) } @@ -666,7 +684,7 @@ type librarySdkMemberType struct { // Function to compute the snapshot relative path to which the named library's // jar should be copied. - snapshotPathGetter func(osPrefix, name string) string + snapshotPathGetter func(ctx android.SdkMemberContext, osPrefix, name string) string // True if only the jar should be copied to the snapshot, false if the jar plus any additional // files like aidl files should also be copied. @@ -724,7 +742,7 @@ func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberConte exportedJar := p.JarToExport if exportedJar != nil { // Delegate the creation of the snapshot relative path to the member type. - snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(p.OsPrefix(), ctx.Name()) + snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(ctx, p.OsPrefix(), ctx.Name()) // Copy the exported jar to the snapshot. builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) @@ -1190,7 +1208,7 @@ func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, exportedJar := p.JarToExport if exportedJar != nil { - snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name()) + snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(ctx, p.OsPrefix(), ctx.Name()) builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) diff --git a/scripts/Android.bp b/scripts/Android.bp index 4773579e3..a37d2597b 100644 --- a/scripts/Android.bp +++ b/scripts/Android.bp @@ -84,6 +84,16 @@ python_binary_host { ], } +python_test_host { + name: "jsonmodify_test", + main: "jsonmodify_test.py", + srcs: [ + "jsonmodify_test.py", + "jsonmodify.py", + ], + test_suites: ["general-tests"], +} + python_binary_host { name: "test_config_fixer", main: "test_config_fixer.py", diff --git a/scripts/jsonmodify.py b/scripts/jsonmodify.py index ba1109e7a..8bd8d4556 100755 --- a/scripts/jsonmodify.py +++ b/scripts/jsonmodify.py @@ -59,6 +59,13 @@ class Replace(str): cur[key] = val +class ReplaceIfEqual(str): + def apply(self, obj, old_val, new_val): + cur, key = follow_path(obj, self) + if cur and cur[key] == int(old_val): + cur[key] = new_val + + class Remove(str): def apply(self, obj): cur, key = follow_path(obj, self) @@ -75,6 +82,14 @@ class AppendList(str): raise ValueError(self + " should be a array.") cur[key].extend(args) +# A JSONDecoder that supports line comments start with // +class JSONWithCommentsDecoder(json.JSONDecoder): + def __init__(self, **kw): + super().__init__(**kw) + + def decode(self, s: str): + s = '\n'.join(l for l in s.split('\n') if not l.lstrip(' ').startswith('//')) + return super().decode(s) def main(): parser = argparse.ArgumentParser() @@ -91,6 +106,11 @@ def main(): help='replace value of the key specified by path. If path doesn\'t exist, no op.', metavar=('path', 'value'), nargs=2, dest='patch', action='append') + parser.add_argument("-se", "--replace-if-equal", type=ReplaceIfEqual, + help='replace value of the key specified by path to new_value if it\'s equal to old_value.' + + 'If path doesn\'t exist or the value is not equal to old_value, no op.', + metavar=('path', 'old_value', 'new_value'), + nargs=3, dest='patch', action='append') parser.add_argument("-r", "--remove", type=Remove, help='remove the key specified by path. If path doesn\'t exist, no op.', metavar='path', @@ -103,9 +123,9 @@ def main(): if args.input: with open(args.input) as f: - obj = json.load(f, object_pairs_hook=collections.OrderedDict) + obj = json.load(f, object_pairs_hook=collections.OrderedDict, cls=JSONWithCommentsDecoder) else: - obj = json.load(sys.stdin, object_pairs_hook=collections.OrderedDict) + obj = json.load(sys.stdin, object_pairs_hook=collections.OrderedDict, cls=JSONWithCommentsDecoder) for p in args.patch: p[0].apply(obj, *p[1:]) diff --git a/scripts/jsonmodify_test.py b/scripts/jsonmodify_test.py new file mode 100644 index 000000000..6f0291dfb --- /dev/null +++ b/scripts/jsonmodify_test.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# +# Copyright (C) 2022 The Android Open Source Project +# +# 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. +# +"""Tests for jsonmodify.""" + +import json +import jsonmodify +import unittest + + +class JsonmodifyTest(unittest.TestCase): + + def test_set_value(self): + obj = json.loads('{"field1": 111}') + field1 = jsonmodify.SetValue("field1") + field1.apply(obj, 222) + field2 = jsonmodify.SetValue("field2") + field2.apply(obj, 333) + expected = json.loads('{"field1": 222, "field2": 333}') + self.assertEqual(obj, expected) + + def test_replace(self): + obj = json.loads('{"field1": 111}') + field1 = jsonmodify.Replace("field1") + field1.apply(obj, 222) + field2 = jsonmodify.Replace("field2") + field2.apply(obj, 333) + expected = json.loads('{"field1": 222}') + self.assertEqual(obj, expected) + + def test_replace_if_equal(self): + obj = json.loads('{"field1": 111, "field2": 222}') + field1 = jsonmodify.ReplaceIfEqual("field1") + field1.apply(obj, 111, 333) + field2 = jsonmodify.ReplaceIfEqual("field2") + field2.apply(obj, 444, 555) + field3 = jsonmodify.ReplaceIfEqual("field3") + field3.apply(obj, 666, 777) + expected = json.loads('{"field1": 333, "field2": 222}') + self.assertEqual(obj, expected) + + def test_remove(self): + obj = json.loads('{"field1": 111, "field2": 222}') + field2 = jsonmodify.Remove("field2") + field2.apply(obj) + field3 = jsonmodify.Remove("field3") + field3.apply(obj) + expected = json.loads('{"field1": 111}') + self.assertEqual(obj, expected) + + def test_append_list(self): + obj = json.loads('{"field1": [111]}') + field1 = jsonmodify.AppendList("field1") + field1.apply(obj, 222, 333) + field2 = jsonmodify.AppendList("field2") + field2.apply(obj, 444, 555, 666) + expected = json.loads('{"field1": [111, 222, 333], "field2": [444, 555, 666]}') + self.assertEqual(obj, expected) + + +if __name__ == '__main__': + unittest.main(verbosity=2) diff --git a/sdk/build_release.go b/sdk/build_release.go index 4c2277e85..0494a28ee 100644 --- a/sdk/build_release.go +++ b/sdk/build_release.go @@ -24,18 +24,22 @@ import ( // buildRelease represents the version of a build system used to create a specific release. // -// The name of the release, is the same as the code for the dessert release, e.g. S, T, etc. +// The name of the release, is the same as the code for the dessert release, e.g. S, Tiramisu, etc. type buildRelease struct { - // The name of the release, e.g. S, T, etc. + // The name of the release, e.g. S, Tiramisu, etc. name string // The index of this structure within the buildReleases list. ordinal int } +func (br *buildRelease) EarlierThan(other *buildRelease) bool { + return br.ordinal < other.ordinal +} + // String returns the name of the build release. -func (s *buildRelease) String() string { - return s.name +func (br *buildRelease) String() string { + return br.name } // buildReleaseSet represents a set of buildRelease objects. diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index d25138f5b..7ab5285c6 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -15,6 +15,7 @@ package sdk import ( + "fmt" "testing" "android/soong/android" @@ -257,8 +258,8 @@ func TestSnapshotWithJavaBootLibrary(t *testing.T) { android.FixtureAddFile("aidl", nil), android.FixtureAddFile("resource.txt", nil), ).RunTestWithBp(t, ` - module_exports { - name: "myexports", + sdk { + name: "mysdk", java_boot_libs: ["myjavalib"], } @@ -278,7 +279,7 @@ func TestSnapshotWithJavaBootLibrary(t *testing.T) { } `) - CheckSnapshot(t, result, "myexports", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -292,11 +293,65 @@ java_import { } `), checkAllCopyRules(` -.intermediates/myexports/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar +.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, expectedCopyRule string) { + result := android.GroupFixturePreparers( + prepareForSdkTestWithJava, + android.FixtureMergeEnv(map[string]string{ + "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": targetBuildRelease, + }), + ).RunTestWithBp(t, ` + sdk { + name: "mysdk", + java_boot_libs: ["updatable-media"], + } + + java_library { + name: "updatable-media", + srcs: ["Test.java"], + system_modules: "none", + sdk_version: "none", + compile_dex: true, + permitted_packages: ["pkg.media"], + apex_available: ["com.android.media"], + } + `) + + CheckSnapshot(t, result, "mysdk", "", + checkAndroidBpContents(fmt.Sprintf(` +// This is auto-generated. DO NOT EDIT. + +java_import { + name: "updatable-media", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["com.android.media"], + jars: ["%s"], + permitted_packages: ["pkg.media"], +} +`, expectedJarPath)), + checkAllCopyRules(expectedCopyRule), + ) + } + + t.Run("updatable-media in S", func(t *testing.T) { + 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", "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 +`) + }) +} + func TestSnapshotWithJavaSystemserverLibrary(t *testing.T) { result := android.GroupFixturePreparers( prepareForSdkTestWithJava, @@ -1284,9 +1339,9 @@ java_sdk_library_import { .intermediates/myjavalib.stubs.source.module_lib/android_common/metalava/myjavalib.stubs.source.module_lib_removed.txt -> sdk_library/module-lib/myjavalib-removed.txt `), checkMergeZips( + ".intermediates/mysdk/common_os/tmp/sdk_library/module-lib/myjavalib_stub_sources.zip", ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip", ".intermediates/mysdk/common_os/tmp/sdk_library/system/myjavalib_stub_sources.zip", - ".intermediates/mysdk/common_os/tmp/sdk_library/module-lib/myjavalib_stub_sources.zip", ), ) } diff --git a/sdk/update.go b/sdk/update.go index b9ef3d0f4..c555ddc7a 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -108,7 +108,7 @@ var ( mergeZips = pctx.AndroidStaticRule("SnapshotMergeZips", blueprint.RuleParams{ - Command: `${config.MergeZipsCmd} $out $in`, + Command: `${config.MergeZipsCmd} -s $out $in`, CommandDeps: []string{ "${config.MergeZipsCmd}", }, @@ -481,7 +481,7 @@ be unnecessary as every module in the sdk already has its own licenses property. // Copy the build number file into the snapshot. builder.CopyToSnapshot(ctx.Config().BuildNumberFile(ctx), BUILD_NUMBER_FILE) - filesToZip := builder.filesToZip + filesToZip := android.SortedUniquePaths(builder.filesToZip) // zip them all zipPath := fmt.Sprintf("%s%s.zip", ctx.ModuleName(), snapshotFileSuffix) @@ -517,7 +517,7 @@ be unnecessary as every module in the sdk already has its own licenses property. Description: outputDesc, Rule: mergeZips, Input: zipFile, - Inputs: builder.zipsToMerge, + Inputs: android.SortedUniquePaths(builder.zipsToMerge), Output: outputZipFile, }) } @@ -1972,6 +1972,12 @@ func (m *memberContext) RequiresTrait(trait android.SdkMemberTrait) bool { return m.requiredTraits.Contains(trait) } +func (m *memberContext) IsTargetBuildBeforeTiramisu() bool { + return m.builder.targetBuildRelease.EarlierThan(buildReleaseT) +} + +var _ android.SdkMemberContext = (*memberContext)(nil) + func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModule *bpModule) { memberType := member.memberType |