Skip to content

Commit

Permalink
Adding Racket to the build system (algorithm-archivists#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaras authored Mar 29, 2023
1 parent f6ce7e4 commit 3753576
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
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)

0 comments on commit 3753576

Please sign in to comment.