This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.py
executable file
·129 lines (101 loc) · 4.63 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#! /usr/bin/env python
import os
import subprocess
import shutil
try:
import argparse as ap
except ImportError:
import pyne._argparse as ap
absexpanduser = lambda x: os.path.abspath(os.path.expanduser(x))
def check_windows_cmake(cmake_cmd):
if os.name == 'nt':
files_on_path = set()
for p in os.environ['PATH'].split(';')[::-1]:
if os.path.exists(p):
files_on_path.update(os.listdir(p))
if 'cl.exe' in files_on_path:
pass
elif 'sh.exe' in files_on_path:
cmake_cmd += ['-G "MSYS Makefiles"']
elif 'gcc.exe' in files_on_path:
cmake_cmd += ['-G "MinGW Makefiles"']
cmake_cmd = ' '.join(cmake_cmd)
def install_cycaless(args):
if not os.path.exists(args.build_dir):
os.mkdir(args.build_dir)
elif args.replace:
shutil.rmtree(args.build_dir)
os.mkdir(args.build_dir)
root_dir = os.path.split(__file__)[0]
src_dir = os.path.join(root_dir, 'src')
makefile = os.path.join(args.build_dir, 'Makefile')
if not os.path.exists(makefile):
cmake_cmd = ['cmake', absexpanduser(root_dir)]
if args.prefix:
cmake_cmd += ['-DCMAKE_INSTALL_PREFIX=' + absexpanduser(args.prefix)]
if args.cmake_prefix_path:
cmake_cmd += ['-DCMAKE_PREFIX_PATH=' + absexpanduser(args.cmake_prefix_path)]
if args.coin_root:
cmake_cmd += ['-DCOIN_ROOT_DIR=' + absexpanduser(args.coin_root)]
if args.boost_root:
cmake_cmd += ['-DBOOST_ROOT=' + absexpanduser(args.boost_root)]
if args.cyclus_root:
cmake_cmd += ['-DCYCLUS_ROOT_DIR='+absexpanduser(args.cyclus_root)]
if args.build_type:
cmake_cmd += ['-DCMAKE_BUILD_TYPE=' + args.build_type]
check_windows_cmake(cmake_cmd)
rtn = subprocess.check_call(cmake_cmd, cwd=absexpanduser(args.build_dir), shell=(os.name=='nt'))
make_cmd = ['make']
if args.threads:
make_cmd += ['-j' + str(args.threads)]
rtn = subprocess.call(make_cmd, cwd=args.build_dir,
shell=(os.name == 'nt'))
if args.test:
make_cmd += ['test']
elif not args.build_only:
make_cmd += ['install']
rtn = subprocess.check_call(make_cmd, cwd=args.build_dir,
shell=(os.name == 'nt'))
def uninstall_cycaless(args):
makefile = os.path.join(args.build_dir, 'Makefile')
if not os.path.exists(args.build_dir) or not os.path.exists(makefile):
sys.exist("May not uninstall cycaless since it has not yet been built.")
rtn = subprocess.check_call(['make', 'uninstall'], cwd=args.build_dir,
shell=(os.name == 'nt'))
def main():
localdir = absexpanduser('~/.local')
description = "A Cycaless installation helper script. "+\
"For more information, please see cyclus.github.com."
parser = ap.ArgumentParser(description=description)
build_dir = 'where to place the build directory'
parser.add_argument('--build_dir', help=build_dir, default='build')
uninst = 'uninstall'
parser.add_argument('--uninstall', action='store_true', help=uninst, default=False)
replace = 'whether or not to remove the build directory if it exists'
parser.add_argument('--replace', type=bool, help=replace, default=False)
threads = "the number of threads to use in the make step"
parser.add_argument('-j', '--threads', type=int, help=threads)
install = "the relative path to the installation directory"
parser.add_argument('--prefix', help=install, default=localdir)
test = 'run tests after building'
parser.add_argument('--test', action='store_true', help=test)
build_only = 'only build the package, do not install'
parser.add_argument('--build-only', action='store_true', help=build_only)
coin = "the relative path to the Coin-OR libraries directory"
parser.add_argument('--coin_root', help=coin)
cyclus = "the relative path to Cyclus installation directory"
parser.add_argument('--cyclus_root',help=cyclus, default=localdir)
boost = "the relative path to the Boost libraries directory"
parser.add_argument('--boost_root', help=boost)
cmake_prefix_path = "the cmake prefix path for use with FIND_PACKAGE, " + \
"FIND_PATH, FIND_PROGRAM, or FIND_LIBRARY macros"
parser.add_argument('--cmake_prefix_path', help=cmake_prefix_path)
build_type = "the CMAKE_BUILD_TYPE"
parser.add_argument('--build_type', help=build_type)
args = parser.parse_args()
if args.uninstall:
uninstall_cycaless(args)
else:
install_cycaless(args)
if __name__ == "__main__":
main()