Let extract_kernel return full kernel release.
Also add relevant soong rules for genrules to use it. Test: use it in GKI APEX Bug: 161563386 Change-Id: I04f80ba91748ee5783088d4e20e6438418863f62
This commit is contained in:
@@ -56,3 +56,23 @@ python_test_host {
|
|||||||
test_config: "post_process_props_unittest.xml",
|
test_config: "post_process_props_unittest.xml",
|
||||||
test_suites: ["general-tests"],
|
test_suites: ["general-tests"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
python_binary_host {
|
||||||
|
name: "extract_kernel",
|
||||||
|
srcs: ["extract_kernel.py"],
|
||||||
|
version: {
|
||||||
|
py2: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
py3: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
genrule_defaults {
|
||||||
|
name: "extract_kernel_release_defaults",
|
||||||
|
tools: ["extract_kernel", "lz4"],
|
||||||
|
out: ["kernel_release.txt"],
|
||||||
|
cmd: "$(location) --tools lz4:$(location lz4) --input $(in) --output-release > $(out)"
|
||||||
|
}
|
||||||
|
@@ -40,10 +40,10 @@ COMPRESSION_ALGO = (
|
|||||||
# LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION "\n";
|
# LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION "\n";
|
||||||
LINUX_BANNER_PREFIX = b'Linux version '
|
LINUX_BANNER_PREFIX = b'Linux version '
|
||||||
LINUX_BANNER_REGEX = LINUX_BANNER_PREFIX + \
|
LINUX_BANNER_REGEX = LINUX_BANNER_PREFIX + \
|
||||||
r'([0-9]+[.][0-9]+[.][0-9]+).* \(.*@.*\) \(.*\) .*\n'
|
r'(?P<release>(?P<version>[0-9]+[.][0-9]+[.][0-9]+).*) \(.*@.*\) \(.*\) .*\n'
|
||||||
|
|
||||||
|
|
||||||
def get_version(input_bytes, start_idx):
|
def get_from_release(input_bytes, start_idx, key):
|
||||||
null_idx = input_bytes.find('\x00', start_idx)
|
null_idx = input_bytes.find('\x00', start_idx)
|
||||||
if null_idx < 0:
|
if null_idx < 0:
|
||||||
return None
|
return None
|
||||||
@@ -53,24 +53,43 @@ def get_version(input_bytes, start_idx):
|
|||||||
return None
|
return None
|
||||||
mo = re.match(LINUX_BANNER_REGEX, linux_banner)
|
mo = re.match(LINUX_BANNER_REGEX, linux_banner)
|
||||||
if mo:
|
if mo:
|
||||||
return mo.group(1)
|
return mo.group(key)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def dump_version(input_bytes):
|
def dump_from_release(input_bytes, key):
|
||||||
|
"""
|
||||||
|
Helper of dump_version and dump_release
|
||||||
|
"""
|
||||||
idx = 0
|
idx = 0
|
||||||
while True:
|
while True:
|
||||||
idx = input_bytes.find(LINUX_BANNER_PREFIX, idx)
|
idx = input_bytes.find(LINUX_BANNER_PREFIX, idx)
|
||||||
if idx < 0:
|
if idx < 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
version = get_version(input_bytes, idx)
|
value = get_from_release(input_bytes, idx, key)
|
||||||
if version:
|
if value:
|
||||||
return version
|
return value
|
||||||
|
|
||||||
idx += len(LINUX_BANNER_PREFIX)
|
idx += len(LINUX_BANNER_PREFIX)
|
||||||
|
|
||||||
|
|
||||||
|
def dump_version(input_bytes):
|
||||||
|
"""
|
||||||
|
Dump kernel version, w.x.y, from input_bytes. Search for the string
|
||||||
|
"Linux version " and do pattern matching after it. See LINUX_BANNER_REGEX.
|
||||||
|
"""
|
||||||
|
return dump_from_release(input_bytes, "version")
|
||||||
|
|
||||||
|
|
||||||
|
def dump_release(input_bytes):
|
||||||
|
"""
|
||||||
|
Dump kernel release, w.x.y-..., from input_bytes. Search for the string
|
||||||
|
"Linux version " and do pattern matching after it. See LINUX_BANNER_REGEX.
|
||||||
|
"""
|
||||||
|
return dump_from_release(input_bytes, "release")
|
||||||
|
|
||||||
|
|
||||||
def dump_configs(input_bytes):
|
def dump_configs(input_bytes):
|
||||||
"""
|
"""
|
||||||
Dump kernel configuration from input_bytes. This can be done when
|
Dump kernel configuration from input_bytes. This can be done when
|
||||||
@@ -140,6 +159,23 @@ def decompress_dump(func, input_bytes):
|
|||||||
if o:
|
if o:
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
|
||||||
|
def dump_to_file(f, dump_fn, input_bytes, desc):
|
||||||
|
"""
|
||||||
|
Call decompress_dump(dump_fn, input_bytes) and write to f. If it fails, return
|
||||||
|
False; otherwise return True.
|
||||||
|
"""
|
||||||
|
if f is not None:
|
||||||
|
o = decompress_dump(dump_fn, input_bytes)
|
||||||
|
if o:
|
||||||
|
f.write(o)
|
||||||
|
else:
|
||||||
|
sys.stderr.write(
|
||||||
|
"Cannot extract kernel {}".format(desc))
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
formatter_class=argparse.RawTextHelpFormatter,
|
formatter_class=argparse.RawTextHelpFormatter,
|
||||||
@@ -165,6 +201,13 @@ def main():
|
|||||||
nargs='?',
|
nargs='?',
|
||||||
type=argparse.FileType('wb'),
|
type=argparse.FileType('wb'),
|
||||||
const=sys.stdout)
|
const=sys.stdout)
|
||||||
|
parser.add_argument('--output-release',
|
||||||
|
help='If specified, write kernel release. Use stdout if '
|
||||||
|
'no file is specified.',
|
||||||
|
metavar='FILE',
|
||||||
|
nargs='?',
|
||||||
|
type=argparse.FileType('wb'),
|
||||||
|
const=sys.stdout)
|
||||||
parser.add_argument('--tools',
|
parser.add_argument('--tools',
|
||||||
help='Decompression tools to use. If not specified, PATH '
|
help='Decompression tools to use. If not specified, PATH '
|
||||||
'is searched.',
|
'is searched.',
|
||||||
@@ -181,25 +224,18 @@ def main():
|
|||||||
input_bytes = args.input.read()
|
input_bytes = args.input.read()
|
||||||
|
|
||||||
ret = 0
|
ret = 0
|
||||||
if args.output_configs is not None:
|
if not dump_to_file(args.output_configs, dump_configs, input_bytes,
|
||||||
o = decompress_dump(dump_configs, input_bytes)
|
"configs in {}".format(args.input.name)):
|
||||||
if o:
|
ret = 1
|
||||||
args.output_configs.write(o)
|
if not dump_to_file(args.output_version, dump_version, input_bytes,
|
||||||
else:
|
"version in {}".format(args.input.name)):
|
||||||
sys.stderr.write(
|
ret = 1
|
||||||
"Cannot extract kernel configs in {}".format(args.input.name))
|
if not dump_to_file(args.output_release, dump_release, input_bytes,
|
||||||
ret = 1
|
"kernel release in {}".format(args.input.name)):
|
||||||
if args.output_version is not None:
|
ret = 1
|
||||||
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
|
return ret
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
exit(main())
|
sys.exit(main())
|
||||||
|
Reference in New Issue
Block a user