1#
2# Copyright (C) 2008 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17#
18# Handle various build version information.
19#
20# Guarantees that the following are defined:
21#     PLATFORM_VERSION
22#     PLATFORM_SDK_VERSION
23#     PLATFORM_VERSION_CODENAME
24#     DEFAULT_APP_TARGET_SDK
25#     BUILD_ID
26#     BUILD_NUMBER
27#     PLATFORM_SECURITY_PATCH
28#     PLATFORM_VNDK_VERSION
29#     PLATFORM_SYSTEMSDK_VERSIONS
30#
31
32# Look for an optional file containing overrides of the defaults,
33# but don't cry if we don't find it.  We could just use -include, but
34# the build.prop target also wants INTERNAL_BUILD_ID_MAKEFILE to be set
35# if the file exists.
36#
37INTERNAL_BUILD_ID_MAKEFILE := $(wildcard $(BUILD_SYSTEM)/build_id.mk)
38ifdef INTERNAL_BUILD_ID_MAKEFILE
39  include $(INTERNAL_BUILD_ID_MAKEFILE)
40endif
41
42DEFAULT_PLATFORM_VERSION := SP1A
43MIN_PLATFORM_VERSION := SP1A
44MAX_PLATFORM_VERSION := SP1A
45
46ALLOWED_VERSIONS := $(call allowed-platform-versions,\
47  $(MIN_PLATFORM_VERSION),\
48  $(MAX_PLATFORM_VERSION),\
49  $(DEFAULT_PLATFORM_VERSION))
50
51ifndef TARGET_PLATFORM_VERSION
52  TARGET_PLATFORM_VERSION := $(DEFAULT_PLATFORM_VERSION)
53endif
54
55ifeq (,$(filter $(ALLOWED_VERSIONS), $(TARGET_PLATFORM_VERSION)))
56  $(warning Invalid TARGET_PLATFORM_VERSION '$(TARGET_PLATFORM_VERSION)', must be one of)
57  $(error $(ALLOWED_VERSIONS))
58endif
59ALLOWED_VERSIONS :=
60MIN_PLATFORM_VERSION :=
61MAX_PLATFORM_VERSION :=
62
63.KATI_READONLY := \
64  DEFAULT_PLATFORM_VERSION \
65  TARGET_PLATFORM_VERSION
66
67# Default versions for each TARGET_PLATFORM_VERSION
68# TODO: PLATFORM_VERSION, PLATFORM_SDK_VERSION, etc. should be conditional
69# on this
70
71# This is the canonical definition of the platform version,
72# which is the version that we reveal to the end user.
73# Update this value when the platform version changes (rather
74# than overriding it somewhere else).  Can be an arbitrary string.
75
76# When you change PLATFORM_VERSION for a given PLATFORM_SDK_VERSION
77# please add that PLATFORM_VERSION as well as clean up obsolete PLATFORM_VERSION's
78# in the following text file:
79# cts/tests/tests/os/assets/platform_versions.txt
80
81# Note that there should be one PLATFORM_VERSION and PLATFORM_VERSION_CODENAME
82# entry for each unreleased API level, regardless of
83# MIN_PLATFORM_VERSION/MAX_PLATFORM_VERSION. PLATFORM_VERSION is used to
84# generate the range of allowed SDK versions, so it must have an entry for every
85# unreleased API level targetable by this branch, not just those that are valid
86# lunch targets for this branch.
87PLATFORM_VERSION.RP1A := R
88PLATFORM_VERSION.SP1A := S
89
90# These are the current development codenames, if the build is not a final
91# release build.  If this is a final release build, it is simply "REL".
92PLATFORM_VERSION_CODENAME.RP1A := R
93PLATFORM_VERSION_CODENAME.SP1A := S
94
95ifndef PLATFORM_VERSION
96  PLATFORM_VERSION := $(PLATFORM_VERSION.$(TARGET_PLATFORM_VERSION))
97  ifndef PLATFORM_VERSION
98    # PLATFORM_VERSION falls back to TARGET_PLATFORM_VERSION
99    PLATFORM_VERSION := $(TARGET_PLATFORM_VERSION)
100  endif
101endif
102.KATI_READONLY := PLATFORM_VERSION
103
104ifndef PLATFORM_SDK_VERSION
105  # This is the canonical definition of the SDK version, which defines
106  # the set of APIs and functionality available in the platform.  It
107  # is a single integer that increases monotonically as updates to
108  # the SDK are released.  It should only be incremented when the APIs for
109  # the new release are frozen (so that developers don't write apps against
110  # intermediate builds).  During development, this number remains at the
111  # SDK version the branch is based on and PLATFORM_VERSION_CODENAME holds
112  # the code-name of the new development work.
113
114  # When you increment the PLATFORM_SDK_VERSION please ensure you also
115  # clear out the following text file of all older PLATFORM_VERSION's:
116  # cts/tests/tests/os/assets/platform_versions.txt
117  PLATFORM_SDK_VERSION := 29
118endif
119.KATI_READONLY := PLATFORM_SDK_VERSION
120
121ifndef PLATFORM_VERSION_CODENAME
122  PLATFORM_VERSION_CODENAME := $(PLATFORM_VERSION_CODENAME.$(TARGET_PLATFORM_VERSION))
123  ifndef PLATFORM_VERSION_CODENAME
124    # PLATFORM_VERSION_CODENAME falls back to TARGET_PLATFORM_VERSION
125    PLATFORM_VERSION_CODENAME := $(TARGET_PLATFORM_VERSION)
126  endif
127
128  # This is all of the *active* development codenames.
129  # This confusing name is needed because
130  # all_codenames has been baked into build.prop for ages.
131  #
132  # Should be either the same as PLATFORM_VERSION_CODENAME or a comma-separated
133  # list of additional codenames after PLATFORM_VERSION_CODENAME.
134  PLATFORM_VERSION_ALL_CODENAMES :=
135
136  # Build a list of all active code names. Avoid duplicates, and stop when we
137  # reach a codename that matches PLATFORM_VERSION_CODENAME (anything beyond
138  # that is not included in our build).
139  _versions_in_target := \
140    $(call find_and_earlier,$(ALL_VERSIONS),$(TARGET_PLATFORM_VERSION))
141  $(foreach version,$(_versions_in_target),\
142    $(eval _codename := $(PLATFORM_VERSION_CODENAME.$(version)))\
143    $(if $(filter $(_codename),$(PLATFORM_VERSION_ALL_CODENAMES)),,\
144      $(eval PLATFORM_VERSION_ALL_CODENAMES += $(_codename))))
145
146  # And convert from space separated to comma separated.
147  PLATFORM_VERSION_ALL_CODENAMES := \
148    $(subst $(space),$(comma),$(strip $(PLATFORM_VERSION_ALL_CODENAMES)))
149
150endif
151.KATI_READONLY := \
152  PLATFORM_VERSION_CODENAME \
153  PLATFORM_VERSION_ALL_CODENAMES
154
155ifeq (REL,$(PLATFORM_VERSION_CODENAME))
156  PLATFORM_PREVIEW_SDK_VERSION := 0
157else
158  ifndef PLATFORM_PREVIEW_SDK_VERSION
159    # This is the definition of a preview SDK version over and above the current
160    # platform SDK version. Unlike the platform SDK version, a higher value
161    # for preview SDK version does NOT mean that all prior preview APIs are
162    # included. Packages reading this value to determine compatibility with
163    # known APIs should check that this value is precisely equal to the preview
164    # SDK version the package was built for, otherwise it should fall back to
165    # assuming the device can only support APIs as of the previous official
166    # public release.
167    # This value will always be forced to 0 for release builds by the logic
168    # in the "ifeq" block above, so the value below will be used on any
169    # non-release builds, and it should always be at least 1, to indicate that
170    # APIs may have changed since the claimed PLATFORM_SDK_VERSION.
171    PLATFORM_PREVIEW_SDK_VERSION := 1
172  endif
173endif
174.KATI_READONLY := PLATFORM_PREVIEW_SDK_VERSION
175
176ifndef DEFAULT_APP_TARGET_SDK
177  # This is the default minSdkVersion and targetSdkVersion to use for
178  # all .apks created by the build system.  It can be overridden by explicitly
179  # setting these in the .apk's AndroidManifest.xml.  It is either the code
180  # name of the development build or, if this is a release build, the official
181  # SDK version of this release.
182  ifeq (REL,$(PLATFORM_VERSION_CODENAME))
183    DEFAULT_APP_TARGET_SDK := $(PLATFORM_SDK_VERSION)
184  else
185    DEFAULT_APP_TARGET_SDK := $(PLATFORM_VERSION_CODENAME)
186  endif
187endif
188.KATI_READONLY := DEFAULT_APP_TARGET_SDK
189
190ifndef PLATFORM_VNDK_VERSION
191  # This is the definition of the VNDK version for the current VNDK libraries.
192  # The version is only available when PLATFORM_VERSION_CODENAME == REL.
193  # Otherwise, it will be set to a CODENAME version. The ABI is allowed to be
194  # changed only before the Android version is released. Once
195  # PLATFORM_VNDK_VERSION is set to actual version, the ABI for this version
196  # will be frozon and emit build errors if any ABI for the VNDK libs are
197  # changed.
198  # After that the snapshot of the VNDK with this version will be generated.
199  #
200  # The VNDK version follows PLATFORM_SDK_VERSION.
201  ifeq (REL,$(PLATFORM_VERSION_CODENAME))
202    PLATFORM_VNDK_VERSION := $(PLATFORM_SDK_VERSION)
203  else
204    PLATFORM_VNDK_VERSION := $(PLATFORM_VERSION_CODENAME)
205  endif
206endif
207.KATI_READONLY := PLATFORM_VNDK_VERSION
208
209ifndef PLATFORM_SYSTEMSDK_MIN_VERSION
210  # This is the oldest version of system SDK that the platform supports. Contrary
211  # to the public SDK where platform essentially supports all previous SDK versions,
212  # platform supports only a few number of recent system SDK versions as some of
213  # old system APIs are gradually deprecated, removed and then deleted.
214  PLATFORM_SYSTEMSDK_MIN_VERSION := 28
215endif
216.KATI_READONLY := PLATFORM_SYSTEMSDK_MIN_VERSION
217
218# This is the list of system SDK versions that the current platform supports.
219PLATFORM_SYSTEMSDK_VERSIONS :=
220ifneq (,$(PLATFORM_SYSTEMSDK_MIN_VERSION))
221  $(if $(call math_is_number,$(PLATFORM_SYSTEMSDK_MIN_VERSION)),,\
222    $(error PLATFORM_SYSTEMSDK_MIN_VERSION must be a number, but was $(PLATFORM_SYSTEMSDK_MIN_VERSION)))
223  PLATFORM_SYSTEMSDK_VERSIONS := $(call int_range_list,$(PLATFORM_SYSTEMSDK_MIN_VERSION),$(PLATFORM_SDK_VERSION))
224endif
225# Platform always supports the current version
226ifeq (REL,$(PLATFORM_VERSION_CODENAME))
227  PLATFORM_SYSTEMSDK_VERSIONS += $(PLATFORM_SDK_VERSION)
228else
229  PLATFORM_SYSTEMSDK_VERSIONS += $(PLATFORM_VERSION_CODENAME)
230endif
231PLATFORM_SYSTEMSDK_VERSIONS := $(strip $(sort $(PLATFORM_SYSTEMSDK_VERSIONS)))
232.KATI_READONLY := PLATFORM_SYSTEMSDK_VERSIONS
233
234ifndef PLATFORM_SECURITY_PATCH
235    #  Used to indicate the security patch that has been applied to the device.
236    #  It must signify that the build includes all security patches issued up through the designated Android Public Security Bulletin.
237    #  It must be of the form "YYYY-MM-DD" on production devices.
238    #  It must match one of the Android Security Patch Level strings of the Public Security Bulletins.
239    #  If there is no $PLATFORM_SECURITY_PATCH set, keep it empty.
240      PLATFORM_SECURITY_PATCH := 2020-07-05
241endif
242.KATI_READONLY := PLATFORM_SECURITY_PATCH
243
244ifndef PLATFORM_SECURITY_PATCH_TIMESTAMP
245  # Used to indicate the matching timestamp for the security patch string in PLATFORM_SECURITY_PATCH.
246  PLATFORM_SECURITY_PATCH_TIMESTAMP := $(shell date -d 'TZ="GMT" $(PLATFORM_SECURITY_PATCH)' +%s)
247endif
248.KATI_READONLY := PLATFORM_SECURITY_PATCH_TIMESTAMP
249
250ifndef PLATFORM_BASE_OS
251  # Used to indicate the base os applied to the device.
252  # Can be an arbitrary string, but must be a single word.
253  #
254  # If there is no $PLATFORM_BASE_OS set, keep it empty.
255  PLATFORM_BASE_OS :=
256endif
257.KATI_READONLY := PLATFORM_BASE_OS
258
259ifndef BUILD_ID
260  # Used to signify special builds.  E.g., branches and/or releases,
261  # like "M5-RC7".  Can be an arbitrary string, but must be a single
262  # word and a valid file name.
263  #
264  # If there is no BUILD_ID set, make it obvious.
265  BUILD_ID := UNKNOWN
266endif
267.KATI_READONLY := BUILD_ID
268
269ifndef BUILD_DATETIME
270  # Used to reproduce builds by setting the same time. Must be the number
271  # of seconds since the Epoch.
272  BUILD_DATETIME := $(shell date +%s)
273endif
274
275DATE := date -d @$(BUILD_DATETIME)
276.KATI_READONLY := DATE
277
278# Everything should be using BUILD_DATETIME_FROM_FILE instead.
279# BUILD_DATETIME and DATE can be removed once BUILD_NUMBER moves
280# to soong_ui.
281$(KATI_obsolete_var BUILD_DATETIME,Use BUILD_DATETIME_FROM_FILE)
282
283HAS_BUILD_NUMBER := true
284ifndef BUILD_NUMBER
285  # BUILD_NUMBER should be set to the source control value that
286  # represents the current state of the source code.  E.g., a
287  # perforce changelist number or a git hash.  Can be an arbitrary string
288  # (to allow for source control that uses something other than numbers),
289  # but must be a single word and a valid file name.
290  #
291  # If no BUILD_NUMBER is set, create a useful "I am an engineering build
292  # from this date/time" value.  Make it start with a non-digit so that
293  # anyone trying to parse it as an integer will probably get "0".
294  BUILD_NUMBER := eng.$(shell echo $${BUILD_USERNAME:0:6}).$(shell $(DATE) +%Y%m%d.%H%M%S)
295  HAS_BUILD_NUMBER := false
296endif
297.KATI_READONLY := BUILD_NUMBER HAS_BUILD_NUMBER
298
299ifndef PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION
300  # Used to set minimum supported target sdk version. Apps targeting sdk
301  # version lower than the set value will result in a warning being shown
302  # when any activity from the app is started.
303  PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION := 23
304endif
305.KATI_READONLY := PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION
306