mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
./build-userland: resolve relative paths
This commit is contained in:
64
common.py
64
common.py
@@ -95,6 +95,11 @@ consts['github_repo_id'] = 'cirosantilli/linux-kernel-module-cheat'
|
||||
consts['asm_ext'] = '.S'
|
||||
consts['c_ext'] = '.c'
|
||||
consts['cxx_ext'] = '.cpp'
|
||||
consts['userland_in_exts'] = [
|
||||
consts['asm_ext'],
|
||||
consts['c_ext'],
|
||||
consts['cxx_ext'],
|
||||
]
|
||||
consts['header_ext'] = '.h'
|
||||
consts['kernel_module_ext'] = '.ko'
|
||||
consts['obj_ext'] = '.o'
|
||||
@@ -1102,6 +1107,50 @@ lunch aosp_{}-eng
|
||||
argcopy.__dict__ = dict(list(defaults.items()) + list(argcopy.__dict__.items()) + list(extra_args.items()))
|
||||
return argcopy
|
||||
|
||||
def resolve_source(self, in_path, magic_in_dir, in_exts):
|
||||
'''
|
||||
Convert a path-like string to a source file to the full source path,
|
||||
e.g. all follogin work and to do the same:
|
||||
|
||||
- hello
|
||||
- hello.
|
||||
- hello.c
|
||||
- userland/hello
|
||||
- userland/hello.
|
||||
- userland/hello.c
|
||||
- /full/path/to/userland/hello
|
||||
- /full/path/to/userland/hello.
|
||||
- /full/path/to/userland/hello.c
|
||||
|
||||
Also works on directories:
|
||||
|
||||
- arch
|
||||
- userland/arch
|
||||
- /full/path/to/userland/arch
|
||||
'''
|
||||
if os.path.isabs(in_path):
|
||||
return in_path
|
||||
else:
|
||||
paths = [
|
||||
os.path.join(magic_in_dir, in_path),
|
||||
os.path.join(
|
||||
magic_in_dir,
|
||||
os.path.relpath(in_path, magic_in_dir),
|
||||
)
|
||||
]
|
||||
for path in paths:
|
||||
name, ext = os.path.splitext(path)
|
||||
if len(ext) > 1:
|
||||
try_exts = [ext]
|
||||
else:
|
||||
try_exts = in_exts + ['']
|
||||
for in_ext in try_exts:
|
||||
path = name + in_ext
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
if not self.env['dry_run']:
|
||||
raise Exception('Source file not found for input: ' + in_path)
|
||||
|
||||
def resolve_executable(self, in_path, magic_in_dir, magic_out_dir, out_ext):
|
||||
if os.path.isabs(in_path):
|
||||
return in_path
|
||||
@@ -1113,14 +1162,18 @@ lunch aosp_{}-eng
|
||||
os.path.relpath(in_path, magic_in_dir),
|
||||
)
|
||||
]
|
||||
paths[:] = [os.path.splitext(path)[0] + out_ext for path in paths]
|
||||
for path in paths:
|
||||
path = os.path.splitext(path)[0] + out_ext
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
if not self.env['dry_run']:
|
||||
raise Exception('Executable file not found. Tried:\n' + '\n'.join(paths))
|
||||
|
||||
def resolve_userland(self, path):
|
||||
def resolve_userland_executable(self, path):
|
||||
'''
|
||||
Convert an userland source path-like string to an
|
||||
absolute userland build output path.
|
||||
'''
|
||||
return self.resolve_executable(
|
||||
path,
|
||||
self.env['userland_source_dir'],
|
||||
@@ -1128,6 +1181,13 @@ lunch aosp_{}-eng
|
||||
self.env['userland_build_ext'],
|
||||
)
|
||||
|
||||
def resolve_userland_source(self, path):
|
||||
return self.resolve_source(
|
||||
path,
|
||||
self.env['userland_source_dir'],
|
||||
self.env['userland_in_exts']
|
||||
)
|
||||
|
||||
def setup(self):
|
||||
'''
|
||||
Similar to timed_main, but gets run only once for all --arch and --emulator,
|
||||
|
||||
Reference in New Issue
Block a user