Merge "Added module_exports/_snapshot as alias for sdk/_snapshot"

This commit is contained in:
Paul Duffin 2019-12-31 14:59:19 +00:00 committed by Gerrit Code Review
commit 28aa544884
6 changed files with 128 additions and 10 deletions

View File

@ -508,11 +508,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",

39
sdk/exports.go Normal file
View File

@ -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
}

66
sdk/exports_test.go Normal file
View File

@ -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"],
}
`))
}

View File

@ -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
}

View File

@ -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)

View File

@ -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.