Skip to content

Adding Racket to the build system #1010

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

Merged
merged 2 commits into from
Mar 29, 2023
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,7 @@ target/

*.out
*.class

# OCaml compilation files
*.cmi
*.cmx
7 changes: 5 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SCons.Warnings.warningAsException()
copy_builder = Builder(action=Copy('$TARGET', '$SOURCE'))

env = Environment(ENV=os.environ,
BUILDERS={'Copier': copy_builder},
BUILDERS={'Copier': copy_builder},
tools=[
'g++', 'gas', 'gcc', 'gfortran', 'gnulink', 'javac'],
toolpath=['builders'])
Expand All @@ -38,13 +38,15 @@ available_languages = {
'python',
'ruby',
'viml',
'racket',
}

languages_to_import = {
'coconut': ['coconut'],
'go': ['go'],
'rust': ['rustc', 'cargo'],
'kotlin': ['kotlin'],
'racket': ['racket'],
}

for language, tools in languages_to_import.items():
Expand Down Expand Up @@ -89,6 +91,7 @@ languages = {
'ruby': 'rb',
'rust': 'rs',
'viml': 'vim',
'racket': 'rkt'
}

# Do not add new Builders here, add them to the BUILDERS argument in the call to Environment above
Expand All @@ -111,7 +114,7 @@ for chapter_dir in contents_path.iterdir():
for code_dir in chapter_dir.glob('**/code'):
# For nested chapters e.g. contents/convolutions/1d/
extended_chapter_path = code_dir.relative_to(contents_path).parent

for language_dir in code_dir.iterdir():
if (language := language_dir.stem) in available_languages:
new_files = [FileInformation(path=file_path,
Expand Down
37 changes: 37 additions & 0 deletions builders/racket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from SCons.Builder import Builder
import SCons.Util

class ToolRacketWarning(SCons.Warnings.SConsWarning):
pass

class RacketNotFound(ToolRacketWarning):
pass

SCons.Warnings.enableWarningClass(ToolRacketWarning)

def _detect(env):
try:
return env['raco']
except KeyError:
pass

go = env.WhereIs('raco')
if go:
return go

SCons.Warnings.warn(RacketNotFound, 'Could not find raco executable')

def exists(env):
env.Detect('raco')

def generate(env):
env['RACO'] = _detect(env)
env['RACOFLAGS'] = []

racket_builder = Builder(
action='"$RACO" exe -o $TARGET $RACOFLAGS $SOURCE',
src_suffix='.rkt',
suffix='$PROGSUFFIX',
)

env.Append(BUILDERS={'Racket': racket_builder})
6 changes: 6 additions & 0 deletions sconscripts/racket_SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Import('files_to_compile env')

for file_info in files_to_compile:
build_target = f'#/build/{file_info.language}/{file_info.chapter}/{file_info.path.stem}'
build_result = env.Racket(build_target, str(file_info.path))
env.Alias(str(file_info.chapter), build_result)