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
....
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:
@@ -1011,7 +1011,17 @@ If you modify a dependency that is not currently considered such as a header fil
./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

2
build
View File

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

View File

@@ -10,12 +10,12 @@ import common
from thread_pool import ThreadPool
class Main(common.BuildCliFunction):
def __init__(self):
super().__init__(
description='''\
def __init__(self, *args, **kwargs):
if not 'description' in kwargs:
kwargs['description'] = '''\
Build our compiled userland examples.
'''
)
super().__init__(*args, **kwargs)
self.default_cstd = 'c11'
self.default_cxxstd = 'c++17'
self.add_argument(
@@ -43,10 +43,11 @@ building with the host toolchain.
''',
)
self.add_argument(
'--target-cwd',
'--target-relative-cwd',
default=False,
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(
@@ -129,16 +130,23 @@ Default: build all examples that have their package dependencies met, e.g.:
)
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):
if self.env['_args_given']['targets']:
targets = self.env['targets']
if self.env['target_cwd']:
cwd = os.getcwd()
if self.env['target_relative_cwd']:
cwd = self._get_cwd()
targets = [os.path.join(cwd, target) for target in targets]
return targets
else:
if self.env['target_cwd']:
return [os.getcwd()]
if self.env['target_relative_cwd']:
return [self._get_cwd()]
else:
return [self.env['userland_source_dir']]

View File

@@ -1,8 +1,33 @@
#!/usr/bin/env bash
"$(git rev-parse --show-toplevel)/build-userland" \
--gcc-which host \
--has-all-packages \
--in-tree \
--target-cwd \
"$@" \
;
#!/usr/bin/env python3
import imp
import os
import subprocess
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
* 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]
: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/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):
'''
@@ -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):
'''
Convert a path-like string to a source file to the full source path,