From 391ca0039bab09a63bd273584ffd8645aad58f4e Mon Sep 17 00:00:00 2001 From: Sammy Plat Date: Wed, 29 Mar 2023 22:00:56 +0200 Subject: [PATCH 1/2] Added Racket (in form of 'raco exe') to the build system --- SConstruct | 7 +++++-- builders/racket.py | 37 +++++++++++++++++++++++++++++++++++ sconscripts/racket_SConscript | 6 ++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 builders/racket.py create mode 100644 sconscripts/racket_SConscript diff --git a/SConstruct b/SConstruct index 150ed3b89..e5ecf82d9 100644 --- a/SConstruct +++ b/SConstruct @@ -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']) @@ -38,6 +38,7 @@ available_languages = { 'python', 'ruby', 'viml', + 'racket', } languages_to_import = { @@ -45,6 +46,7 @@ languages_to_import = { 'go': ['go'], 'rust': ['rustc', 'cargo'], 'kotlin': ['kotlin'], + 'racket': ['racket'], } for language, tools in languages_to_import.items(): @@ -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 @@ -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, diff --git a/builders/racket.py b/builders/racket.py new file mode 100644 index 000000000..2729658fe --- /dev/null +++ b/builders/racket.py @@ -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}) diff --git a/sconscripts/racket_SConscript b/sconscripts/racket_SConscript new file mode 100644 index 000000000..e8d23fd83 --- /dev/null +++ b/sconscripts/racket_SConscript @@ -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) From be07b10fdd019d40002d440272f44db5df522158 Mon Sep 17 00:00:00 2001 From: Sammy Plat Date: Wed, 29 Mar 2023 22:03:50 +0200 Subject: [PATCH 2/2] Added unrelated .gitignore clauses (for OCaml that was leftover from previous experiment) --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 5e1e79300..08c567100 100644 --- a/.gitignore +++ b/.gitignore @@ -531,3 +531,7 @@ target/ *.out *.class + +# OCaml compilation files +*.cmi +*.cmx