mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-28 20:44:26 +01:00
build-baremetal and build-crosstool-ng: make -A work, move arch check to common
This commit is contained in:
@@ -9,10 +9,11 @@ class Main(common.BuildCliFunction):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
description='''\
|
description='''\
|
||||||
Build the baremetal examples with crosstool-NG.
|
Build the baremetal examples with crosstool-NG.
|
||||||
''')
|
''',
|
||||||
|
supported_archs=common.consts['crosstool_ng_supported_archs']
|
||||||
|
)
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
self.assert_crosstool_ng_supports_arch(self.env['arch'])
|
|
||||||
build_dir = self.get_build_dir()
|
build_dir = self.get_build_dir()
|
||||||
bootloader_obj = os.path.join(self.env['baremetal_build_lib_dir'], 'bootloader{}'.format(self.env['obj_ext']))
|
bootloader_obj = os.path.join(self.env['baremetal_build_lib_dir'], 'bootloader{}'.format(self.env['obj_ext']))
|
||||||
common_basename_noext = 'common'
|
common_basename_noext = 'common'
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ class Main(common.BuildCliFunction):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
description='''\
|
description='''\
|
||||||
Build crosstool-NG with Newlib for bare metal compilation
|
Build crosstool-NG with Newlib for bare metal compilation
|
||||||
''')
|
''',
|
||||||
|
supported_archs=common.consts['crosstool_ng_supported_archs']
|
||||||
|
)
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
self.assert_crosstool_ng_supports_arch(self.env['arch'])
|
|
||||||
build_dir = self.get_build_dir()
|
build_dir = self.get_build_dir()
|
||||||
defconfig_dest = os.path.join(self.env['crosstool_ng_util_dir'], 'defconfig')
|
defconfig_dest = os.path.join(self.env['crosstool_ng_util_dir'], 'defconfig')
|
||||||
os.makedirs(self.env['crosstool_ng_util_dir'], exist_ok=True)
|
os.makedirs(self.env['crosstool_ng_util_dir'], exist_ok=True)
|
||||||
|
|||||||
48
common.py
48
common.py
@@ -112,7 +112,7 @@ class LkmcCliFunction(cli_function.CliFunction):
|
|||||||
* command timing
|
* command timing
|
||||||
* some common flags, e.g.: --arch, --dry-run, --verbose
|
* some common flags, e.g.: --arch, --dry-run, --verbose
|
||||||
'''
|
'''
|
||||||
def __init__(self, *args, defaults=None, **kwargs):
|
def __init__(self, *args, defaults=None, supported_archs=None, **kwargs):
|
||||||
'''
|
'''
|
||||||
:ptype defaults: Dict[str,Any]
|
:ptype defaults: Dict[str,Any]
|
||||||
:param defaults: override the default value of an argument
|
:param defaults: override the default value of an argument
|
||||||
@@ -123,6 +123,7 @@ class LkmcCliFunction(cli_function.CliFunction):
|
|||||||
defaults = {}
|
defaults = {}
|
||||||
self._defaults = defaults
|
self._defaults = defaults
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
self.supported_archs = supported_archs
|
||||||
|
|
||||||
# Args for all scripts.
|
# Args for all scripts.
|
||||||
arches = consts['arch_short_to_long_dict']
|
arches = consts['arch_short_to_long_dict']
|
||||||
@@ -353,8 +354,6 @@ Valid emulators: {}
|
|||||||
'''
|
'''
|
||||||
def join(*paths):
|
def join(*paths):
|
||||||
return os.path.join(*paths)
|
return os.path.join(*paths)
|
||||||
if env['arch'] in env['arch_short_to_long_dict']:
|
|
||||||
env['arch'] = env['arch_short_to_long_dict'][env['arch']]
|
|
||||||
if env['emulator'] in env['emulator_short_to_long_dict']:
|
if env['emulator'] in env['emulator_short_to_long_dict']:
|
||||||
env['emulator'] = env['emulator_short_to_long_dict'][env['emulator']]
|
env['emulator'] = env['emulator_short_to_long_dict'][env['emulator']]
|
||||||
if env['userland_build_id'] is None:
|
if env['userland_build_id'] is None:
|
||||||
@@ -612,10 +611,6 @@ Valid emulators: {}
|
|||||||
kwargs['default'] = self._defaults[key]
|
kwargs['default'] = self._defaults[key]
|
||||||
super().add_argument(*args, **kwargs)
|
super().add_argument(*args, **kwargs)
|
||||||
|
|
||||||
def assert_crosstool_ng_supports_arch(self, arch):
|
|
||||||
if arch not in self.env['crosstool_ng_supported_archs']:
|
|
||||||
raise Exception('arch not yet supported: ' + arch)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def base64_encode(string):
|
def base64_encode(string):
|
||||||
return base64.b64encode(string.encode()).decode()
|
return base64.b64encode(string.encode()).decode()
|
||||||
@@ -722,13 +717,15 @@ Valid emulators: {}
|
|||||||
_json = {}
|
_json = {}
|
||||||
return _json
|
return _json
|
||||||
|
|
||||||
@staticmethod
|
def import_path(self, basename):
|
||||||
def import_path(path):
|
|
||||||
'''
|
'''
|
||||||
https://stackoverflow.com/questions/2601047/import-a-python-module-without-the-py-extension
|
https://stackoverflow.com/questions/2601047/import-a-python-module-without-the-py-extension
|
||||||
https://stackoverflow.com/questions/31773310/what-does-the-first-argument-of-the-imp-load-source-method-do
|
https://stackoverflow.com/questions/31773310/what-does-the-first-argument-of-the-imp-load-source-method-do
|
||||||
'''
|
'''
|
||||||
return imp.load_source(os.path.split(path)[1].replace('-', '_'), path)
|
return imp.load_source(basename.replace('-', '_'), os.path.join(self.env['root_dir'], basename))
|
||||||
|
|
||||||
|
def import_path_main(self, path):
|
||||||
|
return self.import_path(path).Main()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def log_error(msg):
|
def log_error(msg):
|
||||||
@@ -746,19 +743,24 @@ Valid emulators: {}
|
|||||||
env['emulators'] = consts['all_long_emulators']
|
env['emulators'] = consts['all_long_emulators']
|
||||||
for emulator in env['emulators']:
|
for emulator in env['emulators']:
|
||||||
for arch in env['archs']:
|
for arch in env['archs']:
|
||||||
if not env['dry_run']:
|
if arch in env['arch_short_to_long_dict']:
|
||||||
start_time = time.time()
|
arch = env['arch_short_to_long_dict'][arch]
|
||||||
env['arch'] = arch
|
if self.supported_archs is None or arch in self.supported_archs:
|
||||||
env['emulator'] = emulator
|
if not env['dry_run']:
|
||||||
self.env = env.copy()
|
start_time = time.time()
|
||||||
self._init_env(self.env)
|
env['arch'] = arch
|
||||||
self.sh = shell_helpers.ShellHelpers(dry_run=self.env['dry_run'])
|
env['emulator'] = emulator
|
||||||
ret = self.timed_main()
|
self.env = env.copy()
|
||||||
if not env['dry_run']:
|
self._init_env(self.env)
|
||||||
end_time = time.time()
|
self.sh = shell_helpers.ShellHelpers(dry_run=self.env['dry_run'])
|
||||||
self._print_time(end_time - start_time)
|
ret = self.timed_main()
|
||||||
if ret is not None and ret != 0:
|
if not env['dry_run']:
|
||||||
return ret
|
end_time = time.time()
|
||||||
|
self._print_time(end_time - start_time)
|
||||||
|
if ret is not None and ret != 0:
|
||||||
|
return ret
|
||||||
|
elif not env['all_archs']:
|
||||||
|
raise Exception('Unsupported arch for this action: ' + arch)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def make_build_dirs(self):
|
def make_build_dirs(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user