Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: ./configure.py --with-build-dir= #4245

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 16 additions & 23 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,11 @@ class SourcePaths:
"""
A collection of paths defined by the project structure and
independent of user configurations.
All paths are relative to the base_dir, which may be relative as well (e.g. ".")
All paths are relative to the base_dir, which is always absolute
"""

def __init__(self, base_dir):
assert os.path.isabs(base_dir), "base_dir must be absolute"
self.base_dir = base_dir
self.doc_dir = os.path.join(self.base_dir, 'doc')
self.src_dir = os.path.join(self.base_dir, 'src')
Expand All @@ -199,7 +200,8 @@ class BuildPaths:
Constructor
"""
def __init__(self, source_paths, options, modules):
self.build_dir = os.path.join(options.with_build_dir, 'build')
self.out_dir = os.path.realpath(options.with_build_dir if options.with_build_dir else os.getcwd())
self.build_dir = os.path.join(self.out_dir, 'build')

self.libobj_dir = os.path.join(self.build_dir, 'obj', 'lib')
self.cliobj_dir = os.path.join(self.build_dir, 'obj', 'cli')
Expand Down Expand Up @@ -264,11 +266,14 @@ def find_headers_in(basedir, srcdir):
self.fuzzer_output_dir = None
self.fuzzobj_dir = None

self.miscobj_dir = os.path.join(self.build_dir, 'obj', 'misc')

def build_dirs(self):
out = [
self.libobj_dir,
self.cliobj_dir,
self.testobj_dir,
self.miscobj_dir,
self.public_include_dir,
self.internal_include_dir,
self.external_include_dir,
Expand Down Expand Up @@ -471,7 +476,7 @@ def add_enable_disable_pair(group, what, default, msg=optparse.SUPPRESS_HELP):
build_group.add_option('--name-amalgamation', metavar='NAME', default='botan_all',
help='specify alternate name for amalgamation files')

build_group.add_option('--with-build-dir', metavar='DIR', default='',
build_group.add_option('--with-build-dir', metavar='DIR', default=None,
help='setup the build in DIR')

build_group.add_option('--with-external-includedir', metavar='DIR', default=[],
Expand Down Expand Up @@ -2054,21 +2059,8 @@ def ar_command():

return osinfo.ar_command

build_dir = options.with_build_dir or os.path.curdir
program_suffix = options.program_suffix or osinfo.program_suffix

def join_with_build_dir(path):
# jom (and mingw32-make) seem to string-compare Makefile targets and
# requirements. For them, `./botan.lib` is NOT equal to `botan.lib` or
# `C:\botan\botan-test.exe` is NOT equal to `C:\botan/botan-test.exe`
#
# `normalize_source_path` will "fix" the path slashes but remove
# a redundant `./` for the "trivial" relative path.
normalized = normalize_source_path(os.path.join(build_dir, path))
if build_dir == '.':
normalized = './%s' % normalized
return normalized

def all_targets(options):
yield 'libs'
if options.with_documentation:
Expand Down Expand Up @@ -2155,9 +2147,9 @@ def test_exe_extra_ldflags():
'python_dir': source_paths.python_dir,

'cli_exe_name': osinfo.cli_exe_name + program_suffix,
'cli_exe': join_with_build_dir(osinfo.cli_exe_name + program_suffix),
'cli_exe': normalize_source_path(os.path.join(build_paths.out_dir, osinfo.cli_exe_name + program_suffix)),
'build_cli_exe': bool('cli' in options.build_targets),
'test_exe': join_with_build_dir('botan-test' + program_suffix),
'test_exe': normalize_source_path(os.path.join(build_paths.out_dir, 'botan-test' + program_suffix)),

'lib_prefix': osinfo.lib_prefix,
'static_suffix': osinfo.static_suffix,
Expand Down Expand Up @@ -2186,7 +2178,7 @@ def test_exe_extra_ldflags():
'with_doxygen': options.with_doxygen,
'maintainer_mode': options.maintainer_mode,

'out_dir': normalize_source_path(build_dir),
'out_dir': normalize_source_path(build_paths.out_dir),
'build_dir': normalize_source_path(build_paths.build_dir),
'module_info_dir': build_paths.doc_module_info,

Expand All @@ -2208,6 +2200,7 @@ def test_exe_extra_ldflags():
'cliobj_dir': build_paths.cliobj_dir,
'testobj_dir': build_paths.testobj_dir,
'fuzzobj_dir': build_paths.fuzzobj_dir,
'miscobj_dir': build_paths.miscobj_dir,

'fuzzer_output_dir': build_paths.fuzzer_output_dir if build_paths.fuzzer_output_dir else '',
'doc_output_dir': build_paths.doc_output_dir,
Expand Down Expand Up @@ -2361,14 +2354,14 @@ def test_exe_extra_ldflags():
if options.build_shared_lib:
lib_targets.append('shared_lib_name')

variables['library_targets'] = ' '.join([join_with_build_dir(variables[t]) for t in lib_targets])
variables['library_targets'] = ' '.join(normalize_source_paths([os.path.join(build_paths.out_dir, variables[t]) for t in lib_targets]))

if options.os == 'llvm' or options.compiler == 'msvc':
# llvm-link and msvc require just naming the file directly
variables['build_dir_link_path'] = ''
variables['link_to_botan'] = normalize_source_path(os.path.join(build_dir, variables['static_lib_name']))
variables['link_to_botan'] = normalize_source_path(os.path.join(build_paths.out_dir, variables['static_lib_name']))
else:
variables['build_dir_link_path'] = '%s%s' % (cc.add_lib_dir_option, build_dir)
variables['build_dir_link_path'] = '%s%s' % (cc.add_lib_dir_option, build_paths.out_dir)
variables['link_to_botan'] = cc.add_lib_option % variables['libname']

return variables
Expand Down Expand Up @@ -3561,7 +3554,7 @@ def main(argv):

setup_logging(options)

source_paths = SourcePaths(os.path.dirname(argv[0]))
source_paths = SourcePaths(os.path.dirname(os.path.realpath(__file__)))
Comment on lines -3564 to +3557
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused the explained issue. argv[0] may be a valid relative path (seen from $($pwd)), but it is not valid when --with-build-dir= drops the generated build files somewhere else and paths in there are relative to whatever argv[0] was.


info_modules = load_info_files(source_paths.lib_dir, 'Modules', "info.txt", ModuleInfo)

Expand Down
12 changes: 6 additions & 6 deletions src/build-data/ninja.in
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,20 @@ build examples: phony | %{example_bin}

%{if build_bogo_shim}

build botan_bogo_shim: link_cli bogo_shim_object | libs
build %{out_dir}/botan_bogo_shim: link_cli bogo_shim_object | libs
cli_name = bogo

# BoGo shim
build %{out_dir}/bogo_shim_object: compile_exe %{bogo_shim_src}
build %{miscobj_dir}/bogo_shim.o: compile_exe %{bogo_shim_src}

%{endif}

%{if build_ct_selftest}

build botan_ct_selftest: link_cli ct_selftest_object | libs
build %{out_dir}/botan_ct_selftest: link_cli ct_selftest_object | libs
cli_name = ct_selftest

build %{out_dir}/ct_selftest_object: compile_exe %{ct_selftest_src}
build %{miscobj_dir}/ct_selftest.o: compile_exe %{ct_selftest_src}

%{endif}

Expand Down Expand Up @@ -176,9 +176,9 @@ build cli: phony %{cli_exe}

build tests: phony %{test_exe}

build bogo_shim: phony botan_bogo_shim
build bogo_shim: phony %{out_dir}/botan_bogo_shim

build ct_selftest: phony botan_ct_selftest
build ct_selftest: phony %{out_dir}/botan_ct_selftest

build libs: phony %{library_targets} $
%{if symlink_shared_lib}
Expand Down
Loading