userland: move more userland/arch/ logic into property tree

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-05-05 00:00:00 +00:00
parent d15714641f
commit 1ca732bf75
5 changed files with 102 additions and 72 deletions

View File

@@ -211,28 +211,10 @@ Default: build all examples that have their package dependencies met, e.g.:
cc_flags_dir = cc_flags.copy() cc_flags_dir = cc_flags.copy()
if dirpath_relative_root_components_len > 0: if dirpath_relative_root_components_len > 0:
if dirpath_relative_root_components[0] == 'arch': if dirpath_relative_root_components[0] == 'arch':
if dirpath_relative_root_components_len > 1: cc_flags_dir.extend([
if dirpath_relative_root_components[1] == self.env['arch']: '-I', os.path.join(self.env['userland_source_arch_arch_dir']), LF,
cc_flags_dir.extend([ '-I', os.path.join(self.env['userland_source_arch_dir']), LF,
'-I', os.path.join(self.env['userland_source_arch_arch_dir']), LF, ])
'-I', os.path.join(self.env['userland_source_arch_dir']), LF,
])
if 'freestanding' in dirpath_relative_root_components:
common_objs_dir = []
cc_flags_dir.extend([
'-ffreestanding', LF,
'-nostdlib', LF,
'-static', LF,
])
else:
if 'c' in dirpath_relative_root_components:
common_objs_dir = []
else:
common_objs_dir = [common_obj_asm]
else:
continue
else:
continue
elif dirpath_relative_root_components[0] == 'libs': elif dirpath_relative_root_components[0] == 'libs':
if dirpath_relative_root_components_len > 1: if dirpath_relative_root_components_len > 1:
pkg_key = dirpath_relative_root_components[1] pkg_key = dirpath_relative_root_components[1]
@@ -268,22 +250,25 @@ Default: build all examples that have their package dependencies met, e.g.:
dirpath_relative_root, dirpath_relative_root,
in_filename in_filename
)) ))
if my_path_properties['pedantic']: if my_path_properties.should_be_built(self.env['arch']):
cc_flags_file.extend(['-pedantic', LF]) if my_path_properties['pedantic']:
common_objs_file = common_objs_dir.copy() cc_flags_file.extend(['-pedantic', LF])
if my_path_properties['lkmc_common_obj']: common_objs_file = common_objs_dir.copy()
common_objs_file.append(common_obj) if my_path_properties['extra_objs_lkmc_common']:
error = thread_pool.submit({ common_objs_file.append(common_obj)
'c_std': my_path_properties['c_std'], if my_path_properties['extra_objs_userland_asm']:
'cc_flags': cc_flags_file + my_path_properties['cc_flags'], common_objs_file.append(common_obj_asm)
'cc_flags_after': cc_flags_after, error = thread_pool.submit({
'cxx_std': my_path_properties['cxx_std'], 'c_std': my_path_properties['c_std'],
'extra_objs': common_objs_file, 'cc_flags': cc_flags_file + my_path_properties['cc_flags'],
'in_path': in_path, 'cc_flags_after': cc_flags_after,
'out_path': self.resolve_userland_executable(in_path), 'cxx_std': my_path_properties['cxx_std'],
}) 'extra_objs': common_objs_file,
if error is not None: 'in_path': in_path,
raise common.ExitLoop() 'out_path': self.resolve_userland_executable(in_path),
})
if error is not None:
raise common.ExitLoop()
except common.ExitLoop: except common.ExitLoop:
pass pass
error = thread_pool.get_error() error = thread_pool.get_error()

View File

@@ -1203,17 +1203,15 @@ lunch aosp_{}-eng
If the input path is a file, add the executable extension automatically. If the input path is a file, add the executable extension automatically.
''' '''
in_path_abs = os.path.abspath(in_path) if self.is_subpath(in_path, magic_in_dir):
magic_in_dir_abs = os.path.abspath(magic_in_dir) # Abspath needed to remove the trailing `/.` which makes e.g. rmrf fail.
magic_out_dir_abs = os.path.abspath(magic_out_dir)
if self.is_subpath(in_path_abs, magic_in_dir_abs):
out = os.path.abspath(os.path.join( out = os.path.abspath(os.path.join(
magic_out_dir_abs, magic_out_dir,
os.path.relpath( os.path.relpath(
os.path.splitext(in_path_abs)[0], os.path.splitext(in_path)[0],
os.path.abspath(magic_in_dir_abs) magic_in_dir
)), )
) ))
if os.path.isfile(in_path): if os.path.isfile(in_path):
out += executable_ext out += executable_ext
return out return out

View File

@@ -23,7 +23,8 @@ class PathProperties:
'exit_status', 'exit_status',
'interactive', 'interactive',
# We should get rid of this if we ever properly implement dependency graphs. # We should get rid of this if we ever properly implement dependency graphs.
'lkmc_common_obj', 'extra_objs_lkmc_common',
'extra_objs_userland_asm',
# We were lazy to properly classify why we are skipping these tests. # We were lazy to properly classify why we are skipping these tests.
# TODO get it done. # TODO get it done.
'skip_run_unclassified', 'skip_run_unclassified',
@@ -55,19 +56,23 @@ class PathProperties:
other_tmp_properties['cc_flags'] = self.properties['cc_flags'] + other_tmp_properties['cc_flags'] other_tmp_properties['cc_flags'] = self.properties['cc_flags'] + other_tmp_properties['cc_flags']
return self.properties.update(other_tmp_properties) return self.properties.update(other_tmp_properties)
def should_be_tested(self, arch): def should_be_built(self, arch):
return \ return \
not self['interactive'] and \
not self['more_than_1s'] and \
not self['no_executable'] and \ not self['no_executable'] and \
not self['receives_signal'] and \
not self['requires_kernel_modules'] and \
not self['skip_run_unclassified'] and \
( (
self['allowed_archs'] is None or self['allowed_archs'] is None or
arch in self['allowed_archs'] arch in self['allowed_archs']
) )
def should_be_tested(self, arch):
return \
self.should_be_built(arch) and \
not self['interactive'] and \
not self['more_than_1s'] and \
not self['receives_signal'] and \
not self['requires_kernel_modules'] and \
not self['skip_run_unclassified']
class PrefixTree: class PrefixTree:
def __init__(self, path_properties_dict=None, children=None): def __init__(self, path_properties_dict=None, children=None):
if path_properties_dict is None: if path_properties_dict is None:
@@ -108,11 +113,19 @@ def get(test_path):
default_c_std = 'c11' default_c_std = 'c11'
default_cxx_std = 'c++17' default_cxx_std = 'c++17'
gnu_extensions = { gnu_extension_properties = {
'c_std': 'gnu11', 'c_std': 'gnu11',
'cc_pedantic': False, 'cc_pedantic': False,
'cxx_std': 'gnu++17' 'cxx_std': 'gnu++17'
} }
freestanding_properties = {
'cc_flags': [
'-ffreestanding', LF,
'-nostdlib', LF,
'-static', LF,
],
'extra_objs_userland_asm': False,
}
path_properties_tuples = ( path_properties_tuples = (
{ {
'c_std': default_c_std, 'c_std': default_c_std,
@@ -124,8 +137,9 @@ path_properties_tuples = (
'cc_pedantic': True, 'cc_pedantic': True,
'cxx_std': None, 'cxx_std': None,
'exit_status': 0, 'exit_status': 0,
'extra_objs_lkmc_common': False,
'extra_objs_userland_asm': False,
'interactive': False, 'interactive': False,
'lkmc_common_obj': False,
'skip_run_unclassified': False, 'skip_run_unclassified': False,
'more_than_1s': False, 'more_than_1s': False,
'no_executable': False, 'no_executable': False,
@@ -142,7 +156,8 @@ path_properties_tuples = (
'cc_flags': [ 'cc_flags': [
'-fno-pie', LF, '-fno-pie', LF,
'-no-pie', LF, '-no-pie', LF,
] ],
'extra_objs_userland_asm': True,
}, },
{ {
'arm': ( 'arm': (
@@ -165,9 +180,33 @@ path_properties_tuples = (
# So we just write divided inline assembly for now. # So we just write divided inline assembly for now.
'-masm-syntax-unified', LF, '-masm-syntax-unified', LF,
] ]
},
{
'c': (
{
'extra_objs_userland_asm': False,
},
{
'freestanding': freestanding_properties,
},
),
'freestanding': freestanding_properties,
}
),
'aarch64': (
{'allowed_archs': {'aarch64'}},
{
'c': (
{
'extra_objs_userland_asm': False,
},
{
'freestanding': freestanding_properties,
},
),
'freestanding': freestanding_properties,
} }
), ),
'aarch64': {'allowed_archs': {'aarch64'}},
'empty.S': {'no_executable': True}, 'empty.S': {'no_executable': True},
'fail.S': {'no_executable': True}, 'fail.S': {'no_executable': True},
'main.c': {'no_executable': True}, 'main.c': {'no_executable': True},
@@ -175,11 +214,15 @@ path_properties_tuples = (
{'allowed_archs': {'x86_64'}}, {'allowed_archs': {'x86_64'}},
{ {
'c': ( 'c': (
{},
{ {
'extra_objs_userland_asm': False,
},
{
'freestanding': freestanding_properties,
'ring0.c': {'receives_signal': True} 'ring0.c': {'receives_signal': True}
} }
), ),
'freestanding': freestanding_properties,
} }
), ),
} }
@@ -192,16 +235,16 @@ path_properties_tuples = (
'infinite_loop.c': {'more_than_1s': True}, 'infinite_loop.c': {'more_than_1s': True},
} }
), ),
'gcc': gnu_extensions, 'gcc': gnu_extension_properties,
'kernel_modules': {**gnu_extensions, **{'requires_kernel_modules': True}}, 'kernel_modules': {**gnu_extension_properties, **{'requires_kernel_modules': True}},
'lkmc': ( 'lkmc': (
{'lkmc_common_obj': True}, {'extra_objs_lkmc_common': True},
{ {
'assert_fail.c': {'exit_status': 1} 'assert_fail.c': {'exit_status': 1}
} }
), ),
'libs': {'skip_run_unclassified': True}, 'libs': {'skip_run_unclassified': True},
'linux': {**gnu_extensions, **{'skip_run_unclassified': True}}, 'linux': {**gnu_extension_properties, **{'skip_run_unclassified': True}},
'posix': ( 'posix': (
{}, {},
{ {

6
run
View File

@@ -549,7 +549,11 @@ Extra options to append at the end of the emulator command line.
debug_args = [] debug_args = []
cmd.extend( cmd.extend(
[ [
os.path.join(self.env['qemu_build_dir'], '{}-linux-user'.format(self.env['arch']), 'qemu-{}'.format(self.env['arch'])), LF, os.path.join(
self.env['qemu_build_dir'],
'{}-linux-user'.format(self.env['arch']),
'qemu-{}'.format(self.env['arch'])
), LF,
'-L', self.env['userland_library_dir'], LF, '-L', self.env['userland_library_dir'], LF,
'-r', self.env['kernel_version'], LF, '-r', self.env['kernel_version'], LF,
'-seed', '0', LF, '-seed', '0', LF,

View File

@@ -180,6 +180,14 @@ class ShellHelpers:
f.write(cmd_string) f.write(cmd_string)
self.chmod(cmd_file) self.chmod(cmd_file)
def rmrf(self, path):
self.print_cmd(['rm', '-r', '-f', path, LF])
if not self.dry_run and os.path.exists(path):
if os.path.isdir(path):
shutil.rmtree(path)
else:
os.unlink(path)
def run_cmd( def run_cmd(
self, self,
cmd, cmd,
@@ -309,14 +317,6 @@ class ShellHelpers:
else: else:
return [x for x in cmd if x != LF] return [x for x in cmd if x != LF]
def rmrf(self, path):
self.print_cmd(['rm', '-r', '-f', path, LF])
if not self.dry_run and os.path.exists(path):
if os.path.isdir(path):
shutil.rmtree(path)
else:
os.unlink(path)
def walk(self, root): def walk(self, root):
''' '''
Extended walk that can take files or directories. Extended walk that can take files or directories.