build-userland-in-tree is now a Python command

./build calls it, we did this to allow --download-dependencies to work
perfectly.
This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-05-05 00:00:00 +00:00
parent aea97698c3
commit 9c8f95d630
5 changed files with 75 additions and 31 deletions

View File

@@ -996,7 +996,7 @@ Build the current directory:
./build ./build
.... ....
Note however that this would try to build the link:userland/libs/[] folder, which depends on certain libraries being installed on the host, e.g. <<blas>>. Note however that if you run this from link:userland/[] toplevel, it would try to build the link:userland/libs/[] folder, which depends on certain libraries being installed on the host, e.g. <<blas>>.
You can install those libraries and do the build in one go with: You can install those libraries and do the build in one go with:
@@ -1011,7 +1011,17 @@ If you modify a dependency that is not currently considered such as a header fil
./build --force-rebuild ./build --force-rebuild
.... ....
Do a more clean out of tree build and run the program instead: The `build` scripts inside link:userland/[] are just symlinks to link:build-userland-in-tree[] which you can also use from toplevel as:
....
./build-userland-in-tree
./build-userland-in-tree c
./build-userland-in-tree c/hello.c
....
which is in turn just a thin wrapper around link:build-userland[], so you can use any option supported by that script freely.
Do a more clean out-of-tree build and run the program instead:
.... ....
./build-userland --gcc-which host --userland-build-id host ./build-userland --gcc-which host --userland-build-id host

2
build
View File

@@ -340,7 +340,7 @@ so looping over all of them would waste time.
dependencies=['buildroot'], dependencies=['buildroot'],
), ),
'userland-host': _Component( 'userland-host': _Component(
self._build_file('build-userland'), self._build_file('build-userland-in-tree'),
apt_get_pkgs={ apt_get_pkgs={
'libdrm-dev', 'libdrm-dev',
'libeigen3-dev', 'libeigen3-dev',

View File

@@ -10,12 +10,12 @@ import common
from thread_pool import ThreadPool from thread_pool import ThreadPool
class Main(common.BuildCliFunction): class Main(common.BuildCliFunction):
def __init__(self): def __init__(self, *args, **kwargs):
super().__init__( if not 'description' in kwargs:
description='''\ kwargs['description'] = '''\
Build our compiled userland examples. Build our compiled userland examples.
''' '''
) super().__init__(*args, **kwargs)
self.default_cstd = 'c11' self.default_cstd = 'c11'
self.default_cxxstd = 'c++17' self.default_cxxstd = 'c++17'
self.add_argument( self.add_argument(
@@ -43,10 +43,11 @@ building with the host toolchain.
''', ''',
) )
self.add_argument( self.add_argument(
'--target-cwd', '--target-relative-cwd',
default=False, default=False,
help='''\ help='''\
Treat targets as relative to the current working directory. Treat targets as relative to the current working directory. If the current working
directory is outside of userland/, use userland/ instead.
''', ''',
) )
self.add_argument( self.add_argument(
@@ -129,16 +130,23 @@ Default: build all examples that have their package dependencies met, e.g.:
) )
return ret return ret
def _get_cwd(self):
cwd = os.path.abspath(os.getcwd())
if cwd.startswith(self.env['userland_source_dir']):
return cwd
else:
return self.env['userland_source_dir']
def _get_targets(self): def _get_targets(self):
if self.env['_args_given']['targets']: if self.env['_args_given']['targets']:
targets = self.env['targets'] targets = self.env['targets']
if self.env['target_cwd']: if self.env['target_relative_cwd']:
cwd = os.getcwd() cwd = self._get_cwd()
targets = [os.path.join(cwd, target) for target in targets] targets = [os.path.join(cwd, target) for target in targets]
return targets return targets
else: else:
if self.env['target_cwd']: if self.env['target_relative_cwd']:
return [os.getcwd()] return [self._get_cwd()]
else: else:
return [self.env['userland_source_dir']] return [self.env['userland_source_dir']]

View File

@@ -1,8 +1,33 @@
#!/usr/bin/env bash #!/usr/bin/env python3
"$(git rev-parse --show-toplevel)/build-userland" \
--gcc-which host \ import imp
--has-all-packages \ import os
--in-tree \ import subprocess
--target-cwd \
"$@" \ git_root = subprocess.check_output([
; 'git',
'rev-parse',
'--show-toplevel',
]).decode().rstrip()
build_userland = imp.load_source(
'build_userland',
os.path.join(git_root, 'build-userland')
)
class Main(build_userland.Main):
def __init__(self):
super().__init__(
description='''\
Same as build-userland, but with pre-set defaults to build in-tree
for the native toolchain.
''',
defaults={
'gcc_which': 'host',
'has_all_packages': True,
'in_tree': True,
'target_relative_cwd': True,
}
)
if __name__ == '__main__':
Main().cli()

View File

@@ -128,7 +128,13 @@ class LkmcCliFunction(cli_function.CliFunction):
* command timing * command timing
* some common flags, e.g.: --arch, --dry-run, --quiet, --verbose * some common flags, e.g.: --arch, --dry-run, --quiet, --verbose
''' '''
def __init__(self, *args, defaults=None, supported_archs=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
@@ -958,7 +964,10 @@ lunch aosp_{}-eng
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(basename.replace('-', '_'), os.path.join(self.env['root_dir'], basename)) return imp.load_source(
basename.replace('-', '_'),
os.path.join(self.env['root_dir'], basename)
)
def import_path_main(self, path): def import_path_main(self, path):
''' '''
@@ -1112,14 +1121,6 @@ lunch aosp_{}-eng
] ]
) )
@staticmethod
def resolve_args(defaults, args, extra_args):
if extra_args is None:
extra_args = {}
argcopy = copy.copy(args)
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): 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, Convert a path-like string to a source file to the full source path,