echo key configs as bash commands

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2018-10-25 00:00:00 +00:00
parent 21627ff9d8
commit 98d2c83317
3 changed files with 22 additions and 13 deletions

View File

@@ -92,8 +92,7 @@ Configure the kernel, but don't build it.
if args.config != []: if args.config != []:
cli_config_fragment_path = os.path.join(build_dir, 'lkmc_cli_config_fragment') cli_config_fragment_path = os.path.join(build_dir, 'lkmc_cli_config_fragment')
cli_config_str = '\n'.join(map(lambda x: 'CONFIG_' + x, args.config)) cli_config_str = '\n'.join(map(lambda x: 'CONFIG_' + x, args.config))
with open(cli_config_fragment_path, 'w') as cli_config_fragment_cli: common.write_string_to_file(cli_config_fragment_path, cli_config_str)
cli_config_fragment_cli.write(cli_config_str)
config_fragments.append(cli_config_fragment_path) config_fragments.append(cli_config_fragment_path)
common.cp( common.cp(
base_config_file, base_config_file,

View File

@@ -154,6 +154,17 @@ mkdir are generally omitted since those are obvious.
def base64_encode(string): def base64_encode(string):
return base64.b64encode(string.encode()).decode() return base64.b64encode(string.encode()).decode()
def write_string_to_file(path, string, mode='w'):
global this_module
if mode == 'a':
redirect = '>>'
else:
redirect = '>'
print_cmd("cat << 'EOF' {} {}\n{}\nEOF".format(redirect, path, string))
if not this_module.dry_run:
with open(path, 'a') as f:
f.write(string)
def copy_dir_if_update_non_recursive(srcdir, destdir, filter_ext=None): def copy_dir_if_update_non_recursive(srcdir, destdir, filter_ext=None):
os.makedirs(destdir, exist_ok=True) os.makedirs(destdir, exist_ok=True)
for basename in os.listdir(srcdir): for basename in os.listdir(srcdir):
@@ -441,7 +452,7 @@ def cmd_to_string(cmd, cwd=None, extra_env=None, extra_paths=None):
out.append('{}={}'.format(shlex.quote(key), shlex.quote(extra_env[key])) + newline_separator) out.append('{}={}'.format(shlex.quote(key), shlex.quote(extra_env[key])) + newline_separator)
for arg in cmd: for arg in cmd:
out.append(shlex.quote(arg) + newline_separator) out.append(shlex.quote(arg) + newline_separator)
return ' '.join(out) + ';\n' return ' '.join(out) + ';'
def print_cmd(cmd, cwd=None, cmd_file=None, extra_env=None, extra_paths=None): def print_cmd(cmd, cwd=None, cmd_file=None, extra_env=None, extra_paths=None):
''' '''
@@ -450,8 +461,12 @@ def print_cmd(cmd, cwd=None, cmd_file=None, extra_env=None, extra_paths=None):
Optionally save the command to cmd_file file, and add extra_env Optionally save the command to cmd_file file, and add extra_env
environment variables to the command generated. environment variables to the command generated.
''' '''
cmd_string = cmd_to_string(cmd, cwd=None, extra_env=None, extra_paths=None) global dry_run
print(this_module.command_prefix + cmd_string, end='') if type(cmd) is str:
cmd_string = cmd
else:
cmd_string = cmd_to_string(cmd, cwd=None, extra_env=None, extra_paths=None)
print(this_module.command_prefix + cmd_string)
if cmd_file is not None: if cmd_file is not None:
with open(cmd_file, 'w') as f: with open(cmd_file, 'w') as f:
f.write('#!/usr/bin/env bash\n') f.write('#!/usr/bin/env bash\n')
@@ -864,7 +879,4 @@ def write_configs(config_path, configs, config_fragments=None):
if not this_module.dry_run: if not this_module.dry_run:
for line in config_fragment_file: for line in config_fragment_file:
config_file.write(line) config_file.write(line)
for config in configs: write_string_to_file(config_path, '\n'.join(configs), mode='a')
print_cmd(['echo', config, '>>', config_path])
if not this_module.dry_run:
config_file.write(config + '\n')

6
run
View File

@@ -112,16 +112,14 @@ def main(args, extra_args=None):
else: else:
if not os.path.exists(common.gem5_fake_iso): if not os.path.exists(common.gem5_fake_iso):
os.makedirs(os.path.dirname(common.gem5_fake_iso), exist_ok=True) os.makedirs(os.path.dirname(common.gem5_fake_iso), exist_ok=True)
with open(common.gem5_fake_iso, 'w') as f: common.write_string_to_file(common.gem5_fake_iso, 'a' * 512)
f.write('a' * 512)
if not os.path.exists(common.image): if not os.path.exists(common.image):
# This is to run gem5 from a prebuilt download. # This is to run gem5 from a prebuilt download.
if (not args.baremetal is None) or (not os.path.exists(common.linux_image)): if (not args.baremetal is None) or (not os.path.exists(common.linux_image)):
raise_image_not_found() raise_image_not_found()
common.run_cmd([os.path.join(common.extract_vmlinux, common.linux_image)]) common.run_cmd([os.path.join(common.extract_vmlinux, common.linux_image)])
os.makedirs(os.path.dirname(common.gem5_readfile), exist_ok=True) os.makedirs(os.path.dirname(common.gem5_readfile), exist_ok=True)
with open(common.gem5_readfile, 'w') as readfile: common.write_string_to_file(common.gem5_readfile, args.gem5_readfile)
readfile.write(args.gem5_readfile)
memory = '{}B'.format(args.memory) memory = '{}B'.format(args.memory)
gem5_exe_args = shlex.split(args.gem5_exe_args) gem5_exe_args = shlex.split(args.gem5_exe_args)
if do_trace: if do_trace: