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 for linking to unbuilt C/C++ objects #85

Merged
merged 1 commit into from
Oct 17, 2024
Merged
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
24 changes: 23 additions & 1 deletion redo/rules/build_executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,34 @@ def _build(self, redo_1, redo_2, redo_3):
source_dir = os.path.dirname(source_to_compile)

# Find any C objects that need to be linked against so that we can
# tell GPRbuild to link with them.
# tell gprbuild to link with them.
with c_source_database() as db:
c_objects = db.get_all_objects(build_target)
existing_c_objects = [ofile for ofile in c_objects if os.path.isfile(ofile)]
c_source_path = list(
set([redo_arg.get_src_dir(obj) for obj in existing_c_objects])
)

# Gprbuild will try to link to all C/C++ objects that it finds source
# files for in directories in c_source_path. However, we often only want to link
# with some of these files, not all. In order to tell gprbuild to not
# link with everything we need to create a list of files for it to
# exclude.
existing_c_basenames = [os.path.basename(os.path.splitext(ofile)[0]) for ofile in existing_c_objects]
source_extensions = ['.h', '.c', '.cpp', '.hpp', '.s', '.S']
c_source_exclude = []

# Iterate over each directory in the C source path list
for directory in c_source_path:
# Walk the directory and find all files
for root, _, files in os.walk(directory):
for file in files:
# Check if the file has one of the supported extensions
basename, fext = os.path.splitext(file)
if fext in source_extensions and \
basename not in existing_c_basenames:
c_source_exclude.append(os.path.basename(file))

# Sym link any c objects into the executable object directory, since
# these would not have gotten symlinked like all the ada objects
# above.
Expand Down Expand Up @@ -261,6 +281,8 @@ def _build(self, redo_1, redo_2, redo_3):
+ " -XSOURCE_DIRS="
+ source_dir
+ (("," + ",".join(c_source_path)) if c_source_path else "")
+ " -XEXCLUDED_SOURCE_FILES="
+ ",".join(c_source_exclude)
+ ((" " + gprbuild_flags.strip()) if gprbuild_flags else "")
+ direct
)
Expand Down
1 change: 1 addition & 0 deletions redo/targets/gpr/a_adamant.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ abstract project a_adamant is
-- Adamant build system and GPRBuild.
ADAMANT_DIR := external("ADAMANT_DIR", "");
SOURCE_DIRS := external_as_list("SOURCE_DIRS", ",");
EXCLUDED_SOURCE_FILES := external_as_list("EXCLUDED_SOURCE_FILES", ",");
OBJECT_DIR := external("OBJECT_DIR", "");
EXEC_DIR := external("EXEC_DIR", "");
CHECK_STYLE := external("CHECK_STYLE", "False");
Expand Down
1 change: 1 addition & 0 deletions redo/targets/gpr/linux_analyze.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ project linux_analyze extends all "a_linux_debug_base.gpr" is
-- to GPRBuild.
-----------------------------------------------
for Source_Dirs use a_adamant.SOURCE_DIRS;
for Excluded_Source_Files use a_adamant.EXCLUDED_SOURCE_FILES;
for Object_Dir use a_adamant.OBJECT_DIR;
for Exec_Dir use a_adamant.EXEC_DIR;

Expand Down
1 change: 1 addition & 0 deletions redo/targets/gpr/linux_coverage.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ project linux_coverage extends all "a_linux_debug_base.gpr" is
-- to GPRBuild.
-----------------------------------------------
for Source_Dirs use a_adamant.SOURCE_DIRS;
for Excluded_Source_Files use a_adamant.EXCLUDED_SOURCE_FILES;
for Object_Dir use a_adamant.OBJECT_DIR;
for Exec_Dir use a_adamant.EXEC_DIR;

Expand Down
1 change: 1 addition & 0 deletions redo/targets/gpr/linux_debug.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ project linux_debug extends all "a_linux_debug_base.gpr" is
-- to GPRBuild.
-----------------------------------------------
for Source_Dirs use a_adamant.SOURCE_DIRS;
for Excluded_Source_Files use a_adamant.EXCLUDED_SOURCE_FILES;
for Object_Dir use a_adamant.OBJECT_DIR;
for Exec_Dir use a_adamant.EXEC_DIR;

Expand Down
1 change: 1 addition & 0 deletions redo/targets/gpr/linux_test.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ project linux_test extends all "a_linux_debug_base.gpr" is
-- to GPRBuild.
-----------------------------------------------
for Source_Dirs use a_adamant.SOURCE_DIRS;
for Excluded_Source_Files use a_adamant.EXCLUDED_SOURCE_FILES;
for Object_Dir use a_adamant.OBJECT_DIR;
for Exec_Dir use a_adamant.EXEC_DIR;

Expand Down