Skip to content

Commit 3753576

Browse files
authored
Adding Racket to the build system (#1010)
1 parent f6ce7e4 commit 3753576

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -531,3 +531,7 @@ target/
531531

532532
*.out
533533
*.class
534+
535+
# OCaml compilation files
536+
*.cmi
537+
*.cmx

SConstruct

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SCons.Warnings.warningAsException()
1818
copy_builder = Builder(action=Copy('$TARGET', '$SOURCE'))
1919

2020
env = Environment(ENV=os.environ,
21-
BUILDERS={'Copier': copy_builder},
21+
BUILDERS={'Copier': copy_builder},
2222
tools=[
2323
'g++', 'gas', 'gcc', 'gfortran', 'gnulink', 'javac'],
2424
toolpath=['builders'])
@@ -38,13 +38,15 @@ available_languages = {
3838
'python',
3939
'ruby',
4040
'viml',
41+
'racket',
4142
}
4243

4344
languages_to_import = {
4445
'coconut': ['coconut'],
4546
'go': ['go'],
4647
'rust': ['rustc', 'cargo'],
4748
'kotlin': ['kotlin'],
49+
'racket': ['racket'],
4850
}
4951

5052
for language, tools in languages_to_import.items():
@@ -89,6 +91,7 @@ languages = {
8991
'ruby': 'rb',
9092
'rust': 'rs',
9193
'viml': 'vim',
94+
'racket': 'rkt'
9295
}
9396

9497
# Do not add new Builders here, add them to the BUILDERS argument in the call to Environment above
@@ -111,7 +114,7 @@ for chapter_dir in contents_path.iterdir():
111114
for code_dir in chapter_dir.glob('**/code'):
112115
# For nested chapters e.g. contents/convolutions/1d/
113116
extended_chapter_path = code_dir.relative_to(contents_path).parent
114-
117+
115118
for language_dir in code_dir.iterdir():
116119
if (language := language_dir.stem) in available_languages:
117120
new_files = [FileInformation(path=file_path,

builders/racket.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from SCons.Builder import Builder
2+
import SCons.Util
3+
4+
class ToolRacketWarning(SCons.Warnings.SConsWarning):
5+
pass
6+
7+
class RacketNotFound(ToolRacketWarning):
8+
pass
9+
10+
SCons.Warnings.enableWarningClass(ToolRacketWarning)
11+
12+
def _detect(env):
13+
try:
14+
return env['raco']
15+
except KeyError:
16+
pass
17+
18+
go = env.WhereIs('raco')
19+
if go:
20+
return go
21+
22+
SCons.Warnings.warn(RacketNotFound, 'Could not find raco executable')
23+
24+
def exists(env):
25+
env.Detect('raco')
26+
27+
def generate(env):
28+
env['RACO'] = _detect(env)
29+
env['RACOFLAGS'] = []
30+
31+
racket_builder = Builder(
32+
action='"$RACO" exe -o $TARGET $RACOFLAGS $SOURCE',
33+
src_suffix='.rkt',
34+
suffix='$PROGSUFFIX',
35+
)
36+
37+
env.Append(BUILDERS={'Racket': racket_builder})

sconscripts/racket_SConscript

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('files_to_compile env')
2+
3+
for file_info in files_to_compile:
4+
build_target = f'#/build/{file_info.language}/{file_info.chapter}/{file_info.path.stem}'
5+
build_result = env.Racket(build_target, str(file_info.path))
6+
env.Alias(str(file_info.chapter), build_result)

0 commit comments

Comments
 (0)