userland: in-tree build shortcuts from inside tree

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-03-15 00:00:00 +00:00
parent 9581fa201c
commit 4943c9ed2e
13 changed files with 39 additions and 16 deletions

View File

@@ -32,9 +32,10 @@ allows us to build examples that rely on it.
'--in-tree', '--in-tree',
default=False, default=False,
help='''\ help='''\
Build in-tree, i.e. place outputs next to source files. Magic build mode tailored to build from within the source tree:
Mostly useful when compiling with the host toolchain to conveniently run
the output files. * place build output inside soure tree to conveniently run it
* if not targets are given, build use the current working directory
''', ''',
) )
self.add_argument( self.add_argument(
@@ -125,6 +126,19 @@ Default: build all examples that have their package dependencies met, e.g.:
self.error = True self.error = True
return ret return ret
def _get_targets(self):
if self.env['_args_given']['targets']:
targets = self.env['targets']
if self.env['in_tree']:
cwd = os.getcwd()
targets = [os.path.join(cwd, target) for target in targets]
return targets
else:
if self.env['in_tree']:
return [os.getcwd()]
else:
return [self.env['userland_source_dir']]
def build(self): def build(self):
build_dir = self.get_build_dir() build_dir = self.get_build_dir()
os.makedirs(build_dir, exist_ok=True) os.makedirs(build_dir, exist_ok=True)
@@ -177,11 +191,7 @@ Default: build all examples that have their package dependencies met, e.g.:
rootdir_abs_len = len(self.env['userland_source_dir']) rootdir_abs_len = len(self.env['userland_source_dir'])
thread_limiter = threading.BoundedSemaphore(self.env['nproc']) thread_limiter = threading.BoundedSemaphore(self.env['nproc'])
self.error = False self.error = False
if self.env['_args_given']['targets']: for target in self._get_targets():
targets = self.env['targets']
else:
targets = [self.env['userland_source_dir']]
for target in targets:
target = self.resolve_userland_source(target) target = self.resolve_userland_source(target)
for path, in_dirnames, in_filenames in self.sh.walk(target): for path, in_dirnames, in_filenames in self.sh.walk(target):
in_dirnames.sort() in_dirnames.sort()
@@ -265,16 +275,16 @@ Default: build all examples that have their package dependencies met, e.g.:
return 0 return 0
def clean(self): def clean(self):
build_dir = self.get_build_dir()
if self.env['in_tree']: if self.env['in_tree']:
for path, dirnames, filenames in os.walk(build_dir): for target in self._get_targets():
for path, dirnames, filenames in os.walk(target):
filenames.sort() filenames.sort()
dirnames.sort() dirnames.sort()
for filename in filenames: for filename in filenames:
if os.path.splitext(filename)[1] in self.env['userland_out_exts']: if os.path.splitext(filename)[1] in self.env['userland_out_exts']:
self.sh.rmrf(os.path.join(path, filename)) self.sh.rmrf(os.path.join(path, filename))
else: else:
self.sh.rmrf(build_dir) self.sh.rmrf(self.get_build_dir())
def get_build_dir(self): def get_build_dir(self):
if self.env['in_tree']: if self.env['in_tree']:

2
build-userland-in-tree Executable file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
"$(git rev-parse --show-toplevel)/build-userland" --gcc-which host --in-tree "$@"

1
userland/arch/aarch64/build Symbolic link
View File

@@ -0,0 +1 @@
../build

1
userland/arch/build Symbolic link
View File

@@ -0,0 +1 @@
../build

1
userland/arch/x86_64/build Symbolic link
View File

@@ -0,0 +1 @@
../build

View File

@@ -0,0 +1 @@
../build

1
userland/build Symbolic link
View File

@@ -0,0 +1 @@
../build-userland-in-tree

1
userland/c/build Symbolic link
View File

@@ -0,0 +1 @@
../build

1
userland/cpp/build Symbolic link
View File

@@ -0,0 +1 @@
../build

1
userland/gcc/build Symbolic link
View File

@@ -0,0 +1 @@
../build

View File

@@ -0,0 +1 @@
../build

1
userland/linux/build Symbolic link
View File

@@ -0,0 +1 @@
../build

1
userland/posix/build Symbolic link
View File

@@ -0,0 +1 @@
../build