Skip to content

Commit edffc2d

Browse files
Improve SCons to use default files (#931)
1 parent e016f4e commit edffc2d

File tree

16 files changed

+32
-91
lines changed

16 files changed

+32
-91
lines changed

SConscript

-10
This file was deleted.

SConstruct

+26-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This provides Builder objects for each of the language implementations in the AA
55
66
Currently, the aim is to provide a way to compile or copy the implementation files to the build directory, as well as to provide ways to run them and capture their output.
77
8-
To run the compilation for all implmeentations in one language, e.g. Rust, run the command `scons build/c`, and the resulting executables will be available in the `cuild/c` directory, each in their respective algorithm directory, containing the executable."""
8+
To run the compilation for all implementations in one language, e.g. C, run the command `scons build/c`, and the resulting executables will be available in the `build/c` directory, each in their respective algorithm directory, containing the executable."""
99

1010
from pathlib import Path
1111
import os
@@ -18,9 +18,32 @@ for tool in ['gcc','gnulink']:
1818
env['CCFLAGS'] = ''
1919

2020
# Add other languages here when you want to add language targets
21-
languages = ['c']
21+
# Put 'name_of_language_directory' : 'file_extension'
22+
languages = {'c': 'c'}
2223

2324
env.C = env.Program
2425

25-
SConscript('SConscript', exports='env languages')
26+
Export('env')
27+
28+
sconscripts = []
29+
files_to_compile = {language: [] for language in languages}
30+
31+
for chapter_dir in Path.cwd().joinpath('contents').iterdir():
32+
if (code_dir := (chapter_dir / 'code')).exists():
33+
for path in code_dir.iterdir():
34+
if path.stem in languages:
35+
# Check for overriding sconscript
36+
if (sconscript_path := path / 'SConscript').exists():
37+
sconscripts.append(sconscript_path)
38+
SConscript(sconscript_path, exports='env')
39+
else:
40+
files_to_compile[path.stem].extend(path.glob(f'*.{languages[path.stem]}'))
41+
42+
sconscript_dir_path = Path('sconscripts')
43+
for language, files in files_to_compile.items():
44+
if files:
45+
if (sconscript_path := sconscript_dir_path / f"{language}_SConscript").exists():
46+
SConscript(sconscript_path, exports = {'files_to_compile': files})
47+
else:
48+
print(f'{language} file found at {files[0]}, but no sconscript file is present ')
2649

contents/IFS/code/c/SConscript

-6
This file was deleted.

contents/barnsley/code/c/SConscript

-6
This file was deleted.

contents/computus/code/c/SConscript

-6
This file was deleted.

contents/euclidean_algorithm/code/c/SConscript

-6
This file was deleted.

contents/flood_fill/code/c/SConscript

-6
This file was deleted.

contents/gaussian_elimination/code/c/SConscript

-6
This file was deleted.

contents/huffman_encoding/code/c/SConscript

-6
This file was deleted.

contents/jarvis_march/code/c/SConscript

-6
This file was deleted.

contents/monte_carlo_integration/code/c/SConscript

-6
This file was deleted.

contents/stable_marriage_problem/code/c/SConscript

-6
This file was deleted.

contents/thomas_algorithm/code/c/SConscript

-6
This file was deleted.

contents/tree_traversal/code/c/SConscript

-6
This file was deleted.

contents/verlet_integration/code/c/SConscript

-6
This file was deleted.

sconscripts/c_SConscript

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('files_to_compile env')
2+
from pathlib import Path
3+
4+
for file in files_to_compile:
5+
chapter_name = file.parent.parent.parent.stem
6+
env.C(f'#/build/c/{chapter_name}', str(file))

0 commit comments

Comments
 (0)