Skip to content

Commit

Permalink
Merge pull request #3880 from Rohde-Schwarz/chore/split_public_and_in…
Browse files Browse the repository at this point in the history
…ternal_headers

Chore: Split public and internal headers
  • Loading branch information
reneme authored Jan 10, 2024
2 parents fb4df9a + e036a7f commit 1e77255
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 31 deletions.
35 changes: 25 additions & 10 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,16 @@ def __init__(self, source_paths, options, modules):
self.doc_output_dir_doxygen = os.path.join(self.doc_output_dir, 'doxygen') if options.with_doxygen else None
self.doc_module_info = os.path.join(self.build_dir, 'module_info') if options.with_doxygen else None

# We split the header include paths into 'public', 'internal' and 'external'
# to allow for better control over what is exposed to each compilation unit.
# For instance, the examples should only see the public headers, while the
# test suite should see both public and internal headers.
self.include_dir = os.path.join(self.build_dir, 'include')
self.botan_include_dir = os.path.join(self.include_dir, 'botan')
self.internal_include_dir = os.path.join(self.botan_include_dir, 'internal')
self.public_include_basedir = os.path.join(self.include_dir, 'public')
self.internal_include_basedir = os.path.join(self.include_dir, 'internal')
self.external_include_dir = os.path.join(self.include_dir, 'external')
self.public_include_dir = os.path.join(self.public_include_basedir, 'botan')
self.internal_include_dir = os.path.join(self.internal_include_basedir, 'botan', 'internal')

self.internal_headers = sorted(flatten([m.internal_headers() for m in modules]))
self.external_headers = sorted(flatten([m.external_headers() for m in modules]))
Expand Down Expand Up @@ -262,7 +268,7 @@ def build_dirs(self):
self.libobj_dir,
self.cliobj_dir,
self.testobj_dir,
self.botan_include_dir,
self.public_include_dir,
self.internal_include_dir,
self.external_include_dir,
self.handbook_output_dir,
Expand All @@ -275,10 +281,15 @@ def build_dirs(self):
out += [self.example_obj_dir, self.example_output_dir]
return out

def format_include_paths(self, cc, external_includes):
dash_i = cc.add_include_dir_option
def format_public_include_flags(self, cc):
return cc.add_include_dir_option + ' ' + normalize_source_path(self.public_include_basedir)

def format_internal_include_flags(self, cc):
return cc.add_include_dir_option + ' ' + normalize_source_path(self.internal_include_basedir)

def format_external_include_flags(self, cc, external_includes):
dash_isystem = cc.add_system_include_dir_option
output = dash_i + ' ' + normalize_source_path(self.include_dir)
output = ''
if self.external_headers:
output += ' ' + dash_isystem + ' ' + normalize_source_path(self.external_include_dir)
for external_include in external_includes:
Expand Down Expand Up @@ -2202,8 +2213,6 @@ def test_exe_extra_ldflags():
'handbook_output_dir': build_paths.handbook_output_dir,
'doc_output_dir_doxygen': build_paths.doc_output_dir_doxygen,

'compiler_include_dirs': '%s %s' % (normalize_source_path(build_paths.include_dir), normalize_source_path(build_paths.external_include_dir)),

'os': options.os,
'arch': options.arch,
'compiler': options.compiler,
Expand Down Expand Up @@ -2265,7 +2274,13 @@ def test_exe_extra_ldflags():
'fuzzer_lib': (cc.add_lib_option % options.fuzzer_lib) if options.fuzzer_lib else '',
'libs_used': [lib.replace('.lib', '') for lib in link_to('libs')],

'include_paths': build_paths.format_include_paths(cc, options.with_external_includedir),
'public_include_path': build_paths.public_include_dir,
'internal_include_path': build_paths.internal_include_dir,
'external_include_path': build_paths.external_include_dir,

'public_include_flags': build_paths.format_public_include_flags(cc),
'internal_include_flags': build_paths.format_internal_include_flags(cc),
'external_include_flags': build_paths.format_external_include_flags(cc, options.with_external_includedir),
'module_defines': sorted(flatten([m.defines() for m in modules])),

'build_bogo_shim': bool('bogo_shim' in options.build_targets),
Expand Down Expand Up @@ -3375,7 +3390,7 @@ def link_headers(headers, visibility, directory):
raise UserError('Error linking %s into %s: %s' % (header_file, directory, ex)) from ex

link_headers(build_paths.public_headers, 'public',
build_paths.botan_include_dir)
build_paths.public_include_dir)

link_headers(build_paths.internal_headers, 'internal',
build_paths.internal_include_dir)
Expand Down
12 changes: 6 additions & 6 deletions src/build-data/compile_commands.json.in
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
[
%{for lib_build_info}
{ "directory": "%{abs_root_dir}",
"command": "%{cxx} %{lib_flags} %{cc_sysroot} %{cxx_abi_flags} %{cc_lang_flags} %{os_feature_macros} %{cc_compile_flags} -DBOTAN_IS_BEING_BUILT %{cc_warning_flags} %{isa_flags} %{include_paths} %{dash_c} %{src} %{dash_o}%{obj}",
"command": "%{cxx} %{lib_flags} %{cc_sysroot} %{cxx_abi_flags} %{cc_lang_flags} %{os_feature_macros} %{cc_compile_flags} -DBOTAN_IS_BEING_BUILT %{cc_warning_flags} %{isa_flags} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{dash_c} %{src} %{dash_o}%{obj}",
"file": "%{src}"
},
%{endfor}

%{for test_build_info}
{ "directory": "%{abs_root_dir}",
"command": "%{cxx} %{cc_sysroot} %{cxx_abi_flags} %{cc_lang_flags} %{os_feature_macros} %{cc_compile_flags} -DBOTAN_IS_BEING_BUILT %{cc_warning_flags} %{isa_flags} %{include_paths} %{dash_c} %{src} %{dash_o}%{obj}",
"command": "%{cxx} %{cc_sysroot} %{cxx_abi_flags} %{cc_lang_flags} %{os_feature_macros} %{cc_compile_flags} -DBOTAN_IS_BEING_BUILT %{cc_warning_flags} %{isa_flags} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{dash_c} %{src} %{dash_o}%{obj}",
"file": "%{src}"
},
%{endfor}

%{for examples_build_info}
{ "directory": "%{abs_root_dir}",
"command": "%{cxx} %{cc_sysroot} %{cxx_abi_flags} %{cc_lang_flags} %{os_feature_macros} %{cc_compile_flags} %{cc_warning_flags} %{isa_flags} %{include_paths} %{dash_c} %{src} %{dash_o}%{obj}",
"command": "%{cxx} %{cc_sysroot} %{cxx_abi_flags} %{cc_lang_flags} %{os_feature_macros} %{cc_compile_flags} %{cc_warning_flags} %{isa_flags} %{public_include_flags} %{external_include_flags} %{dash_c} %{src} %{dash_o}%{obj}",
"file": "%{src}"
},
%{endfor}

%{for fuzzer_build_info}
{ "directory": "%{abs_root_dir}",
"command": "%{cxx} %{cc_sysroot} %{cxx_abi_flags} %{cc_lang_flags} %{os_feature_macros} %{cc_compile_flags} -DBOTAN_IS_BEING_BUILT %{cc_warning_flags} %{isa_flags} %{include_paths} %{dash_c} %{src} %{dash_o}%{obj}",
"command": "%{cxx} %{cc_sysroot} %{cxx_abi_flags} %{cc_lang_flags} %{os_feature_macros} %{cc_compile_flags} -DBOTAN_IS_BEING_BUILT %{cc_warning_flags} %{isa_flags} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{dash_c} %{src} %{dash_o}%{obj}",
"file": "%{src}"
},
%{endfor}

%{if build_bogo_shim}
{ "directory": "%{abs_root_dir}",
"command": "%{cxx} %{cc_sysroot} %{cxx_abi_flags} %{cc_lang_flags} %{os_feature_macros} %{cc_compile_flags} -DBOTAN_IS_BEING_BUILT %{cc_warning_flags} %{include_paths} %{dash_c} %{bogo_shim_src} %{dash_o}%{out_dir}/botan_bogo_shim",
"command": "%{cxx} %{cc_sysroot} %{cxx_abi_flags} %{cc_lang_flags} %{os_feature_macros} %{cc_compile_flags} -DBOTAN_IS_BEING_BUILT %{cc_warning_flags} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{dash_c} %{bogo_shim_src} %{dash_o}%{out_dir}/botan_bogo_shim",
"file": "%{bogo_shim_src}"
},
%{endif}


%{for cli_build_info}
{ "directory": "%{abs_root_dir}",
"command": "%{cxx} %{cc_sysroot} %{cxx_abi_flags} %{cc_lang_flags} %{os_feature_macros} %{cc_compile_flags} -DBOTAN_IS_BEING_BUILT %{cc_warning_flags} %{isa_flags} %{include_paths} %{dash_c} %{src} %{dash_o}%{obj}",
"command": "%{cxx} %{cc_sysroot} %{cxx_abi_flags} %{cc_lang_flags} %{os_feature_macros} %{cc_compile_flags} -DBOTAN_IS_BEING_BUILT %{cc_warning_flags} %{isa_flags} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{dash_c} %{src} %{dash_o}%{obj}",
"file": "%{src}"
}%{omitlast ,}
%{endfor}
Expand Down
12 changes: 6 additions & 6 deletions src/build-data/makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ bogo_shim: %{out_dir}/botan_bogo_shim

# BoGo shim
%{out_dir}/botan_bogo_shim: %{bogo_shim_src} $(LIBRARIES)
$(CXX) $(BUILD_FLAGS) -DBOTAN_IS_BEING_BUILT %{include_paths} %{bogo_shim_src} $(BUILD_DIR_LINK_PATH) $(LDFLAGS) $(EXE_LINKS_TO) %{output_to_exe}$@
$(CXX) $(BUILD_FLAGS) -DBOTAN_IS_BEING_BUILT %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{bogo_shim_src} $(BUILD_DIR_LINK_PATH) $(LDFLAGS) $(EXE_LINKS_TO) %{output_to_exe}$@

%{endif}

Expand All @@ -142,30 +142,30 @@ bogo_shim: %{out_dir}/botan_bogo_shim

%{for lib_build_info}
%{obj}: %{src}
$(CXX) $(LIB_FLAGS) $(BUILD_FLAGS) -DBOTAN_IS_BEING_BUILT %{isa_flags} %{include_paths} %{dash_c} %{src} %{dash_o}$@
$(CXX) $(LIB_FLAGS) $(BUILD_FLAGS) -DBOTAN_IS_BEING_BUILT %{isa_flags} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{dash_c} %{src} %{dash_o}$@
%{endfor}

%{for cli_build_info}
%{obj}: %{src}
$(CXX) $(BUILD_FLAGS) -DBOTAN_IS_BEING_BUILT %{isa_flags} %{include_paths} %{dash_c} %{src} %{dash_o}$@
$(CXX) $(BUILD_FLAGS) -DBOTAN_IS_BEING_BUILT %{isa_flags} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{dash_c} %{src} %{dash_o}$@
%{endfor}

%{for test_build_info}
%{obj}: %{src}
$(CXX) $(BUILD_FLAGS) -DBOTAN_IS_BEING_BUILT %{isa_flags} %{include_paths} %{dash_c} %{src} %{dash_o}$@
$(CXX) $(BUILD_FLAGS) -DBOTAN_IS_BEING_BUILT %{isa_flags} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{dash_c} %{src} %{dash_o}$@
%{endfor}

%{for fuzzer_build_info}
%{obj}: %{src}
$(CXX) $(BUILD_FLAGS) -DBOTAN_IS_BEING_BUILT %{isa_flags} %{include_paths} %{dash_c} %{src} %{dash_o}$@
$(CXX) $(BUILD_FLAGS) -DBOTAN_IS_BEING_BUILT %{isa_flags} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{dash_c} %{src} %{dash_o}$@

%{exe}: %{obj} $(LIBRARIES)
$(EXE_LINK_CMD) $(ABI_FLAGS) %{obj} $(BUILD_DIR_LINK_PATH) $(LANG_EXE_FLAGS) $(LDFLAGS) $(EXE_LINKS_TO) %{fuzzer_lib} %{output_to_exe}$@
%{endfor}

%{for examples_build_info}
%{obj}: %{src}
$(CXX) $(BUILD_FLAGS) %{isa_flags} %{include_paths} %{dash_c} %{src} %{dash_o}$@
$(CXX) $(BUILD_FLAGS) %{isa_flags} %{public_include_flags} %{external_include_flags} %{dash_c} %{src} %{dash_o}$@

%{exe}: %{obj} $(LIBRARIES)
$(EXE_LINK_CMD) $(ABI_FLAGS) %{obj} $(BUILD_DIR_LINK_PATH) $(LANG_EXE_FLAGS) $(LDFLAGS) $(EXE_LINKS_TO) %{fuzzer_lib} %{output_to_exe}$@
Expand Down
6 changes: 3 additions & 3 deletions src/build-data/ninja.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ rule compile_lib
%{if ninja_header_deps_style}
deps = %{ninja_header_deps_style}
%{endif}
command = %{cxx} %{lib_flags} ${ABI_FLAGS} ${LANG_FLAGS} ${CXXFLAGS} -DBOTAN_IS_BEING_BUILT ${WARN_FLAGS} ${isa_flags} %{include_paths} %{header_deps_flag} %{header_deps_out|concat: $out.d} %{dash_c} $in %{dash_o}$out
command = %{cxx} %{lib_flags} ${ABI_FLAGS} ${LANG_FLAGS} ${CXXFLAGS} -DBOTAN_IS_BEING_BUILT ${WARN_FLAGS} ${isa_flags} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{header_deps_flag} %{header_deps_out|concat: $out.d} %{dash_c} $in %{dash_o}$out

rule compile_exe
%{if header_deps_out}
Expand All @@ -37,7 +37,7 @@ rule compile_exe
%{if ninja_header_deps_style}
deps = %{ninja_header_deps_style}
%{endif}
command = %{cxx} ${ABI_FLAGS} ${LANG_FLAGS} ${CXXFLAGS} -DBOTAN_IS_BEING_BUILT ${WARN_FLAGS} ${isa_flags} %{include_paths} %{header_deps_flag} %{header_deps_out|concat: $out.d} %{dash_c} $in %{dash_o}$out
command = %{cxx} ${ABI_FLAGS} ${LANG_FLAGS} ${CXXFLAGS} -DBOTAN_IS_BEING_BUILT ${WARN_FLAGS} ${isa_flags} %{public_include_flags} %{internal_include_flags} %{external_include_flags} %{header_deps_flag} %{header_deps_out|concat: $out.d} %{dash_c} $in %{dash_o}$out

rule compile_example_exe
%{if header_deps_out}
Expand All @@ -46,7 +46,7 @@ rule compile_example_exe
%{if ninja_header_deps_style}
deps = %{ninja_header_deps_style}
%{endif}
command = %{cxx} ${ABI_FLAGS} ${LANG_FLAGS} ${CXXFLAGS} ${WARN_FLAGS} ${isa_flags} %{include_paths} %{header_deps_flag} %{header_deps_out|concat: $out.d} %{dash_c} $in %{dash_o}$out
command = %{cxx} ${ABI_FLAGS} ${LANG_FLAGS} ${CXXFLAGS} ${WARN_FLAGS} ${isa_flags} %{public_include_flags} %{external_include_flags} %{header_deps_flag} %{header_deps_out|concat: $out.d} %{dash_c} $in %{dash_o}$out

# The primary target
build all: phony %{all_targets}
Expand Down
9 changes: 5 additions & 4 deletions src/scripts/ci_check_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ def main(args=None):
with open(os.path.join(args[1]), encoding='utf8') as f:
build_config = json.load(f)

include_dir = os.path.join(build_config['build_dir'], 'include', 'botan')
public_include_dir = build_config['public_include_path']
internal_include_dir = build_config['internal_include_path']

internal_inc = re.compile(r'#include <botan/(internal/.*)>')

for header in build_config['public_headers']:
contents = open(os.path.join(include_dir, header), encoding='utf8').read()
contents = open(os.path.join(public_include_dir, header), encoding='utf8').read()

match = internal_inc.search(contents)
if match:
Expand All @@ -45,9 +46,9 @@ def main(args=None):
for header in all_headers:

if header in build_config['public_headers']:
path = os.path.join(include_dir, header)
path = os.path.join(public_include_dir, header)
else:
path = os.path.join(include_dir, 'internal', header)
path = os.path.join(internal_include_dir, header)

contents = open(path, encoding='utf8').read()

Expand Down
4 changes: 2 additions & 2 deletions src/scripts/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ def copy_executable(src, dst):
makedirs(prepend_destdir(d))

for header in cfg['public_headers']:
full_header_path = os.path.join(build_dir, 'include', 'botan', header)
full_header_path = os.path.join(cfg['public_include_path'], header)
copy_file(full_header_path,
prepend_destdir(os.path.join(target_include_dir, header)))

for header in cfg['external_headers']:
full_header_path = os.path.join(build_dir, 'include', 'external', header)
full_header_path = os.path.join(cfg['external_include_path'], header)
copy_file(full_header_path,
prepend_destdir(os.path.join(target_include_dir, header)))

Expand Down

0 comments on commit 1e77255

Please sign in to comment.