Skip to content

Commit 2784428

Browse files
committed
Windows compat and a bugfix in CTrunc
1 parent 5c2bd5b commit 2784428

File tree

14 files changed

+212
-147
lines changed

14 files changed

+212
-147
lines changed

CMakeLists.txt

Lines changed: 88 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,13 @@ endif()
1818
# Install the Mathematica package
1919
# ##############################################################################
2020

21-
if(WIN32)
22-
message(FATAL_ERROR "Installation on Windows is not yet supported - on it!.")
23-
endif()
24-
25-
set(WolframLanguage_wolframscript_EXE "")
26-
execute_process(
27-
COMMAND bash -c "which wolframscript"
28-
OUTPUT_VARIABLE WolframLanguage_wolframscript_EXE
29-
ERROR_QUIET)
30-
if(WolframLanguage_wolframscript_EXE STREQUAL "")
31-
execute_process(
32-
COMMAND bash -c "which wolfram"
33-
OUTPUT_VARIABLE WolframLanguage_wolframscript_EXE
34-
ERROR_QUIET)
35-
endif()
36-
if(WolframLanguage_wolframscript_EXE STREQUAL "")
37-
execute_process(
38-
COMMAND bash -c "which math"
39-
OUTPUT_VARIABLE WolframLanguage_wolframscript_EXE
40-
ERROR_QUIET)
41-
endif()
21+
find_program(WolframLanguage_wolframscript_EXE NAMES wolframscript wolfram math)
4222

4323
# See if the variable WolframLanguage_wolframscript_EXE is defined
4424
if(DEFINED ENV{WOLFRAM_SCRIPT})
4525
set(WolframLanguage_wolframscript_EXE $ENV{WOLFRAM_SCRIPT})
4626
elseif(NOT (WolframLanguage_wolframscript_EXE STREQUAL ""))
47-
# nothing to do, we found it with which
27+
# nothing to do, we found it with find_program
4828
else()
4929
set(WolframLanguage_wolframscript_EXE "")
5030
endif()
@@ -60,7 +40,11 @@ if(NOT DEFINED WolframLanguage_wolframscript_EXE
6040
SHA256=78ba32abdf798bc616bab7c73aac32a17bbd7b06ad9e26a6add69de8f3ae4791)
6141
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)
6242
if("${CPM_SOURCE_CACHE}" STREQUAL "OFF" OR NOT DEFINED CPM_SOURCE_CACHE)
63-
set(CPM_SOURCE_CACHE $ENV{HOME}/.cache/CPM)
43+
if(WIN32)
44+
set(CPM_SOURCE_CACHE $ENV{LOCALAPPDATA}/CPM)
45+
else()
46+
set(CPM_SOURCE_CACHE $ENV{HOME}/.cache/CPM)
47+
endif()
6448
endif()
6549
# Get codeparser
6650
cpmaddpackage(
@@ -130,51 +114,89 @@ install(
130114
# Testing
131115
# ##############################################################################
132116

133-
add_custom_target(
134-
test
135-
COMMAND
136-
${WolframLanguage_wolframscript_EXE} -script
137-
${CMAKE_CURRENT_SOURCE_DIR}/tests/Test.m | tee
138-
${CMAKE_CURRENT_BINARY_DIR}/test.log
139-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/Test.m
140-
COMMENT "Running tests"
141-
VERBATIM)
142-
143-
# Run a single test file or directory:
144-
# make test-single FILE=FEDeriK/FunctionalDTests.m
145-
# make test-single FILE=FEDeriK
146-
# Note: $(FILE) is expanded by Make at build time, not by CMake at configure
147-
# time. VERBATIM is intentionally omitted so that Make resolves the variable.
148-
add_custom_target(
149-
test-single
150-
COMMAND
151-
${WolframLanguage_wolframscript_EXE} -script
152-
${CMAKE_CURRENT_SOURCE_DIR}/tests/Test.m $(FILE) | tee
153-
${CMAKE_CURRENT_BINARY_DIR}/test.log
154-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/Test.m
155-
COMMENT "Running tests")
117+
if(WIN32)
118+
add_custom_target(
119+
test
120+
COMMAND
121+
${WolframLanguage_wolframscript_EXE} -script
122+
${CMAKE_CURRENT_SOURCE_DIR}/tests/Test.m
123+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/Test.m
124+
COMMENT "Running tests"
125+
VERBATIM)
126+
127+
add_custom_target(
128+
test-single
129+
COMMAND
130+
${WolframLanguage_wolframscript_EXE} -script
131+
${CMAKE_CURRENT_SOURCE_DIR}/tests/Test.m $(FILE)
132+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/Test.m
133+
COMMENT "Running tests")
134+
else()
135+
add_custom_target(
136+
test
137+
COMMAND
138+
${WolframLanguage_wolframscript_EXE} -script
139+
${CMAKE_CURRENT_SOURCE_DIR}/tests/Test.m | tee
140+
${CMAKE_CURRENT_BINARY_DIR}/test.log
141+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/Test.m
142+
COMMENT "Running tests"
143+
VERBATIM)
144+
145+
# Run a single test file or directory:
146+
# make test-single FILE=FEDeriK/FunctionalDTests.m
147+
# make test-single FILE=FEDeriK
148+
# Note: $(FILE) is expanded by Make at build time, not by CMake at configure
149+
# time. VERBATIM is intentionally omitted so that Make resolves the variable.
150+
add_custom_target(
151+
test-single
152+
COMMAND
153+
${WolframLanguage_wolframscript_EXE} -script
154+
${CMAKE_CURRENT_SOURCE_DIR}/tests/Test.m $(FILE) | tee
155+
${CMAKE_CURRENT_BINARY_DIR}/test.log
156+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/Test.m
157+
COMMENT "Running tests")
158+
endif()
156159

157160
# ##############################################################################
158161
# Benchmarks
159162
# ##############################################################################
160163

161-
add_custom_target(
162-
bench
163-
COMMAND
164-
${WolframLanguage_wolframscript_EXE} -script
165-
${CMAKE_CURRENT_SOURCE_DIR}/benchmarks/Benchmark.m | tee
166-
${CMAKE_CURRENT_BINARY_DIR}/bench.log
167-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/benchmarks/Benchmark.m
168-
COMMENT "Running benchmarks"
169-
VERBATIM)
170-
171-
# Run a single benchmark file:
172-
# make bench-single FILE=ScalarBench.m
173-
add_custom_target(
174-
bench-single
175-
COMMAND
176-
${WolframLanguage_wolframscript_EXE} -script
177-
${CMAKE_CURRENT_SOURCE_DIR}/benchmarks/Benchmark.m $(FILE) | tee
178-
${CMAKE_CURRENT_BINARY_DIR}/bench.log
179-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/benchmarks/Benchmark.m
180-
COMMENT "Running benchmark")
164+
if(WIN32)
165+
add_custom_target(
166+
bench
167+
COMMAND
168+
${WolframLanguage_wolframscript_EXE} -script
169+
${CMAKE_CURRENT_SOURCE_DIR}/benchmarks/Benchmark.m
170+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/benchmarks/Benchmark.m
171+
COMMENT "Running benchmarks"
172+
VERBATIM)
173+
174+
add_custom_target(
175+
bench-single
176+
COMMAND
177+
${WolframLanguage_wolframscript_EXE} -script
178+
${CMAKE_CURRENT_SOURCE_DIR}/benchmarks/Benchmark.m $(FILE)
179+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/benchmarks/Benchmark.m
180+
COMMENT "Running benchmark")
181+
else()
182+
add_custom_target(
183+
bench
184+
COMMAND
185+
${WolframLanguage_wolframscript_EXE} -script
186+
${CMAKE_CURRENT_SOURCE_DIR}/benchmarks/Benchmark.m | tee
187+
${CMAKE_CURRENT_BINARY_DIR}/bench.log
188+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/benchmarks/Benchmark.m
189+
COMMENT "Running benchmarks"
190+
VERBATIM)
191+
192+
# Run a single benchmark file:
193+
# make bench-single FILE=ScalarBench.m
194+
add_custom_target(
195+
bench-single
196+
COMMAND
197+
${WolframLanguage_wolframscript_EXE} -script
198+
${CMAKE_CURRENT_SOURCE_DIR}/benchmarks/Benchmark.m $(FILE) | tee
199+
${CMAKE_CURRENT_BINARY_DIR}/bench.log
200+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/benchmarks/Benchmark.m
201+
COMMENT "Running benchmark")
202+
endif()

FunKit.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@
9191
StyleBox[\"dependencies\",\nFontSize->10,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\"]\)\!\(\*
9292
StyleBox[\"...\",\nFontSize->10,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\"]\)"];
9393

94+
If[$OperatingSystem === "Windows" && !TrueQ[Global`$UseFORMOnWindows],
95+
Print["FunKit: Skipping TensorBases (not available on Windows without FORM). Set Global`$UseFORMOnWindows = True before loading FunKit to override."];
96+
,
97+
If[$OperatingSystem === "Windows" && TrueQ[Global`$UseFORMOnWindows],
98+
Print["FunKit: Loading TensorBases on Windows -- user has set Global`$UseFORMOnWindows = True. Ensure FormTracer/FORM are available."];
99+
];
94100
TensorBasesInstalled[]:=Module[{TensorBasesDirectory},
95101
TensorBasesDirectory=SelectFirst[
96102
Join[
@@ -125,6 +131,7 @@
125131
StyleBox[\"TensorBases\",\nFontSize->10,\nFontWeight->\"Bold\",\nFontSlant->\"Italic\"]\)\!\(\*
126132
StyleBox[\" \",\nFontSize->10,\nFontSlant->\"Italic\"]\)\!\(\*
127133
StyleBox[\"loaded\",\nFontSize->10,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\"]\)"];
134+
];
128135

129136

130137
(* ::Input::Initialization:: *)
@@ -248,18 +255,26 @@
248255
StyleBox[\"DiANE\",\nFontSize->10,\nFontWeight->\"Bold\",\nFontSlant->\"Italic\"]\)\!\(\*
249256
StyleBox[\" \",\nFontSize->10,\nFontSlant->\"Italic\"]\)\!\(\*
250257
StyleBox[\"loaded\",\nFontSize->10,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\"]\)"];
258+
If[$OperatingSystem === "Windows" && !TrueQ[Global`$UseFORMOnWindows],
259+
Print["FunKit: Skipping DiRK module (requires TensorBases). Set Global`$UseFORMOnWindows = True before loading FunKit to override."];
260+
,
251261
Get[$FunKitDirectory<>"modules/DiRK.m"];
252262
PrintTemporary["\!\(\*
253263
StyleBox[\"...\",\nFontSize->10,\nFontSlant->\"Italic\"]\)\!\(\*
254264
StyleBox[\"DiRK\",\nFontSize->10,\nFontWeight->\"Bold\",\nFontSlant->\"Italic\"]\)\!\(\*
255265
StyleBox[\" \",\nFontSize->10,\nFontSlant->\"Italic\"]\)\!\(\*
256266
StyleBox[\"loaded\",\nFontSize->10,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\"]\)"];
267+
];
268+
If[$OperatingSystem === "Windows" && !TrueQ[Global`$UseFORMOnWindows],
269+
Print["FunKit: Skipping TRACY module (requires FORM/FormTracer). Set Global`$UseFORMOnWindows = True before loading FunKit to override."];
270+
,
257271
Get[$FunKitDirectory<>"modules/TRACY.m"];
258272
PrintTemporary["\!\(\*
259273
StyleBox[\"...\",\nFontSize->10,\nFontSlant->\"Italic\"]\)\!\(\*
260274
StyleBox[\"TRACY\",\nFontSize->10,\nFontWeight->\"Bold\",\nFontSlant->\"Italic\"]\)\!\(\*
261275
StyleBox[\" \",\nFontSize->10,\nFontSlant->\"Italic\"]\)\!\(\*
262276
StyleBox[\"loaded\",\nFontSize->10,\nFontWeight->\"Plain\",\nFontSlant->\"Italic\"]\)"];
277+
];
263278
Get[$FunKitDirectory<>"modules/COEN.m"];
264279
PrintTemporary["\!\(\*
265280
StyleBox[\"...\",\nFontSize->10,\nFontSlant->\"Italic\"]\)\!\(\*

PacletInfo.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
(* ::Package:: *)
22

3-
PacletObject[<|"Name" -> "FunKit", "Version" -> "0.3.0", "WolframVersion" -> "11.0+", "Extensions" -> {{"Kernel", "Context" -> {{"FunKit`", "FunKit.m"}}}, {"Documentation", "Language" -> "English"}}|>]
3+
PacletObject[<|"Name" -> "FunKit", "Version" -> "0.3.1", "WolframVersion" -> "11.0+", "Extensions" -> {{"Kernel", "Context" -> {{"FunKit`", "FunKit.m"}}}, {"Documentation", "Language" -> "English"}}|>]

modules/COEN/Cpp.m

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@
176176
clangFormatExists = Quiet[RunProcess[{"clang-format", "--help"}]] =!= $Failed;
177177

178178
CreateClangFormat[path_:"./"] :=
179-
If[Not @ FileExistsQ[path <> ".clang-format"],
180-
Export[path <> "/.clang-format", "BasedOnStyle: LLVM
179+
If[Not @ FileExistsQ[FileNameJoin[{path, ".clang-format"}]],
180+
Export[FileNameJoin[{path, ".clang-format"}], "BasedOnStyle: LLVM
181181
UseTab: Never
182182
IndentWidth: 2
183183
TabWidth: 2
@@ -203,23 +203,23 @@
203203
If[clangFormatExists,
204204
preprocessed = wrapLargeStatementsForClangFormat[expression];
205205
Export[tmpfileName, preprocessed, "Text"];
206-
CreateClangFormat["/tmp/"];
207-
RunProcess[$SystemShell, All, "clang-format -style=file:/tmp/.clang-format " <> tmpfileName <> " > " <> tmpfileName <> "_formatted && mv " <> tmpfileName <> "_formatted " <> tmpfileName];
206+
CreateClangFormat[$TemporaryDirectory];
207+
Export[tmpfileName, RunProcess[{"clang-format", "-style=file:" <> FileNameJoin[{$TemporaryDirectory, ".clang-format"}], tmpfileName}, "StandardOutput"], "Text"];
208208
Export[tmpfileName, fixClangFormatOffIndentation[Import[tmpfileName, "Text"]], "Text"];
209209
,
210210
Export[tmpfileName, expression, "Text"];
211211
];
212212
If[FileExistsQ[fileName],
213213
If[Import[fileName, "Text"] == Import[tmpfileName, "Text"],
214214
Message[WriteCodeToFile::unchanged, fileName];
215-
RunProcess[$SystemShell, All, "rm " <> tmpfileName]
215+
Quiet[DeleteFile[tmpfileName]]
216216
,
217217
Message[WriteCodeToFile::exported, fileName];
218-
RunProcess[$SystemShell, All, "mv " <> tmpfileName <> " " <> fileName]
218+
RenameFile[tmpfileName, fileName]
219219
]
220220
,
221221
Message[WriteCodeToFile::exported, fileName];
222-
RunProcess[$SystemShell, All, "mv " <> tmpfileName <> " " <> fileName]
222+
RenameFile[tmpfileName, fileName]
223223
]
224224
];
225225

@@ -289,24 +289,23 @@
289289

290290
FormatCppCode[expression_String, OptionsPattern[]] :=
291291
Module[{tmpfileName1, tmpfileName2, preprocessed, output},
292-
tmpfileName1 = "/tmp/in_" <> makeTemporaryFileName[];
293-
tmpfileName2 = "/tmp/out_" <> makeTemporaryFileName[];
292+
tmpfileName1 = FileNameJoin[{$TemporaryDirectory, "in_" <> makeTemporaryFileName[]}];
293+
tmpfileName2 = FileNameJoin[{$TemporaryDirectory, "out_" <> makeTemporaryFileName[]}];
294294
If[clangFormatExists && TrueQ[OptionValue["Format"]],
295295
preprocessed = wrapLargeStatementsForClangFormat[expression];
296296
Export[tmpfileName1, preprocessed, "Text"];
297-
(*RunProcess[$SystemShell, All, "rm /tmp/.clang-format"];*)
298-
CreateClangFormat["/tmp/"];
299-
RunProcess[$SystemShell, All, "clang-format -style=file:/tmp/.clang-format " <> tmpfileName1 <> " > " <> tmpfileName2];
297+
CreateClangFormat[$TemporaryDirectory];
298+
Export[tmpfileName2, RunProcess[{"clang-format", "-style=file:" <> FileNameJoin[{$TemporaryDirectory, ".clang-format"}], tmpfileName1}, "StandardOutput"], "Text"];
300299
,
301300
Export[tmpfileName1, expression, "Text"];
302301
];
303302
If[FileExistsQ[tmpfileName2],
304303
output = Import[tmpfileName2, "Text"];
305304
output = fixClangFormatOffIndentation[output];
306-
RunProcess[$SystemShell, All, "rm " <> tmpfileName1 <> " " <> tmpfileName2];
305+
Quiet[DeleteFile[{tmpfileName1, tmpfileName2}]];
307306
Return[output];
308307
];
309-
RunProcess[$SystemShell, All, "rm " <> tmpfileName1];
308+
Quiet[DeleteFile[tmpfileName1]];
310309
Return[expression]
311310
];
312311

@@ -356,15 +355,18 @@
356355
Return[res];
357356
];
358357

358+
CppCodeFORM[___] /; ($OperatingSystem === "Windows" && !TrueQ[Global`$UseFORMOnWindows]) :=
359+
(Message[FunKit::warning, "CppCodeFORM requires FORM/FormTracer, which is not available on Windows. Set Global`$UseFORMOnWindows = True to override."]; Abort[]);
360+
359361
CppCodeFORM[expr_] :=
360362
Module[{origVars, tmpfileName, import},
361363
origVars = FormTracer`GetExtraVars[];
362-
tmpfileName = "/tmp/FO_" <> makeTemporaryFileName[];
364+
tmpfileName = FileNameJoin[{$TemporaryDirectory, "FO_" <> makeTemporaryFileName[]}];
363365
FormTracer`AddExtraVars @@ GetAllCustomSymbols[expr];
364366
FormTracer`FormTrace[expr // Rationalize, {}, {}, {tmpfileName, "O4"}];
365367
FormTracer`DefineExtraVars[origVars];
366368
import = Import[tmpfileName, "Text"];
367-
RunProcess[$SystemShell, All, "rm " <> tmpfileName];
369+
Quiet[DeleteFile[tmpfileName]];
368370
import // formatFORMCode
369371
];
370372

modules/COEN/Tools.m

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,38 @@
2828

2929
(**********************************************************************************
3030
bashrc, zshrc and zshprofile sourcing to infer PATH
31+
(Unix only -- on Windows, PATH is already correct from the environment)
3132
**********************************************************************************)
3233

33-
haveBashrc = 0 == RunProcess[$SystemShell, All, "source ~/.bashrc"]["ExitCode"];
34-
35-
haveZshrc = 0 == RunProcess[$SystemShell, All, "source ~/.zshrc"]["ExitCode"];
36-
37-
haveZshProfile = 0 == RunProcess[$SystemShell, All, "source ~/.zprofile"]["ExitCode"];
38-
39-
inferredPATH = RunProcess[
40-
$SystemShell
41-
,
42-
All
43-
,
44-
If[haveBashrc,
45-
"source ~/.bashrc;"
46-
,
47-
""
48-
] <>
49-
If[haveZshrc,
50-
"source ~/.zshrc;"
34+
If[$OperatingSystem =!= "Windows",
35+
Module[{haveBashrc, haveZshrc, haveZshProfile, inferredPATH},
36+
haveBashrc = 0 == RunProcess[$SystemShell, All, "source ~/.bashrc"]["ExitCode"];
37+
haveZshrc = 0 == RunProcess[$SystemShell, All, "source ~/.zshrc"]["ExitCode"];
38+
haveZshProfile = 0 == RunProcess[$SystemShell, All, "source ~/.zprofile"]["ExitCode"];
39+
inferredPATH = RunProcess[
40+
$SystemShell
5141
,
52-
""
53-
] <>
54-
If[haveZshProfile,
55-
"source ~/.zprofile;"
42+
All
5643
,
57-
""
58-
] <> " echo $PATH"
59-
]["StandardOutput"];
60-
61-
SetEnvironment["PATH" -> inferredPATH];
44+
If[haveBashrc,
45+
"source ~/.bashrc;"
46+
,
47+
""
48+
] <>
49+
If[haveZshrc,
50+
"source ~/.zshrc;"
51+
,
52+
""
53+
] <>
54+
If[haveZshProfile,
55+
"source ~/.zprofile;"
56+
,
57+
""
58+
] <> " echo $PATH"
59+
]["StandardOutput"];
60+
SetEnvironment["PATH" -> inferredPATH];
61+
];
62+
];
6263

6364
(**********************************************************************************
6465
Parallel map with automatic fallback

0 commit comments

Comments
 (0)