2015-01-31 09:27:36 +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.
2016-05-19 06:37:25 +08:00
package android
2015-01-31 09:27:36 +08:00
import (
"encoding/json"
"fmt"
2016-11-04 00:43:26 +08:00
"io/ioutil"
2015-01-31 09:27:36 +08:00
"os"
2015-04-03 05:37:16 +08:00
"path/filepath"
2015-01-31 09:27:36 +08:00
"runtime"
2015-09-24 06:26:20 +08:00
"strings"
2015-04-16 03:33:28 +08:00
"sync"
2015-12-18 08:39:19 +08:00
2019-12-14 12:41:13 +08:00
"github.com/google/blueprint"
2017-12-12 07:52:26 +08:00
"github.com/google/blueprint/bootstrap"
2019-12-14 12:41:13 +08:00
"github.com/google/blueprint/pathtools"
2015-12-18 08:39:19 +08:00
"github.com/google/blueprint/proptools"
2019-11-23 08:03:51 +08:00
"android/soong/android/soongconfig"
2015-01-31 09:27:36 +08:00
)
2015-12-18 08:39:19 +08:00
var Bool = proptools . Bool
2016-12-09 07:45:07 +08:00
var String = proptools . String
2020-08-06 22:00:37 +08:00
var StringDefault = proptools . StringDefault
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-21 01:03:43 +08:00
2020-07-24 07:43:25 +08:00
const FutureApiLevelInt = 10000
var FutureApiLevel = ApiLevel {
value : "current" ,
number : FutureApiLevelInt ,
isPreview : true ,
}
2015-12-18 08:39:19 +08:00
2015-01-31 09:27:36 +08:00
// The configuration file name
2015-07-14 15:39:06 +08:00
const configFileName = "soong.config"
const productVariablesFileName = "soong.variables"
2015-01-31 09:27:36 +08:00
// A FileConfigurableOptions contains options which can be configured by the
// config file. These will be included in the config struct.
type FileConfigurableOptions struct {
2020-09-17 18:09:58 +08:00
Mega_device * bool ` json:",omitempty" `
Host_bionic * bool ` json:",omitempty" `
Host_bionic_arm64 * bool ` json:",omitempty" `
2015-01-31 09:27:36 +08:00
}
2015-09-19 01:57:10 +08:00
func ( f * FileConfigurableOptions ) SetDefaultConfig ( ) {
* f = FileConfigurableOptions { }
2015-01-31 09:27:36 +08:00
}
2016-08-18 06:24:12 +08:00
// A Config object represents the entire build configuration for Android.
2015-04-11 06:43:55 +08:00
type Config struct {
* config
}
2017-03-30 08:29:06 +08:00
func ( c Config ) BuildDir ( ) string {
return c . buildDir
}
2016-08-18 06:24:12 +08:00
// A DeviceConfig object represents the configuration for a particular device being built. For
// now there will only be one of these, but in the future there may be multiple devices being
// built
type DeviceConfig struct {
* deviceConfig
}
2019-11-23 08:03:51 +08:00
type VendorConfig soongconfig . SoongConfig
2018-03-27 03:41:18 +08:00
2015-04-08 08:11:30 +08:00
type config struct {
2015-01-31 09:27:36 +08:00
FileConfigurableOptions
2018-03-10 13:22:06 +08:00
productVariables productVariables
2015-01-31 09:27:36 +08:00
2018-03-13 09:06:05 +08:00
// Only available on configs created by TestConfig
TestProductVariables * productVariables
2020-09-29 14:23:17 +08:00
BazelContext BazelContext
2017-12-12 07:52:26 +08:00
PrimaryBuilder string
2015-07-14 15:39:06 +08:00
ConfigFileName string
ProductVariablesFileName string
2020-10-10 08:25:15 +08:00
Targets map [ OsType ] [ ] Target
BuildOSTarget Target // the Target for tools run on the build machine
BuildOSCommonTarget Target // the Target for common (java) tools run on the build machine
AndroidCommonTarget Target // the Target for common modules for the Android device
AndroidFirstDeviceTarget Target // the first Target for modules for the Android device
2015-07-09 09:13:11 +08:00
2019-09-18 05:45:31 +08:00
// multilibConflicts for an ArchType is true if there is earlier configured device architecture with the same
// multilib value.
multilibConflicts map [ ArchType ] bool
2016-08-18 06:24:12 +08:00
deviceConfig * deviceConfig
2020-06-24 05:37:05 +08:00
srcDir string // the path of the root source directory
buildDir string // the path of the build output directory
moduleListFile string // the path to the file which lists blueprint files to parse.
2015-04-16 03:33:28 +08:00
2017-10-11 14:07:38 +08:00
env map [ string ] string
2015-09-12 08:06:19 +08:00
envLock sync . Mutex
envDeps map [ string ] string
envFrozen bool
2015-12-12 05:51:06 +08:00
inMake bool
2016-08-25 06:25:47 +08:00
2017-09-06 12:56:44 +08:00
captureBuild bool // true for tests, saves build parameters for each module
ignoreEnvironment bool // true for tests, returns empty from all Getenv calls
2017-07-14 05:43:27 +08:00
2017-12-12 07:52:26 +08:00
stopBefore bootstrap . StopBefore
2019-12-14 12:41:13 +08:00
fs pathtools . FileSystem
mockBpList string
2020-06-08 07:56:32 +08:00
// If testAllowNonExistentPaths is true then PathForSource and PathForModuleSrc won't error
// in tests when a path doesn't exist.
testAllowNonExistentPaths bool
2020-10-30 09:23:58 +08:00
ninjaFileDepsSet sync . Map
2016-08-18 06:24:12 +08:00
OncePer
}
type deviceConfig struct {
2017-07-07 07:59:48 +08:00
config * config
2016-08-18 06:24:12 +08:00
OncePer
2015-01-31 09:27:36 +08:00
}
2015-08-28 04:28:01 +08:00
type jsonConfigurable interface {
2015-09-19 01:57:10 +08:00
SetDefaultConfig ( )
2015-08-28 04:28:01 +08:00
}
func loadConfig ( config * config ) error {
2020-01-11 09:11:46 +08:00
err := loadFromConfigFile ( & config . FileConfigurableOptions , absolutePath ( config . ConfigFileName ) )
2015-08-28 04:28:01 +08:00
if err != nil {
return err
}
2020-01-11 09:11:46 +08:00
return loadFromConfigFile ( & config . productVariables , absolutePath ( config . ProductVariablesFileName ) )
2015-08-28 04:28:01 +08:00
}
2015-01-31 09:27:36 +08:00
2015-08-28 04:28:01 +08:00
// loads configuration options from a JSON file in the cwd.
func loadFromConfigFile ( configurable jsonConfigurable , filename string ) error {
2015-01-31 09:27:36 +08:00
// Try to open the file
2015-08-28 04:28:01 +08:00
configFileReader , err := os . Open ( filename )
2015-01-31 09:27:36 +08:00
defer configFileReader . Close ( )
if os . IsNotExist ( err ) {
// Need to create a file, so that blueprint & ninja don't get in
// a dependency tracking loop.
// Make a file-configurable-options with defaults, write it out using
// a json writer.
2015-09-19 01:57:10 +08:00
configurable . SetDefaultConfig ( )
err = saveToConfigFile ( configurable , filename )
2015-01-31 09:27:36 +08:00
if err != nil {
return err
}
2018-02-28 03:26:02 +08:00
} else if err != nil {
return fmt . Errorf ( "config file: could not open %s: %s" , filename , err . Error ( ) )
2015-01-31 09:27:36 +08:00
} else {
// Make a decoder for it
jsonDecoder := json . NewDecoder ( configFileReader )
2015-08-28 04:28:01 +08:00
err = jsonDecoder . Decode ( configurable )
2015-01-31 09:27:36 +08:00
if err != nil {
2018-02-28 03:26:02 +08:00
return fmt . Errorf ( "config file: %s did not parse correctly: %s" , filename , err . Error ( ) )
2015-01-31 09:27:36 +08:00
}
}
// No error
return nil
}
2016-11-04 00:43:26 +08:00
// atomically writes the config file in case two copies of soong_build are running simultaneously
// (for example, docs generation and ninja manifest generation)
2015-08-28 04:28:01 +08:00
func saveToConfigFile ( config jsonConfigurable , filename string ) error {
2015-01-31 09:27:36 +08:00
data , err := json . MarshalIndent ( & config , "" , " " )
if err != nil {
return fmt . Errorf ( "cannot marshal config data: %s" , err . Error ( ) )
}
2016-11-04 00:43:26 +08:00
f , err := ioutil . TempFile ( filepath . Dir ( filename ) , "config" )
2015-01-31 09:27:36 +08:00
if err != nil {
2015-08-28 04:28:01 +08:00
return fmt . Errorf ( "cannot create empty config file %s: %s\n" , filename , err . Error ( ) )
2015-01-31 09:27:36 +08:00
}
2016-11-04 00:43:26 +08:00
defer os . Remove ( f . Name ( ) )
defer f . Close ( )
2015-01-31 09:27:36 +08:00
2016-11-04 00:43:26 +08:00
_ , err = f . Write ( data )
2015-01-31 09:27:36 +08:00
if err != nil {
2015-08-28 04:28:01 +08:00
return fmt . Errorf ( "default config file: %s could not be written: %s" , filename , err . Error ( ) )
}
2016-11-04 00:43:26 +08:00
_ , err = f . WriteString ( "\n" )
2015-08-28 04:28:01 +08:00
if err != nil {
return fmt . Errorf ( "default config file: %s could not be written: %s" , filename , err . Error ( ) )
2015-01-31 09:27:36 +08:00
}
2016-11-04 00:43:26 +08:00
f . Close ( )
os . Rename ( f . Name ( ) , filename )
2015-01-31 09:27:36 +08:00
return nil
}
2020-01-11 09:11:46 +08:00
// NullConfig returns a mostly empty Config for use by standalone tools like dexpreopt_gen that
// use the android package.
func NullConfig ( buildDir string ) Config {
return Config {
config : & config {
buildDir : buildDir ,
fs : pathtools . OsFs ,
} ,
}
}
2016-10-07 07:12:58 +08:00
// TestConfig returns a Config object suitable for using for tests
2019-12-14 12:41:13 +08:00
func TestConfig ( buildDir string , env map [ string ] string , bp string , fs map [ string ] [ ] byte ) Config {
2019-04-23 06:51:26 +08:00
envCopy := make ( map [ string ] string )
for k , v := range env {
envCopy [ k ] = v
}
// Copy the real PATH value to the test environment, it's needed by HostSystemTool() used in x86_darwin_host.go
envCopy [ "PATH" ] = originalEnv [ "PATH" ]
2017-07-07 07:59:48 +08:00
config := & config {
2018-03-10 13:22:06 +08:00
productVariables : productVariables {
2020-07-24 08:32:15 +08:00
DeviceName : stringPtr ( "test_device" ) ,
Platform_sdk_version : intPtr ( 30 ) ,
Platform_sdk_codename : stringPtr ( "S" ) ,
Platform_version_active_codenames : [ ] string { "S" } ,
DeviceSystemSdkVersions : [ ] string { "14" , "15" } ,
Platform_systemsdk_versions : [ ] string { "29" , "30" } ,
AAPTConfig : [ ] string { "normal" , "large" , "xlarge" , "hdpi" , "xhdpi" , "xxhdpi" } ,
AAPTPreferredConfig : stringPtr ( "xhdpi" ) ,
AAPTCharacteristics : stringPtr ( "nosdcard" ) ,
AAPTPrebuiltDPI : [ ] string { "xhdpi" , "xxhdpi" } ,
UncompressPrivAppDex : boolPtr ( true ) ,
2017-07-07 07:59:48 +08:00
} ,
2017-10-11 14:07:38 +08:00
buildDir : buildDir ,
captureBuild : true ,
2019-04-23 06:51:26 +08:00
env : envCopy ,
2020-06-08 07:56:32 +08:00
// Set testAllowNonExistentPaths so that test contexts don't need to specify every path
// passed to PathForSource or PathForModuleSrc.
testAllowNonExistentPaths : true ,
2020-09-29 14:23:17 +08:00
BazelContext : noopBazelContext { } ,
2017-07-07 07:59:48 +08:00
}
config . deviceConfig = & deviceConfig {
config : config ,
}
2018-03-10 13:22:06 +08:00
config . TestProductVariables = & config . productVariables
2017-07-07 07:59:48 +08:00
2019-12-14 12:41:13 +08:00
config . mockFileSystem ( bp , fs )
2017-09-30 08:58:17 +08:00
if err := config . fromEnv ( ) ; err != nil {
panic ( err )
}
2017-07-07 07:59:48 +08:00
return Config { config }
2016-10-07 07:12:58 +08:00
}
2019-12-14 12:41:13 +08:00
func TestArchConfigNativeBridge ( buildDir string , env map [ string ] string , bp string , fs map [ string ] [ ] byte ) Config {
testConfig := TestArchConfig ( buildDir , env , bp , fs )
2019-03-26 19:39:31 +08:00
config := testConfig . config
2019-05-15 07:01:24 +08:00
config . Targets [ Android ] = [ ] Target {
2020-09-14 18:43:17 +08:00
{ Android , Arch { ArchType : X86_64 , ArchVariant : "silvermont" , Abi : [ ] string { "arm64-v8a" } } , NativeBridgeDisabled , "" , "" , false } ,
{ Android , Arch { ArchType : X86 , ArchVariant : "silvermont" , Abi : [ ] string { "armeabi-v7a" } } , NativeBridgeDisabled , "" , "" , false } ,
{ Android , Arch { ArchType : Arm64 , ArchVariant : "armv8-a" , Abi : [ ] string { "arm64-v8a" } } , NativeBridgeEnabled , "x86_64" , "arm64" , false } ,
{ Android , Arch { ArchType : Arm , ArchVariant : "armv7-a-neon" , Abi : [ ] string { "armeabi-v7a" } } , NativeBridgeEnabled , "x86" , "arm" , false } ,
2019-03-26 19:39:31 +08:00
}
return testConfig
}
2019-12-14 12:41:13 +08:00
func TestArchConfigFuchsia ( buildDir string , env map [ string ] string , bp string , fs map [ string ] [ ] byte ) Config {
testConfig := TestConfig ( buildDir , env , bp , fs )
2019-01-18 06:44:05 +08:00
config := testConfig . config
config . Targets = map [ OsType ] [ ] Target {
Fuchsia : [ ] Target {
2020-09-14 18:43:17 +08:00
{ Fuchsia , Arch { ArchType : Arm64 , ArchVariant : "" , Abi : [ ] string { "arm64-v8a" } } , NativeBridgeDisabled , "" , "" , false } ,
2019-01-18 06:44:05 +08:00
} ,
BuildOs : [ ] Target {
2020-09-14 18:43:17 +08:00
{ BuildOs , Arch { ArchType : X86_64 } , NativeBridgeDisabled , "" , "" , false } ,
2019-01-18 06:44:05 +08:00
} ,
}
return testConfig
}
2017-09-16 08:33:55 +08:00
// TestConfig returns a Config object suitable for using for tests that need to run the arch mutator
2019-12-14 12:41:13 +08:00
func TestArchConfig ( buildDir string , env map [ string ] string , bp string , fs map [ string ] [ ] byte ) Config {
testConfig := TestConfig ( buildDir , env , bp , fs )
2017-09-16 08:33:55 +08:00
config := testConfig . config
2018-10-11 08:02:29 +08:00
config . Targets = map [ OsType ] [ ] Target {
Android : [ ] Target {
2020-09-14 18:43:17 +08:00
{ Android , Arch { ArchType : Arm64 , ArchVariant : "armv8-a" , Abi : [ ] string { "arm64-v8a" } } , NativeBridgeDisabled , "" , "" , false } ,
{ Android , Arch { ArchType : Arm , ArchVariant : "armv7-a-neon" , Abi : [ ] string { "armeabi-v7a" } } , NativeBridgeDisabled , "" , "" , false } ,
2017-09-16 08:33:55 +08:00
} ,
2018-10-11 08:02:29 +08:00
BuildOs : [ ] Target {
2020-09-14 18:43:17 +08:00
{ BuildOs , Arch { ArchType : X86_64 } , NativeBridgeDisabled , "" , "" , false } ,
{ BuildOs , Arch { ArchType : X86 } , NativeBridgeDisabled , "" , "" , false } ,
2017-09-16 08:33:55 +08:00
} ,
}
2019-05-15 07:01:24 +08:00
if runtime . GOOS == "darwin" {
config . Targets [ BuildOs ] = config . Targets [ BuildOs ] [ : 1 ]
}
2019-10-17 02:03:10 +08:00
config . BuildOSTarget = config . Targets [ BuildOs ] [ 0 ]
config . BuildOSCommonTarget = getCommonTargets ( config . Targets [ BuildOs ] ) [ 0 ]
config . AndroidCommonTarget = getCommonTargets ( config . Targets [ Android ] ) [ 0 ]
2020-10-10 08:25:15 +08:00
config . AndroidFirstDeviceTarget = firstTarget ( config . Targets [ Android ] , "lib64" , "lib32" ) [ 0 ]
2019-05-09 12:29:15 +08:00
config . TestProductVariables . DeviceArch = proptools . StringPtr ( "arm64" )
config . TestProductVariables . DeviceArchVariant = proptools . StringPtr ( "armv8-a" )
config . TestProductVariables . DeviceSecondaryArch = proptools . StringPtr ( "arm" )
config . TestProductVariables . DeviceSecondaryArchVariant = proptools . StringPtr ( "armv7-a-neon" )
2018-10-05 14:28:25 +08:00
2017-09-16 08:33:55 +08:00
return testConfig
}
2020-09-29 14:23:17 +08:00
// Returns a config object which is "reset" for another bootstrap run.
// Only per-run data is reset. Data which needs to persist across multiple
// runs in the same program execution is carried over (such as Bazel context
// or environment deps).
func ConfigForAdditionalRun ( c Config ) ( Config , error ) {
newConfig , err := NewConfig ( c . srcDir , c . buildDir , c . moduleListFile )
if err != nil {
return Config { } , err
}
newConfig . BazelContext = c . BazelContext
newConfig . envDeps = c . envDeps
return newConfig , nil
}
2015-01-31 09:27:36 +08:00
// New creates a new Config object. The srcDir argument specifies the path to
// the root source directory. It also loads the config file, if found.
2020-06-24 05:37:05 +08:00
func NewConfig ( srcDir , buildDir string , moduleListFile string ) ( Config , error ) {
2015-01-31 09:27:36 +08:00
// Make a config with default options
2016-08-18 06:24:12 +08:00
config := & config {
ConfigFileName : filepath . Join ( buildDir , configFileName ) ,
ProductVariablesFileName : filepath . Join ( buildDir , productVariablesFileName ) ,
2017-10-11 14:07:38 +08:00
env : originalEnv ,
2019-09-18 05:45:31 +08:00
srcDir : srcDir ,
buildDir : buildDir ,
multilibConflicts : make ( map [ ArchType ] bool ) ,
2019-12-14 12:41:13 +08:00
2020-06-24 05:37:05 +08:00
moduleListFile : moduleListFile ,
fs : pathtools . NewOsFs ( absSrcDir ) ,
2015-03-26 05:43:57 +08:00
}
2015-01-31 09:27:36 +08:00
2017-07-07 07:59:48 +08:00
config . deviceConfig = & deviceConfig {
2016-08-18 06:24:12 +08:00
config : config ,
}
2020-07-29 04:27:34 +08:00
// Soundness check of the build and source directories. This won't catch strange
// configurations with symlinks, but at least checks the obvious case.
2015-09-24 06:26:20 +08:00
absBuildDir , err := filepath . Abs ( buildDir )
if err != nil {
return Config { } , err
}
absSrcDir , err := filepath . Abs ( srcDir )
if err != nil {
return Config { } , err
}
if strings . HasPrefix ( absSrcDir , absBuildDir ) {
return Config { } , fmt . Errorf ( "Build dir must not contain source directory" )
}
2015-01-31 09:27:36 +08:00
// Load any configurable options from the configuration file
2016-08-18 06:24:12 +08:00
err = loadConfig ( config )
2015-01-31 09:27:36 +08:00
if err != nil {
2015-04-11 06:43:55 +08:00
return Config { } , err
2015-01-31 09:27:36 +08:00
}
2015-12-12 05:51:06 +08:00
inMakeFile := filepath . Join ( buildDir , ".soong.in_make" )
2020-01-11 09:11:46 +08:00
if _ , err := os . Stat ( absolutePath ( inMakeFile ) ) ; err == nil {
2015-12-12 05:51:06 +08:00
config . inMake = true
}
2016-06-02 08:09:44 +08:00
targets , err := decodeTargetProductVariables ( config )
2015-07-09 09:13:11 +08:00
if err != nil {
return Config { } , err
}
2020-02-26 03:26:33 +08:00
// Make the CommonOS OsType available for all products.
targets [ CommonOS ] = [ ] Target { commonTargetMap [ CommonOS . Name ] }
2016-10-20 05:04:41 +08:00
var archConfig [ ] archConfig
2016-01-13 15:07:05 +08:00
if Bool ( config . Mega_device ) {
2016-10-20 05:04:41 +08:00
archConfig = getMegaDeviceConfig ( )
2018-10-25 07:10:32 +08:00
} else if config . NdkAbis ( ) {
2016-10-20 05:04:41 +08:00
archConfig = getNdkAbisConfig ( )
Add script for building all target arch's needed in AML (Android Mainline)
prebuilts.
This runs Soong in skip-make mode, using normal in-make mode only to query
platform versions.
The same ${OUT_DIR} cannot be used for both skip-make and in-make builds,
because Soong generates a smaller build.ninja file in in-make builds where
many build targets are expected to be provided by the mk files. Thus this
script avoids using ${OUT_DIR} if it's an in-make build, defaulting instead
to out-aml/.
The script is based on build-ndk-prebuilts.sh, but uses a separate Soong
variable Aml_abis to enable the appropriate target architectures for
Mainline modules. Aml_abis is very similar to Ndk_abis, except "armeabi-v7a"
is used instead of "armeabi", which is necessary to match prebuilt
dependencies, e.g. for LLVM.
Test: build/soong/scripts/build-aml-prebuilts.sh libart libdexfile_external
(verify that libraries for arm, arm64, x86, x86_64 are built)
Test: build/soong/scripts/build-aml-prebuilts.sh \
out-aml/soong/.intermediates/external/conscrypt/conscrypt-module-sdk/android_common/conscrypt-module-sdk-current.zip
(verify that the zip file contains libconscrypt_jni.so's for all four arches)
Test: build/soong/scripts/build-aml-prebuilts.sh com.android.art.{release,debug,testing,host}
(verify that the build completes)
Test: Two identical build/soong/scripts/build-aml-prebuilts.sh runs after each other
(verify that the 2nd run completes both Soong and ninja steps quickly without any building)
Change-Id: I35712f9f8f0b1cbb77107314c5927c6720e6c3bf
2019-11-15 23:00:31 +08:00
} else if config . AmlAbis ( ) {
archConfig = getAmlAbisConfig ( )
2016-10-20 05:04:41 +08:00
}
if archConfig != nil {
2019-01-12 11:02:16 +08:00
androidTargets , err := decodeArchSettings ( Android , archConfig )
2016-01-13 15:07:05 +08:00
if err != nil {
return Config { } , err
}
2018-10-11 08:02:29 +08:00
targets [ Android ] = androidTargets
2016-01-13 15:07:05 +08:00
}
2019-09-18 05:45:31 +08:00
multilib := make ( map [ string ] bool )
for _ , target := range targets [ Android ] {
if seen := multilib [ target . Arch . ArchType . Multilib ] ; seen {
config . multilibConflicts [ target . Arch . ArchType ] = true
}
multilib [ target . Arch . ArchType . Multilib ] = true
}
2016-06-02 08:09:44 +08:00
config . Targets = targets
2019-10-17 02:03:10 +08:00
config . BuildOSTarget = config . Targets [ BuildOs ] [ 0 ]
config . BuildOSCommonTarget = getCommonTargets ( config . Targets [ BuildOs ] ) [ 0 ]
if len ( config . Targets [ Android ] ) > 0 {
config . AndroidCommonTarget = getCommonTargets ( config . Targets [ Android ] ) [ 0 ]
2020-10-10 08:25:15 +08:00
config . AndroidFirstDeviceTarget = firstTarget ( config . Targets [ Android ] , "lib64" , "lib32" ) [ 0 ]
2019-10-17 02:03:10 +08:00
}
2015-07-09 09:13:11 +08:00
2017-09-30 08:58:17 +08:00
if err := config . fromEnv ( ) ; err != nil {
return Config { } , err
}
2020-06-17 08:51:46 +08:00
if Bool ( config . productVariables . GcovCoverage ) && Bool ( config . productVariables . ClangCoverage ) {
return Config { } , fmt . Errorf ( "GcovCoverage and ClangCoverage cannot both be set" )
}
config . productVariables . Native_coverage = proptools . BoolPtr (
Bool ( config . productVariables . GcovCoverage ) ||
Bool ( config . productVariables . ClangCoverage ) )
2020-09-29 14:23:17 +08:00
config . BazelContext , err = NewBazelContext ( config )
if err != nil {
return Config { } , err
}
2016-08-18 06:24:12 +08:00
return Config { config } , nil
2015-01-31 09:27:36 +08:00
}
2020-01-11 09:11:46 +08:00
var TestConfigOsFs = map [ string ] [ ] byte { }
2019-12-14 12:41:13 +08:00
// mockFileSystem replaces all reads with accesses to the provided map of
// filenames to contents stored as a byte slice.
func ( c * config ) mockFileSystem ( bp string , fs map [ string ] [ ] byte ) {
mockFS := map [ string ] [ ] byte { }
if _ , exists := mockFS [ "Android.bp" ] ; ! exists {
mockFS [ "Android.bp" ] = [ ] byte ( bp )
}
for k , v := range fs {
mockFS [ k ] = v
}
// no module list file specified; find every file named Blueprints or Android.bp
pathsToParse := [ ] string { }
for candidate := range mockFS {
base := filepath . Base ( candidate )
if base == "Blueprints" || base == "Android.bp" {
pathsToParse = append ( pathsToParse , candidate )
}
}
if len ( pathsToParse ) < 1 {
panic ( fmt . Sprintf ( "No Blueprint or Android.bp files found in mock filesystem: %v\n" , mockFS ) )
}
mockFS [ blueprint . MockModuleListFile ] = [ ] byte ( strings . Join ( pathsToParse , "\n" ) )
c . fs = pathtools . MockFs ( mockFS )
c . mockBpList = blueprint . MockModuleListFile
}
2017-09-30 08:58:17 +08:00
func ( c * config ) fromEnv ( ) error {
2019-05-02 22:32:11 +08:00
switch c . Getenv ( "EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9" ) {
2019-10-01 20:57:31 +08:00
case "" , "true" :
2019-10-17 21:52:07 +08:00
// Do nothing
2017-09-30 08:58:17 +08:00
default :
2019-10-17 21:52:07 +08:00
return fmt . Errorf ( "The environment variable EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9 is no longer supported. Java language level 9 is now the global default." )
2017-09-30 08:58:17 +08:00
}
return nil
}
2017-12-12 07:52:26 +08:00
func ( c * config ) StopBefore ( ) bootstrap . StopBefore {
return c . stopBefore
}
func ( c * config ) SetStopBefore ( stopBefore bootstrap . StopBefore ) {
c . stopBefore = stopBefore
2015-07-09 09:13:11 +08:00
}
2017-12-12 07:52:26 +08:00
var _ bootstrap . ConfigStopBefore = ( * config ) ( nil )
2016-05-27 06:13:03 +08:00
func ( c * config ) BlueprintToolLocation ( ) string {
return filepath . Join ( c . buildDir , "host" , c . PrebuiltOS ( ) , "bin" )
}
2017-12-12 07:52:26 +08:00
var _ bootstrap . ConfigBlueprintToolLocation = ( * config ) ( nil )
2018-11-17 13:05:32 +08:00
func ( c * config ) HostToolPath ( ctx PathContext , tool string ) Path {
return PathForOutput ( ctx , "host" , c . PrebuiltOS ( ) , "bin" , tool )
}
2019-12-10 05:47:14 +08:00
func ( c * config ) HostJNIToolPath ( ctx PathContext , path string ) Path {
ext := ".so"
if runtime . GOOS == "darwin" {
ext = ".dylib"
}
return PathForOutput ( ctx , "host" , c . PrebuiltOS ( ) , "lib64" , path + ext )
}
func ( c * config ) HostJavaToolPath ( ctx PathContext , path string ) Path {
return PathForOutput ( ctx , "host" , c . PrebuiltOS ( ) , "framework" , path )
}
2017-05-09 05:15:59 +08:00
// HostSystemTool looks for non-hermetic tools from the system we're running on.
// Generally shouldn't be used, but useful to find the XCode SDK, etc.
func ( c * config ) HostSystemTool ( name string ) string {
for _ , dir := range filepath . SplitList ( c . Getenv ( "PATH" ) ) {
path := filepath . Join ( dir , name )
if s , err := os . Stat ( path ) ; err != nil {
continue
} else if m := s . Mode ( ) ; ! s . IsDir ( ) && m & 0111 != 0 {
return path
}
}
return name
}
2015-01-31 09:27:36 +08:00
// PrebuiltOS returns the name of the host OS used in prebuilts directories
2015-04-08 08:11:30 +08:00
func ( c * config ) PrebuiltOS ( ) string {
2015-01-31 09:27:36 +08:00
switch runtime . GOOS {
case "linux" :
return "linux-x86"
case "darwin" :
return "darwin-x86"
default :
panic ( "Unknown GOOS" )
}
}
// GoRoot returns the path to the root directory of the Go toolchain.
2015-04-08 08:11:30 +08:00
func ( c * config ) GoRoot ( ) string {
2015-01-31 09:27:36 +08:00
return fmt . Sprintf ( "%s/prebuilts/go/%s" , c . srcDir , c . PrebuiltOS ( ) )
}
2019-04-11 13:59:54 +08:00
func ( c * config ) PrebuiltBuildTool ( ctx PathContext , tool string ) Path {
return PathForSource ( ctx , "prebuilts/build-tools" , c . PrebuiltOS ( ) , "bin" , tool )
}
2015-04-08 08:11:30 +08:00
func ( c * config ) CpPreserveSymlinksFlags ( ) string {
2015-08-28 04:28:01 +08:00
switch runtime . GOOS {
2015-01-31 09:27:36 +08:00
case "darwin" :
return "-R"
case "linux" :
return "-d"
default :
return ""
}
}
2015-03-26 05:43:57 +08:00
2015-04-08 08:11:30 +08:00
func ( c * config ) Getenv ( key string ) string {
2015-03-26 05:43:57 +08:00
var val string
var exists bool
2015-04-16 03:33:28 +08:00
c . envLock . Lock ( )
2017-02-07 07:40:41 +08:00
defer c . envLock . Unlock ( )
if c . envDeps == nil {
c . envDeps = make ( map [ string ] string )
}
2015-03-26 05:43:57 +08:00
if val , exists = c . envDeps [ key ] ; ! exists {
2015-09-12 08:06:19 +08:00
if c . envFrozen {
panic ( "Cannot access new environment variables after envdeps are frozen" )
}
2017-10-11 14:07:38 +08:00
val , _ = c . env [ key ]
2015-03-26 05:43:57 +08:00
c . envDeps [ key ] = val
}
return val
}
2016-11-24 08:52:04 +08:00
func ( c * config ) GetenvWithDefault ( key string , defaultValue string ) string {
ret := c . Getenv ( key )
if ret == "" {
return defaultValue
}
return ret
}
func ( c * config ) IsEnvTrue ( key string ) bool {
value := c . Getenv ( key )
return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
}
func ( c * config ) IsEnvFalse ( key string ) bool {
value := c . Getenv ( key )
return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
}
2015-04-08 08:11:30 +08:00
func ( c * config ) EnvDeps ( ) map [ string ] string {
2015-09-12 08:06:19 +08:00
c . envLock . Lock ( )
2017-02-07 07:40:41 +08:00
defer c . envLock . Unlock ( )
2015-09-12 08:06:19 +08:00
c . envFrozen = true
2015-03-26 05:43:57 +08:00
return c . envDeps
}
2015-04-03 05:37:16 +08:00
2015-12-12 05:51:06 +08:00
func ( c * config ) EmbeddedInMake ( ) bool {
return c . inMake
}
2018-01-11 08:06:12 +08:00
func ( c * config ) BuildId ( ) string {
2018-03-10 13:22:06 +08:00
return String ( c . productVariables . BuildId )
2018-01-11 08:06:12 +08:00
}
2020-02-22 08:55:46 +08:00
func ( c * config ) BuildNumberFile ( ctx PathContext ) Path {
return PathForOutput ( ctx , String ( c . productVariables . BuildNumberFile ) )
2018-01-11 08:06:12 +08:00
}
2015-04-03 05:37:16 +08:00
// DeviceName returns the name of the current device target
// TODO: take an AndroidModuleContext to select the device name for multi-device builds
2015-04-08 08:11:30 +08:00
func ( c * config ) DeviceName ( ) string {
2018-03-10 13:22:06 +08:00
return * c . productVariables . DeviceName
2015-04-03 05:37:16 +08:00
}
2019-03-18 23:53:16 +08:00
func ( c * config ) DeviceResourceOverlays ( ) [ ] string {
return c . productVariables . DeviceResourceOverlays
}
func ( c * config ) ProductResourceOverlays ( ) [ ] string {
return c . productVariables . ProductResourceOverlays
2015-04-14 04:58:27 +08:00
}
2018-05-10 02:11:35 +08:00
func ( c * config ) PlatformVersionName ( ) string {
return String ( c . productVariables . Platform_version_name )
}
2020-07-24 08:32:15 +08:00
func ( c * config ) PlatformSdkVersion ( ) ApiLevel {
return uncheckedFinalApiLevel ( * c . productVariables . Platform_sdk_version )
2015-04-14 04:58:27 +08:00
}
2018-04-19 02:06:47 +08:00
func ( c * config ) PlatformSdkCodename ( ) string {
return String ( c . productVariables . Platform_sdk_codename )
}
2019-04-03 13:56:43 +08:00
func ( c * config ) PlatformSecurityPatch ( ) string {
return String ( c . productVariables . Platform_security_patch )
}
func ( c * config ) PlatformPreviewSdkVersion ( ) string {
return String ( c . productVariables . Platform_preview_sdk_version )
}
func ( c * config ) PlatformMinSupportedTargetSdkVersion ( ) string {
return String ( c . productVariables . Platform_min_supported_target_sdk_version )
}
func ( c * config ) PlatformBaseOS ( ) string {
return String ( c . productVariables . Platform_base_os )
}
Replace stringly-typed API levels.
Handling of API levels within Soong is currently fairly difficult
since it isn't always clear based on context what kind of API level a
given string represents, how much canonicalizing and error checking
the code receiving the string are expected to do, or how those errors
should be treated.
The API level struct does not export its raw data, so as to keep its
"constructor" private to the android package, and to prevent misuse of
the `number` field, which is only an implementation detail for preview
API levels. API levels can be parsed with either
`android.ApiLevelFromUser`, which returns any errors to the caller, or
`android.ApiLevelOrPanic`, which is used in the case where the input
is trusted and any errors in parsing should panic. Even within the
`android` package, these APIs should be preferred over direct
construction.
For cases where there are context specific parsing requirements, such
as handling the "minimum" alias in the cc module,
`nativeApiLevelFromUser` and `nativeApiLevelOrPanic` should be used
instead.
Test: treehugger
Bug: http://b/154667674
Change-Id: Id52921fda32cb437fb1775ac2183299dedc0cf20
2020-07-07 05:49:35 +08:00
func ( c * config ) MinSupportedSdkVersion ( ) ApiLevel {
return uncheckedFinalApiLevel ( 16 )
}
func ( c * config ) FinalApiLevels ( ) [ ] ApiLevel {
var levels [ ] ApiLevel
2020-07-24 08:32:15 +08:00
for i := 1 ; i <= c . PlatformSdkVersion ( ) . FinalOrFutureInt ( ) ; i ++ {
Replace stringly-typed API levels.
Handling of API levels within Soong is currently fairly difficult
since it isn't always clear based on context what kind of API level a
given string represents, how much canonicalizing and error checking
the code receiving the string are expected to do, or how those errors
should be treated.
The API level struct does not export its raw data, so as to keep its
"constructor" private to the android package, and to prevent misuse of
the `number` field, which is only an implementation detail for preview
API levels. API levels can be parsed with either
`android.ApiLevelFromUser`, which returns any errors to the caller, or
`android.ApiLevelOrPanic`, which is used in the case where the input
is trusted and any errors in parsing should panic. Even within the
`android` package, these APIs should be preferred over direct
construction.
For cases where there are context specific parsing requirements, such
as handling the "minimum" alias in the cc module,
`nativeApiLevelFromUser` and `nativeApiLevelOrPanic` should be used
instead.
Test: treehugger
Bug: http://b/154667674
Change-Id: Id52921fda32cb437fb1775ac2183299dedc0cf20
2020-07-07 05:49:35 +08:00
levels = append ( levels , uncheckedFinalApiLevel ( i ) )
}
return levels
}
func ( c * config ) PreviewApiLevels ( ) [ ] ApiLevel {
var levels [ ] ApiLevel
for i , codename := range c . PlatformVersionActiveCodenames ( ) {
levels = append ( levels , ApiLevel {
value : codename ,
number : i ,
isPreview : true ,
} )
}
return levels
}
func ( c * config ) AllSupportedApiLevels ( ) [ ] ApiLevel {
var levels [ ] ApiLevel
levels = append ( levels , c . FinalApiLevels ( ) ... )
return append ( levels , c . PreviewApiLevels ( ) ... )
2017-08-18 07:19:59 +08:00
}
2020-07-24 08:32:15 +08:00
func ( c * config ) DefaultAppTargetSdk ( ctx EarlyModuleContext ) ApiLevel {
2018-04-19 02:06:47 +08:00
if Bool ( c . productVariables . Platform_sdk_final ) {
return c . PlatformSdkVersion ( )
} else {
2020-07-24 08:32:15 +08:00
codename := c . PlatformSdkCodename ( )
if codename == "" {
return NoneApiLevel
}
if codename == "REL" {
panic ( "Platform_sdk_codename should not be REL when Platform_sdk_final is true" )
}
return ApiLevelOrPanic ( ctx , codename )
2018-04-19 02:06:47 +08:00
}
}
2017-11-23 08:19:37 +08:00
func ( c * config ) AppsDefaultVersionName ( ) string {
2018-03-10 13:22:06 +08:00
return String ( c . productVariables . AppsDefaultVersionName )
2017-11-23 08:19:37 +08:00
}
2017-07-29 03:39:46 +08:00
// Codenames that are active in the current lunch target.
func ( c * config ) PlatformVersionActiveCodenames ( ) [ ] string {
2018-03-10 13:22:06 +08:00
return c . productVariables . Platform_version_active_codenames
2017-07-29 03:39:46 +08:00
}
2017-10-31 08:32:15 +08:00
func ( c * config ) ProductAAPTConfig ( ) [ ] string {
2019-02-01 06:31:51 +08:00
return c . productVariables . AAPTConfig
2015-04-14 04:58:27 +08:00
}
2017-10-31 08:32:15 +08:00
func ( c * config ) ProductAAPTPreferredConfig ( ) string {
2018-03-10 13:22:06 +08:00
return String ( c . productVariables . AAPTPreferredConfig )
2015-04-14 04:58:27 +08:00
}
2017-10-31 08:32:15 +08:00
func ( c * config ) ProductAAPTCharacteristics ( ) string {
2018-03-10 13:22:06 +08:00
return String ( c . productVariables . AAPTCharacteristics )
2017-10-31 08:32:15 +08:00
}
func ( c * config ) ProductAAPTPrebuiltDPI ( ) [ ] string {
2019-02-01 06:31:51 +08:00
return c . productVariables . AAPTPrebuiltDPI
2015-04-14 04:58:27 +08:00
}
2015-09-24 06:26:20 +08:00
func ( c * config ) DefaultAppCertificateDir ( ctx PathContext ) SourcePath {
2018-03-10 13:22:06 +08:00
defaultCert := String ( c . productVariables . DefaultAppCertificate )
2017-12-02 09:16:02 +08:00
if defaultCert != "" {
return PathForSource ( ctx , filepath . Dir ( defaultCert ) )
} else {
2019-04-10 12:36:26 +08:00
return PathForSource ( ctx , "build/make/target/product/security" )
2017-12-02 09:16:02 +08:00
}
2015-04-14 04:58:27 +08:00
}
2017-12-15 03:22:55 +08:00
func ( c * config ) DefaultAppCertificate ( ctx PathContext ) ( pem , key SourcePath ) {
2018-03-10 13:22:06 +08:00
defaultCert := String ( c . productVariables . DefaultAppCertificate )
2017-12-02 09:16:02 +08:00
if defaultCert != "" {
2017-12-15 03:22:55 +08:00
return PathForSource ( ctx , defaultCert + ".x509.pem" ) , PathForSource ( ctx , defaultCert + ".pk8" )
2017-12-02 09:16:02 +08:00
} else {
2017-12-15 03:22:55 +08:00
defaultDir := c . DefaultAppCertificateDir ( ctx )
return defaultDir . Join ( ctx , "testkey.x509.pem" ) , defaultDir . Join ( ctx , "testkey.pk8" )
2017-12-02 09:16:02 +08:00
}
2015-04-14 04:58:27 +08:00
}
2015-12-18 08:39:19 +08:00
2018-12-24 10:31:58 +08:00
func ( c * config ) ApexKeyDir ( ctx ModuleContext ) SourcePath {
// TODO(b/121224311): define another variable such as TARGET_APEX_KEY_OVERRIDE
defaultCert := String ( c . productVariables . DefaultAppCertificate )
2019-04-10 12:36:26 +08:00
if defaultCert == "" || filepath . Dir ( defaultCert ) == "build/make/target/product/security" {
2018-12-24 10:31:58 +08:00
// When defaultCert is unset or is set to the testkeys path, use the APEX keys
// that is under the module dir
2019-03-06 04:46:40 +08:00
return pathForModuleSrc ( ctx )
2018-12-24 10:31:58 +08:00
} else {
// If not, APEX keys are under the specified directory
return PathForSource ( ctx , filepath . Dir ( defaultCert ) )
}
}
2015-12-18 08:39:19 +08:00
func ( c * config ) AllowMissingDependencies ( ) bool {
2018-03-10 13:22:06 +08:00
return Bool ( c . productVariables . Allow_missing_dependencies )
2015-12-18 08:39:19 +08:00
}
2016-01-13 15:07:05 +08:00
2020-07-08 00:09:23 +08:00
// Returns true if a full platform source tree cannot be assumed.
2017-09-19 08:41:52 +08:00
func ( c * config ) UnbundledBuild ( ) bool {
2018-03-10 13:22:06 +08:00
return Bool ( c . productVariables . Unbundled_build )
2017-09-19 08:41:52 +08:00
}
2020-06-17 08:13:15 +08:00
// Returns true if building apps that aren't bundled with the platform.
// UnbundledBuild() is always true when this is true.
func ( c * config ) UnbundledBuildApps ( ) bool {
return Bool ( c . productVariables . Unbundled_build_apps )
}
2020-07-08 00:09:23 +08:00
// Returns true if building modules against prebuilt SDKs.
func ( c * config ) AlwaysUsePrebuiltSdks ( ) bool {
return Bool ( c . productVariables . Always_use_prebuilt_sdks )
2018-12-19 14:46:24 +08:00
}
2020-10-29 03:20:06 +08:00
// Returns true if the boot jars check should be skipped.
func ( c * config ) SkipBootJarsCheck ( ) bool {
return Bool ( c . productVariables . Skip_boot_jars_check )
}
2019-01-17 04:06:11 +08:00
func ( c * config ) Fuchsia ( ) bool {
return Bool ( c . productVariables . Fuchsia )
}
2017-11-01 04:55:34 +08:00
func ( c * config ) MinimizeJavaDebugInfo ( ) bool {
2018-03-10 13:22:06 +08:00
return Bool ( c . productVariables . MinimizeJavaDebugInfo ) && ! Bool ( c . productVariables . Eng )
2017-11-01 04:55:34 +08:00
}
2018-09-06 07:28:13 +08:00
func ( c * config ) Debuggable ( ) bool {
return Bool ( c . productVariables . Debuggable )
}
2018-11-30 07:08:44 +08:00
func ( c * config ) Eng ( ) bool {
return Bool ( c . productVariables . Eng )
}
2018-07-07 17:02:07 +08:00
func ( c * config ) DevicePrimaryArchType ( ) ArchType {
2018-10-11 08:02:29 +08:00
return c . Targets [ Android ] [ 0 ] . Arch . ArchType
2018-07-07 17:02:07 +08:00
}
2017-04-27 08:34:03 +08:00
func ( c * config ) SkipMegaDeviceInstall ( path string ) bool {
return Bool ( c . Mega_device ) &&
strings . HasPrefix ( path , filepath . Join ( c . buildDir , "target" , "product" ) )
2016-01-13 15:07:05 +08:00
}
2016-01-07 06:41:07 +08:00
func ( c * config ) SanitizeHost ( ) [ ] string {
2018-03-10 13:22:06 +08:00
return append ( [ ] string ( nil ) , c . productVariables . SanitizeHost ... )
2016-01-07 06:41:07 +08:00
}
func ( c * config ) SanitizeDevice ( ) [ ] string {
2018-03-10 13:22:06 +08:00
return append ( [ ] string ( nil ) , c . productVariables . SanitizeDevice ... )
2016-11-03 05:34:39 +08:00
}
2017-06-29 00:10:48 +08:00
func ( c * config ) SanitizeDeviceDiag ( ) [ ] string {
2018-03-10 13:22:06 +08:00
return append ( [ ] string ( nil ) , c . productVariables . SanitizeDeviceDiag ... )
2017-06-29 00:10:48 +08:00
}
2016-11-03 05:34:39 +08:00
func ( c * config ) SanitizeDeviceArch ( ) [ ] string {
2018-03-10 13:22:06 +08:00
return append ( [ ] string ( nil ) , c . productVariables . SanitizeDeviceArch ... )
2016-01-07 06:41:07 +08:00
}
2016-06-02 08:09:44 +08:00
2017-01-20 05:54:55 +08:00
func ( c * config ) EnableCFI ( ) bool {
2018-03-10 13:22:06 +08:00
if c . productVariables . EnableCFI == nil {
2017-01-25 06:20:54 +08:00
return true
} else {
2018-03-10 13:22:06 +08:00
return * c . productVariables . EnableCFI
2017-01-25 06:20:54 +08:00
}
2017-01-20 05:54:55 +08:00
}
2019-02-02 00:42:56 +08:00
func ( c * config ) DisableScudo ( ) bool {
return Bool ( c . productVariables . DisableScudo )
}
2016-06-02 08:09:44 +08:00
func ( c * config ) Android64 ( ) bool {
2018-10-11 08:02:29 +08:00
for _ , t := range c . Targets [ Android ] {
2016-06-02 08:09:44 +08:00
if t . Arch . ArchType . Multilib == "lib64" {
return true
}
}
return false
}
2016-08-18 06:24:12 +08:00
2016-08-30 07:14:13 +08:00
func ( c * config ) UseGoma ( ) bool {
2018-03-10 13:22:06 +08:00
return Bool ( c . productVariables . UseGoma )
2016-08-30 07:14:13 +08:00
}
2019-07-17 20:30:04 +08:00
func ( c * config ) UseRBE ( ) bool {
return Bool ( c . productVariables . UseRBE )
}
2020-01-28 03:19:44 +08:00
func ( c * config ) UseRBEJAVAC ( ) bool {
return Bool ( c . productVariables . UseRBEJAVAC )
}
func ( c * config ) UseRBER8 ( ) bool {
return Bool ( c . productVariables . UseRBER8 )
}
func ( c * config ) UseRBED8 ( ) bool {
return Bool ( c . productVariables . UseRBED8 )
}
2019-11-16 05:18:43 +08:00
func ( c * config ) UseRemoteBuild ( ) bool {
return c . UseGoma ( ) || c . UseRBE ( )
}
2018-06-20 13:47:35 +08:00
func ( c * config ) RunErrorProne ( ) bool {
return c . IsEnvTrue ( "RUN_ERROR_PRONE" )
}
2018-11-06 08:49:08 +08:00
func ( c * config ) XrefCorpusName ( ) string {
return c . Getenv ( "XREF_CORPUS" )
}
2020-01-10 09:34:23 +08:00
// Returns Compilation Unit encoding to use. Can be 'json' (default), 'proto' or 'all'.
func ( c * config ) XrefCuEncoding ( ) string {
if enc := c . Getenv ( "KYTHE_KZIP_ENCODING" ) ; enc != "" {
return enc
}
return "json"
}
2018-11-06 08:49:08 +08:00
func ( c * config ) EmitXrefRules ( ) bool {
return c . XrefCorpusName ( ) != ""
}
2016-09-27 06:45:04 +08:00
func ( c * config ) ClangTidy ( ) bool {
2018-03-10 13:22:06 +08:00
return Bool ( c . productVariables . ClangTidy )
2016-09-27 06:45:04 +08:00
}
func ( c * config ) TidyChecks ( ) string {
2018-03-10 13:22:06 +08:00
if c . productVariables . TidyChecks == nil {
2016-09-27 06:45:04 +08:00
return ""
}
2018-03-10 13:22:06 +08:00
return * c . productVariables . TidyChecks
2016-09-27 06:45:04 +08:00
}
2016-07-28 01:56:55 +08:00
func ( c * config ) LibartImgHostBaseAddress ( ) string {
return "0x60000000"
}
func ( c * config ) LibartImgDeviceBaseAddress ( ) string {
2020-03-07 08:55:28 +08:00
return "0x70000000"
2016-07-28 01:56:55 +08:00
}
2016-12-20 05:44:41 +08:00
func ( c * config ) ArtUseReadBarrier ( ) bool {
2018-03-10 13:22:06 +08:00
return Bool ( c . productVariables . ArtUseReadBarrier )
2016-12-20 05:44:41 +08:00
}
2018-03-13 06:30:26 +08:00
func ( c * config ) EnforceRROForModule ( name string ) bool {
2018-03-10 13:22:06 +08:00
enforceList := c . productVariables . EnforceRROTargets
2020-03-09 11:37:05 +08:00
// TODO(b/150820813) Some modules depend on static overlay, remove this after eliminating the dependency.
exemptedList := c . productVariables . EnforceRROExemptedTargets
2020-07-09 23:58:14 +08:00
if len ( exemptedList ) > 0 {
2020-03-09 11:37:05 +08:00
if InList ( name , exemptedList ) {
return false
}
}
2020-07-09 23:58:14 +08:00
if len ( enforceList ) > 0 {
2019-10-01 13:13:41 +08:00
if InList ( "*" , enforceList ) {
2018-03-13 06:30:26 +08:00
return true
}
2019-02-01 06:31:51 +08:00
return InList ( name , enforceList )
2018-03-13 06:30:26 +08:00
}
return false
}
2020-10-07 09:56:10 +08:00
func ( c * config ) EnforceRROExemptedForModule ( name string ) bool {
return InList ( name , c . productVariables . EnforceRROExemptedTargets )
}
2018-03-13 06:30:26 +08:00
func ( c * config ) EnforceRROExcludedOverlay ( path string ) bool {
2018-03-10 13:22:06 +08:00
excluded := c . productVariables . EnforceRROExcludedOverlays
2020-07-09 23:58:14 +08:00
if len ( excluded ) > 0 {
2020-02-11 23:54:35 +08:00
return HasAnyPrefix ( path , excluded )
2018-03-13 06:30:26 +08:00
}
return false
}
func ( c * config ) ExportedNamespaces ( ) [ ] string {
2018-03-10 13:22:06 +08:00
return append ( [ ] string ( nil ) , c . productVariables . NamespacesToExport ... )
2018-03-13 06:30:26 +08:00
}
func ( c * config ) HostStaticBinaries ( ) bool {
2018-03-10 13:22:06 +08:00
return Bool ( c . productVariables . HostStaticBinaries )
2018-03-13 06:30:26 +08:00
}
2018-10-06 05:20:06 +08:00
func ( c * config ) UncompressPrivAppDex ( ) bool {
return Bool ( c . productVariables . UncompressPrivAppDex )
}
func ( c * config ) ModulesLoadedByPrivilegedModules ( ) [ ] string {
return c . productVariables . ModulesLoadedByPrivilegedModules
}
2020-11-02 13:24:57 +08:00
func ( c * config ) DexpreoptGlobalConfigPath ( ctx PathContext ) OptionalPath {
2020-01-11 09:11:46 +08:00
if c . productVariables . DexpreoptGlobalConfig == nil {
2020-11-02 13:24:57 +08:00
return OptionalPathForPath ( nil )
}
return OptionalPathForPath (
pathForBuildToolDep ( ctx , * c . productVariables . DexpreoptGlobalConfig ) )
}
func ( c * config ) DexpreoptGlobalConfig ( ctx PathContext ) ( [ ] byte , error ) {
path := c . DexpreoptGlobalConfigPath ( ctx )
if ! path . Valid ( ) {
2020-01-11 09:11:46 +08:00
return nil , nil
}
2020-11-02 13:24:57 +08:00
ctx . AddNinjaFileDeps ( path . String ( ) )
return ioutil . ReadFile ( absolutePath ( path . String ( ) ) )
2018-11-13 02:13:39 +08:00
}
2019-01-24 05:04:05 +08:00
func ( c * config ) FrameworksBaseDirExists ( ctx PathContext ) bool {
return ExistentPathForSource ( ctx , "frameworks" , "base" ) . Valid ( )
}
2019-05-14 17:52:49 +08:00
func ( c * config ) VndkSnapshotBuildArtifacts ( ) bool {
return Bool ( c . productVariables . VndkSnapshotBuildArtifacts )
}
2019-09-18 05:45:31 +08:00
func ( c * config ) HasMultilibConflict ( arch ArchType ) bool {
return c . multilibConflicts [ arch ]
}
2016-08-18 06:24:12 +08:00
func ( c * deviceConfig ) Arches ( ) [ ] Arch {
var arches [ ] Arch
2018-10-11 08:02:29 +08:00
for _ , target := range c . config . Targets [ Android ] {
2016-08-18 06:24:12 +08:00
arches = append ( arches , target . Arch )
}
return arches
}
2016-11-19 06:54:24 +08:00
2018-03-09 03:00:50 +08:00
func ( c * deviceConfig ) BinderBitness ( ) string {
2018-03-10 13:22:06 +08:00
is32BitBinder := c . config . productVariables . Binder32bit
2018-03-09 03:00:50 +08:00
if is32BitBinder != nil && * is32BitBinder {
return "32"
}
return "64"
}
2016-12-06 09:16:02 +08:00
func ( c * deviceConfig ) VendorPath ( ) string {
2018-03-10 13:22:06 +08:00
if c . config . productVariables . VendorPath != nil {
return * c . config . productVariables . VendorPath
2016-12-06 09:16:02 +08:00
}
return "vendor"
}
Install VNDK snapshot libraries for system build
When BOARD_VNDK_VERSION := <VNDK version>, or
PRODUCT_EXTRA_VNDK_VERSIONS includes the needed <VNDK version> list,
the prebuilt VNDK libs in prebuilts/vndk/ directory will be
installed.
Each prebuilt VNDK module uses "vndk_prebuilt_shared" for shared
VNDK/VNDK-SP libs.
Following is the sample configuration of a vndk snapshot module:
vndk_prebuilt_shared {
name: "libfoo",
version: "27",
vendor_available: true,
vndk: {
enabled: true,
},
arch: {
arm64: {
srcs: ["arm/lib64/libfoo.so"],
},
arm: {
srcs: ["arm/lib/libfoo.so"],
},
},
}
The Android.bp for the snapshot modules will be auto-generated by a
script.
Bug: 38304393
Bug: 65377115
Bug: 68123344
Test: set BOARD_VNDK_VERSION := 27
copy a snapshot for v27
build with make command
Change-Id: Ib93107530dbabb4a24583f4d6e4f0c513c9adfec
2017-11-17 11:10:28 +08:00
func ( c * deviceConfig ) VndkVersion ( ) string {
2018-03-10 13:22:06 +08:00
return String ( c . config . productVariables . DeviceVndkVersion )
Install VNDK snapshot libraries for system build
When BOARD_VNDK_VERSION := <VNDK version>, or
PRODUCT_EXTRA_VNDK_VERSIONS includes the needed <VNDK version> list,
the prebuilt VNDK libs in prebuilts/vndk/ directory will be
installed.
Each prebuilt VNDK module uses "vndk_prebuilt_shared" for shared
VNDK/VNDK-SP libs.
Following is the sample configuration of a vndk snapshot module:
vndk_prebuilt_shared {
name: "libfoo",
version: "27",
vendor_available: true,
vndk: {
enabled: true,
},
arch: {
arm64: {
srcs: ["arm/lib64/libfoo.so"],
},
arm: {
srcs: ["arm/lib/libfoo.so"],
},
},
}
The Android.bp for the snapshot modules will be auto-generated by a
script.
Bug: 38304393
Bug: 65377115
Bug: 68123344
Test: set BOARD_VNDK_VERSION := 27
copy a snapshot for v27
build with make command
Change-Id: Ib93107530dbabb4a24583f4d6e4f0c513c9adfec
2017-11-17 11:10:28 +08:00
}
2020-08-06 22:00:37 +08:00
func ( c * deviceConfig ) CurrentApiLevelForVendorModules ( ) string {
return StringDefault ( c . config . productVariables . DeviceCurrentApiLevelForVendorModules , "current" )
}
2017-12-07 16:18:15 +08:00
func ( c * deviceConfig ) PlatformVndkVersion ( ) string {
2018-03-10 13:22:06 +08:00
return String ( c . config . productVariables . Platform_vndk_version )
2017-12-07 16:18:15 +08:00
}
2019-11-18 18:52:14 +08:00
func ( c * deviceConfig ) ProductVndkVersion ( ) string {
return String ( c . config . productVariables . ProductVndkVersion )
}
Install VNDK snapshot libraries for system build
When BOARD_VNDK_VERSION := <VNDK version>, or
PRODUCT_EXTRA_VNDK_VERSIONS includes the needed <VNDK version> list,
the prebuilt VNDK libs in prebuilts/vndk/ directory will be
installed.
Each prebuilt VNDK module uses "vndk_prebuilt_shared" for shared
VNDK/VNDK-SP libs.
Following is the sample configuration of a vndk snapshot module:
vndk_prebuilt_shared {
name: "libfoo",
version: "27",
vendor_available: true,
vndk: {
enabled: true,
},
arch: {
arm64: {
srcs: ["arm/lib64/libfoo.so"],
},
arm: {
srcs: ["arm/lib/libfoo.so"],
},
},
}
The Android.bp for the snapshot modules will be auto-generated by a
script.
Bug: 38304393
Bug: 65377115
Bug: 68123344
Test: set BOARD_VNDK_VERSION := 27
copy a snapshot for v27
build with make command
Change-Id: Ib93107530dbabb4a24583f4d6e4f0c513c9adfec
2017-11-17 11:10:28 +08:00
func ( c * deviceConfig ) ExtraVndkVersions ( ) [ ] string {
2018-03-10 13:22:06 +08:00
return c . config . productVariables . ExtraVndkVersions
2016-11-19 06:54:24 +08:00
}
2016-12-09 07:45:07 +08:00
2018-11-13 12:19:56 +08:00
func ( c * deviceConfig ) VndkUseCoreVariant ( ) bool {
return Bool ( c . config . productVariables . VndkUseCoreVariant )
}
2018-01-15 14:05:10 +08:00
func ( c * deviceConfig ) SystemSdkVersions ( ) [ ] string {
2019-02-01 06:31:51 +08:00
return c . config . productVariables . DeviceSystemSdkVersions
2018-01-15 14:05:10 +08:00
}
func ( c * deviceConfig ) PlatformSystemSdkVersions ( ) [ ] string {
2018-03-10 13:22:06 +08:00
return c . config . productVariables . Platform_systemsdk_versions
2018-01-15 14:05:10 +08:00
}
2017-11-08 15:03:48 +08:00
func ( c * deviceConfig ) OdmPath ( ) string {
2018-03-10 13:22:06 +08:00
if c . config . productVariables . OdmPath != nil {
return * c . config . productVariables . OdmPath
2017-11-08 15:03:48 +08:00
}
return "odm"
}
2018-01-10 18:00:15 +08:00
func ( c * deviceConfig ) ProductPath ( ) string {
2018-03-10 13:22:06 +08:00
if c . config . productVariables . ProductPath != nil {
return * c . config . productVariables . ProductPath
2017-11-08 15:03:48 +08:00
}
2018-01-10 18:00:15 +08:00
return "product"
2017-11-08 15:03:48 +08:00
}
2019-06-25 15:47:17 +08:00
func ( c * deviceConfig ) SystemExtPath ( ) string {
if c . config . productVariables . SystemExtPath != nil {
return * c . config . productVariables . SystemExtPath
2018-05-29 20:28:54 +08:00
}
2019-06-25 15:47:17 +08:00
return "system_ext"
2018-05-29 20:28:54 +08:00
}
2016-12-09 07:45:07 +08:00
func ( c * deviceConfig ) BtConfigIncludeDir ( ) string {
2018-03-10 13:22:06 +08:00
return String ( c . config . productVariables . BtConfigIncludeDir )
2016-12-09 07:45:07 +08:00
}
2017-02-10 08:16:31 +08:00
2017-07-03 12:18:12 +08:00
func ( c * deviceConfig ) DeviceKernelHeaderDirs ( ) [ ] string {
2018-03-10 13:22:06 +08:00
return c . config . productVariables . DeviceKernelHeaders
2017-07-03 12:18:12 +08:00
}
2020-03-20 15:22:27 +08:00
func ( c * deviceConfig ) SamplingPGO ( ) bool {
return Bool ( c . config . productVariables . SamplingPGO )
}
2020-06-09 20:07:36 +08:00
// JavaCoverageEnabledForPath returns whether Java code coverage is enabled for
// path. Coverage is enabled by default when the product variable
// JavaCoveragePaths is empty. If JavaCoveragePaths is not empty, coverage is
// enabled for any path which is part of this variable (and not part of the
// JavaCoverageExcludePaths product variable). Value "*" in JavaCoveragePaths
// represents any path.
func ( c * deviceConfig ) JavaCoverageEnabledForPath ( path string ) bool {
coverage := false
2020-06-25 04:36:59 +08:00
if len ( c . config . productVariables . JavaCoveragePaths ) == 0 ||
2020-06-09 20:07:36 +08:00
InList ( "*" , c . config . productVariables . JavaCoveragePaths ) ||
HasAnyPrefix ( path , c . config . productVariables . JavaCoveragePaths ) {
coverage = true
}
2020-07-09 23:58:14 +08:00
if coverage && len ( c . config . productVariables . JavaCoverageExcludePaths ) > 0 {
2020-06-09 20:07:36 +08:00
if HasAnyPrefix ( path , c . config . productVariables . JavaCoverageExcludePaths ) {
coverage = false
}
}
return coverage
}
2020-06-17 08:51:46 +08:00
// Returns true if gcov or clang coverage is enabled.
2017-02-10 08:16:31 +08:00
func ( c * deviceConfig ) NativeCoverageEnabled ( ) bool {
2020-06-17 08:51:46 +08:00
return Bool ( c . config . productVariables . GcovCoverage ) ||
Bool ( c . config . productVariables . ClangCoverage )
2017-02-10 08:16:31 +08:00
}
2019-12-07 07:22:41 +08:00
func ( c * deviceConfig ) ClangCoverageEnabled ( ) bool {
return Bool ( c . config . productVariables . ClangCoverage )
}
2017-02-10 08:16:31 +08:00
2020-06-17 08:51:46 +08:00
func ( c * deviceConfig ) GcovCoverageEnabled ( ) bool {
return Bool ( c . config . productVariables . GcovCoverage )
}
2020-06-09 19:44:06 +08:00
// NativeCoverageEnabledForPath returns whether (GCOV- or Clang-based) native
// code coverage is enabled for path. By default, coverage is not enabled for a
// given path unless it is part of the NativeCoveragePaths product variable (and
// not part of the NativeCoverageExcludePaths product variable). Value "*" in
// NativeCoveragePaths represents any path.
func ( c * deviceConfig ) NativeCoverageEnabledForPath ( path string ) bool {
2017-02-28 01:01:54 +08:00
coverage := false
2020-07-09 23:58:14 +08:00
if len ( c . config . productVariables . NativeCoveragePaths ) > 0 {
2020-06-09 19:44:06 +08:00
if InList ( "*" , c . config . productVariables . NativeCoveragePaths ) || HasAnyPrefix ( path , c . config . productVariables . NativeCoveragePaths ) {
2017-07-14 05:46:05 +08:00
coverage = true
2017-02-10 08:16:31 +08:00
}
}
2020-07-09 23:58:14 +08:00
if coverage && len ( c . config . productVariables . NativeCoverageExcludePaths ) > 0 {
2020-06-09 19:44:06 +08:00
if HasAnyPrefix ( path , c . config . productVariables . NativeCoverageExcludePaths ) {
2017-07-14 05:46:05 +08:00
coverage = false
2017-02-28 01:01:54 +08:00
}
}
return coverage
2017-02-10 08:16:31 +08:00
}
2017-07-14 05:46:05 +08:00
2018-01-30 15:11:42 +08:00
func ( c * deviceConfig ) PgoAdditionalProfileDirs ( ) [ ] string {
2018-03-10 13:22:06 +08:00
return c . config . productVariables . PgoAdditionalProfileDirs
2018-01-30 15:11:42 +08:00
}
2018-03-26 11:00:00 +08:00
func ( c * deviceConfig ) VendorSepolicyDirs ( ) [ ] string {
return c . config . productVariables . BoardVendorSepolicyDirs
}
func ( c * deviceConfig ) OdmSepolicyDirs ( ) [ ] string {
return c . config . productVariables . BoardOdmSepolicyDirs
}
2020-05-18 00:28:35 +08:00
func ( c * deviceConfig ) SystemExtPublicSepolicyDirs ( ) [ ] string {
return c . config . productVariables . SystemExtPublicSepolicyDirs
2018-03-26 11:00:00 +08:00
}
2020-05-18 00:28:35 +08:00
func ( c * deviceConfig ) SystemExtPrivateSepolicyDirs ( ) [ ] string {
return c . config . productVariables . SystemExtPrivateSepolicyDirs
2018-03-26 11:00:00 +08:00
}
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I49206e656564206d6f7265206361666665696e65
2019-04-15 19:21:29 +08:00
func ( c * deviceConfig ) SepolicyM4Defs ( ) [ ] string {
return c . config . productVariables . BoardSepolicyM4Defs
}
2019-01-05 11:57:48 +08:00
func ( c * deviceConfig ) OverrideManifestPackageNameFor ( name string ) ( manifestName string , overridden bool ) {
2019-01-19 06:27:16 +08:00
return findOverrideValue ( c . config . productVariables . ManifestPackageNameOverrides , name ,
"invalid override rule %q in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES should be <module_name>:<manifest_name>" )
}
func ( c * deviceConfig ) OverrideCertificateFor ( name string ) ( certificatePath string , overridden bool ) {
2019-03-01 00:22:30 +08:00
return findOverrideValue ( c . config . productVariables . CertificateOverrides , name ,
2019-01-19 06:27:16 +08:00
"invalid override rule %q in PRODUCT_CERTIFICATE_OVERRIDES should be <module_name>:<certificate_module_name>" )
}
2019-01-24 08:27:47 +08:00
func ( c * deviceConfig ) OverridePackageNameFor ( name string ) string {
newName , overridden := findOverrideValue (
c . config . productVariables . PackageNameOverrides ,
name ,
"invalid override rule %q in PRODUCT_PACKAGE_NAME_OVERRIDES should be <module_name>:<package_name>" )
if overridden {
return newName
}
return name
}
2019-01-19 06:27:16 +08:00
func findOverrideValue ( overrides [ ] string , name string , errorMsg string ) ( newValue string , overridden bool ) {
2019-01-05 11:57:48 +08:00
if overrides == nil || len ( overrides ) == 0 {
return "" , false
}
for _ , o := range overrides {
split := strings . Split ( o , ":" )
if len ( split ) != 2 {
// This shouldn't happen as this is first checked in make, but just in case.
2019-01-19 06:27:16 +08:00
panic ( fmt . Errorf ( errorMsg , o ) )
2019-01-05 11:57:48 +08:00
}
if matchPattern ( split [ 0 ] , name ) {
return substPattern ( split [ 0 ] , split [ 1 ] , name ) , true
}
}
return "" , false
}
2017-07-14 05:46:05 +08:00
func ( c * config ) IntegerOverflowDisabledForPath ( path string ) bool {
2020-07-09 23:58:14 +08:00
if len ( c . productVariables . IntegerOverflowExcludePaths ) == 0 {
2017-07-14 05:46:05 +08:00
return false
}
2020-02-11 23:54:35 +08:00
return HasAnyPrefix ( path , c . productVariables . IntegerOverflowExcludePaths )
2017-07-14 05:46:05 +08:00
}
2017-10-31 17:26:14 +08:00
func ( c * config ) CFIDisabledForPath ( path string ) bool {
2020-07-09 23:58:14 +08:00
if len ( c . productVariables . CFIExcludePaths ) == 0 {
2017-10-31 17:26:14 +08:00
return false
}
2020-02-11 23:54:35 +08:00
return HasAnyPrefix ( path , c . productVariables . CFIExcludePaths )
2017-10-31 17:26:14 +08:00
}
func ( c * config ) CFIEnabledForPath ( path string ) bool {
2020-07-09 23:58:14 +08:00
if len ( c . productVariables . CFIIncludePaths ) == 0 {
2017-10-31 17:26:14 +08:00
return false
}
2020-02-11 23:54:35 +08:00
return HasAnyPrefix ( path , c . productVariables . CFIIncludePaths )
2017-10-31 17:26:14 +08:00
}
2017-12-05 03:24:31 +08:00
2018-03-27 03:41:18 +08:00
func ( c * config ) VendorConfig ( name string ) VendorConfig {
2019-11-23 08:03:51 +08:00
return soongconfig . Config ( c . productVariables . VendorVars [ name ] )
2018-03-27 03:41:18 +08:00
}
2018-10-25 07:10:32 +08:00
func ( c * config ) NdkAbis ( ) bool {
return Bool ( c . productVariables . Ndk_abis )
}
Add script for building all target arch's needed in AML (Android Mainline)
prebuilts.
This runs Soong in skip-make mode, using normal in-make mode only to query
platform versions.
The same ${OUT_DIR} cannot be used for both skip-make and in-make builds,
because Soong generates a smaller build.ninja file in in-make builds where
many build targets are expected to be provided by the mk files. Thus this
script avoids using ${OUT_DIR} if it's an in-make build, defaulting instead
to out-aml/.
The script is based on build-ndk-prebuilts.sh, but uses a separate Soong
variable Aml_abis to enable the appropriate target architectures for
Mainline modules. Aml_abis is very similar to Ndk_abis, except "armeabi-v7a"
is used instead of "armeabi", which is necessary to match prebuilt
dependencies, e.g. for LLVM.
Test: build/soong/scripts/build-aml-prebuilts.sh libart libdexfile_external
(verify that libraries for arm, arm64, x86, x86_64 are built)
Test: build/soong/scripts/build-aml-prebuilts.sh \
out-aml/soong/.intermediates/external/conscrypt/conscrypt-module-sdk/android_common/conscrypt-module-sdk-current.zip
(verify that the zip file contains libconscrypt_jni.so's for all four arches)
Test: build/soong/scripts/build-aml-prebuilts.sh com.android.art.{release,debug,testing,host}
(verify that the build completes)
Test: Two identical build/soong/scripts/build-aml-prebuilts.sh runs after each other
(verify that the 2nd run completes both Soong and ninja steps quickly without any building)
Change-Id: I35712f9f8f0b1cbb77107314c5927c6720e6c3bf
2019-11-15 23:00:31 +08:00
func ( c * config ) AmlAbis ( ) bool {
return Bool ( c . productVariables . Aml_abis )
}
2018-11-29 00:30:10 +08:00
func ( c * config ) ExcludeDraftNdkApis ( ) bool {
return Bool ( c . productVariables . Exclude_draft_ndk_apis )
}
2018-11-08 01:50:25 +08:00
func ( c * config ) FlattenApex ( ) bool {
2019-08-13 02:56:16 +08:00
return Bool ( c . productVariables . Flatten_apex )
2018-11-08 01:50:25 +08:00
}
2019-01-07 11:07:27 +08:00
func ( c * config ) EnforceSystemCertificate ( ) bool {
return Bool ( c . productVariables . EnforceSystemCertificate )
}
2020-06-12 02:32:11 +08:00
func ( c * config ) EnforceSystemCertificateAllowList ( ) [ ] string {
return c . productVariables . EnforceSystemCertificateAllowList
2019-01-07 11:07:27 +08:00
}
2019-10-29 14:44:45 +08:00
func ( c * config ) EnforceProductPartitionInterface ( ) bool {
return Bool ( c . productVariables . EnforceProductPartitionInterface )
}
2019-12-05 15:27:44 +08:00
func ( c * config ) InstallExtraFlattenedApexes ( ) bool {
return Bool ( c . productVariables . InstallExtraFlattenedApexes )
}
2019-02-01 06:12:44 +08:00
func ( c * config ) ProductHiddenAPIStubs ( ) [ ] string {
return c . productVariables . ProductHiddenAPIStubs
2019-01-17 07:15:52 +08:00
}
2019-02-01 06:12:44 +08:00
func ( c * config ) ProductHiddenAPIStubsSystem ( ) [ ] string {
return c . productVariables . ProductHiddenAPIStubsSystem
2019-01-17 07:15:52 +08:00
}
2019-02-01 06:12:44 +08:00
func ( c * config ) ProductHiddenAPIStubsTest ( ) [ ] string {
return c . productVariables . ProductHiddenAPIStubsTest
2019-01-17 07:15:52 +08:00
}
2019-04-11 03:27:35 +08:00
2019-04-19 01:08:46 +08:00
func ( c * deviceConfig ) TargetFSConfigGen ( ) [ ] string {
2019-04-11 03:27:35 +08:00
return c . config . productVariables . TargetFSConfigGen
}
Build contexts files with Soong
This is to migrate sepolicy Makefiles into Soong. For the first part,
file_contexts, hwservice_contexts, property_contexts, and
service_contexts are migrated. Build-time tests for contexts files are
still in Makefile; they will also be done with Soong after porting the
module sepolicy.
The motivation of migrating is based on generating property_contexts
dynamically: if we were to amend contexts files at build time in the
future, it would be nicer to manage them in Soong. To do that, building
contexts files with Soong can be very helpful.
Bug: 127949646
Bug: 129377144
Test: 1) Build blueline-userdebug, flash, and boot.
Test: 2) Build blueline-userdebug with TARGET_FLATTEN_APEX=true, flash,
and boot.
Test: 3) Build aosp_arm-userdebug.
Change-Id: I49206e656564206d6f7265206361666665696e65
2019-04-15 19:21:29 +08:00
func ( c * config ) ProductPublicSepolicyDirs ( ) [ ] string {
return c . productVariables . ProductPublicSepolicyDirs
}
func ( c * config ) ProductPrivateSepolicyDirs ( ) [ ] string {
return c . productVariables . ProductPrivateSepolicyDirs
}
func ( c * config ) ProductCompatibleProperty ( ) bool {
return Bool ( c . productVariables . ProductCompatibleProperty )
}
2019-05-09 12:29:15 +08:00
2019-05-17 03:28:22 +08:00
func ( c * config ) MissingUsesLibraries ( ) [ ] string {
return c . productVariables . MissingUsesLibraries
}
2019-05-09 12:29:15 +08:00
func ( c * deviceConfig ) DeviceArch ( ) string {
return String ( c . config . productVariables . DeviceArch )
}
func ( c * deviceConfig ) DeviceArchVariant ( ) string {
return String ( c . config . productVariables . DeviceArchVariant )
}
func ( c * deviceConfig ) DeviceSecondaryArch ( ) string {
return String ( c . config . productVariables . DeviceSecondaryArch )
}
func ( c * deviceConfig ) DeviceSecondaryArchVariant ( ) string {
return String ( c . config . productVariables . DeviceSecondaryArchVariant )
}
2020-01-22 08:12:26 +08:00
func ( c * deviceConfig ) BoardUsesRecoveryAsBoot ( ) bool {
return Bool ( c . config . productVariables . BoardUsesRecoveryAsBoot )
}
2020-07-30 00:51:57 +08:00
func ( c * deviceConfig ) BoardKernelBinaries ( ) [ ] string {
return c . config . productVariables . BoardKernelBinaries
}
2020-07-01 21:31:13 +08:00
2020-08-06 05:36:09 +08:00
func ( c * deviceConfig ) BoardKernelModuleInterfaceVersions ( ) [ ] string {
return c . config . productVariables . BoardKernelModuleInterfaceVersions
}
2020-10-22 06:40:17 +08:00
func ( c * deviceConfig ) BoardMoveRecoveryResourcesToVendorBoot ( ) bool {
return Bool ( c . config . productVariables . BoardMoveRecoveryResourcesToVendorBoot )
}
2020-07-01 21:31:13 +08:00
// The ConfiguredJarList struct provides methods for handling a list of (apex, jar) pairs.
// Such lists are used in the build system for things like bootclasspath jars or system server jars.
// The apex part is either an apex name, or a special names "platform" or "system_ext". Jar is a
// module name. The pairs come from Make product variables as a list of colon-separated strings.
//
// Examples:
// - "com.android.art:core-oj"
// - "platform:framework"
// - "system_ext:foo"
//
type ConfiguredJarList struct {
apexes [ ] string // A list of apex components.
jars [ ] string // A list of jar components.
}
// The length of the list.
func ( l * ConfiguredJarList ) Len ( ) int {
return len ( l . jars )
}
// Jar component of idx-th pair on the list.
func ( l * ConfiguredJarList ) Jar ( idx int ) string {
return l . jars [ idx ]
}
2020-10-29 03:20:06 +08:00
// Apex component of idx-th pair on the list.
func ( l * ConfiguredJarList ) Apex ( idx int ) string {
return l . apexes [ idx ]
}
2020-07-01 21:31:13 +08:00
// If the list contains a pair with the given jar.
func ( l * ConfiguredJarList ) ContainsJar ( jar string ) bool {
return InList ( jar , l . jars )
}
// If the list contains the given (apex, jar) pair.
func ( l * ConfiguredJarList ) containsApexJarPair ( apex , jar string ) bool {
for i := 0 ; i < l . Len ( ) ; i ++ {
2020-10-24 01:28:55 +08:00
if apex == l . apexes [ i ] && jar == l . jars [ i ] {
2020-07-01 21:31:13 +08:00
return true
}
}
return false
}
// Index of the first pair with the given jar on the list, or -1 if none.
func ( l * ConfiguredJarList ) IndexOfJar ( jar string ) int {
return IndexList ( jar , l . jars )
}
2020-10-24 01:26:03 +08:00
func copyAndAppend ( list [ ] string , item string ) [ ] string {
// Create the result list to be 1 longer than the input.
result := make ( [ ] string , len ( list ) + 1 )
// Copy the whole input list into the result.
count := copy ( result , list )
// Insert the extra item at the end.
result [ count ] = item
return result
}
2020-07-01 21:31:13 +08:00
// Append an (apex, jar) pair to the list.
2020-10-24 01:26:03 +08:00
func ( l * ConfiguredJarList ) Append ( apex string , jar string ) ConfiguredJarList {
// Create a copy of the backing arrays before appending to avoid sharing backing
// arrays that are mutated across instances.
apexes := copyAndAppend ( l . apexes , apex )
jars := copyAndAppend ( l . jars , jar )
return ConfiguredJarList { apexes , jars }
2020-07-01 21:31:13 +08:00
}
// Filter out sublist.
2020-10-24 01:26:03 +08:00
func ( l * ConfiguredJarList ) RemoveList ( list ConfiguredJarList ) ConfiguredJarList {
2020-07-01 21:31:13 +08:00
apexes := make ( [ ] string , 0 , l . Len ( ) )
jars := make ( [ ] string , 0 , l . Len ( ) )
for i , jar := range l . jars {
2020-10-24 01:28:55 +08:00
apex := l . apexes [ i ]
2020-07-01 21:31:13 +08:00
if ! list . containsApexJarPair ( apex , jar ) {
apexes = append ( apexes , apex )
jars = append ( jars , jar )
}
}
2020-10-24 01:26:03 +08:00
return ConfiguredJarList { apexes , jars }
2020-07-01 21:31:13 +08:00
}
// A copy of the list of strings containing jar components.
func ( l * ConfiguredJarList ) CopyOfJars ( ) [ ] string {
return CopyOf ( l . jars )
}
// A copy of the list of strings with colon-separated (apex, jar) pairs.
func ( l * ConfiguredJarList ) CopyOfApexJarPairs ( ) [ ] string {
pairs := make ( [ ] string , 0 , l . Len ( ) )
for i , jar := range l . jars {
2020-10-24 01:28:55 +08:00
apex := l . apexes [ i ]
2020-07-01 21:31:13 +08:00
pairs = append ( pairs , apex + ":" + jar )
}
return pairs
}
// A list of build paths based on the given directory prefix.
func ( l * ConfiguredJarList ) BuildPaths ( ctx PathContext , dir OutputPath ) WritablePaths {
paths := make ( WritablePaths , l . Len ( ) )
for i , jar := range l . jars {
paths [ i ] = dir . Join ( ctx , ModuleStem ( jar ) + ".jar" )
}
return paths
}
2020-10-24 04:14:20 +08:00
// Called when loading configuration from JSON into a configuration structure.
func ( l * ConfiguredJarList ) UnmarshalJSON ( b [ ] byte ) error {
// Try and unmarshal into a []string each item of which contains a pair
// <apex>:<jar>.
var list [ ] string
err := json . Unmarshal ( b , & list )
if err != nil {
// Did not work so return
return err
}
apexes , jars , err := splitListOfPairsIntoPairOfLists ( list )
if err != nil {
return err
}
l . apexes = apexes
l . jars = jars
return nil
}
2020-07-01 21:31:13 +08:00
func ModuleStem ( module string ) string {
// b/139391334: the stem of framework-minus-apex is framework. This is hard coded here until we
// find a good way to query the stem of a module before any other mutators are run.
if module == "framework-minus-apex" {
return "framework"
}
return module
}
// A list of on-device paths.
func ( l * ConfiguredJarList ) DevicePaths ( cfg Config , ostype OsType ) [ ] string {
paths := make ( [ ] string , l . Len ( ) )
for i , jar := range l . jars {
apex := l . apexes [ i ]
name := ModuleStem ( jar ) + ".jar"
var subdir string
if apex == "platform" {
subdir = "system/framework"
} else if apex == "system_ext" {
subdir = "system_ext/framework"
} else {
subdir = filepath . Join ( "apex" , apex , "javalib" )
}
if ostype . Class == Host {
paths [ i ] = filepath . Join ( cfg . Getenv ( "OUT_DIR" ) , "host" , cfg . PrebuiltOS ( ) , subdir , name )
} else {
paths [ i ] = filepath . Join ( "/" , subdir , name )
}
}
return paths
}
2020-10-24 01:26:03 +08:00
func ( l * ConfiguredJarList ) String ( ) string {
var pairs [ ] string
for i := 0 ; i < l . Len ( ) ; i ++ {
pairs = append ( pairs , l . apexes [ i ] + ":" + l . jars [ i ] )
}
return strings . Join ( pairs , "," )
}
2020-10-24 04:04:03 +08:00
func splitListOfPairsIntoPairOfLists ( list [ ] string ) ( [ ] string , [ ] string , error ) {
// Now we need to populate this list by splitting each item in the slice of
// pairs and appending them to the appropriate list of apexes or jars.
apexes := make ( [ ] string , len ( list ) )
jars := make ( [ ] string , len ( list ) )
for i , apexjar := range list {
apex , jar , err := splitConfiguredJarPair ( apexjar )
if err != nil {
return nil , nil , err
}
apexes [ i ] = apex
jars [ i ] = jar
}
return apexes , jars , nil
}
2020-07-01 21:31:13 +08:00
// Expected format for apexJarValue = <apex name>:<jar name>
2020-10-24 04:04:03 +08:00
func splitConfiguredJarPair ( str string ) ( string , string , error ) {
2020-07-01 21:31:13 +08:00
pair := strings . SplitN ( str , ":" , 2 )
if len ( pair ) == 2 {
2020-10-24 04:04:03 +08:00
return pair [ 0 ] , pair [ 1 ] , nil
2020-07-01 21:31:13 +08:00
} else {
2020-10-24 04:04:03 +08:00
return "error-apex" , "error-jar" , fmt . Errorf ( "malformed (apex, jar) pair: '%s', expected format: <apex>:<jar>" , str )
2020-07-01 21:31:13 +08:00
}
}
2020-10-24 04:23:44 +08:00
func CreateTestConfiguredJarList ( list [ ] string ) ConfiguredJarList {
2020-10-24 04:04:03 +08:00
apexes , jars , err := splitListOfPairsIntoPairOfLists ( list )
if err != nil {
2020-10-24 04:23:44 +08:00
panic ( err )
2020-07-01 21:31:13 +08:00
}
2020-10-24 04:04:03 +08:00
return ConfiguredJarList { apexes , jars }
2020-07-01 21:31:13 +08:00
}
func EmptyConfiguredJarList ( ) ConfiguredJarList {
return ConfiguredJarList { }
}
var earlyBootJarsKey = NewOnceKey ( "earlyBootJars" )
func ( c * config ) BootJars ( ) [ ] string {
return c . Once ( earlyBootJarsKey , func ( ) interface { } {
2020-10-24 04:14:20 +08:00
list := c . productVariables . BootJars . CopyOfJars ( )
list = append ( list , c . productVariables . UpdatableBootJars . CopyOfJars ( ) ... )
return list
2020-07-01 21:31:13 +08:00
} ) . ( [ ] string )
}
2020-10-29 03:20:06 +08:00
func ( c * config ) NonUpdatableBootJars ( ) ConfiguredJarList {
return c . productVariables . BootJars
}
func ( c * config ) UpdatableBootJars ( ) ConfiguredJarList {
return c . productVariables . UpdatableBootJars
}