From 8150da6e9d373f5fb9bd10a353c0dc370538ba73 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Mon, 16 Dec 2019 17:21:27 +0000 Subject: [PATCH] Added module_exports/_snapshot as alias for sdk/_snapshot Bug: 146341462 Test: m nothing Change-Id: I27e1ef494a2b0874074aa43614612189b17e7860 --- Android.bp | 2 ++ sdk/exports.go | 39 +++++++++++++++++++++++++++ sdk/exports_test.go | 66 +++++++++++++++++++++++++++++++++++++++++++++ sdk/sdk.go | 19 +++++++------ sdk/testing.go | 4 ++- sdk/update.go | 8 +++++- 6 files changed, 128 insertions(+), 10 deletions(-) create mode 100644 sdk/exports.go create mode 100644 sdk/exports_test.go diff --git a/Android.bp b/Android.bp index 75761027d..3a3bd9c0d 100644 --- a/Android.bp +++ b/Android.bp @@ -507,11 +507,13 @@ bootstrap_go_package { ], srcs: [ "sdk/bp.go", + "sdk/exports.go", "sdk/sdk.go", "sdk/update.go", ], testSrcs: [ "sdk/cc_sdk_test.go", + "sdk/exports_test.go", "sdk/java_sdk_test.go", "sdk/sdk_test.go", "sdk/testing.go", diff --git a/sdk/exports.go b/sdk/exports.go new file mode 100644 index 000000000..c882462fa --- /dev/null +++ b/sdk/exports.go @@ -0,0 +1,39 @@ +// Copyright (C) 2019 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. + +package sdk + +import "android/soong/android" + +func init() { + android.RegisterModuleType("module_exports", ModuleExportsFactory) + android.RegisterModuleType("module_exports_snapshot", ModuleExportsSnapshotsFactory) +} + +// module_exports defines the exports of a mainline module. The exports are Soong modules +// which are required by Soong modules that are not part of the mainline module. +func ModuleExportsFactory() android.Module { + s := newSdkModule() + s.properties.Module_exports = true + return s +} + +// module_exports_snapshot is a versioned snapshot of prebuilt versions of all the exports +// of a mainline module. +func ModuleExportsSnapshotsFactory() android.Module { + s := newSdkModule() + s.properties.Snapshot = true + s.properties.Module_exports = true + return s +} diff --git a/sdk/exports_test.go b/sdk/exports_test.go new file mode 100644 index 000000000..b905d719a --- /dev/null +++ b/sdk/exports_test.go @@ -0,0 +1,66 @@ +// Copyright 2019 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. + +package sdk + +import ( + "testing" +) + +// Ensure that module_exports generates a module_exports_snapshot module. +func TestModuleExportsSnapshot(t *testing.T) { + packageBp := ` + module_exports { + name: "myexports", + java_libs: [ + "myjavalib", + ], + } + + java_library { + name: "myjavalib", + srcs: ["Test.java"], + system_modules: "none", + sdk_version: "none", + } + ` + + result := testSdkWithFs(t, ``, + map[string][]byte{ + "package/Test.java": nil, + "package/Android.bp": []byte(packageBp), + }) + + result.CheckSnapshot("myexports", "android_common", "package", + checkAndroidBpContents(` +// This is auto-generated. DO NOT EDIT. + +java_import { + name: "myexports_myjavalib@current", + sdk_member_name: "myjavalib", + jars: ["java/myjavalib.jar"], +} + +java_import { + name: "myjavalib", + prefer: false, + jars: ["java/myjavalib.jar"], +} + +module_exports_snapshot { + name: "myexports@current", + java_libs: ["myexports_myjavalib@current"], +} +`)) +} diff --git a/sdk/sdk.go b/sdk/sdk.go index 62bc06fd5..42f5503ed 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -33,7 +33,7 @@ func init() { pctx.Import("android/soong/android") pctx.Import("android/soong/java/config") - android.RegisterModuleType("sdk", ModuleFactory) + android.RegisterModuleType("sdk", SdkModuleFactory) android.RegisterModuleType("sdk_snapshot", SnapshotModuleFactory) android.PreDepsMutators(RegisterPreDepsMutators) android.PostDepsMutators(RegisterPostDepsMutators) @@ -60,6 +60,9 @@ type sdk struct { type sdkProperties struct { Snapshot bool `blueprint:"mutated"` + + // True if this is a module_exports (or module_exports_snapshot) module type. + Module_exports bool `blueprint:"mutated"` } type sdkMemberDependencyTag struct { @@ -182,18 +185,18 @@ func createDynamicSdkMemberTypes(sdkMemberTypes []android.SdkMemberType) *dynami // sdk defines an SDK which is a logical group of modules (e.g. native libs, headers, java libs, etc.) // which Mainline modules like APEX can choose to build with. -func ModuleFactory() android.Module { - s := &sdk{} +func SdkModuleFactory() android.Module { + return newSdkModule() +} +func newSdkModule() *sdk { + s := &sdk{} // Get the dynamic sdk member type data for the currently registered sdk member types. s.dynamicSdkMemberTypes = getDynamicSdkMemberTypes(android.SdkMemberTypes) - // Create an instance of the dynamically created struct that contains all the // properties for the member type specific list properties. s.dynamicMemberTypeListProperties = s.dynamicSdkMemberTypes.createMemberListProperties() - s.AddProperties(&s.properties, s.dynamicMemberTypeListProperties) - android.InitAndroidMultiTargetsArchModule(s, android.HostAndDeviceSupported, android.MultilibCommon) android.InitDefaultableModule(s) android.AddLoadHook(s, func(ctx android.LoadHookContext) { @@ -208,8 +211,8 @@ func ModuleFactory() android.Module { // sdk_snapshot is a versioned snapshot of an SDK. This is an auto-generated module. func SnapshotModuleFactory() android.Module { - s := ModuleFactory() - s.(*sdk).properties.Snapshot = true + s := newSdkModule() + s.properties.Snapshot = true return s } diff --git a/sdk/testing.go b/sdk/testing.go index c0d6f51ab..809788912 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -84,8 +84,10 @@ func testSdkContext(bp string, fs map[string][]byte) (*android.TestContext, andr ctx.PostDepsMutators(apex.RegisterPostDepsMutators) // from this package - ctx.RegisterModuleType("sdk", ModuleFactory) + ctx.RegisterModuleType("sdk", SdkModuleFactory) ctx.RegisterModuleType("sdk_snapshot", SnapshotModuleFactory) + ctx.RegisterModuleType("module_exports", ModuleExportsFactory) + ctx.RegisterModuleType("module_exports_snapshot", ModuleExportsSnapshotsFactory) ctx.PreDepsMutators(RegisterPreDepsMutators) ctx.PostDepsMutators(RegisterPostDepsMutators) diff --git a/sdk/update.go b/sdk/update.go index d31fa3002..5bc3b8354 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -209,7 +209,13 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath { // Create the snapshot module. snapshotName := ctx.ModuleName() + string(android.SdkVersionSeparator) + builder.version - snapshotModule := bpFile.newModule("sdk_snapshot") + var snapshotModuleType string + if s.properties.Module_exports { + snapshotModuleType = "module_exports_snapshot" + } else { + snapshotModuleType = "sdk_snapshot" + } + snapshotModule := bpFile.newModule(snapshotModuleType) snapshotModule.AddProperty("name", snapshotName) // Make sure that the snapshot has the same visibility as the sdk.