Skip to content

Commit

Permalink
Add build target keyword parameter 'build_dir' [v2]
Browse files Browse the repository at this point in the history
This allows the user to place the build products in a subdirectory of
the build directory, which is useful when multiple build products have
the same base filename.

v2:
	Move build_dir to Target class.
	Error if path separator in build_dir

Signed-off-by: Keith Packard <keithp@keithp.com>
  • Loading branch information
keith-packard committed Aug 16, 2018
1 parent b400cbe commit ee2e06d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/markdown/Reference-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ be passed to [shared and static libraries](#library).
in the D programming language
- `d_unittest`, when set to true, the D modules are compiled in debug mode
- `d_module_versions` list of module versions set when compiling D sources
- `build_dir` provides a subdirectory to place the built
target. Useful when building multiple targets with the same base filename.

The list of `sources`, `objects`, and `dependencies` is always
flattened, which means you can freely nest and add lists while
Expand Down
4 changes: 3 additions & 1 deletion mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ def get_target_dir(self, target):
dirname = target.get_subdir()
else:
dirname = 'meson-out'
return dirname
if target.build_dir == '':
return dirname
return os.path.join(dirname, target.build_dir)

def get_target_dir_relative_to(self, t, o):
'''Get a target dir relative to another target's directory'''
Expand Down
9 changes: 9 additions & 0 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
buildtarget_kwargs = set([
'build_by_default',
'build_rpath',
'build_dir',
'dependencies',
'extra_files',
'gui_app',
Expand Down Expand Up @@ -306,6 +307,7 @@ def __init__(self, name, subdir, subproject, build_by_default):
This is not supported, it can cause unexpected failures and will become
a hard error in the future.''' % name)
self.name = name
self.build_dir = ''
self.subdir = subdir
self.subproject = subproject
self.build_by_default = build_by_default
Expand All @@ -328,6 +330,8 @@ def get_id(self):
name_part = self.name.replace('/', '@').replace('\\', '@')
assert not has_path_sep(self.type_suffix())
myid = name_part + self.type_suffix()
if self.build_dir:
myid = self.build_dir + '@@' + myid
if self.subdir:
subdir_part = self.subdir.replace('/', '@').replace('\\', '@')
myid = subdir_part + '@@' + myid
Expand All @@ -339,6 +343,11 @@ def process_kwargs(self, kwargs):
if not isinstance(self.build_by_default, bool):
raise InvalidArguments('build_by_default must be a boolean value.')
self.option_overrides = self.parse_overrides(kwargs)
self.build_dir = kwargs.get('build_dir', '')
if not isinstance(self.build_dir, str):
raise InvalidArguments('Build_dir must be a string.')
if has_path_sep(self.build_dir):
raise InvalidArguments('Build_dir "%s" has a path separator in its name.' % self.build_dir)

def parse_overrides(self, kwargs):
result = {}
Expand Down

0 comments on commit ee2e06d

Please sign in to comment.