forked from justinmeza/lci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
99 lines (83 loc) · 2.82 KB
/
install.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/python
import subprocess
import argparse
import sys
import os
# Checks if a string is a positive integer
def positiveInt(string):
value = int(string)
if not value >= 1:
msg = string + " is not a positive integer"
raise argparse.ArgumentTypeError(msg)
return value
"""
Runs a subprocess using the command parameter.
Before running the command it displays a message
that contains the provided description and where
the output will be sent. If an error occurs,
the errorMsg is displayed.
"""
def runSubProc(command, description, errorMsg, output):
msg = description
msg += "and writing results to " + output +"."
print(msg + "\n")
outputFile = open(output, "w")
if os.name == "nt":
proc = subprocess.Popen(command, stdout=outputFile, stderr=subprocess.STDOUT, shell=True)
else:
proc = subprocess.Popen(command, stdout=outputFile, stderr=subprocess.STDOUT, shell=True)
proc.wait()
if proc.returncode != 0:
print("Error installing: " + errorMsg)
sys.exit(1)
# Remove the CMakeCache.txt so we can garuntee a fresh configure
if os.path.exists("CMakeCache.txt"):
os.remove("CMakeCache.txt")
parser = argparse.ArgumentParser(description="Installation script for lci")
parser.add_argument('-p', '--prefix', default=None, help="Installation prefix")
parser.add_argument('-m', '--enableMemCheck', action="store_true", help="Enable memory testing")
parser.add_argument('-d', '--buildDocs', action="store_true", help="Build documentation")
parser.add_argument('-t', '--runTests', action="store_true", help="Run Tests")
parser.add_argument('-j', metavar="NumProcs", type=positiveInt, default=1, help="Number of processes for make to use and (if enabled) how many processes CTest should use.")
args = parser.parse_args()
j = str(args.j)
cmakeCommand = ["cmake"]
makeCommand = "make"
# Support for Windows
if os.name == "nt":
cmakeCommand.append("-G \"MinGW Makefiles\"")
makeCommand = "mingw32-make"
if args.prefix != None:
cmakeCommand.append("-DCMAKE_INSTALL_PREFIX:STRING=\""+args.prefix+"\"")
if args.enableMemCheck:
cmakeCommand.append("-DPERFORM_MEM_TESTS:BOOL=ON")
cmakeCommand.append(".")
# Windows does weird things if this is not joined...
cmakeCommand = " ".join(cmakeCommand)
runSubProc(
cmakeCommand,
"Running cmake with command: \n\"" + cmakeCommand + "\"\n",
"There was a CMake error",
"configure.out")
runSubProc(
[makeCommand, "-j"+j],
"Running make ",
"There was a make error",
"make.out")
if args.buildDocs:
runSubProc(
[makeCommand, "-j"+j, "docs"],
"Building documentation ",
"There was a documentation building error",
"docs.out")
runSubProc(
makeCommand + " install",
"Installing ",
"There was an installation error",
"install.out")
if args.runTests:
runSubProc(
["ctest", "-j"+j],
"Testing ",
"There was a testing error",
"test.out")