mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-26 19:51:35 +01:00
CliFunction
This commit is contained in:
95
build
95
build
@@ -7,6 +7,7 @@ import re
|
||||
import os
|
||||
|
||||
import common
|
||||
from shell_helpers import LF
|
||||
|
||||
class Component:
|
||||
'''
|
||||
@@ -49,11 +50,11 @@ class Component:
|
||||
def run_cmd(cmd, arch):
|
||||
global args
|
||||
cmd_abs = cmd.copy()
|
||||
cmd_abs[0] = os.path.join(common.root_dir, cmd[0])
|
||||
cmd_abs[0] = os.path.join(kwargs['root_dir'], cmd[0])
|
||||
cmd_abs.extend(['--arch', arch])
|
||||
if args.extra_args:
|
||||
cmd_abs.append(args.extra_args)
|
||||
common.run_cmd(cmd_abs, dry_run=args.dry_run)
|
||||
if kwargs['extra_args']:
|
||||
cmd_abs.append(kwargs['extra_args'])
|
||||
self.sh.run_cmd(cmd_abs, dry_run=kwargs['dry_run'])
|
||||
|
||||
buildroot_component = Component(
|
||||
lambda arch: run_cmd(['build-buildroot'], arch),
|
||||
@@ -86,15 +87,15 @@ name_to_component_map = {
|
||||
# Leaves without dependencies.
|
||||
'baremetal-qemu': Component(
|
||||
lambda arch: run_cmd(['build-baremetal', '--qemu'], arch),
|
||||
supported_archs=common.crosstool_ng_supported_archs,
|
||||
supported_archs=kwargs['crosstool_ng_supported_archs'],
|
||||
),
|
||||
'baremetal-gem5': Component(
|
||||
lambda arch: run_cmd(['build-baremetal', '--gem5'], arch),
|
||||
supported_archs=common.crosstool_ng_supported_archs,
|
||||
supported_archs=kwargs['crosstool_ng_supported_archs'],
|
||||
),
|
||||
'baremetal-gem5-pbx': Component(
|
||||
lambda arch: run_cmd(['build-baremetal', '--gem5', '--machine', 'RealViewPBX'], arch),
|
||||
supported_archs=common.crosstool_ng_supported_archs,
|
||||
supported_archs=kwargs['crosstool_ng_supported_archs'],
|
||||
),
|
||||
'buildroot': buildroot_component,
|
||||
'buildroot-gcc': buildroot_component,
|
||||
@@ -103,7 +104,7 @@ name_to_component_map = {
|
||||
),
|
||||
'crosstool-ng': Component(
|
||||
lambda arch: run_cmd(['build-crosstool-ng'], arch),
|
||||
supported_archs=common.crosstool_ng_supported_archs,
|
||||
supported_archs=kwargs['crosstool_ng_supported_archs'],
|
||||
# http://crosstool-ng.github.io/docs/os-setup/
|
||||
apt_get_pkgs={
|
||||
'bison',
|
||||
@@ -197,7 +198,7 @@ name_to_component_map = {
|
||||
'gem5-baremetal',
|
||||
'baremetal-gem5-pbx',
|
||||
],
|
||||
supported_archs=common.crosstool_ng_supported_archs,
|
||||
supported_archs=kwargs['crosstool_ng_supported_archs'],
|
||||
),
|
||||
'all-linux': Component(dependencies=[
|
||||
'qemu-gem5-buildroot',
|
||||
@@ -296,10 +297,10 @@ group = parser.add_mutually_exclusive_group(required=False)
|
||||
group.add_argument('-A', '--all-archs', default=False, action='store_true', help='''\
|
||||
Build the selected components for all archs.
|
||||
''')
|
||||
group.add_argument('-a', '--arch', choices=common.arch_choices, default=[], action='append', help='''\
|
||||
group.add_argument('-a', '--arch', choices=kwargs['arch_choices'], default=[], action='append', help='''\
|
||||
Build the selected components for this arch. Select multiple archs by
|
||||
passing this option multiple times. Default: [{}]
|
||||
'''.format(common.default_arch))
|
||||
'''.format(kwargs['default_arch']))
|
||||
parser.add_argument('-D', '--download-dependencies', default=False, action='store_true', help='''\
|
||||
Also download all dependencies required for a given build: Ubuntu packages,
|
||||
Python packages and git submodules.
|
||||
@@ -314,27 +315,27 @@ Extra args to pass to all scripts.
|
||||
)
|
||||
parser.add_argument('components', choices=list(name_to_component_map.keys()) + [[]], default=[], nargs='*', help='''\
|
||||
Which components to build. Default: qemu-buildroot
|
||||
'''.format(common.default_arch))
|
||||
common.add_dry_run_argument(parser)
|
||||
'''.format(kwargs['default_arch']))
|
||||
self.add_dry_run_argument(parser)
|
||||
args = parser.parse_args()
|
||||
common.setup_dry_run_arguments(args)
|
||||
self.setup_dry_run_arguments(args)
|
||||
|
||||
# Decide archs.
|
||||
if args.arch == []:
|
||||
if args.all or args.all_archs:
|
||||
archs = common.all_archs.copy()
|
||||
if kwargs['arch'] == []:
|
||||
if kwargs['all'] or kwargs['all_archs']:
|
||||
archs = kwargs['all_archs'].copy()
|
||||
else:
|
||||
archs = set([common.default_arch])
|
||||
archs = set([kwargs['default_arch']])
|
||||
else:
|
||||
archs = set()
|
||||
for arch in args.arch:
|
||||
if arch in common.arch_short_to_long_dict:
|
||||
arch = common.arch_short_to_long_dict[arch]
|
||||
for arch in kwargs['arch']:
|
||||
if arch in kwargs['arch_short_to_long_dict']:
|
||||
arch = kwargs['arch_short_to_long_dict'][arch]
|
||||
archs.add(arch)
|
||||
|
||||
# Decide components.
|
||||
components = args.components
|
||||
if args.all:
|
||||
components = kwargs['components']
|
||||
if kwargs['all']:
|
||||
components = ['all']
|
||||
elif components == []:
|
||||
components = ['qemu-buildroot']
|
||||
@@ -350,7 +351,7 @@ for component_name in components:
|
||||
selected_components.append(component)
|
||||
todo.extend(component.dependencies)
|
||||
|
||||
if args.download_dependencies:
|
||||
if kwargs['download_dependencies']:
|
||||
apt_get_pkgs = {
|
||||
# Core requirements for this repo.
|
||||
'git',
|
||||
@@ -388,12 +389,12 @@ if args.download_dependencies:
|
||||
python2_pkgs.update(component.python2_pkgs)
|
||||
python3_pkgs.update(component.python3_pkgs)
|
||||
if apt_get_pkgs or apt_build_deps:
|
||||
if args.travis:
|
||||
if kwargs['travis']:
|
||||
interacive_pkgs = {
|
||||
'libsdl2-dev',
|
||||
}
|
||||
apt_get_pkgs.difference_update(interacive_pkgs)
|
||||
if common.in_docker:
|
||||
if kwargs['in_docker']:
|
||||
sudo = []
|
||||
# https://askubuntu.com/questions/909277/avoiding-user-interaction-with-tzdata-when-installing-certbot-in-a-docker-contai
|
||||
os.environ['DEBIAN_FRONTEND'] = 'noninteractive'
|
||||
@@ -406,35 +407,35 @@ if args.download_dependencies:
|
||||
f.write(sources_txt)
|
||||
else:
|
||||
sudo = ['sudo']
|
||||
if common.in_docker or args.travis:
|
||||
if kwargs['in_docker'] or kwargs['travis']:
|
||||
y = ['-y']
|
||||
else:
|
||||
y = []
|
||||
common.run_cmd(
|
||||
sudo + ['apt-get', 'update', common.Newline]
|
||||
self.sh.run_cmd(
|
||||
sudo + ['apt-get', 'update', LF]
|
||||
)
|
||||
if apt_get_pkgs:
|
||||
common.run_cmd(
|
||||
sudo + ['apt-get', 'install'] + y + [common.Newline] +
|
||||
common.add_newlines(sorted(apt_get_pkgs))
|
||||
self.sh.run_cmd(
|
||||
sudo + ['apt-get', 'install'] + y + [LF] +
|
||||
self.sh.add_newlines(sorted(apt_get_pkgs))
|
||||
)
|
||||
if apt_build_deps:
|
||||
common.run_cmd(
|
||||
self.sh.run_cmd(
|
||||
sudo +
|
||||
['apt-get', 'build-dep'] + y + [common.Newline] +
|
||||
common.add_newlines(sorted(apt_build_deps))
|
||||
['apt-get', 'build-dep'] + y + [LF] +
|
||||
self.sh.add_newlines(sorted(apt_build_deps))
|
||||
)
|
||||
if python2_pkgs:
|
||||
common.run_cmd(
|
||||
['python', '-m', 'pip', 'install', '--user', common.Newline] +
|
||||
common.add_newlines(sorted(python2_pkgs))
|
||||
self.sh.run_cmd(
|
||||
['python', '-m', 'pip', 'install', '--user', LF] +
|
||||
self.sh.add_newlines(sorted(python2_pkgs))
|
||||
)
|
||||
if python3_pkgs:
|
||||
# Not with pip executable directly:
|
||||
# https://stackoverflow.com/questions/49836676/error-after-upgrading-pip-cannot-import-name-main/51846054#51846054
|
||||
common.run_cmd(
|
||||
['python3', '-m', 'pip', 'install', '--user', common.Newline] +
|
||||
common.add_newlines(sorted(python3_pkgs))
|
||||
self.sh.run_cmd(
|
||||
['python3', '-m', 'pip', 'install', '--user', LF] +
|
||||
self.sh.add_newlines(sorted(python3_pkgs))
|
||||
)
|
||||
git_cmd_common = ['git', 'submodule', 'update', '--init', '--recursive']
|
||||
if submodules:
|
||||
@@ -448,9 +449,9 @@ if args.download_dependencies:
|
||||
# * https://stackoverflow.com/questions/4640020/progress-indicator-for-git-clone
|
||||
#
|
||||
# `--jobs"`: https://stackoverflow.com/questions/26957237/how-to-make-git-clone-faster-with-multiple-threads/52327638#52327638
|
||||
common.run_cmd(
|
||||
git_cmd_common + ['--', common.Newline] +
|
||||
common.add_newlines([os.path.join(common.submodules_dir, x) for x in sorted(submodules)])
|
||||
self.sh.run_cmd(
|
||||
git_cmd_common + ['--', LF] +
|
||||
self.sh.add_newlines([os.path.join(kwargs['submodules_dir'], x) for x in sorted(submodules)])
|
||||
)
|
||||
if submodules_shallow:
|
||||
# == Shallow cloning.
|
||||
@@ -472,9 +473,9 @@ if args.download_dependencies:
|
||||
# * https://stackoverflow.com/questions/2144406/git-shallow-submodules/47374702#47374702
|
||||
# * https://unix.stackexchange.com/questions/338578/why-is-the-git-clone-of-the-linux-kernel-source-code-much-larger-than-the-extrac
|
||||
#
|
||||
common.run_cmd(
|
||||
git_cmd_common + ['--depth', '1', '--', common.Newline] +
|
||||
common.add_newlines([os.path.join(common.submodules_dir, x) for x in sorted(submodules_shallow)])
|
||||
self.sh.run_cmd(
|
||||
git_cmd_common + ['--depth', '1', '--', LF] +
|
||||
self.sh.add_newlines([os.path.join(kwargs['submodules_dir'], x) for x in sorted(submodules_shallow)])
|
||||
)
|
||||
|
||||
# Do the build.
|
||||
|
||||
Reference in New Issue
Block a user