2023-05-06 21:29:01 +02:00
# Copyright (C) 2023 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2023-06-10 03:51:00 +02:00
# -----------------------------------------------------------------
# Choose the flag files
# -----------------------------------------------------------------
2023-06-13 08:29:25 +02:00
# Release configs are defined in reflease_config_map files, which map
# the short name (e.g. -next) used in lunch to the starlark files
# defining the build flag values.
#
# (If you're thinking about aconfig flags, there is one build flag,
2023-06-22 00:17:42 +02:00
# RELEASE_ACONFIG_VALUE_SETS, that sets which aconfig_value_set
2023-06-13 08:29:25 +02:00
# module to use to set the aconfig flag values.)
#
# The short release config names *can* appear multiple times, to allow
# for AOSP and vendor specific flags under the same name, but the
# individual flag values must appear in exactly one config. Vendor
# does not override AOSP, or anything like that. This is because
# vendor code usually includes prebuilts, and having vendor compile
# with different flags from AOSP increases the likelihood of flag
# mismatch.
2023-06-10 03:51:00 +02:00
# Do this first, because we're going to unset TARGET_RELEASE before
# including anyone, so they don't start making conditionals based on it.
# This logic is in make because starlark doesn't understand optional
# vendor files.
# If this is a google source tree, restrict it to only the one file
# which has OWNERS control. If it isn't let others define their own.
# TODO: Remove wildcard for build/release one when all branch manifests
# have updated.
2024-03-08 02:08:05 +01:00
config_map_files := $( wildcard build/trunk_release/release_config_map.mk) \
$( wildcard build/release/release_config_map.mk) \
$( wildcard vendor/google_shared/build/release/release_config_map.mk) \
2023-06-10 03:51:00 +02:00
$( if $( wildcard vendor/google/release/release_config_map.mk) , \
vendor/google/release/release_config_map.mk, \
$( sort \
$( wildcard device/*/release/release_config_map.mk) \
$( wildcard device/*/*/release/release_config_map.mk) \
$( wildcard vendor/*/release/release_config_map.mk) \
$( wildcard vendor/*/*/release/release_config_map.mk) \
) \
)
2023-11-06 23:14:51 +01:00
# PRODUCT_RELEASE_CONFIG_MAPS is set by Soong using an initial run of product
# config to capture only the list of config maps needed by the build.
# Keep them in the order provided, but remove duplicates.
$( foreach map ,$ ( PRODUCT_RELEASE_CONFIG_MAPS ) , \
$( if $( filter $( map) ,$( config_map_files) ) ,,$( eval config_map_files += $( map) ) ) \
)
2024-01-31 00:04:02 +01:00
# Declare an alias release-config
#
# This should be used to declare a release as an alias of another, meaning no
# release config files should be present.
#
# $1 config name
# $2 release config for which it is an alias
d e f i n e a l i a s - r e l e a s e - c o n f i g
$( call _declare-release-config,$( 1) ,,$( 2) ,true)
e n d e f
2023-11-06 23:14:51 +01:00
# Declare or extend a release-config.
#
2024-01-23 20:15:49 +01:00
# The order of processing is:
# 1. Recursively apply any overridden release configs. Only apply each config
# the first time we reach it.
# 2. Apply any files for this release config, in the order they were added to
# the declaration.
#
# Example:
# With these declarations:
# $(declare-release-config foo, foo.scl)
# $(declare-release-config bar, bar.scl, foo)
# $(declare-release-config baz, baz.scl, bar)
# $(declare-release-config bif, bif.scl, foo baz)
# $(declare-release-config bop, bop.scl, bar baz)
#
# TARGET_RELEASE:
# - bar will use: foo.scl bar.scl
# - baz will use: foo.scl bar.scl baz.scl
# - bif will use: foo.scl bar.scl baz.scl bif.scl
# - bop will use: foo.scl bar.scl baz.scl bop.scl
#
2023-06-10 03:51:00 +02:00
# $1 config name
# $2 release config files
2024-01-23 20:15:49 +01:00
# $3 overridden release config
2023-06-10 03:51:00 +02:00
d e f i n e d e c l a r e - r e l e a s e - c o n f i g
2024-01-31 00:04:02 +01:00
$( call _declare-release-config,$( 1) ,$( 2) ,$( 3) ,)
e n d e f
d e f i n e _ d e c l a r e - r e l e a s e - c o n f i g
2024-01-23 20:15:49 +01:00
$( if $( strip $( 2) $( 3) ) ,, \
$( error declare-release-config: config $( strip $( 1) ) must have release config files, override another release config, or both) \
2023-06-10 03:51:00 +02:00
)
2024-01-31 00:04:02 +01:00
$( if $( strip $( 4) ) ,$( eval _all_release_configs.$( strip $( 1) ) .ALIAS := true ) )
2023-06-10 03:51:00 +02:00
$( eval _all_release_configs := $( sort $( _all_release_configs) $( strip $( 1) ) ) )
2023-11-27 21:12:36 +01:00
$( if $( strip $( 3) ) , \
$( if $( filter $( _all_release_configs) , $( strip $( 3) ) ) ,
$( if $( filter $( _all_release_configs.$( strip $( 1) ) .OVERRIDES) ,$( strip $( 3) ) ) ,,
$( eval _all_release_configs.$( strip $( 1) ) .OVERRIDES := $( _all_release_configs.$( strip $( 1) ) .OVERRIDES) $( strip $( 3) ) ) ) , \
$( error No release config $( strip $( 3) ) ) \
) \
)
2023-06-13 08:29:25 +02:00
$( eval _all_release_configs.$( strip $( 1) ) .DECLARED_IN := $( _included) $( _all_release_configs.$( strip $( 1) ) .DECLARED_IN) )
$( eval _all_release_configs.$( strip $( 1) ) .FILES := $( _all_release_configs.$( strip $( 1) ) .FILES) $( strip $( 2) ) )
2023-06-10 03:51:00 +02:00
e n d e f
2023-11-06 23:14:51 +01:00
# Include the config map files and populate _flag_declaration_files.
2024-03-14 18:48:55 +01:00
# If the file is found more than once, only include it the first time.
2023-11-06 23:14:51 +01:00
_flag_declaration_files :=
2024-03-14 18:48:55 +01:00
_included_config_map_files :=
2023-06-10 03:51:00 +02:00
$( foreach f , $ ( config_map_files ) , \
2023-11-06 23:14:51 +01:00
$( eval FLAG_DECLARATION_FILES:= ) \
2024-03-14 18:48:55 +01:00
$( if $( filter $( _included_config_map_files) ,$( f) ) ,,\
$( eval _included := $( f) ) \
$( eval include $( f) ) \
$( eval _flag_declaration_files += $( FLAG_DECLARATION_FILES) ) \
$( eval _included_config_map_files += $( f) ) \
) \
2023-11-06 23:14:51 +01:00
)
FLAG_DECLARATION_FILES :=
2023-11-09 21:28:55 +01:00
i f e q ( $( TARGET_RELEASE ) , )
# We allow some internal paths to explicitly set TARGET_RELEASE to the
# empty string. For the most part, 'make' treats unset and empty string as
# the same. But the following line differentiates, and will only assign
# if the variable was completely unset.
TARGET_RELEASE ?= was_unset
ifeq ( $( TARGET_RELEASE) ,was_unset)
$( error No release config set for target; please set TARGET_RELEASE, or if building on the command line use 'lunch <target>-<release>-<build_type>' , where release is one of: $( _all_release_configs) )
endif
# Instead of leaving this string empty, we want to default to a valid
# setting. Full builds coming through this path is a bug, but in case
# of such a bug, we want to at least get consistent, valid results.
TARGET_RELEASE = trunk_staging
e n d i f
2023-06-10 03:51:00 +02:00
i f e q ( $( filter $ ( _all_release_configs ) , $ ( TARGET_RELEASE ) ) , )
$( error No release config found for TARGET_RELEASE: $( TARGET_RELEASE) . Available releases are: $( _all_release_configs) )
e n d i f
2023-11-09 21:28:55 +01:00
# Choose flag files
# Don't sort this, use it in the order they gave us.
# Do allow duplicate entries, retaining only the first usage.
2023-06-10 03:51:00 +02:00
flag_value_files :=
2024-01-23 20:15:49 +01:00
# Apply overrides recursively
#
# $1 release config that we override
applied_releases :=
d e f i n e _ a p p l y - r e l e a s e - c o n f i g - o v e r r i d e s
$( foreach r ,$ ( 1) , \
$( if $( filter $( r) ,$( applied_releases) ) ,, \
$( foreach o,$( _all_release_configs.$( r) .OVERRIDES) ,$( call _apply-release-config-overrides,$( o) ) ) \
$( eval applied_releases += $( r) ) \
2023-11-27 21:12:36 +01:00
$( foreach f,$( _all_release_configs.$( r) .FILES) , \
$( if $( filter $( f) ,$( flag_value_files) ) ,,$( eval flag_value_files += $( f) ) ) \
) \
2024-01-23 20:15:49 +01:00
) \
2023-11-09 21:28:55 +01:00
)
2024-01-23 20:15:49 +01:00
e n d e f
$( call _apply -release -config -overrides ,$ ( TARGET_RELEASE ) )
2023-06-10 03:51:00 +02:00
# Unset variables so they can't use them
d e f i n e d e c l a r e - r e l e a s e - c o n f i g
$( error declare -release -config can only be called from inside release_config_map .mk files )
e n d e f
2024-01-23 20:15:49 +01:00
d e f i n e a p p l y - r e l e a s e - c o n f i g - o v e r r i d e s
$( error invalid use of apply -release -config -overrides )
e n d e f
2023-06-10 03:51:00 +02:00
# TODO: Remove this check after enough people have sourced lunch that we don't
# need to worry about it trying to do get_build_vars TARGET_RELEASE. Maybe after ~9/2023
i f n e q ( $( CALLED_FROM_SETUP ) , t r u e )
d e f i n e T A R G E T _ R E L E A S E
$( error TARGET_RELEASE may not be accessed directly . Use individual flags .)
e n d e f
e l s e
TARGET_RELEASE :=
e n d i f
.KATI_READONLY := TARGET_RELEASE
2024-01-31 00:04:02 +01:00
# Verify that alias configs do not have config files.
$( foreach r ,$ ( _all_release_configs ) ,\
$( if $( _all_release_configs.$( r) .ALIAS) ,$( if $( _all_release_configs.$( r) .FILES) ,\
$( error Alias release config " $( r) " may not specify release config files $( _all_release_configs.$( r) .FILES) ) \
) ) )
2023-06-10 03:51:00 +02:00
$( foreach config , $ ( _all_release_configs ) , \
$( eval _all_release_configs.$( config) .DECLARED_IN:= ) \
$( eval _all_release_configs.$( config) .FILES:= ) \
)
_all_release_configs :=
config_map_files :=
2024-01-23 20:15:49 +01:00
applied_releases :=
2023-06-10 03:51:00 +02:00
# -----------------------------------------------------------------
# Flag declarations and values
# -----------------------------------------------------------------
# This part is in starlark. We generate a root starlark file that loads
# all of the flags declaration files that we found, and the flag_value_files
# that we chose from the config map above. Then we run that, and load the
# results of that into the make environment.
2023-11-06 23:14:51 +01:00
# _flag_declaration_files is the combined list of FLAG_DECLARATION_FILES set by
# release_config_map.mk files above.
2023-05-19 18:13:36 +02:00
2023-06-07 01:55:58 +02:00
# Because starlark can't find files with $(wildcard), write an entrypoint starlark script that
# contains the result of the above wildcards for the starlark code to use.
filename_to_starlark = $( subst /,_,$( subst .,_,$( 1) ) )
2023-11-08 18:51:04 +01:00
_c := load( "//build/make/core/release_config.scl" , "release_config" )
2023-06-10 03:51:00 +02:00
_c += $( newline) def add( d, k, v) :
_c += $( newline) $( space) d = dict( d)
_c += $( newline) $( space) d[ k] = v
_c += $( newline) $( space) return d
2023-11-06 23:14:51 +01:00
_c += $( foreach f,$( _flag_declaration_files) ,$( newline) load( " $( f) " , flags_$( call filename_to_starlark,$( f) ) = "flags" ) )
_c += $( newline) all_flags = [ ] $( foreach f,$( _flag_declaration_files) ,+ [ add( x, "declared_in" , " $( f) " ) for x in flags_$( call filename_to_starlark,$( f) ) ] )
2023-06-10 03:51:00 +02:00
_c += $( foreach f,$( flag_value_files) ,$( newline) load( " // $( f) " , values_$( call filename_to_starlark,$( f) ) = "values" ) )
_c += $( newline) all_values = [ ] $( foreach f,$( flag_value_files) ,+ [ add( x, "set_in" , " $( f) " ) for x in values_$( call filename_to_starlark,$( f) ) ] )
_c += $( newline) variables_to_export_to_make = release_config( all_flags, all_values)
2023-11-08 18:51:04 +01:00
$( file >$ ( OUT_DIR ) /release_config_entrypoint .scl ,$ ( _c ) )
2023-06-07 01:55:58 +02:00
_c :=
filename_to_starlark :=
2023-05-06 21:29:01 +02:00
2023-06-07 01:55:58 +02:00
# Exclude the entrypoint file as a dependency (by passing it as the 2nd argument) so that we don't
# rerun kati every build. Kati will replay the $(file) command that generates it every build,
# updating its timestamp.
#
# We also need to pass --allow_external_entrypoint to rbcrun in case the OUT_DIR is set to something
# outside of the source tree.
2023-11-08 18:51:04 +01:00
$( call run -starlark ,$ ( OUT_DIR ) /release_config_entrypoint .scl ,$ ( OUT_DIR ) /release_config_entrypoint .scl ,--allow_external_entrypoint )
2023-05-19 18:13:36 +02:00