17
17
# Get number of CPU cores
18
18
CPUS = os .getenv ('CPUS' ) or os .cpu_count () or 1
19
19
20
+ BUILD_TYPE = os .environ ["BUILD_TYPE" ].title () if "BUILD_TYPE" in os .environ else "Release"
21
+ BUILD_DOCS = "ON" if "BUILD_DOCS" in os .environ and os .environ ["BUILD_DOCS" ] in ("1" , "ON" , "on" ) else "OFF"
22
+
20
23
21
24
def execute (cmd : str , cwd : Optional [str ] = None ):
22
25
popen = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .STDOUT ,
@@ -41,26 +44,18 @@ def ensure_spidermonkey():
41
44
execute ("bash ./setup.sh" , cwd = TOP_DIR )
42
45
43
46
44
- def ensure_githooks ():
45
- execute ("ln -s -f ../../githooks/pre-commit .git/hooks/pre-commit" , cwd = TOP_DIR )
46
-
47
-
48
47
def run_cmake_build ():
49
48
os .makedirs (BUILD_DIR , exist_ok = True ) # mkdir -p
50
- build_type = os .environ ["BUILD_TYPE" ].title () if "BUILD_TYPE" in os .environ else "Release"
51
- build_docs = "ON" if "BUILD_DOCS" in os .environ and os .environ ["BUILD_DOCS" ] in ("1" , "ON" , "on" ) else "OFF"
52
49
53
50
if platform .system () == "Windows" :
54
51
# use Clang/LLVM toolset for Visual Studio
55
- execute (f"cmake -DBUILD_DOCS={ build_docs } -DPM_BUILD_TYPE={ build_type } .. -T ClangCL" , cwd = BUILD_DIR )
52
+ execute (f"cmake -DBUILD_DOCS={ BUILD_DOCS } -DPM_BUILD_TYPE={ BUILD_TYPE } .. -T ClangCL" , cwd = BUILD_DIR )
56
53
else :
57
- execute (f"cmake -DBUILD_DOCS={ build_docs } -DPM_BUILD_TYPE={ build_type } .." , cwd = BUILD_DIR )
54
+ execute (f"cmake -DBUILD_DOCS={ BUILD_DOCS } -DPM_BUILD_TYPE={ BUILD_TYPE } .." , cwd = BUILD_DIR )
58
55
execute (f"cmake --build . -j{ CPUS } --config Release" , cwd = BUILD_DIR )
59
56
60
57
61
58
def copy_artifacts ():
62
- if "BUILD_TYPE" in os .environ and os .environ ["BUILD_TYPE" ].title () == "None" :
63
- return # do not copy artifacts if we did not build them
64
59
65
60
if platform .system () == "Windows" :
66
61
execute ("cp ./build/src/*/pythonmonkey.pyd ./python/pythonmonkey/" , cwd = TOP_DIR ) # Release or Debug build
@@ -71,10 +66,11 @@ def copy_artifacts():
71
66
72
67
73
68
def build ():
74
- ensure_spidermonkey ()
75
- ensure_githooks ()
69
+ if BUILD_TYPE != "None" : # do not build SpiderMonkey if we are not compiling
70
+ ensure_spidermonkey ()
76
71
run_cmake_build ()
77
- copy_artifacts ()
72
+ if BUILD_TYPE != "None" : # do not copy artifacts if we did not build them
73
+ copy_artifacts ()
78
74
79
75
80
76
if __name__ == "__main__" :
0 commit comments