2015-07-09 09:13:11 +08:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// This file offers AndroidMkEntriesProvider, which individual modules implement to output
|
|
|
|
// Android.mk entries that contain information about the modules built through Soong. Kati reads
|
|
|
|
// and combines them with the legacy Make-based module definitions to produce the complete view of
|
|
|
|
// the source tree, which makes this a critical point of Make-Soong interoperability.
|
|
|
|
//
|
|
|
|
// Naturally, Soong-only builds do not rely on this mechanism.
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
package android
|
2015-07-09 09:13:11 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2016-02-10 09:43:51 +08:00
|
|
|
"fmt"
|
2015-07-09 09:13:11 +08:00
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2021-01-07 11:34:31 +08:00
|
|
|
"reflect"
|
2015-07-09 09:13:11 +08:00
|
|
|
"sort"
|
2016-06-02 06:25:32 +08:00
|
|
|
"strings"
|
2015-07-09 09:13:11 +08:00
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2018-09-29 01:19:18 +08:00
|
|
|
"github.com/google/blueprint/bootstrap"
|
2015-07-09 09:13:11 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2020-03-05 04:15:08 +08:00
|
|
|
RegisterAndroidMkBuildComponents(InitRegistrationContext)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RegisterAndroidMkBuildComponents(ctx RegistrationContext) {
|
|
|
|
ctx.RegisterSingletonType("androidmk", AndroidMkSingleton)
|
2015-07-09 09:13:11 +08:00
|
|
|
}
|
|
|
|
|
2021-03-07 23:44:41 +08:00
|
|
|
// Enable androidmk support.
|
|
|
|
// * Register the singleton
|
|
|
|
// * Configure that we are inside make
|
|
|
|
var PrepareForTestWithAndroidMk = GroupFixturePreparers(
|
|
|
|
FixtureRegisterWithContext(RegisterAndroidMkBuildComponents),
|
|
|
|
FixtureModifyConfig(SetKatiEnabledForTests),
|
|
|
|
)
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// Deprecated: Use AndroidMkEntriesProvider instead, especially if you're not going to use the
|
|
|
|
// Custom function. It's easier to use and test.
|
2015-07-09 09:13:11 +08:00
|
|
|
type AndroidMkDataProvider interface {
|
2017-08-11 08:00:19 +08:00
|
|
|
AndroidMk() AndroidMkData
|
2016-10-07 07:12:58 +08:00
|
|
|
BaseModuleName() string
|
2015-07-09 09:13:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type AndroidMkData struct {
|
2019-04-02 09:37:36 +08:00
|
|
|
Class string
|
|
|
|
SubName string
|
2020-06-15 13:24:19 +08:00
|
|
|
DistFiles TaggedDistFiles
|
2019-04-02 09:37:36 +08:00
|
|
|
OutputFile OptionalPath
|
|
|
|
Disabled bool
|
|
|
|
Include string
|
|
|
|
Required []string
|
|
|
|
Host_required []string
|
|
|
|
Target_required []string
|
2015-07-09 09:13:11 +08:00
|
|
|
|
2017-08-11 08:07:28 +08:00
|
|
|
Custom func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData)
|
2015-07-09 09:13:11 +08:00
|
|
|
|
2017-08-11 07:32:23 +08:00
|
|
|
Extra []AndroidMkExtraFunc
|
2017-08-11 08:07:28 +08:00
|
|
|
|
2020-06-24 22:26:26 +08:00
|
|
|
Entries AndroidMkEntries
|
2015-07-09 09:13:11 +08:00
|
|
|
}
|
|
|
|
|
2017-08-11 07:32:23 +08:00
|
|
|
type AndroidMkExtraFunc func(w io.Writer, outputFile Path)
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// Interface for modules to declare their Android.mk outputs. Note that every module needs to
|
|
|
|
// implement this in order to be included in the final Android-<product_name>.mk output, even if
|
|
|
|
// they only need to output the common set of entries without any customizations.
|
2019-04-04 06:47:29 +08:00
|
|
|
type AndroidMkEntriesProvider interface {
|
2020-11-17 04:50:29 +08:00
|
|
|
// Returns AndroidMkEntries objects that contain all basic info plus extra customization data
|
|
|
|
// if needed. This is the core func to implement.
|
|
|
|
// Note that one can return multiple objects. For example, java_library may return an additional
|
|
|
|
// AndroidMkEntries object for its hostdex sub-module.
|
2019-12-03 12:24:29 +08:00
|
|
|
AndroidMkEntries() []AndroidMkEntries
|
2020-11-17 04:50:29 +08:00
|
|
|
// Modules don't need to implement this as it's already implemented by ModuleBase.
|
|
|
|
// AndroidMkEntries uses BaseModuleName() instead of ModuleName() because certain modules
|
|
|
|
// e.g. Prebuilts, override the Name() func and return modified names.
|
|
|
|
// If a different name is preferred, use SubName or OverrideName in AndroidMkEntries.
|
2019-04-04 06:47:29 +08:00
|
|
|
BaseModuleName() string
|
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// The core data struct that modules use to provide their Android.mk data.
|
2019-04-04 06:47:29 +08:00
|
|
|
type AndroidMkEntries struct {
|
2020-11-17 04:50:29 +08:00
|
|
|
// Android.mk class string, e.g EXECUTABLES, JAVA_LIBRARIES, ETC
|
|
|
|
Class string
|
|
|
|
// Optional suffix to append to the module name. Useful when a module wants to return multiple
|
|
|
|
// AndroidMkEntries objects. For example, when a java_library returns an additional entry for
|
|
|
|
// its hostdex sub-module, this SubName field is set to "-hostdex" so that it can have a
|
|
|
|
// different name than the parent's.
|
|
|
|
SubName string
|
|
|
|
// If set, this value overrides the base module name. SubName is still appended.
|
|
|
|
OverrideName string
|
|
|
|
// Dist files to output
|
|
|
|
DistFiles TaggedDistFiles
|
|
|
|
// The output file for Kati to process and/or install. If absent, the module is skipped.
|
|
|
|
OutputFile OptionalPath
|
|
|
|
// If true, the module is skipped and does not appear on the final Android-<product name>.mk
|
|
|
|
// file. Useful when a module needs to be skipped conditionally.
|
|
|
|
Disabled bool
|
|
|
|
// The postprocessing mk file to include, e.g. $(BUILD_SYSTEM)/soong_cc_prebuilt.mk
|
|
|
|
// If not set, $(BUILD_SYSTEM)/prebuilt.mk is used.
|
|
|
|
Include string
|
|
|
|
// Required modules that need to be built and included in the final build output when building
|
|
|
|
// this module.
|
|
|
|
Required []string
|
|
|
|
// Required host modules that need to be built and included in the final build output when
|
|
|
|
// building this module.
|
|
|
|
Host_required []string
|
|
|
|
// Required device modules that need to be built and included in the final build output when
|
|
|
|
// building this module.
|
2019-04-04 06:47:29 +08:00
|
|
|
Target_required []string
|
|
|
|
|
|
|
|
header bytes.Buffer
|
|
|
|
footer bytes.Buffer
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// Funcs to append additional Android.mk entries or modify the common ones. Multiple funcs are
|
|
|
|
// accepted so that common logic can be factored out as a shared func.
|
2019-08-28 08:33:16 +08:00
|
|
|
ExtraEntries []AndroidMkExtraEntriesFunc
|
2020-11-17 04:50:29 +08:00
|
|
|
// Funcs to add extra lines to the module's Android.mk output. Unlike AndroidMkExtraEntriesFunc,
|
|
|
|
// which simply sets Make variable values, this can be used for anything since it can write any
|
|
|
|
// Make statements directly to the final Android-*.mk file.
|
|
|
|
// Primarily used to call macros or declare/update Make targets.
|
2019-08-30 05:56:03 +08:00
|
|
|
ExtraFooters []AndroidMkExtraFootersFunc
|
2019-04-04 06:47:29 +08:00
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// A map that holds the up-to-date Make variable values. Can be accessed from tests.
|
|
|
|
EntryMap map[string][]string
|
|
|
|
// A list of EntryMap keys in insertion order. This serves a few purposes:
|
|
|
|
// 1. Prevents churns. Golang map doesn't provide consistent iteration order, so without this,
|
|
|
|
// the outputted Android-*.mk file may change even though there have been no content changes.
|
|
|
|
// 2. Allows modules to refer to other variables, like LOCAL_BAR_VAR := $(LOCAL_FOO_VAR),
|
|
|
|
// without worrying about the variables being mixed up in the actual mk file.
|
|
|
|
// 3. Makes troubleshooting and spotting errors easier.
|
2019-04-04 06:47:29 +08:00
|
|
|
entryOrder []string
|
|
|
|
}
|
|
|
|
|
2020-07-04 04:18:24 +08:00
|
|
|
type AndroidMkExtraEntriesContext interface {
|
|
|
|
Provider(provider blueprint.ProviderKey) interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type androidMkExtraEntriesContext struct {
|
|
|
|
ctx fillInEntriesContext
|
|
|
|
mod blueprint.Module
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *androidMkExtraEntriesContext) Provider(provider blueprint.ProviderKey) interface{} {
|
|
|
|
return a.ctx.ModuleProvider(a.mod, provider)
|
|
|
|
}
|
|
|
|
|
|
|
|
type AndroidMkExtraEntriesFunc func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries)
|
2020-12-08 02:23:54 +08:00
|
|
|
type AndroidMkExtraFootersFunc func(w io.Writer, name, prefix, moduleDir string)
|
2019-08-28 08:33:16 +08:00
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// Utility funcs to manipulate Android.mk variable entries.
|
|
|
|
|
|
|
|
// SetString sets a Make variable with the given name to the given value.
|
2019-04-04 06:47:29 +08:00
|
|
|
func (a *AndroidMkEntries) SetString(name, value string) {
|
|
|
|
if _, ok := a.EntryMap[name]; !ok {
|
|
|
|
a.entryOrder = append(a.entryOrder, name)
|
|
|
|
}
|
|
|
|
a.EntryMap[name] = []string{value}
|
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// SetPath sets a Make variable with the given name to the given path string.
|
2019-09-05 11:17:54 +08:00
|
|
|
func (a *AndroidMkEntries) SetPath(name string, path Path) {
|
|
|
|
if _, ok := a.EntryMap[name]; !ok {
|
|
|
|
a.entryOrder = append(a.entryOrder, name)
|
|
|
|
}
|
|
|
|
a.EntryMap[name] = []string{path.String()}
|
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// SetOptionalPath sets a Make variable with the given name to the given path string if it is valid.
|
|
|
|
// It is a no-op if the given path is invalid.
|
2020-07-04 02:56:24 +08:00
|
|
|
func (a *AndroidMkEntries) SetOptionalPath(name string, path OptionalPath) {
|
|
|
|
if path.Valid() {
|
|
|
|
a.SetPath(name, path.Path())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// AddPath appends the given path string to a Make variable with the given name.
|
2020-07-04 02:56:24 +08:00
|
|
|
func (a *AndroidMkEntries) AddPath(name string, path Path) {
|
|
|
|
if _, ok := a.EntryMap[name]; !ok {
|
|
|
|
a.entryOrder = append(a.entryOrder, name)
|
|
|
|
}
|
|
|
|
a.EntryMap[name] = append(a.EntryMap[name], path.String())
|
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// AddOptionalPath appends the given path string to a Make variable with the given name if it is
|
|
|
|
// valid. It is a no-op if the given path is invalid.
|
2020-07-04 02:56:24 +08:00
|
|
|
func (a *AndroidMkEntries) AddOptionalPath(name string, path OptionalPath) {
|
|
|
|
if path.Valid() {
|
|
|
|
a.AddPath(name, path.Path())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// SetPaths sets a Make variable with the given name to a slice of the given path strings.
|
2020-07-22 11:31:17 +08:00
|
|
|
func (a *AndroidMkEntries) SetPaths(name string, paths Paths) {
|
|
|
|
if _, ok := a.EntryMap[name]; !ok {
|
|
|
|
a.entryOrder = append(a.entryOrder, name)
|
|
|
|
}
|
|
|
|
a.EntryMap[name] = paths.Strings()
|
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// SetOptionalPaths sets a Make variable with the given name to a slice of the given path strings
|
|
|
|
// only if there are a non-zero amount of paths.
|
2020-07-22 11:31:17 +08:00
|
|
|
func (a *AndroidMkEntries) SetOptionalPaths(name string, paths Paths) {
|
|
|
|
if len(paths) > 0 {
|
|
|
|
a.SetPaths(name, paths)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// AddPaths appends the given path strings to a Make variable with the given name.
|
2020-07-22 11:31:17 +08:00
|
|
|
func (a *AndroidMkEntries) AddPaths(name string, paths Paths) {
|
|
|
|
if _, ok := a.EntryMap[name]; !ok {
|
|
|
|
a.entryOrder = append(a.entryOrder, name)
|
|
|
|
}
|
|
|
|
a.EntryMap[name] = append(a.EntryMap[name], paths.Strings()...)
|
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// SetBoolIfTrue sets a Make variable with the given name to true if the given flag is true.
|
|
|
|
// It is a no-op if the given flag is false.
|
2019-04-04 06:47:29 +08:00
|
|
|
func (a *AndroidMkEntries) SetBoolIfTrue(name string, flag bool) {
|
|
|
|
if flag {
|
|
|
|
if _, ok := a.EntryMap[name]; !ok {
|
|
|
|
a.entryOrder = append(a.entryOrder, name)
|
|
|
|
}
|
|
|
|
a.EntryMap[name] = []string{"true"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// SetBool sets a Make variable with the given name to if the given bool flag value.
|
2019-09-05 11:17:54 +08:00
|
|
|
func (a *AndroidMkEntries) SetBool(name string, flag bool) {
|
|
|
|
if _, ok := a.EntryMap[name]; !ok {
|
|
|
|
a.entryOrder = append(a.entryOrder, name)
|
|
|
|
}
|
|
|
|
if flag {
|
|
|
|
a.EntryMap[name] = []string{"true"}
|
|
|
|
} else {
|
|
|
|
a.EntryMap[name] = []string{"false"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// AddStrings appends the given strings to a Make variable with the given name.
|
2019-04-04 06:47:29 +08:00
|
|
|
func (a *AndroidMkEntries) AddStrings(name string, value ...string) {
|
|
|
|
if len(value) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if _, ok := a.EntryMap[name]; !ok {
|
|
|
|
a.entryOrder = append(a.entryOrder, name)
|
|
|
|
}
|
|
|
|
a.EntryMap[name] = append(a.EntryMap[name], value...)
|
|
|
|
}
|
|
|
|
|
2020-11-25 04:42:58 +08:00
|
|
|
// AddCompatibilityTestSuites adds the supplied test suites to the EntryMap, with special handling
|
|
|
|
// for partial MTS test suites.
|
|
|
|
func (a *AndroidMkEntries) AddCompatibilityTestSuites(suites ...string) {
|
|
|
|
// MTS supports a full test suite and partial per-module MTS test suites, with naming mts-${MODULE}.
|
|
|
|
// To reduce repetition, if we find a partial MTS test suite without an full MTS test suite,
|
|
|
|
// we add the full test suite to our list.
|
|
|
|
if PrefixInList(suites, "mts-") && !InList("mts", suites) {
|
|
|
|
suites = append(suites, "mts")
|
|
|
|
}
|
|
|
|
a.AddStrings("LOCAL_COMPATIBILITY_SUITE", suites...)
|
|
|
|
}
|
|
|
|
|
2020-11-26 22:33:21 +08:00
|
|
|
// The contributions to the dist.
|
|
|
|
type distContributions struct {
|
|
|
|
// List of goals and the dist copy instructions.
|
|
|
|
copiesForGoals []*copiesForGoals
|
|
|
|
}
|
|
|
|
|
|
|
|
// getCopiesForGoals returns a copiesForGoals into which copy instructions that
|
|
|
|
// must be processed when building one or more of those goals can be added.
|
|
|
|
func (d *distContributions) getCopiesForGoals(goals string) *copiesForGoals {
|
|
|
|
copiesForGoals := &copiesForGoals{goals: goals}
|
|
|
|
d.copiesForGoals = append(d.copiesForGoals, copiesForGoals)
|
|
|
|
return copiesForGoals
|
|
|
|
}
|
|
|
|
|
|
|
|
// Associates a list of dist copy instructions with a set of goals for which they
|
|
|
|
// should be run.
|
|
|
|
type copiesForGoals struct {
|
|
|
|
// goals are a space separated list of build targets that will trigger the
|
|
|
|
// copy instructions.
|
|
|
|
goals string
|
|
|
|
|
|
|
|
// A list of instructions to copy a module's output files to somewhere in the
|
|
|
|
// dist directory.
|
|
|
|
copies []distCopy
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adds a copy instruction.
|
|
|
|
func (d *copiesForGoals) addCopyInstruction(from Path, dest string) {
|
|
|
|
d.copies = append(d.copies, distCopy{from, dest})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction on a path that must be copied into the dist.
|
|
|
|
type distCopy struct {
|
|
|
|
// The path to copy from.
|
|
|
|
from Path
|
|
|
|
|
|
|
|
// The destination within the dist directory to copy to.
|
|
|
|
dest string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the contributions that the module makes to the dist.
|
|
|
|
func (a *AndroidMkEntries) getDistContributions(mod blueprint.Module) *distContributions {
|
2019-04-04 06:47:29 +08:00
|
|
|
amod := mod.(Module).base()
|
|
|
|
name := amod.BaseModuleName()
|
|
|
|
|
2020-11-26 00:37:46 +08:00
|
|
|
// Collate the set of associated tag/paths available for copying to the dist.
|
|
|
|
// Start with an empty (nil) set.
|
2020-07-24 17:13:49 +08:00
|
|
|
var availableTaggedDists TaggedDistFiles
|
2020-06-15 13:24:19 +08:00
|
|
|
|
2020-11-26 00:37:46 +08:00
|
|
|
// Then merge in any that are provided explicitly by the module.
|
2020-07-21 19:32:19 +08:00
|
|
|
if a.DistFiles != nil {
|
2020-11-26 00:37:46 +08:00
|
|
|
// Merge the DistFiles into the set.
|
|
|
|
availableTaggedDists = availableTaggedDists.merge(a.DistFiles)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no paths have been provided for the DefaultDistTag and the output file is
|
|
|
|
// valid then add that as the default dist path.
|
|
|
|
if _, ok := availableTaggedDists[DefaultDistTag]; !ok && a.OutputFile.Valid() {
|
|
|
|
availableTaggedDists = availableTaggedDists.addPathsForTag(DefaultDistTag, a.OutputFile.Path())
|
|
|
|
}
|
|
|
|
|
2020-11-24 07:32:56 +08:00
|
|
|
// If the distFiles created by GenerateTaggedDistFiles contains paths for the
|
|
|
|
// DefaultDistTag then that takes priority so delete any existing paths.
|
|
|
|
if _, ok := amod.distFiles[DefaultDistTag]; ok {
|
|
|
|
delete(availableTaggedDists, DefaultDistTag)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, merge the distFiles created by GenerateTaggedDistFiles.
|
|
|
|
availableTaggedDists = availableTaggedDists.merge(amod.distFiles)
|
|
|
|
|
2020-11-26 00:37:46 +08:00
|
|
|
if len(availableTaggedDists) == 0 {
|
2020-07-24 17:13:49 +08:00
|
|
|
// Nothing dist-able for this module.
|
|
|
|
return nil
|
2019-04-04 06:47:29 +08:00
|
|
|
}
|
|
|
|
|
2020-11-26 22:33:21 +08:00
|
|
|
// Collate the contributions this module makes to the dist.
|
|
|
|
distContributions := &distContributions{}
|
|
|
|
|
2020-06-15 13:24:19 +08:00
|
|
|
// Iterate over this module's dist structs, merged from the dist and dists properties.
|
|
|
|
for _, dist := range amod.Dists() {
|
|
|
|
// Get the list of goals this dist should be enabled for. e.g. sdk, droidcore
|
|
|
|
goals := strings.Join(dist.Targets, " ")
|
|
|
|
|
|
|
|
// Get the tag representing the output files to be dist'd. e.g. ".jar", ".proguard_map"
|
|
|
|
var tag string
|
|
|
|
if dist.Tag == nil {
|
|
|
|
// If the dist struct does not specify a tag, use the default output files tag.
|
2020-11-26 00:37:46 +08:00
|
|
|
tag = DefaultDistTag
|
2020-06-15 13:24:19 +08:00
|
|
|
} else {
|
|
|
|
tag = *dist.Tag
|
2019-04-04 06:47:29 +08:00
|
|
|
}
|
|
|
|
|
2020-06-15 13:24:19 +08:00
|
|
|
// Get the paths of the output files to be dist'd, represented by the tag.
|
|
|
|
// Can be an empty list.
|
|
|
|
tagPaths := availableTaggedDists[tag]
|
|
|
|
if len(tagPaths) == 0 {
|
|
|
|
// Nothing to dist for this tag, continue to the next dist.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(tagPaths) > 1 && (dist.Dest != nil || dist.Suffix != nil) {
|
2020-11-26 00:37:46 +08:00
|
|
|
errorMessage := "%s: Cannot apply dest/suffix for more than one dist " +
|
|
|
|
"file for %q goals tag %q in module %s. The list of dist files, " +
|
2020-06-15 13:24:19 +08:00
|
|
|
"which should have a single element, is:\n%s"
|
2020-11-26 00:37:46 +08:00
|
|
|
panic(fmt.Errorf(errorMessage, mod, goals, tag, name, tagPaths))
|
2020-06-15 13:24:19 +08:00
|
|
|
}
|
|
|
|
|
2020-11-26 22:33:21 +08:00
|
|
|
copiesForGoals := distContributions.getCopiesForGoals(goals)
|
2020-06-15 13:24:19 +08:00
|
|
|
|
2020-11-26 22:33:21 +08:00
|
|
|
// Iterate over each path adding a copy instruction to copiesForGoals
|
2020-06-15 13:24:19 +08:00
|
|
|
for _, path := range tagPaths {
|
|
|
|
// It's possible that the Path is nil from errant modules. Be defensive here.
|
|
|
|
if path == nil {
|
|
|
|
tagName := "default" // for error message readability
|
|
|
|
if dist.Tag != nil {
|
|
|
|
tagName = *dist.Tag
|
|
|
|
}
|
|
|
|
panic(fmt.Errorf("Dist file should not be nil for the %s tag in %s", tagName, name))
|
|
|
|
}
|
|
|
|
|
|
|
|
dest := filepath.Base(path.String())
|
|
|
|
|
|
|
|
if dist.Dest != nil {
|
2019-04-04 06:47:29 +08:00
|
|
|
var err error
|
2020-06-15 13:24:19 +08:00
|
|
|
if dest, err = validateSafePath(*dist.Dest); err != nil {
|
2019-04-04 06:47:29 +08:00
|
|
|
// This was checked in ModuleBase.GenerateBuildActions
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 13:24:19 +08:00
|
|
|
if dist.Suffix != nil {
|
2019-04-04 06:47:29 +08:00
|
|
|
ext := filepath.Ext(dest)
|
2020-06-15 13:24:19 +08:00
|
|
|
suffix := *dist.Suffix
|
2019-04-04 06:47:29 +08:00
|
|
|
dest = strings.TrimSuffix(dest, ext) + suffix + ext
|
|
|
|
}
|
|
|
|
|
2020-06-15 13:24:19 +08:00
|
|
|
if dist.Dir != nil {
|
2019-04-04 06:47:29 +08:00
|
|
|
var err error
|
2020-06-15 13:24:19 +08:00
|
|
|
if dest, err = validateSafePath(*dist.Dir, dest); err != nil {
|
2019-04-04 06:47:29 +08:00
|
|
|
// This was checked in ModuleBase.GenerateBuildActions
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-26 22:33:21 +08:00
|
|
|
copiesForGoals.addCopyInstruction(path, dest)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return distContributions
|
|
|
|
}
|
|
|
|
|
|
|
|
// generateDistContributionsForMake generates make rules that will generate the
|
|
|
|
// dist according to the instructions in the supplied distContribution.
|
|
|
|
func generateDistContributionsForMake(distContributions *distContributions) []string {
|
|
|
|
var ret []string
|
|
|
|
for _, d := range distContributions.copiesForGoals {
|
|
|
|
ret = append(ret, fmt.Sprintf(".PHONY: %s\n", d.goals))
|
|
|
|
// Create dist-for-goals calls for each of the copy instructions.
|
|
|
|
for _, c := range d.copies {
|
2020-06-15 13:24:19 +08:00
|
|
|
ret = append(
|
|
|
|
ret,
|
2020-11-26 22:33:21 +08:00
|
|
|
fmt.Sprintf("$(call dist-for-goals,%s,%s:%s)\n", d.goals, c.from.String(), c.dest))
|
2019-04-04 06:47:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 13:24:19 +08:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2020-11-26 22:33:21 +08:00
|
|
|
// Compute the list of Make strings to declare phony goals and dist-for-goals
|
|
|
|
// calls from the module's dist and dists properties.
|
|
|
|
func (a *AndroidMkEntries) GetDistForGoals(mod blueprint.Module) []string {
|
|
|
|
distContributions := a.getDistContributions(mod)
|
|
|
|
if distContributions == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return generateDistContributionsForMake(distContributions)
|
|
|
|
}
|
|
|
|
|
2021-01-07 11:34:31 +08:00
|
|
|
// 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, " "))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// 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.
|
2020-07-04 04:18:24 +08:00
|
|
|
type fillInEntriesContext interface {
|
|
|
|
ModuleDir(module blueprint.Module) string
|
|
|
|
Config() Config
|
|
|
|
ModuleProvider(module blueprint.Module, provider blueprint.ProviderKey) interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint.Module) {
|
2020-06-15 13:24:19 +08:00
|
|
|
a.EntryMap = make(map[string][]string)
|
|
|
|
amod := mod.(Module).base()
|
|
|
|
name := amod.BaseModuleName()
|
2020-10-14 09:43:54 +08:00
|
|
|
if a.OverrideName != "" {
|
|
|
|
name = a.OverrideName
|
|
|
|
}
|
2020-06-15 13:24:19 +08:00
|
|
|
|
|
|
|
if a.Include == "" {
|
|
|
|
a.Include = "$(BUILD_PREBUILT)"
|
|
|
|
}
|
|
|
|
a.Required = append(a.Required, amod.commonProperties.Required...)
|
|
|
|
a.Host_required = append(a.Host_required, amod.commonProperties.Host_required...)
|
|
|
|
a.Target_required = append(a.Target_required, amod.commonProperties.Target_required...)
|
|
|
|
|
|
|
|
for _, distString := range a.GetDistForGoals(mod) {
|
|
|
|
fmt.Fprintf(&a.header, distString)
|
|
|
|
}
|
|
|
|
|
2019-04-04 06:47:29 +08:00
|
|
|
fmt.Fprintln(&a.header, "\ninclude $(CLEAR_VARS)")
|
|
|
|
|
|
|
|
// Collect make variable assignment entries.
|
2020-07-04 04:18:24 +08:00
|
|
|
a.SetString("LOCAL_PATH", ctx.ModuleDir(mod))
|
2019-04-04 06:47:29 +08:00
|
|
|
a.SetString("LOCAL_MODULE", name+a.SubName)
|
2021-01-07 11:34:31 +08:00
|
|
|
a.AddStrings("LOCAL_LICENSE_KINDS", amod.commonProperties.Effective_license_kinds...)
|
|
|
|
a.AddStrings("LOCAL_LICENSE_CONDITIONS", amod.commonProperties.Effective_license_conditions...)
|
2021-05-11 05:53:30 +08:00
|
|
|
a.AddStrings("LOCAL_NOTICE_FILE", amod.commonProperties.Effective_license_text.Strings()...)
|
2021-01-07 11:34:31 +08:00
|
|
|
// 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)
|
2021-04-16 03:43:39 +08:00
|
|
|
} else if len(amod.commonProperties.Effective_licenses) > 0 {
|
|
|
|
a.SetString("LOCAL_LICENSE_PACKAGE_NAME", strings.Join(amod.commonProperties.Effective_licenses, " "))
|
2021-01-07 11:34:31 +08:00
|
|
|
}
|
2019-04-04 06:47:29 +08:00
|
|
|
a.SetString("LOCAL_MODULE_CLASS", a.Class)
|
|
|
|
a.SetString("LOCAL_PREBUILT_MODULE_FILE", a.OutputFile.String())
|
|
|
|
a.AddStrings("LOCAL_REQUIRED_MODULES", a.Required...)
|
|
|
|
a.AddStrings("LOCAL_HOST_REQUIRED_MODULES", a.Host_required...)
|
|
|
|
a.AddStrings("LOCAL_TARGET_REQUIRED_MODULES", a.Target_required...)
|
|
|
|
|
mark platform un-availability
A module is marked unavailable for platform when 1) it does not have
"//apex_available:platform" in its apex_available property, or 2)
it depends on another module that is unavailable for platform.
In that case, LOCAL_NOT_AVAILABLE_FOR_PLATFORM is set to true for the
module in the Make world. Later, that flag is used to ensure that there
is no module with the flag is installed to the device.
The reason why this isn't entirely done in Soong is because Soong
doesn't know if a module will be installed to the device or not. To
explain this, let's have an example.
cc_test { name: "mytest", static_libs: ["libfoo"]}
cc_library_static { name: "libfoo", static_libs: ["libbar"]}
cc_library { name: "libbar", apex_available: ["com.android.xxx"]}
Here, libbar is not available for platform, but is used by libfoo which
is available for platform (apex_available defaults to
"//apex_available:platform"). libfoo is again depended on by mytest
which again is available for platform. The use of libbar should be
allowed in the context of test; we don't want to make libbar available
to platform just for the dependency from test because it will allow
non-test uses of the library as well.
Soong by itself can't tell whether libfoo and libbar are used only in the
context of a test. There could be another module depending them, e.g.,
cc_library_shared { name: "mylib", static_libs: ["libfoo"] }
can exist and it might be installed to the device, in which case
we really should trigger an error.
Since Make has the knowledge of what's installed and what's not,
the check should be done there.
Bug: 153073816
Test: m
Test: remove "//apex_available:platform" from libmdnssd (it is currently
installed to /system/lib), and check that `m system_image` fails
Change-Id: Ia304cc5f41f173229e8a154e90cea4dce46dcebe
2020-04-07 15:37:39 +08:00
|
|
|
if am, ok := mod.(ApexModule); ok {
|
|
|
|
a.SetBoolIfTrue("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", am.NotAvailableForPlatform())
|
|
|
|
}
|
|
|
|
|
2019-04-04 06:47:29 +08:00
|
|
|
archStr := amod.Arch().ArchType.String()
|
|
|
|
host := false
|
|
|
|
switch amod.Os().Class {
|
|
|
|
case Host:
|
2020-09-14 18:43:17 +08:00
|
|
|
if amod.Target().HostCross {
|
|
|
|
// Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common.
|
|
|
|
if amod.Arch().ArchType != Common {
|
|
|
|
a.SetString("LOCAL_MODULE_HOST_CROSS_ARCH", archStr)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Make cannot identify LOCAL_MODULE_HOST_ARCH:= common.
|
|
|
|
if amod.Arch().ArchType != Common {
|
|
|
|
a.SetString("LOCAL_MODULE_HOST_ARCH", archStr)
|
|
|
|
}
|
2019-04-04 06:47:29 +08:00
|
|
|
}
|
|
|
|
host = true
|
|
|
|
case Device:
|
|
|
|
// Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common.
|
2019-10-17 02:03:10 +08:00
|
|
|
if amod.Arch().ArchType != Common {
|
2019-03-26 19:39:31 +08:00
|
|
|
if amod.Target().NativeBridge {
|
2019-07-11 16:23:53 +08:00
|
|
|
hostArchStr := amod.Target().NativeBridgeHostArchName
|
2019-03-26 19:39:31 +08:00
|
|
|
if hostArchStr != "" {
|
|
|
|
a.SetString("LOCAL_MODULE_TARGET_ARCH", hostArchStr)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
a.SetString("LOCAL_MODULE_TARGET_ARCH", archStr)
|
|
|
|
}
|
2019-04-04 06:47:29 +08:00
|
|
|
}
|
|
|
|
|
2020-12-03 10:55:06 +08:00
|
|
|
if !amod.InRamdisk() && !amod.InVendorRamdisk() {
|
2021-04-06 22:35:10 +08:00
|
|
|
a.AddPaths("LOCAL_FULL_INIT_RC", amod.initRcPaths)
|
2020-12-03 10:55:06 +08:00
|
|
|
}
|
2021-04-17 04:41:59 +08:00
|
|
|
if len(amod.vintfFragmentsPaths) > 0 {
|
|
|
|
a.AddPaths("LOCAL_FULL_VINTF_FRAGMENTS", amod.vintfFragmentsPaths)
|
|
|
|
}
|
2019-04-04 06:47:29 +08:00
|
|
|
a.SetBoolIfTrue("LOCAL_PROPRIETARY_MODULE", Bool(amod.commonProperties.Proprietary))
|
|
|
|
if Bool(amod.commonProperties.Vendor) || Bool(amod.commonProperties.Soc_specific) {
|
|
|
|
a.SetString("LOCAL_VENDOR_MODULE", "true")
|
|
|
|
}
|
|
|
|
a.SetBoolIfTrue("LOCAL_ODM_MODULE", Bool(amod.commonProperties.Device_specific))
|
|
|
|
a.SetBoolIfTrue("LOCAL_PRODUCT_MODULE", Bool(amod.commonProperties.Product_specific))
|
2019-06-25 15:47:17 +08:00
|
|
|
a.SetBoolIfTrue("LOCAL_SYSTEM_EXT_MODULE", Bool(amod.commonProperties.System_ext_specific))
|
2019-04-04 06:47:29 +08:00
|
|
|
if amod.commonProperties.Owner != nil {
|
|
|
|
a.SetString("LOCAL_MODULE_OWNER", *amod.commonProperties.Owner)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-19 12:21:55 +08:00
|
|
|
if len(amod.noticeFiles) > 0 {
|
|
|
|
a.SetString("LOCAL_NOTICE_FILE", strings.Join(amod.noticeFiles.Strings(), " "))
|
2019-04-04 06:47:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if host {
|
|
|
|
makeOs := amod.Os().String()
|
|
|
|
if amod.Os() == Linux || amod.Os() == LinuxBionic {
|
|
|
|
makeOs = "linux"
|
|
|
|
}
|
|
|
|
a.SetString("LOCAL_MODULE_HOST_OS", makeOs)
|
|
|
|
a.SetString("LOCAL_IS_HOST_MODULE", "true")
|
|
|
|
}
|
|
|
|
|
|
|
|
prefix := ""
|
|
|
|
if amod.ArchSpecific() {
|
|
|
|
switch amod.Os().Class {
|
|
|
|
case Host:
|
2020-09-14 18:43:17 +08:00
|
|
|
if amod.Target().HostCross {
|
|
|
|
prefix = "HOST_CROSS_"
|
|
|
|
} else {
|
|
|
|
prefix = "HOST_"
|
|
|
|
}
|
2019-04-04 06:47:29 +08:00
|
|
|
case Device:
|
|
|
|
prefix = "TARGET_"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-04 04:18:24 +08:00
|
|
|
if amod.Arch().ArchType != ctx.Config().Targets[amod.Os()][0].Arch.ArchType {
|
2019-04-04 06:47:29 +08:00
|
|
|
prefix = "2ND_" + prefix
|
|
|
|
}
|
|
|
|
}
|
2020-07-04 04:18:24 +08:00
|
|
|
|
|
|
|
extraCtx := &androidMkExtraEntriesContext{
|
|
|
|
ctx: ctx,
|
|
|
|
mod: mod,
|
|
|
|
}
|
|
|
|
|
2019-08-28 08:33:16 +08:00
|
|
|
for _, extra := range a.ExtraEntries {
|
2020-07-04 04:18:24 +08:00
|
|
|
extra(extraCtx, a)
|
2019-04-04 06:47:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write to footer.
|
|
|
|
fmt.Fprintln(&a.footer, "include "+a.Include)
|
2020-07-04 04:18:24 +08:00
|
|
|
blueprintDir := ctx.ModuleDir(mod)
|
2019-08-30 05:56:03 +08:00
|
|
|
for _, footerFunc := range a.ExtraFooters {
|
2020-12-08 02:23:54 +08:00
|
|
|
footerFunc(&a.footer, name, prefix, blueprintDir)
|
2019-08-30 05:56:03 +08:00
|
|
|
}
|
2019-04-04 06:47:29 +08:00
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// write flushes the AndroidMkEntries's in-struct data populated by AndroidMkEntries into the
|
|
|
|
// given Writer object.
|
2019-04-04 06:47:29 +08:00
|
|
|
func (a *AndroidMkEntries) write(w io.Writer) {
|
2019-08-30 05:56:03 +08:00
|
|
|
if a.Disabled {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !a.OutputFile.Valid() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-04-04 06:47:29 +08:00
|
|
|
w.Write(a.header.Bytes())
|
|
|
|
for _, name := range a.entryOrder {
|
|
|
|
fmt.Fprintln(w, name+" := "+strings.Join(a.EntryMap[name], " "))
|
|
|
|
}
|
|
|
|
w.Write(a.footer.Bytes())
|
|
|
|
}
|
|
|
|
|
2019-08-30 05:56:03 +08:00
|
|
|
func (a *AndroidMkEntries) FooterLinesForTests() []string {
|
|
|
|
return strings.Split(string(a.footer.Bytes()), "\n")
|
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// AndroidMkSingleton is a singleton to collect Android.mk data from all modules and dump them into
|
|
|
|
// the final Android-<product_name>.mk file output.
|
2017-11-29 09:34:01 +08:00
|
|
|
func AndroidMkSingleton() Singleton {
|
2015-07-09 09:13:11 +08:00
|
|
|
return &androidMkSingleton{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type androidMkSingleton struct{}
|
|
|
|
|
2017-11-29 09:34:01 +08:00
|
|
|
func (c *androidMkSingleton) GenerateBuildActions(ctx SingletonContext) {
|
2020-11-17 04:50:29 +08:00
|
|
|
// Skip if Soong wasn't invoked from Make.
|
2020-11-23 13:22:30 +08:00
|
|
|
if !ctx.Config().KatiEnabled() {
|
2015-12-12 05:51:06 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-09-29 01:19:18 +08:00
|
|
|
var androidMkModulesList []blueprint.Module
|
2015-07-09 09:13:11 +08:00
|
|
|
|
2018-09-29 01:19:18 +08:00
|
|
|
ctx.VisitAllModulesBlueprint(func(module blueprint.Module) {
|
2017-11-29 09:34:01 +08:00
|
|
|
androidMkModulesList = append(androidMkModulesList, module)
|
2016-01-12 04:55:55 +08:00
|
|
|
})
|
2015-07-09 09:13:11 +08:00
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// Sort the module list by the module names to eliminate random churns, which may erroneously
|
|
|
|
// invoke additional build processes.
|
2019-01-15 04:47:35 +08:00
|
|
|
sort.SliceStable(androidMkModulesList, func(i, j int) bool {
|
|
|
|
return ctx.ModuleName(androidMkModulesList[i]) < ctx.ModuleName(androidMkModulesList[j])
|
|
|
|
})
|
2015-12-18 10:00:23 +08:00
|
|
|
|
2018-03-10 13:22:06 +08:00
|
|
|
transMk := PathForOutput(ctx, "Android"+String(ctx.Config().productVariables.Make_suffix)+".mk")
|
2015-09-24 06:26:20 +08:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2015-07-09 09:13:11 +08:00
|
|
|
|
2020-01-11 09:11:46 +08:00
|
|
|
err := translateAndroidMk(ctx, absolutePath(transMk.String()), androidMkModulesList)
|
2015-07-09 09:13:11 +08:00
|
|
|
if err != nil {
|
|
|
|
ctx.Errorf(err.Error())
|
|
|
|
}
|
|
|
|
|
2017-11-29 09:34:01 +08:00
|
|
|
ctx.Build(pctx, BuildParams{
|
|
|
|
Rule: blueprint.Phony,
|
|
|
|
Output: transMk,
|
2015-07-09 09:13:11 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-09-29 01:19:18 +08:00
|
|
|
func translateAndroidMk(ctx SingletonContext, mkFile string, mods []blueprint.Module) error {
|
2015-07-09 09:13:11 +08:00
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
|
2016-02-10 09:43:51 +08:00
|
|
|
fmt.Fprintln(buf, "LOCAL_MODULE_MAKEFILE := $(lastword $(MAKEFILE_LIST))")
|
2015-07-09 09:13:11 +08:00
|
|
|
|
2020-12-22 01:11:10 +08:00
|
|
|
typeStats := make(map[string]int)
|
2015-07-09 09:13:11 +08:00
|
|
|
for _, mod := range mods {
|
|
|
|
err := translateAndroidMkModule(ctx, buf, mod)
|
|
|
|
if err != nil {
|
|
|
|
os.Remove(mkFile)
|
|
|
|
return err
|
|
|
|
}
|
2016-07-26 07:00:20 +08:00
|
|
|
|
2018-09-29 01:19:18 +08:00
|
|
|
if amod, ok := mod.(Module); ok && ctx.PrimaryModule(amod) == amod {
|
2020-12-22 01:11:10 +08:00
|
|
|
typeStats[ctx.ModuleType(amod)] += 1
|
2016-07-26 07:00:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
keys := []string{}
|
|
|
|
fmt.Fprintln(buf, "\nSTATS.SOONG_MODULE_TYPE :=")
|
2020-12-22 01:11:10 +08:00
|
|
|
for k := range typeStats {
|
2016-07-26 07:00:20 +08:00
|
|
|
keys = append(keys, k)
|
|
|
|
}
|
|
|
|
sort.Strings(keys)
|
|
|
|
for _, mod_type := range keys {
|
|
|
|
fmt.Fprintln(buf, "STATS.SOONG_MODULE_TYPE +=", mod_type)
|
2020-12-22 01:11:10 +08:00
|
|
|
fmt.Fprintf(buf, "STATS.SOONG_MODULE_TYPE.%s := %d\n", mod_type, typeStats[mod_type])
|
2015-07-09 09:13:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't write to the file if it hasn't changed
|
2020-01-11 09:11:46 +08:00
|
|
|
if _, err := os.Stat(absolutePath(mkFile)); !os.IsNotExist(err) {
|
|
|
|
if data, err := ioutil.ReadFile(absolutePath(mkFile)); err == nil {
|
2015-07-09 09:13:11 +08:00
|
|
|
matches := buf.Len() == len(data)
|
|
|
|
|
|
|
|
if matches {
|
|
|
|
for i, value := range buf.Bytes() {
|
|
|
|
if value != data[i] {
|
|
|
|
matches = false
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if matches {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-11 09:11:46 +08:00
|
|
|
return ioutil.WriteFile(absolutePath(mkFile), buf.Bytes(), 0666)
|
2015-07-09 09:13:11 +08:00
|
|
|
}
|
|
|
|
|
2017-11-29 09:34:01 +08:00
|
|
|
func translateAndroidMkModule(ctx SingletonContext, w io.Writer, mod blueprint.Module) error {
|
2018-09-06 07:23:54 +08:00
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
panic(fmt.Errorf("%s in translateAndroidMkModule for module %s variant %s",
|
|
|
|
r, ctx.ModuleName(mod), ctx.ModuleSubDir(mod)))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2021-01-07 11:34:31 +08:00
|
|
|
// Additional cases here require review for correct license propagation to make.
|
2018-09-29 01:19:18 +08:00
|
|
|
switch x := mod.(type) {
|
|
|
|
case AndroidMkDataProvider:
|
|
|
|
return translateAndroidModule(ctx, w, mod, x)
|
|
|
|
case bootstrap.GoBinaryTool:
|
|
|
|
return translateGoBinaryModule(ctx, w, mod, x)
|
2019-04-04 06:47:29 +08:00
|
|
|
case AndroidMkEntriesProvider:
|
|
|
|
return translateAndroidMkEntriesModule(ctx, w, mod, x)
|
2018-09-29 01:19:18 +08:00
|
|
|
default:
|
2021-01-07 11:34:31 +08:00
|
|
|
// Not exported to make so no make variables to set.
|
2016-02-10 09:43:51 +08:00
|
|
|
return nil
|
2015-07-09 09:13:11 +08:00
|
|
|
}
|
2018-09-29 01:19:18 +08:00
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// A simple, special Android.mk entry output func to make it possible to build blueprint tools using
|
|
|
|
// m by making them phony targets.
|
2018-09-29 01:19:18 +08:00
|
|
|
func translateGoBinaryModule(ctx SingletonContext, w io.Writer, mod blueprint.Module,
|
|
|
|
goBinary bootstrap.GoBinaryTool) error {
|
|
|
|
|
|
|
|
name := ctx.ModuleName(mod)
|
|
|
|
fmt.Fprintln(w, ".PHONY:", name)
|
|
|
|
fmt.Fprintln(w, name+":", goBinary.InstallPath())
|
|
|
|
fmt.Fprintln(w, "")
|
2021-01-07 11:34:31 +08:00
|
|
|
// 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.
|
2018-09-29 01:19:18 +08:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-04 04:18:24 +08:00
|
|
|
func (data *AndroidMkData) fillInData(ctx fillInEntriesContext, mod blueprint.Module) {
|
2019-04-04 06:47:29 +08:00
|
|
|
// Get the preamble content through AndroidMkEntries logic.
|
2020-06-24 22:26:26 +08:00
|
|
|
data.Entries = AndroidMkEntries{
|
2019-04-04 06:47:29 +08:00
|
|
|
Class: data.Class,
|
|
|
|
SubName: data.SubName,
|
2020-06-15 13:24:19 +08:00
|
|
|
DistFiles: data.DistFiles,
|
2019-04-04 06:47:29 +08:00
|
|
|
OutputFile: data.OutputFile,
|
|
|
|
Disabled: data.Disabled,
|
|
|
|
Include: data.Include,
|
|
|
|
Required: data.Required,
|
|
|
|
Host_required: data.Host_required,
|
|
|
|
Target_required: data.Target_required,
|
2016-06-14 08:19:03 +08:00
|
|
|
}
|
2020-07-04 04:18:24 +08:00
|
|
|
data.Entries.fillInEntries(ctx, mod)
|
2016-06-14 08:19:03 +08:00
|
|
|
|
2019-07-11 15:18:47 +08:00
|
|
|
// copy entries back to data since it is used in Custom
|
2020-06-24 22:26:26 +08:00
|
|
|
data.Required = data.Entries.Required
|
|
|
|
data.Host_required = data.Entries.Host_required
|
|
|
|
data.Target_required = data.Entries.Target_required
|
2019-07-11 15:18:47 +08:00
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// A support func for the deprecated AndroidMkDataProvider interface. Use AndroidMkEntryProvider
|
|
|
|
// instead.
|
2019-07-11 15:18:47 +08:00
|
|
|
func translateAndroidModule(ctx SingletonContext, w io.Writer, mod blueprint.Module,
|
|
|
|
provider AndroidMkDataProvider) error {
|
|
|
|
|
|
|
|
amod := mod.(Module).base()
|
|
|
|
if shouldSkipAndroidMkProcessing(amod) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
data := provider.AndroidMk()
|
|
|
|
if data.Include == "" {
|
|
|
|
data.Include = "$(BUILD_PREBUILT)"
|
|
|
|
}
|
|
|
|
|
2020-07-04 04:18:24 +08:00
|
|
|
data.fillInData(ctx, mod)
|
2019-07-11 15:18:47 +08:00
|
|
|
|
2017-08-11 08:07:28 +08:00
|
|
|
prefix := ""
|
|
|
|
if amod.ArchSpecific() {
|
|
|
|
switch amod.Os().Class {
|
|
|
|
case Host:
|
2020-09-14 18:43:17 +08:00
|
|
|
if amod.Target().HostCross {
|
|
|
|
prefix = "HOST_CROSS_"
|
|
|
|
} else {
|
|
|
|
prefix = "HOST_"
|
|
|
|
}
|
2017-08-11 08:07:28 +08:00
|
|
|
case Device:
|
|
|
|
prefix = "TARGET_"
|
2016-03-25 04:14:12 +08:00
|
|
|
|
2015-07-09 09:13:11 +08:00
|
|
|
}
|
|
|
|
|
2018-10-11 08:02:29 +08:00
|
|
|
if amod.Arch().ArchType != ctx.Config().Targets[amod.Os()][0].Arch.ArchType {
|
2017-08-11 08:07:28 +08:00
|
|
|
prefix = "2ND_" + prefix
|
|
|
|
}
|
2016-02-10 09:43:51 +08:00
|
|
|
}
|
2015-07-09 09:13:11 +08:00
|
|
|
|
2019-04-04 06:47:29 +08:00
|
|
|
name := provider.BaseModuleName()
|
2017-08-11 08:07:28 +08:00
|
|
|
blueprintDir := filepath.Dir(ctx.BlueprintFile(mod))
|
|
|
|
|
|
|
|
if data.Custom != nil {
|
2021-01-07 11:34:31 +08:00
|
|
|
// List of module types allowed to use .Custom(...)
|
|
|
|
// Additions to the list require careful review for proper license handling.
|
2020-07-04 04:18:24 +08:00
|
|
|
switch reflect.TypeOf(mod).String() { // ctx.ModuleType(mod) doesn't work: aidl_interface creates phony without type
|
2021-01-07 11:34:31 +08:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|
2017-08-11 08:07:28 +08:00
|
|
|
data.Custom(w, name, prefix, blueprintDir, data)
|
|
|
|
} else {
|
|
|
|
WriteAndroidMkData(w, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// A support func for the deprecated AndroidMkDataProvider interface. Use AndroidMkEntryProvider
|
|
|
|
// instead.
|
2017-08-11 08:07:28 +08:00
|
|
|
func WriteAndroidMkData(w io.Writer, data AndroidMkData) {
|
|
|
|
if data.Disabled {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !data.OutputFile.Valid() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-06-24 22:26:26 +08:00
|
|
|
// write preamble via Entries
|
|
|
|
data.Entries.footer = bytes.Buffer{}
|
|
|
|
data.Entries.write(w)
|
2017-08-11 08:07:28 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
for _, extra := range data.Extra {
|
2017-08-11 07:32:23 +08:00
|
|
|
extra(w, data.OutputFile.Path())
|
2015-07-09 09:13:11 +08:00
|
|
|
}
|
|
|
|
|
2017-09-08 04:20:25 +08:00
|
|
|
fmt.Fprintln(w, "include "+data.Include)
|
2015-07-09 09:13:11 +08:00
|
|
|
}
|
2019-04-02 09:37:36 +08:00
|
|
|
|
2019-04-04 06:47:29 +08:00
|
|
|
func translateAndroidMkEntriesModule(ctx SingletonContext, w io.Writer, mod blueprint.Module,
|
|
|
|
provider AndroidMkEntriesProvider) error {
|
|
|
|
if shouldSkipAndroidMkProcessing(mod.(Module).base()) {
|
|
|
|
return nil
|
2019-04-02 09:37:36 +08:00
|
|
|
}
|
2019-04-04 06:47:29 +08:00
|
|
|
|
2021-01-07 11:34:31 +08:00
|
|
|
// Any new or special cases here need review to verify correct propagation of license information.
|
2019-12-03 12:24:29 +08:00
|
|
|
for _, entries := range provider.AndroidMkEntries() {
|
2020-07-04 04:18:24 +08:00
|
|
|
entries.fillInEntries(ctx, mod)
|
2019-12-03 12:24:29 +08:00
|
|
|
entries.write(w)
|
|
|
|
}
|
2019-04-04 06:47:29 +08:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func shouldSkipAndroidMkProcessing(module *ModuleBase) bool {
|
|
|
|
if !module.commonProperties.NamespaceExportedToMake {
|
|
|
|
// TODO(jeffrygaston) do we want to validate that there are no modules being
|
|
|
|
// exported to Kati that depend on this module?
|
|
|
|
return true
|
2019-04-02 09:37:36 +08:00
|
|
|
}
|
2019-04-04 06:47:29 +08:00
|
|
|
|
|
|
|
return !module.Enabled() ||
|
2020-12-17 02:20:23 +08:00
|
|
|
module.commonProperties.HideFromMake ||
|
2019-04-04 06:47:29 +08:00
|
|
|
// Make does not understand LinuxBionic
|
|
|
|
module.Os() == LinuxBionic
|
2019-04-02 09:37:36 +08:00
|
|
|
}
|
2020-09-22 03:11:02 +08:00
|
|
|
|
2020-11-17 04:50:29 +08:00
|
|
|
// A utility func to format LOCAL_TEST_DATA outputs. See the comments on DataPath to understand how
|
|
|
|
// to use this func.
|
2020-09-22 03:11:02 +08:00
|
|
|
func AndroidMkDataPaths(data []DataPath) []string {
|
|
|
|
var testFiles []string
|
|
|
|
for _, d := range data {
|
|
|
|
rel := d.SrcPath.Rel()
|
|
|
|
path := d.SrcPath.String()
|
2020-11-17 04:50:29 +08:00
|
|
|
// LOCAL_TEST_DATA requires the rel portion of the path to be removed from the path.
|
2020-09-22 03:11:02 +08:00
|
|
|
if !strings.HasSuffix(path, rel) {
|
|
|
|
panic(fmt.Errorf("path %q does not end with %q", path, rel))
|
|
|
|
}
|
|
|
|
path = strings.TrimSuffix(path, rel)
|
|
|
|
testFileString := path + ":" + rel
|
|
|
|
if len(d.RelativeInstallPath) > 0 {
|
|
|
|
testFileString += ":" + d.RelativeInstallPath
|
|
|
|
}
|
|
|
|
testFiles = append(testFiles, testFileString)
|
|
|
|
}
|
|
|
|
return testFiles
|
|
|
|
}
|