Merge "Remove USER exclusion for dalvik.vm.dex2oat-resolve-startup-strings"
diff --git a/Changes.md b/Changes.md
index 1ed6bf8..165be01 100644
--- a/Changes.md
+++ b/Changes.md
@@ -1,5 +1,20 @@
# Build System Changes for Android.mk Writers
+## `LOCAL_MODULE_TAGS := eng debug` deprecation {#LOCAL_MODULE_TAGS}
+
+`LOCAL_MODULE_TAGS` value `eng` and `debug` are being deprecated. They allowed
+modules to specify that they should always be installed on `-eng`, or `-eng`
+and `-userdebug` builds. This conflicted with the ability for products to
+specify which modules should be installed, effectively making it impossible to
+build a stripped down product configuration that did not include those modules.
+
+For the equivalent functionality, specify the modules in `PRODUCT_PACKAGES_ENG`
+or `PRODUCT_PACKAGES_DEBUG` in the appropriate product makefiles.
+
+Core android packages like `su` got added to the list in
+`build/make/target/product/base_system.mk`, but for device-specific modules
+there are often better base product makefiles to use instead.
+
## `USER` deprecation {#USER}
`USER` will soon be `nobody` in many cases due to the addition of a sandbox
diff --git a/core/Makefile b/core/Makefile
index 4309e2c..fbf6d57 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -2586,10 +2586,71 @@
$(BUILT_ASSEMBLED_VENDOR_MANIFEST): $(BUILT_SYSTEM_MATRIX)
$(BUILT_ASSEMBLED_VENDOR_MANIFEST): $(BUILT_VENDOR_MANIFEST)
$(BUILT_ASSEMBLED_VENDOR_MANIFEST): $(INTERNAL_VENDORIMAGE_FILES)
+
+$(BUILT_ASSEMBLED_VENDOR_MANIFEST): PRIVATE_FLAGS :=
+
+# -- Kernel version and configurations.
+ifeq ($(PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS),true)
+
+# BOARD_KERNEL_CONFIG_FILE and BOARD_KERNEL_VERSION can be used to override the values extracted
+# from INSTALLED_KERNEL_TARGET.
+ifdef BOARD_KERNEL_CONFIG_FILE
+ifdef BOARD_KERNEL_VERSION
+$(BUILT_ASSEMBLED_VENDOR_MANIFEST): $(BOARD_KERNEL_CONFIG_FILE)
+$(BUILT_ASSEMBLED_VENDOR_MANIFEST): PRIVATE_FLAGS += --kernel $(BOARD_KERNEL_VERSION):$(BOARD_KERNEL_CONFIG_FILE)
+my_board_extracted_kernel := true
+endif # BOARD_KERNEL_VERSION
+endif # BOARD_KERNEL_CONFIG_FILE
+
+ifneq ($(my_board_extracted_kernel),true)
+ifndef INSTALLED_KERNEL_TARGET
+$(warning No INSTALLED_KERNEL_TARGET is defined when PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS \
+ is true. Information about the updated kernel cannot be built into OTA update package. \
+ You can fix this by: (1) setting TARGET_NO_KERNEL to false and installing the built kernel \
+ to $(PRODUCT_OUT)/kernel, so that kernel information will be extracted from the built kernel; \
+ or (2) extracting kernel configuration and defining BOARD_KERNEL_CONFIG_FILE and \
+ BOARD_KERNEL_VERSION manually; or (3) unsetting PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS \
+ manually.)
+else
+intermediates := $(call intermediates-dir-for,ETC,$(notdir $(BUILT_ASSEMBLED_VENDOR_MANIFEST)))
+
+# Tools for decompression that is not in PATH.
+# Check $(EXTRACT_KERNEL) for decompression algorithms supported by the script.
+# Algorithms that are in the script but not in this list will be found in PATH.
+my_decompress_tools := \
+ lz4:$(HOST_OUT_EXECUTABLES)/lz4 \
+
+my_kernel_configs := $(intermediates)/kernel_configs.txt
+my_kernel_version := $(intermediates)/kernel_version.txt
+$(my_kernel_configs): .KATI_IMPLICIT_OUTPUTS := $(my_kernel_version)
+$(my_kernel_configs): PRIVATE_KERNEL_VERSION_FILE := $(my_kernel_version)
+$(my_kernel_configs): PRIVATE_DECOMPRESS_TOOLS := $(my_decompress_tools)
+$(my_kernel_configs): $(foreach pair,$(my_decompress_tools),$(call word-colon,2,$(pair)))
+$(my_kernel_configs): $(EXTRACT_KERNEL) $(INSTALLED_KERNEL_TARGET)
+ $< --tools $(PRIVATE_DECOMPRESS_TOOLS) --input $(INSTALLED_KERNEL_TARGET) \
+ --output-configs $@ \
+ --output-version $(PRIVATE_KERNEL_VERSION_FILE)
+
+$(BUILT_ASSEMBLED_VENDOR_MANIFEST): $(my_kernel_configs) $(my_kernel_version)
+$(BUILT_ASSEMBLED_VENDOR_MANIFEST): PRIVATE_FLAGS += --kernel $$(cat $(my_kernel_version)):$(my_kernel_configs)
+
+intermediates :=
+my_kernel_configs :=
+my_kernel_version :=
+my_decompress_tools :=
+
+endif # my_board_extracted_kernel
+my_board_extracted_kernel :=
+
+endif # INSTALLED_KERNEL_TARGET
+endif # PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS
+
+$(BUILT_ASSEMBLED_VENDOR_MANIFEST):
@echo "Verifying vendor VINTF manifest."
PRODUCT_ENFORCE_VINTF_MANIFEST=$(PRODUCT_ENFORCE_VINTF_MANIFEST) \
$(PRIVATE_SYSTEM_ASSEMBLE_VINTF_ENV_VARS) \
$(HOST_OUT_EXECUTABLES)/assemble_vintf \
+ $(PRIVATE_FLAGS) \
-c $(BUILT_SYSTEM_MATRIX) \
-i $(BUILT_VENDOR_MANIFEST) \
$$([ -d $(TARGET_OUT_VENDOR)/etc/vintf/manifest ] && \
diff --git a/core/base_rules.mk b/core/base_rules.mk
index fd369f2..3d1f186 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -162,6 +162,19 @@
$(error user tag detected on module.)
endif
+my_bad_module_tags := $(filter eng debug,$(my_module_tags))
+ifdef my_bad_module_tags
+ ifeq (true,$(LOCAL_UNINSTALLABLE_MODULE))
+ $(call pretty-warning,LOCAL_MODULE_TAGS := $(my_bad_module_tags) does not do anything for uninstallable modules)
+ endif
+ ifeq ($(BUILD_BROKEN_ENG_DEBUG_TAGS),false)
+ $(call pretty-error,LOCAL_MODULE_TAGS := $(my_bad_module_tags) is obsolete. See $(CHANGES_URL)#LOCAL_MODULE_TAGS)
+ else
+ $(call pretty-warning,LOCAL_MODULE_TAGS := $(my_bad_module_tags) is deprecated. See $(CHANGES_URL)#LOCAL_MODULE_TAGS)
+ endif
+ my_bad_module_tags :=
+endif
+
# Only the tags mentioned in this test are expected to be set by module
# makefiles. Anything else is either a typo or a source of unexpected
# behaviors.
diff --git a/core/clang/TARGET_arm.mk b/core/clang/TARGET_arm.mk
index 6140d7c..f18747a 100644
--- a/core/clang/TARGET_arm.mk
+++ b/core/clang/TARGET_arm.mk
@@ -7,3 +7,4 @@
# Address sanitizer clang config
$(clang_2nd_arch_prefix)ADDRESS_SANITIZER_LINKER := /system/bin/linker_asan
+$(clang_2nd_arch_prefix)ADDRESS_SANITIZER_LINKER_FILE := /system/bin/bootstrap/linker_asan
diff --git a/core/clang/TARGET_arm64.mk b/core/clang/TARGET_arm64.mk
index 9fe5530..42bed0a 100644
--- a/core/clang/TARGET_arm64.mk
+++ b/core/clang/TARGET_arm64.mk
@@ -7,3 +7,4 @@
# Address sanitizer clang config
ADDRESS_SANITIZER_LINKER := /system/bin/linker_asan64
+ADDRESS_SANITIZER_LINKER_FILE := /system/bin/bootstrap/linker_asan64
diff --git a/core/clang/TARGET_mips.mk b/core/clang/TARGET_mips.mk
index dfd99b2..3e54a66 100644
--- a/core/clang/TARGET_mips.mk
+++ b/core/clang/TARGET_mips.mk
@@ -6,3 +6,4 @@
# Address sanitizer clang config
$(clang_2nd_arch_prefix)ADDRESS_SANITIZER_LINKER := /system/bin/linker_asan
+$(clang_2nd_arch_prefix)ADDRESS_SANITIZER_LINKER_FILE := /system/bin/bootstrap/linker_asan
diff --git a/core/clang/TARGET_mips64.mk b/core/clang/TARGET_mips64.mk
index a3684cc..cb6a3cd 100644
--- a/core/clang/TARGET_mips64.mk
+++ b/core/clang/TARGET_mips64.mk
@@ -6,3 +6,4 @@
# Address sanitizer clang config
$(clang_2nd_arch_prefix)ADDRESS_SANITIZER_LINKER := /system/bin/linker_asan64
+$(clang_2nd_arch_prefix)ADDRESS_SANITIZER_LINKER_FILE := /system/bin/bootstrap/linker_asan64
diff --git a/core/clang/TARGET_x86.mk b/core/clang/TARGET_x86.mk
index 5e2d57e..5491a05 100644
--- a/core/clang/TARGET_x86.mk
+++ b/core/clang/TARGET_x86.mk
@@ -7,3 +7,4 @@
# Address sanitizer clang config
$(clang_2nd_arch_prefix)ADDRESS_SANITIZER_LINKER := /system/bin/linker_asan
+$(clang_2nd_arch_prefix)ADDRESS_SANITIZER_LINKER_FILE := /system/bin/bootstrap/linker_asan
diff --git a/core/clang/TARGET_x86_64.mk b/core/clang/TARGET_x86_64.mk
index 86b3798..167db72 100644
--- a/core/clang/TARGET_x86_64.mk
+++ b/core/clang/TARGET_x86_64.mk
@@ -7,3 +7,4 @@
# Address sanitizer clang config
ADDRESS_SANITIZER_LINKER := /system/bin/linker_asan64
+ADDRESS_SANITIZER_LINKER_FILE := /system/bin/bootstrap/linker_asan64
diff --git a/core/config.mk b/core/config.mk
index ab0ec6d..e8cb1e5 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -34,6 +34,7 @@
# Mark variables deprecated/obsolete
CHANGES_URL := https://android.googlesource.com/platform/build/+/master/Changes.md
+.KATI_READONLY := CHANGES_URL
$(KATI_obsolete_var PATH,Do not use PATH directly. See $(CHANGES_URL)#PATH)
$(KATI_obsolete_var PYTHONPATH,Do not use PYTHONPATH directly. See $(CHANGES_URL)#PYTHONPATH)
$(KATI_obsolete_var OUT,Use OUT_DIR instead. See $(CHANGES_URL)#OUT)
@@ -95,8 +96,6 @@
# This is marked as obsolete in envsetup.mk after reading the BoardConfig.mk
$(KATI_deprecate_export It is a global setting. See $(CHANGES_URL)#export_keyword)
-CHANGES_URL :=
-
# Used to force goals to build. Only use for conditionally defined goals.
.PHONY: FORCE
FORCE:
@@ -219,6 +218,7 @@
BUILD_BROKEN_DUP_COPY_HEADERS :=
BUILD_BROKEN_DUP_RULES :=
BUILD_BROKEN_PHONY_TARGETS :=
+BUILD_BROKEN_ENG_DEBUG_TAGS :=
# ###############################################################
# Include sub-configuration files
@@ -730,6 +730,8 @@
JETIFIER := prebuilts/sdk/tools/jetifier/jetifier-standalone/bin/jetifier-standalone
+EXTRACT_KERNEL := build/make/tools/extract_kernel.py
+
COLUMN:= column
USE_OPENJDK9 := true
diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk
index 6c9caa8..bbf3b7d 100644
--- a/core/config_sanitizers.mk
+++ b/core/config_sanitizers.mk
@@ -341,7 +341,7 @@
ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
my_linker := $($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_LINKER)
# Make sure linker_asan get installed.
- $(LOCAL_INSTALLED_MODULE) : | $(PRODUCT_OUT)$($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_LINKER)
+ $(LOCAL_INSTALLED_MODULE) : | $(PRODUCT_OUT)$($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_LINKER_FILE)
endif
endif
endif
diff --git a/core/definitions.mk b/core/definitions.mk
index aaa9ddf..fc766a5 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -2694,6 +2694,7 @@
# Generate a greylist.txt from a classes.jar
define hiddenapi-generate-csv
+ifneq ($(UNSAFE_DISABLE_HIDDENAPI_FLAGS),true)
ifneq (,$(wildcard frameworks/base))
# Only generate this target if we're in a tree with frameworks/base present.
$(2): $(1) $(CLASS2GREYLIST) $(INTERNAL_PLATFORM_HIDDENAPI_STUB_FLAGS)
@@ -2712,6 +2713,7 @@
PRIVATE_METADATA_INPUTS := $$(PRIVATE_METADATA_INPUTS) $(3)
endif
+endif # UNSAFE_DISABLE_HIDDENAPI_FLAGS
endef
diff --git a/core/dex_preopt.mk b/core/dex_preopt.mk
index f102662..21bac87 100644
--- a/core/dex_preopt.mk
+++ b/core/dex_preopt.mk
@@ -31,6 +31,7 @@
include $(BUILD_SYSTEM)/dex_preopt_libart.mk
# === hiddenapi rules ===
+ifneq ($(UNSAFE_DISABLE_HIDDENAPI_FLAGS),true)
hiddenapi_stubs_jar = $(call intermediates-dir-for,JAVA_LIBRARIES,$(1),,COMMON)/javalib.jar
@@ -88,6 +89,7 @@
# Additional inputs are filled with `hiddenapi-generate-csv`
$(INTERNAL_PLATFORM_HIDDENAPI_GREYLIST_METADATA): $(SOONG_HIDDENAPI_GREYLIST_METADATA)
$(INTERNAL_PLATFORM_HIDDENAPI_GREYLIST_METADATA): PRIVATE_METADATA_INPUTS := $(SOONG_HIDDENAPI_GREYLIST_METADATA)
+endif # UNSAFE_DISABLE_HIDDENAPI_FLAGS
ifeq ($(PRODUCT_DIST_BOOT_AND_SYSTEM_JARS),true)
boot_profile_jars_zip := $(PRODUCT_OUT)/boot_profile_jars.zip
diff --git a/core/envsetup.mk b/core/envsetup.mk
index 17448f1..1426935 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -271,7 +271,8 @@
BUILD_BROKEN_ANDROIDMK_EXPORTS \
BUILD_BROKEN_DUP_COPY_HEADERS \
BUILD_BROKEN_DUP_RULES \
- BUILD_BROKEN_PHONY_TARGETS
+ BUILD_BROKEN_PHONY_TARGETS \
+ BUILD_BROKEN_ENG_DEBUG_TAGS
$(foreach var,$(vars),$(eval $(var) := $$(strip $$($(var)))))
@@ -281,14 +282,10 @@
.KATI_READONLY := $(vars)
-CHANGES_URL := https://android.googlesource.com/platform/build/+/master/Changes.md
-
ifneq ($(BUILD_BROKEN_ANDROIDMK_EXPORTS),true)
$(KATI_obsolete_export It is a global setting. See $(CHANGES_URL)#export_keyword)
endif
-CHANGES_URL :=
-
###########################################
# Now we can substitute with the real value of TARGET_COPY_OUT_RAMDISK
ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
diff --git a/core/package_internal.mk b/core/package_internal.mk
index 9ddbd1b..06dc1b7 100644
--- a/core/package_internal.mk
+++ b/core/package_internal.mk
@@ -576,9 +576,11 @@
module_run_appcompat :=
ifeq (true,$(non_system_module))
ifeq (,$(TARGET_BUILD_APPS)$(filter true,$(TARGET_BUILD_PDK))) # ! unbundled app build
+ifneq ($(UNSAFE_DISABLE_HIDDENAPI_FLAGS),true)
module_run_appcompat := true
endif
endif
+endif
ifeq ($(module_run_appcompat),true)
$(LOCAL_BUILT_MODULE) : $(appcompat-files)
diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk
index 0b48a77..cd48025 100644
--- a/core/prebuilt_internal.mk
+++ b/core/prebuilt_internal.mk
@@ -74,9 +74,11 @@
module_run_appcompat :=
ifeq (true,$(non_system_module))
ifeq (,$(TARGET_BUILD_APPS)$(filter true,$(TARGET_BUILD_PDK))) # ! unbundled app build
+ifneq ($(UNSAFE_DISABLE_HIDDENAPI_FLAGS),true)
module_run_appcompat := true
endif
endif
+endif
ifdef LOCAL_COMPRESSED_MODULE
ifneq (true,$(LOCAL_COMPRESSED_MODULE))
diff --git a/core/soong_app_prebuilt.mk b/core/soong_app_prebuilt.mk
index 3d28ea7..14d796c 100644
--- a/core/soong_app_prebuilt.mk
+++ b/core/soong_app_prebuilt.mk
@@ -48,9 +48,11 @@
module_run_appcompat :=
ifeq (true,$(non_system_module))
ifeq (,$(TARGET_BUILD_APPS)$(filter true,$(TARGET_BUILD_PDK))) # ! unbundled app build
+ifneq ($(UNSAFE_DISABLE_HIDDENAPI_FLAGS),true)
module_run_appcompat := true
endif
endif
+endif
ifeq ($(module_run_appcompat),true)
$(LOCAL_BUILT_MODULE): $(appcompat-files)
diff --git a/tools/extract_kernel.py b/tools/extract_kernel.py
new file mode 100755
index 0000000..16ccb22
--- /dev/null
+++ b/tools/extract_kernel.py
@@ -0,0 +1,196 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2018 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.
+
+"""
+A tool to extract kernel information from a kernel image.
+"""
+
+import argparse
+import subprocess
+import sys
+import re
+
+CONFIG_PREFIX = b'IKCFG_ST'
+GZIP_HEADER = b'\037\213\010'
+COMPRESSION_ALGO = (
+ (["gzip", "-d"], GZIP_HEADER),
+ (["xz", "-d"], b'\3757zXZ\000'),
+ (["bzip2", "-d"], b'BZh'),
+ (["lz4", "-d", "-l"], b'\002\041\114\030'),
+
+ # These are not supported in the build system yet.
+ # (["unlzma"], b'\135\0\0\0'),
+ # (["lzop", "-d"], b'\211\114\132'),
+)
+
+# "Linux version " UTS_RELEASE " (" LINUX_COMPILE_BY "@"
+# LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION "\n";
+LINUX_BANNER_PREFIX = b'Linux version '
+LINUX_BANNER_REGEX = LINUX_BANNER_PREFIX + \
+ r'([0-9]+[.][0-9]+[.][0-9]+).* \(.*@.*\) \(.*\) .*\n'
+
+
+def get_version(input_bytes, start_idx):
+ null_idx = input_bytes.find('\x00', start_idx)
+ if null_idx < 0:
+ return None
+ linux_banner = input_bytes[start_idx:null_idx].decode()
+ mo = re.match(LINUX_BANNER_REGEX, linux_banner)
+ if mo:
+ return mo.group(1)
+ return None
+
+
+def dump_version(input_bytes):
+ idx = 0
+ while True:
+ idx = input_bytes.find(LINUX_BANNER_PREFIX, idx)
+ if idx < 0:
+ return None
+
+ version = get_version(input_bytes, idx)
+ if version:
+ return version
+
+ idx += len(LINUX_BANNER_PREFIX)
+
+
+def dump_configs(input_bytes):
+ """
+ Dump kernel configuration from input_bytes. This can be done when
+ CONFIG_IKCONFIG is enabled, which is a requirement on Treble devices.
+
+ The kernel configuration is archived in GZip format right after the magic
+ string 'IKCFG_ST' in the built kernel.
+ """
+
+ # Search for magic string + GZip header
+ idx = input_bytes.find(CONFIG_PREFIX + GZIP_HEADER)
+ if idx < 0:
+ return None
+
+ # Seek to the start of the archive
+ idx += len(CONFIG_PREFIX)
+
+ sp = subprocess.Popen(["gzip", "-d", "-c"], stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ o, _ = sp.communicate(input=input_bytes[idx:])
+ if sp.returncode == 1: # error
+ return None
+
+ # success or trailing garbage warning
+ assert sp.returncode in (0, 2), sp.returncode
+
+ return o
+
+
+def try_decompress(cmd, search_bytes, input_bytes):
+ idx = input_bytes.find(search_bytes)
+ if idx < 0:
+ return None
+
+ idx = 0
+ sp = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ o, _ = sp.communicate(input=input_bytes[idx:])
+ # ignore errors
+ return o
+
+
+def decompress_dump(func, input_bytes):
+ """
+ Run func(input_bytes) first; and if that fails (returns value evaluates to
+ False), then try different decompression algorithm before running func.
+ """
+ o = func(input_bytes)
+ if o:
+ return o
+ for cmd, search_bytes in COMPRESSION_ALGO:
+ decompressed = try_decompress(cmd, search_bytes, input_bytes)
+ if decompressed:
+ o = func(decompressed)
+ if o:
+ return o
+ # Force decompress the whole file even if header doesn't match
+ decompressed = try_decompress(cmd, b"", input_bytes)
+ if decompressed:
+ o = func(decompressed)
+ if o:
+ return o
+
+def main():
+ parser = argparse.ArgumentParser(
+ formatter_class=argparse.RawTextHelpFormatter,
+ description=__doc__ +
+ "\nThese algorithms are tried when decompressing the image:\n " +
+ " ".join(tup[0][0] for tup in COMPRESSION_ALGO))
+ parser.add_argument('--input',
+ help='Input kernel image. If not specified, use stdin',
+ metavar='FILE',
+ type=argparse.FileType('rb'),
+ default=sys.stdin)
+ parser.add_argument('--output-configs',
+ help='If specified, write configs. Use stdout if no file '
+ 'is specified.',
+ metavar='FILE',
+ nargs='?',
+ type=argparse.FileType('wb'),
+ const=sys.stdout)
+ parser.add_argument('--output-version',
+ help='If specified, write version. Use stdout if no file '
+ 'is specified.',
+ metavar='FILE',
+ nargs='?',
+ type=argparse.FileType('wb'),
+ const=sys.stdout)
+ parser.add_argument('--tools',
+ help='Decompression tools to use. If not specified, PATH '
+ 'is searched.',
+ metavar='ALGORITHM:EXECUTABLE',
+ nargs='*')
+ args = parser.parse_args()
+
+ tools = {pair[0]: pair[1]
+ for pair in (token.split(':') for token in args.tools or [])}
+ for cmd, _ in COMPRESSION_ALGO:
+ if cmd[0] in tools:
+ cmd[0] = tools[cmd[0]]
+
+ input_bytes = args.input.read()
+
+ ret = 0
+ if args.output_configs is not None:
+ o = decompress_dump(dump_configs, input_bytes)
+ if o:
+ args.output_configs.write(o)
+ else:
+ sys.stderr.write(
+ "Cannot extract kernel configs in {}".format(args.input.name))
+ ret = 1
+ if args.output_version is not None:
+ o = decompress_dump(dump_version, input_bytes)
+ if o:
+ args.output_version.write(o)
+ else:
+ sys.stderr.write(
+ "Cannot extract kernel versions in {}".format(args.input.name))
+ ret = 1
+
+ return ret
+
+
+if __name__ == '__main__':
+ exit(main())
diff --git a/tools/test_extract_kernel.py b/tools/test_extract_kernel.py
new file mode 100644
index 0000000..1a1cfcb
--- /dev/null
+++ b/tools/test_extract_kernel.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2018 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.
+
+import unittest
+from extract_kernel import get_version, dump_version
+
+class ExtractKernelTest(unittest.TestCase):
+ def test_extract_version(self):
+ self.assertEqual("4.9.100", get_version(
+ b'Linux version 4.9.100-a123 (a@a) (a) a\n\x00', 0))
+ self.assertEqual("4.9.123", get_version(
+ b'Linux version 4.9.123 (@) () \n\x00', 0))
+
+ def test_dump_self(self):
+ self.assertEqual("4.9.1", dump_version(
+ b"trash\x00Linux version 4.8.8\x00trash\x00"
+ "other trash Linux version 4.9.1-g3 (2@s) (2) a\n\x00"))