Export soong license data to make.
See: http://go/android-license-checking-in-soong-v2-design Bug: 151953481 Bug: 151177513 Bug: 67772237 Change-Id: If9d661dfcaa732c459d38d8ad7ec4a0e540846b8
This commit is contained in:
@@ -28,6 +28,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -434,6 +435,17 @@ func (a *AndroidMkEntries) GetDistForGoals(mod blueprint.Module) []string {
|
|||||||
return generateDistContributionsForMake(distContributions)
|
return generateDistContributionsForMake(distContributions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write the license variables to Make for AndroidMkData.Custom(..) methods that do not call WriteAndroidMkData(..)
|
||||||
|
// It's required to propagate the license metadata even for module types that have non-standard interfaces to Make.
|
||||||
|
func (a *AndroidMkEntries) WriteLicenseVariables(w io.Writer) {
|
||||||
|
fmt.Fprintln(w, "LOCAL_LICENSE_KINDS :=", strings.Join(a.EntryMap["LOCAL_LICENSE_KINDS"], " "))
|
||||||
|
fmt.Fprintln(w, "LOCAL_LICENSE_CONDITIONS :=", strings.Join(a.EntryMap["LOCAL_LICENSE_CONDITIONS"], " "))
|
||||||
|
fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", strings.Join(a.EntryMap["LOCAL_NOTICE_FILE"], " "))
|
||||||
|
if pn, ok := a.EntryMap["LOCAL_LICENSE_PACKAGE_NAME"]; ok {
|
||||||
|
fmt.Fprintln(w, "LOCAL_LICENSE_PACKAGE_NAME :=", strings.Join(pn, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// fillInEntries goes through the common variable processing and calls the extra data funcs to
|
// fillInEntries goes through the common variable processing and calls the extra data funcs to
|
||||||
// generate and fill in AndroidMkEntries's in-struct data, ready to be flushed to a file.
|
// generate and fill in AndroidMkEntries's in-struct data, ready to be flushed to a file.
|
||||||
func (a *AndroidMkEntries) fillInEntries(config Config, bpPath string, mod blueprint.Module) {
|
func (a *AndroidMkEntries) fillInEntries(config Config, bpPath string, mod blueprint.Module) {
|
||||||
@@ -460,6 +472,13 @@ func (a *AndroidMkEntries) fillInEntries(config Config, bpPath string, mod bluep
|
|||||||
// Collect make variable assignment entries.
|
// Collect make variable assignment entries.
|
||||||
a.SetString("LOCAL_PATH", filepath.Dir(bpPath))
|
a.SetString("LOCAL_PATH", filepath.Dir(bpPath))
|
||||||
a.SetString("LOCAL_MODULE", name+a.SubName)
|
a.SetString("LOCAL_MODULE", name+a.SubName)
|
||||||
|
a.AddStrings("LOCAL_LICENSE_KINDS", amod.commonProperties.Effective_license_kinds...)
|
||||||
|
a.AddStrings("LOCAL_LICENSE_CONDITIONS", amod.commonProperties.Effective_license_conditions...)
|
||||||
|
a.AddStrings("LOCAL_NOTICE_FILE", amod.commonProperties.Effective_license_text...)
|
||||||
|
// TODO(b/151177513): Does this code need to set LOCAL_MODULE_IS_CONTAINER ?
|
||||||
|
if amod.commonProperties.Effective_package_name != nil {
|
||||||
|
a.SetString("LOCAL_LICENSE_PACKAGE_NAME", *amod.commonProperties.Effective_package_name)
|
||||||
|
}
|
||||||
a.SetString("LOCAL_MODULE_CLASS", a.Class)
|
a.SetString("LOCAL_MODULE_CLASS", a.Class)
|
||||||
a.SetString("LOCAL_PREBUILT_MODULE_FILE", a.OutputFile.String())
|
a.SetString("LOCAL_PREBUILT_MODULE_FILE", a.OutputFile.String())
|
||||||
a.AddStrings("LOCAL_REQUIRED_MODULES", a.Required...)
|
a.AddStrings("LOCAL_REQUIRED_MODULES", a.Required...)
|
||||||
@@ -682,6 +701,7 @@ func translateAndroidMkModule(ctx SingletonContext, w io.Writer, mod blueprint.M
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Additional cases here require review for correct license propagation to make.
|
||||||
switch x := mod.(type) {
|
switch x := mod.(type) {
|
||||||
case AndroidMkDataProvider:
|
case AndroidMkDataProvider:
|
||||||
return translateAndroidModule(ctx, w, mod, x)
|
return translateAndroidModule(ctx, w, mod, x)
|
||||||
@@ -690,6 +710,7 @@ func translateAndroidMkModule(ctx SingletonContext, w io.Writer, mod blueprint.M
|
|||||||
case AndroidMkEntriesProvider:
|
case AndroidMkEntriesProvider:
|
||||||
return translateAndroidMkEntriesModule(ctx, w, mod, x)
|
return translateAndroidMkEntriesModule(ctx, w, mod, x)
|
||||||
default:
|
default:
|
||||||
|
// Not exported to make so no make variables to set.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -703,6 +724,10 @@ func translateGoBinaryModule(ctx SingletonContext, w io.Writer, mod blueprint.Mo
|
|||||||
fmt.Fprintln(w, ".PHONY:", name)
|
fmt.Fprintln(w, ".PHONY:", name)
|
||||||
fmt.Fprintln(w, name+":", goBinary.InstallPath())
|
fmt.Fprintln(w, name+":", goBinary.InstallPath())
|
||||||
fmt.Fprintln(w, "")
|
fmt.Fprintln(w, "")
|
||||||
|
// Assuming no rules in make include go binaries in distributables.
|
||||||
|
// If the assumption is wrong, make will fail to build without the necessary .meta_lic and .meta_module files.
|
||||||
|
// In that case, add the targets and rules here to build a .meta_lic file for `name` and a .meta_module for
|
||||||
|
// `goBinary.InstallPath()` pointing to the `name`.meta_lic file.
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -768,6 +793,25 @@ func translateAndroidModule(ctx SingletonContext, w io.Writer, mod blueprint.Mod
|
|||||||
blueprintDir := filepath.Dir(ctx.BlueprintFile(mod))
|
blueprintDir := filepath.Dir(ctx.BlueprintFile(mod))
|
||||||
|
|
||||||
if data.Custom != nil {
|
if data.Custom != nil {
|
||||||
|
// List of module types allowed to use .Custom(...)
|
||||||
|
// Additions to the list require careful review for proper license handling.
|
||||||
|
switch reflect.TypeOf(mod).String() { // ctx.ModuleType(mod) doesn't work: aidl_interface creates phony without type
|
||||||
|
case "*aidl.aidlApi": // writes non-custom before adding .phony
|
||||||
|
case "*aidl.aidlMapping": // writes non-custom before adding .phony
|
||||||
|
case "*android.customModule": // appears in tests only
|
||||||
|
case "*apex.apexBundle": // license properties written
|
||||||
|
case "*bpf.bpf": // license properties written (both for module and objs)
|
||||||
|
case "*genrule.Module": // writes non-custom before adding .phony
|
||||||
|
case "*java.SystemModules": // doesn't go through base_rules
|
||||||
|
case "*java.systemModulesImport": // doesn't go through base_rules
|
||||||
|
case "*phony.phony": // license properties written
|
||||||
|
case "*selinux.selinuxContextsModule": // license properties written
|
||||||
|
case "*sysprop.syspropLibrary": // license properties written
|
||||||
|
default:
|
||||||
|
if ctx.Config().IsEnvTrue("ANDROID_REQUIRE_LICENSES") {
|
||||||
|
return fmt.Errorf("custom make rules not allowed for %q (%q) module %q", ctx.ModuleType(mod), reflect.TypeOf(mod), ctx.ModuleName(mod))
|
||||||
|
}
|
||||||
|
}
|
||||||
data.Custom(w, name, prefix, blueprintDir, data)
|
data.Custom(w, name, prefix, blueprintDir, data)
|
||||||
} else {
|
} else {
|
||||||
WriteAndroidMkData(w, data)
|
WriteAndroidMkData(w, data)
|
||||||
@@ -804,6 +848,7 @@ func translateAndroidMkEntriesModule(ctx SingletonContext, w io.Writer, mod blue
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Any new or special cases here need review to verify correct propagation of license information.
|
||||||
for _, entries := range provider.AndroidMkEntries() {
|
for _, entries := range provider.AndroidMkEntries() {
|
||||||
entries.fillInEntries(ctx.Config(), ctx.BlueprintFile(mod), mod)
|
entries.fillInEntries(ctx.Config(), ctx.BlueprintFile(mod), mod)
|
||||||
entries.write(w)
|
entries.write(w)
|
||||||
|
@@ -63,6 +63,16 @@ func (class apexFileClass) nameInMake() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the full module name for a dependency module, which appends the apex module name unless re-using a system lib.
|
||||||
|
func (a *apexBundle) fullModuleName(apexBundleName string, fi *apexFile) string {
|
||||||
|
linkToSystemLib := a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform()
|
||||||
|
|
||||||
|
if linkToSystemLib {
|
||||||
|
return fi.androidMkModuleName
|
||||||
|
}
|
||||||
|
return fi.androidMkModuleName + "." + apexBundleName + a.suffix
|
||||||
|
}
|
||||||
|
|
||||||
func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, moduleDir string,
|
func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, moduleDir string,
|
||||||
apexAndroidMkData android.AndroidMkData) []string {
|
apexAndroidMkData android.AndroidMkData) []string {
|
||||||
|
|
||||||
@@ -114,12 +124,7 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, mo
|
|||||||
|
|
||||||
linkToSystemLib := a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform()
|
linkToSystemLib := a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform()
|
||||||
|
|
||||||
var moduleName string
|
moduleName := a.fullModuleName(apexBundleName, &fi)
|
||||||
if linkToSystemLib {
|
|
||||||
moduleName = fi.androidMkModuleName
|
|
||||||
} else {
|
|
||||||
moduleName = fi.androidMkModuleName + "." + apexBundleName + a.suffix
|
|
||||||
}
|
|
||||||
|
|
||||||
if !android.InList(moduleName, moduleNames) {
|
if !android.InList(moduleName, moduleNames) {
|
||||||
moduleNames = append(moduleNames, moduleName)
|
moduleNames = append(moduleNames, moduleName)
|
||||||
@@ -311,14 +316,16 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, mo
|
|||||||
return moduleNames
|
return moduleNames
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *apexBundle) writeRequiredModules(w io.Writer) {
|
func (a *apexBundle) writeRequiredModules(w io.Writer, apexBundleName string) {
|
||||||
var required []string
|
var required []string
|
||||||
var targetRequired []string
|
var targetRequired []string
|
||||||
var hostRequired []string
|
var hostRequired []string
|
||||||
|
installMapSet := make(map[string]bool) // set of dependency module:location mappings
|
||||||
for _, fi := range a.filesInfo {
|
for _, fi := range a.filesInfo {
|
||||||
required = append(required, fi.requiredModuleNames...)
|
required = append(required, fi.requiredModuleNames...)
|
||||||
targetRequired = append(targetRequired, fi.targetRequiredModuleNames...)
|
targetRequired = append(targetRequired, fi.targetRequiredModuleNames...)
|
||||||
hostRequired = append(hostRequired, fi.hostRequiredModuleNames...)
|
hostRequired = append(hostRequired, fi.hostRequiredModuleNames...)
|
||||||
|
installMapSet[a.fullModuleName(apexBundleName, &fi)+":"+fi.installDir+"/"+fi.builtFile.Base()] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(required) > 0 {
|
if len(required) > 0 {
|
||||||
@@ -330,6 +337,11 @@ func (a *apexBundle) writeRequiredModules(w io.Writer) {
|
|||||||
if len(hostRequired) > 0 {
|
if len(hostRequired) > 0 {
|
||||||
fmt.Fprintln(w, "LOCAL_HOST_REQUIRED_MODULES +=", strings.Join(hostRequired, " "))
|
fmt.Fprintln(w, "LOCAL_HOST_REQUIRED_MODULES +=", strings.Join(hostRequired, " "))
|
||||||
}
|
}
|
||||||
|
if len(installMapSet) > 0 {
|
||||||
|
var installs []string
|
||||||
|
installs = append(installs, android.SortedStringKeys(installMapSet)...)
|
||||||
|
fmt.Fprintln(w, "LOCAL_LICENSE_INSTALL_MAP +=", strings.Join(installs, " "))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *apexBundle) androidMkForType() android.AndroidMkData {
|
func (a *apexBundle) androidMkForType() android.AndroidMkData {
|
||||||
@@ -347,16 +359,18 @@ func (a *apexBundle) androidMkForType() android.AndroidMkData {
|
|||||||
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
|
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
|
||||||
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
|
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
|
||||||
fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix)
|
fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix)
|
||||||
|
data.Entries.WriteLicenseVariables(w)
|
||||||
if len(moduleNames) > 0 {
|
if len(moduleNames) > 0 {
|
||||||
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
|
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
|
||||||
}
|
}
|
||||||
a.writeRequiredModules(w)
|
a.writeRequiredModules(w, name)
|
||||||
fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
|
fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
|
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
|
||||||
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
|
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
|
||||||
fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix)
|
fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix)
|
||||||
|
data.Entries.WriteLicenseVariables(w)
|
||||||
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
|
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
|
||||||
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFile.String())
|
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFile.String())
|
||||||
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.ToMakePath().String())
|
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.ToMakePath().String())
|
||||||
@@ -389,7 +403,7 @@ func (a *apexBundle) androidMkForType() android.AndroidMkData {
|
|||||||
if len(a.requiredDeps) > 0 {
|
if len(a.requiredDeps) > 0 {
|
||||||
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.requiredDeps, " "))
|
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.requiredDeps, " "))
|
||||||
}
|
}
|
||||||
a.writeRequiredModules(w)
|
a.writeRequiredModules(w, name)
|
||||||
var postInstallCommands []string
|
var postInstallCommands []string
|
||||||
if a.prebuiltFileToDelete != "" {
|
if a.prebuiltFileToDelete != "" {
|
||||||
postInstallCommands = append(postInstallCommands, "rm -rf "+
|
postInstallCommands = append(postInstallCommands, "rm -rf "+
|
||||||
|
@@ -120,6 +120,7 @@ func (bpf *bpf) AndroidMk() android.AndroidMkData {
|
|||||||
names = append(names, objName)
|
names = append(names, objName)
|
||||||
fmt.Fprintln(w, "include $(CLEAR_VARS)")
|
fmt.Fprintln(w, "include $(CLEAR_VARS)")
|
||||||
fmt.Fprintln(w, "LOCAL_MODULE := ", objName)
|
fmt.Fprintln(w, "LOCAL_MODULE := ", objName)
|
||||||
|
data.Entries.WriteLicenseVariables(w)
|
||||||
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", obj.String())
|
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", obj.String())
|
||||||
fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", obj.Base())
|
fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", obj.Base())
|
||||||
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC")
|
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC")
|
||||||
@@ -129,6 +130,7 @@ func (bpf *bpf) AndroidMk() android.AndroidMkData {
|
|||||||
}
|
}
|
||||||
fmt.Fprintln(w, "include $(CLEAR_VARS)")
|
fmt.Fprintln(w, "include $(CLEAR_VARS)")
|
||||||
fmt.Fprintln(w, "LOCAL_MODULE := ", name)
|
fmt.Fprintln(w, "LOCAL_MODULE := ", name)
|
||||||
|
data.Entries.WriteLicenseVariables(w)
|
||||||
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(names, " "))
|
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(names, " "))
|
||||||
fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
|
fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
|
||||||
},
|
},
|
||||||
|
@@ -192,6 +192,7 @@ func (system *SystemModules) AndroidMk() android.AndroidMkData {
|
|||||||
|
|
||||||
fmt.Fprintln(w, name+":", "$("+makevar+")")
|
fmt.Fprintln(w, name+":", "$("+makevar+")")
|
||||||
fmt.Fprintln(w, ".PHONY:", name)
|
fmt.Fprintln(w, ".PHONY:", name)
|
||||||
|
// TODO(b/151177513): Licenses: Doesn't go through base_rules. May have to generate meta_lic and meta_module here.
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -52,6 +52,7 @@ func (p *phony) AndroidMk() android.AndroidMkData {
|
|||||||
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
|
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
|
||||||
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
|
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
|
||||||
fmt.Fprintln(w, "LOCAL_MODULE :=", name)
|
fmt.Fprintln(w, "LOCAL_MODULE :=", name)
|
||||||
|
data.Entries.WriteLicenseVariables(w)
|
||||||
if p.Host() {
|
if p.Host() {
|
||||||
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
|
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
|
||||||
}
|
}
|
||||||
|
@@ -307,6 +307,7 @@ func (m *syspropLibrary) AndroidMk() android.AndroidMkData {
|
|||||||
// Actual implementation libraries are created on LoadHookMutator
|
// Actual implementation libraries are created on LoadHookMutator
|
||||||
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
|
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
|
||||||
fmt.Fprintf(w, "LOCAL_MODULE := %s\n", m.Name())
|
fmt.Fprintf(w, "LOCAL_MODULE := %s\n", m.Name())
|
||||||
|
data.Entries.WriteLicenseVariables(w)
|
||||||
fmt.Fprintf(w, "LOCAL_MODULE_CLASS := FAKE\n")
|
fmt.Fprintf(w, "LOCAL_MODULE_CLASS := FAKE\n")
|
||||||
fmt.Fprintf(w, "LOCAL_MODULE_TAGS := optional\n")
|
fmt.Fprintf(w, "LOCAL_MODULE_TAGS := optional\n")
|
||||||
fmt.Fprintf(w, "include $(BUILD_SYSTEM)/base_rules.mk\n\n")
|
fmt.Fprintf(w, "include $(BUILD_SYSTEM)/base_rules.mk\n\n")
|
||||||
|
Reference in New Issue
Block a user