| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# @HEADER |
| 4 |
# ***************************************************************************** |
| 5 |
# TriBITS: Tribal Build, Integrate, and Test System |
| 6 |
# |
| 7 |
# Copyright 2013-2016 NTESS and the TriBITS contributors. |
| 8 |
# SPDX-License-Identifier: BSD-3-Clause |
| 9 |
# ***************************************************************************** |
| 10 |
# @HEADER |
| 11 |
|
| 12 |
# |
| 13 |
# Imports |
| 14 |
# |
| 15 |
|
| 16 |
from FindGeneralScriptSupport import * |
| 17 |
import InstallProgramDriver |
| 18 |
|
| 19 |
|
| 20 |
# |
| 21 |
# Defaults and constants |
| 22 |
# |
| 23 |
|
| 24 |
devtools_install_dir = os.path.dirname(os.path.abspath(__file__)) |
| 25 |
|
| 26 |
scratch_dir = os.getcwd() |
| 27 |
|
| 28 |
sourceGitUrlBase_default = "https://github.com/tribitsdevtools/" |
| 29 |
|
| 30 |
# tool default versions |
| 31 |
autoconf_version_default = "2.69" |
| 32 |
cmake_version_default = "3.3.2" |
| 33 |
gcc_version_default = "4.8.3" |
| 34 |
mpich_version_default = "3.1.3" |
| 35 |
|
| 36 |
# Common (compile independent) tools |
| 37 |
commonToolsArray = [ "gitdist", "autoconf", "cmake" ] |
| 38 |
commonToolsChoices = (["all"] + commonToolsArray + [""]) |
| 39 |
|
| 40 |
# Compiler toolset |
| 41 |
compilerToolsetArray = [ "gcc", "mpich" ]; |
| 42 |
compilerToolsetChoices = (["all"] + compilerToolsetArray + [""]) |
| 43 |
|
| 44 |
|
| 45 |
# |
| 46 |
# Utility functions |
| 47 |
# |
| 48 |
|
| 49 |
usageHelp = r"""install-devtools.py [OPTIONS] |
| 50 |
|
| 51 |
This script drives the installation of a number of tools needed by many |
| 52 |
TriBITS-based projects. The most typical usage is to first create a scratch |
| 53 |
directory with:: |
| 54 |
|
| 55 |
mkdir scratch |
| 56 |
cd scratch |
| 57 |
|
| 58 |
and then run: |
| 59 |
|
| 60 |
install-devtools.py --install-dir=<dev_env_base> \ |
| 61 |
--parallel=<num-procs> --do-all |
| 62 |
|
| 63 |
By default, this installs the following tools in the dev env install |
| 64 |
directory: |
| 65 |
|
| 66 |
<dev_env_base>/ |
| 67 |
common_tools/ |
| 68 |
autoconf-<autoconf-version>/ |
| 69 |
cmake-<cmake-version>/ |
| 70 |
gitdist |
| 71 |
gcc-<gcc-version>/ |
| 72 |
load_dev_env.[sh,csh] |
| 73 |
toolset/ |
| 74 |
gcc-<gcc-version>/ |
| 75 |
mpich-<mpich-version>/ |
| 76 |
|
| 77 |
The default versions of the tools installed are: |
| 78 |
|
| 79 |
* autoconf-"""+autoconf_version_default+""" |
| 80 |
* cmake-"""+cmake_version_default+""" |
| 81 |
* gcc-"""+gcc_version_default+""" |
| 82 |
* mpich-"""+mpich_version_default+""" |
| 83 |
|
| 84 |
The tools installed under common_tools/ only need to be installed once |
| 85 |
independent of any compilers that may be used to build TriBITS-based projects. |
| 86 |
|
| 87 |
The tools installed under gcc-<gcc-version>/ are specific to a GCC compiler |
| 88 |
and MPICH configuration and build. |
| 89 |
|
| 90 |
The download and install of each of these tools is drive by its own |
| 91 |
install-<toolname>.py script in the same directory as install-devtools.py. |
| 92 |
|
| 93 |
Before running this script, some version of a C and C++ compiler must already |
| 94 |
be installed on the system. |
| 95 |
|
| 96 |
At a high level, this script performs the following actions. |
| 97 |
|
| 98 |
1) Create the base directories (if they don't already exist) and install |
| 99 |
load_dev_env.sh (csh). (if --initial-setup is passed in.) |
| 100 |
|
| 101 |
2) Download the sources for all of the requested common tools and compiler |
| 102 |
toolset. (if --download is passed in.) |
| 103 |
|
| 104 |
3) Configure, build, and install the requested common tools under |
| 105 |
common_tools/. (if --install is passed in.) |
| 106 |
|
| 107 |
4) Configure, build, and install the downloaded GCC and MPICH tools. First |
| 108 |
install GCC then MPICH using the installed GCC and install under |
| 109 |
gcc-<gcc-version>/. (if --install is passed in.) |
| 110 |
|
| 111 |
The informational arguments to this function are: |
| 112 |
|
| 113 |
--install-dir=<dev_env_base> |
| 114 |
|
| 115 |
The base directory that will be used for the install. There is not |
| 116 |
default. If this is not specified then it will abort. |
| 117 |
|
| 118 |
--source-git-url-base=<url_base> |
| 119 |
|
| 120 |
Gives the base URL for to get the tool sources from. The default is: |
| 121 |
|
| 122 |
"""+sourceGitUrlBase_default+""" |
| 123 |
|
| 124 |
This is used to build the full git URL as: |
| 125 |
|
| 126 |
<url_base><tool_name>-<tool_version>-base |
| 127 |
|
| 128 |
This can also accommodate gitolite repos and other directory structures, |
| 129 |
for example, with: |
| 130 |
|
| 131 |
git@<host-name>:prerequisites/ |
| 132 |
|
| 133 |
--common-tools=all |
| 134 |
|
| 135 |
Specifies the tools to download and install under common_tools/. One can |
| 136 |
pick specific tools with: |
| 137 |
|
| 138 |
--common-tools=autoconf,cmake,... |
| 139 |
|
| 140 |
This will download and install the default versions of these tools. To |
| 141 |
select specific versions, use: |
| 142 |
|
| 143 |
--common-tools=autoconf:"""+autoconf_version_default+""",cmake:"""+cmake_version_default+""",... |
| 144 |
|
| 145 |
The default is 'all'. To install none of these, pass in empty: |
| 146 |
|
| 147 |
--common-tools='' |
| 148 |
|
| 149 |
(NOTE: A version of 'git' is *not* installed using this script but can be |
| 150 |
installed using the script install-git.py. But note the extra packages |
| 151 |
that must be installed on a system in order to fully install git and its |
| 152 |
documentation. All of the git-related TriBITS tools can use any recent |
| 153 |
version of git and most systems will already have a current-enough version |
| 154 |
of git so there is no need to install one to be effective doing |
| 155 |
development.) |
| 156 |
|
| 157 |
--compiler-toolset=all |
| 158 |
|
| 159 |
Specifies GCC and MPICH (and other compiler-specific tools) to download |
| 160 |
and install under gcc-<gcc-version>/toolset/. One can pick specific |
| 161 |
components with: |
| 162 |
|
| 163 |
--compiler-toolset=gcc,mpich |
| 164 |
|
| 165 |
or specific versions with: |
| 166 |
|
| 167 |
--compiler-toolset=gcc:"""+gcc_version_default+""",mpich:"""+mpich_version_default+""" |
| 168 |
|
| 169 |
Of course if one is only installing GCC with an existing installed MPICH, |
| 170 |
one will need to also reinstall MPICH as well. |
| 171 |
|
| 172 |
The default is 'all'. To install none of these, pass in empty: |
| 173 |
|
| 174 |
--compiler-toolset='' |
| 175 |
|
| 176 |
The action arguments are: |
| 177 |
|
| 178 |
--initial-setup: Create <dev_env_base>/ directories and install |
| 179 |
load_dev_env.sh |
| 180 |
|
| 181 |
--download: Download all of the requested tools |
| 182 |
|
| 183 |
--install: Configure, build, and install all of the requested tools |
| 184 |
|
| 185 |
--do-all: Do everything. Implies --initial-setup --downlaod --install |
| 186 |
|
| 187 |
To change modify the permissions of the installed files, see the options |
| 188 |
--install-owner, --install-group, and --install-for-all. |
| 189 |
|
| 190 |
Note that the user can see what operations and command would be run without |
| 191 |
actually running them by passing in --no-op. This can be used to show how to |
| 192 |
run each of the individual install command so that the user can run it for |
| 193 |
him/her-self and customize it as needed. |
| 194 |
|
| 195 |
If the user needs more customization, then they can just run with --do-all |
| 196 |
--no-op and see what commands are run to install things and then they can run |
| 197 |
the commands themselves manually and make whatever modifications they need. |
| 198 |
|
| 199 |
NOTE: The actual tool installs are performed using the scripts: |
| 200 |
|
| 201 |
* install-autoconf.py |
| 202 |
* install-cmake.py |
| 203 |
* install-gcc.py |
| 204 |
* install-git.py |
| 205 |
* install-mpich.py |
| 206 |
* install-openmpi.py |
| 207 |
|
| 208 |
More information about what versions are installed, how they are installed, |
| 209 |
etc. is found in these scripts. Note that some of these scripts apply patches |
| 210 |
for certain versions. For details, look at the --help output from these |
| 211 |
scripts and look at the implementation of these scripts. |
| 212 |
""" |
| 213 |
|
| 214 |
|
| 215 |
# Get and process command-line arguments |
| 216 |
def getCmndLineOptions(cmndLineArgs, skipEchoCmndLine=False): |
| 217 |
|
| 218 |
from optparse import OptionParser |
| 219 |
|
| 220 |
clp = OptionParser(usage=usageHelp) |
| 221 |
|
| 222 |
clp.add_option( |
| 223 |
"--install-dir", dest="installDir", type="string", default="", |
| 224 |
help="The base directory <dev_env_base> that will be used for the install." \ |
| 225 |
+" There is not default. If this is not specified then will abort.") |
| 226 |
|
| 227 |
InstallProgramDriver.insertInstallPermissionsOptions(clp) |
| 228 |
|
| 229 |
clp.add_option( |
| 230 |
"--source-git-url-base", dest="sourceGitUrlBase", type="string", |
| 231 |
default=sourceGitUrlBase_default, |
| 232 |
help="Gives the base URL <url_base> for the git repos to object the source from.") |
| 233 |
|
| 234 |
clp.add_option( |
| 235 |
"--load-dev-env-file-base-name", dest="loadDevEnvFileBaseName", |
| 236 |
type="string", default="load_dev_env", |
| 237 |
help="Base name of the load dev env script that will be installed." \ |
| 238 |
" (Default = 'load_dev_env')" ) |
| 239 |
|
| 240 |
clp.add_option( |
| 241 |
"--common-tools", dest="commonTools", type="string", default="all", |
| 242 |
help="Specifies the common tools to download and install under common_tools/." \ |
| 243 |
" Can be 'all', or empty '', or any combination of" \ |
| 244 |
" '"+(",".join(commonToolsArray))+"' (separated by commas, no spaces).") |
| 245 |
|
| 246 |
clp.add_option( |
| 247 |
"--compiler-toolset", dest="compilerToolset", type="string", default="all", |
| 248 |
help="Specifies GCC and MPICH and other compiler-specific tools to" \ |
| 249 |
" download and install under gcc-<gcc-version>/toolset/." \ |
| 250 |
" Can be 'all', or empty '', or any combination of" \ |
| 251 |
" '"+(",".join(compilerToolsetArray))+"' (separated by commas, no spaces).") |
| 252 |
|
| 253 |
clp.add_option( |
| 254 |
"--parallel", dest="parallelLevel", type="string", default="1", |
| 255 |
help="Number of parallel processes to use in the build. The default is" \ |
| 256 |
" just '1'. Use something like '8' to get faster parallel builds." ) |
| 257 |
|
| 258 |
clp.add_option( |
| 259 |
"--do-op", dest="skipOp", action="store_false", |
| 260 |
help="Do all of the requested actions [default].") |
| 261 |
clp.add_option( |
| 262 |
"--no-op", dest="skipOp", action="store_true", default=False, |
| 263 |
help="Skip all of the requested actions and just print what would be done.") |
| 264 |
|
| 265 |
clp.add_option( |
| 266 |
"--show-defaults", dest="showDefaults", action="store_true", default=False, |
| 267 |
help="[ACTION] Show the defaults and exit." ) |
| 268 |
|
| 269 |
clp.add_option( |
| 270 |
"--initial-setup", dest="doInitialSetup", action="store_true", default=False, |
| 271 |
help="[ACTION] Create base directories under <dev_env_base>/ and install" \ |
| 272 |
" load_dev_env.[sh,csh].") |
| 273 |
|
| 274 |
clp.add_option( |
| 275 |
"--download", dest="doDownload", action="store_true", default=False, |
| 276 |
help="[ACTION] Download all of the tools specified by --common-tools" \ |
| 277 |
" and --compiler-toolset. WARNING: If the source for a tool has" \ |
| 278 |
" already been downloaded, it will be deleted (along with the build" \ |
| 279 |
" directory) and downloaded from scratch!") |
| 280 |
|
| 281 |
clp.add_option( |
| 282 |
"--install", dest="doInstall", action="store_true", default=False, |
| 283 |
help="[ACTION] Configure, build, and install all of the tools specified by" \ |
| 284 |
" --common-tools and --compiler-toolset.") |
| 285 |
|
| 286 |
clp.add_option( |
| 287 |
"--show-final-instructions", dest="showFinalInstructions", action="store_true", |
| 288 |
default=False, |
| 289 |
help="[ACTION] Show final instructions for using the installed dev env." ) |
| 290 |
|
| 291 |
clp.add_option( |
| 292 |
"--do-all", dest="doAll", action="store_true", default=False, |
| 293 |
help="[AGGR ACTION] Do everything. Implies --initial-setup --downlaod" \ |
| 294 |
+" --install --show-final-instructions") |
| 295 |
|
| 296 |
(options, args) = clp.parse_args(args=cmndLineArgs) |
| 297 |
|
| 298 |
# NOTE: Above, in the pairs of boolean options, the *last* add_option(...) |
| 299 |
# takes effect! That is why the commands are ordered the way they are! |
| 300 |
|
| 301 |
# |
| 302 |
# Echo the command-line |
| 303 |
# |
| 304 |
|
| 305 |
if not skipEchoCmndLine: |
| 306 |
|
| 307 |
cmndLine = "**************************************************************************\n" |
| 308 |
cmndLine += "Script: install-devtools.py \\\n" |
| 309 |
cmndLine += " --install-dir='"+options.installDir+"' \\\n" |
| 310 |
cmndLine += InstallProgramDriver.echoInsertPermissionsOptions(options) |
| 311 |
cmndLine += " --source-git-url-base='"+options.sourceGitUrlBase+"' \\\n" |
| 312 |
cmndLine += " --load-dev-env-file-base-name='"+options.loadDevEnvFileBaseName+"' \\\n" |
| 313 |
cmndLine += " --common-tools='"+options.commonTools+"' \\\n" |
| 314 |
cmndLine += " --compiler-toolset='"+options.compilerToolset+"' \\\n" |
| 315 |
cmndLine += " --parallel='"+options.parallelLevel+"' \\\n" |
| 316 |
if not options.skipOp: |
| 317 |
cmndLine += " --do-op \\\n" |
| 318 |
else: |
| 319 |
cmndLine += " --no-op \\\n" |
| 320 |
if options.doInitialSetup: |
| 321 |
cmndLine += " --initial-setup \\\n" |
| 322 |
if options.doDownload: |
| 323 |
cmndLine += " --download \\\n" |
| 324 |
if options.doInstall: |
| 325 |
cmndLine += " --install \\\n" |
| 326 |
if options.showFinalInstructions: |
| 327 |
cmndLine += " --show-final-instructions \\\n" |
| 328 |
if options.doAll: |
| 329 |
cmndLine += " --do-all \\\n" |
| 330 |
|
| 331 |
print(cmndLine) |
| 332 |
|
| 333 |
if options.showDefaults: |
| 334 |
sys.exit(0); |
| 335 |
|
| 336 |
# |
| 337 |
# Check the input arguments |
| 338 |
# |
| 339 |
|
| 340 |
if options.installDir == "": |
| 341 |
print("\nError, you must set --install-dir=<dev_env_base>!") |
| 342 |
raise Exception("Bad input option --install-dir") |
| 343 |
options.installDir = os.path.abspath(os.path.expanduser(options.installDir)) |
| 344 |
|
| 345 |
if options.commonTools == "all": |
| 346 |
options.commonTools = ",".join(commonToolsArray) |
| 347 |
#print("options.commonTools = '"+options.commonTools+"'") |
| 348 |
|
| 349 |
if options.compilerToolset == "all": |
| 350 |
options.compilerToolset = ",".join(compilerToolsetArray) |
| 351 |
#print("options.compilerToolset = '"+options.compilerToolset+"'") |
| 352 |
|
| 353 |
if options.doAll: |
| 354 |
options.doInitialSetup = True |
| 355 |
options.doDownload = True |
| 356 |
options.doInstall = True |
| 357 |
options.showFinalInstructions = True |
| 358 |
|
| 359 |
# |
| 360 |
# Return the options |
| 361 |
# |
| 362 |
|
| 363 |
return options |
| 364 |
|
| 365 |
|
| 366 |
# |
| 367 |
# Get array of selected tools (can be empty) |
| 368 |
# |
| 369 |
def getToolsSelectedArray(toolsSelectedStr, validToolsArray): |
| 370 |
validToolsArraySet = set(validToolsArray) |
| 371 |
if toolsSelectedStr == "": |
| 372 |
return [] |
| 373 |
toolsArray = [] |
| 374 |
for toolName in toolsSelectedStr.split(","): |
| 375 |
if not toolName in validToolsArraySet: |
| 376 |
raise Exception("Error, '"+toolName+"' is not one of" \ |
| 377 |
" '"+(",".join(validToolsArray))+"'") |
| 378 |
toolsArray.append(toolName) |
| 379 |
return toolsArray |
| 380 |
|
| 381 |
|
| 382 |
# |
| 383 |
# Do substututions in a string given replacements |
| 384 |
# |
| 385 |
def substituteStrings(inputStr, subPairArray): |
| 386 |
outputStr = "" |
| 387 |
inputStrArray = inputStr.splitlines() |
| 388 |
if inputStrArray[-1] == "": inputStrArray = inputStrArray[0:-1] |
| 389 |
for line in inputStrArray: |
| 390 |
#print("line = '"+line+"'") |
| 391 |
for (str1, str2) in subPairArray: |
| 392 |
#print("(str1, str2) =", (str1, str2)) |
| 393 |
line = line.replace(str1, str2) |
| 394 |
outputStr += (line + "\n") |
| 395 |
return outputStr |
| 396 |
|
| 397 |
|
| 398 |
# |
| 399 |
# Configure a file by substituting strings |
| 400 |
# |
| 401 |
def configureFile(fileInPath, subPairArray, fileOutPath): |
| 402 |
fileInStr = open(fileInPath, 'r').read() |
| 403 |
fileOutStr = substituteStrings(fileInStr, subPairArray) |
| 404 |
open(fileOutPath, 'w').write(fileOutStr) |
| 405 |
|
| 406 |
# |
| 407 |
# Assert an install directory exists |
| 408 |
# |
| 409 |
def assertInstallDirExists(dirPath, inOptions): |
| 410 |
if not os.path.exists(dirPath) and not inOptions.skipOp: |
| 411 |
raise Exception( |
| 412 |
"Error, the install directory '"+dirPath+"'" \ |
| 413 |
" does not exist!") |
| 414 |
|
| 415 |
|
| 416 |
# |
| 417 |
# Write the files load_dev_env.[sh,csh] |
| 418 |
# |
| 419 |
def writeLoadDevEnvFiles(devEnvBaseDir, compilersToolsetBaseDir, inOptions): |
| 420 |
|
| 421 |
subPairArray = [ |
| 422 |
("@DEV_ENV_BASE@", devEnvBaseDir), |
| 423 |
("@CMAKE_VERSION@", cmake_version_default), |
| 424 |
("@AUTOCONF_VERSION@", autoconf_version_default), |
| 425 |
("@GCC_VERSION@", gcc_version_default), |
| 426 |
("@MPICH_VERSION@", mpich_version_default) |
| 427 |
] |
| 428 |
|
| 429 |
load_dev_env_base = inOptions.loadDevEnvFileBaseName |
| 430 |
|
| 431 |
configureFile( |
| 432 |
os.path.join(devtools_install_dir, "load_dev_env.sh.in"), |
| 433 |
subPairArray, |
| 434 |
os.path.join(compilersToolsetBaseDir, load_dev_env_base+".sh") |
| 435 |
) |
| 436 |
|
| 437 |
configureFile( |
| 438 |
os.path.join(devtools_install_dir, "load_dev_env.csh.in"), |
| 439 |
subPairArray, |
| 440 |
os.path.join(compilersToolsetBaseDir, load_dev_env_base+".csh") |
| 441 |
) |
| 442 |
|
| 443 |
|
| 444 |
# |
| 445 |
# Download the source for tool |
| 446 |
# |
| 447 |
def downloadToolSource(toolName, toolVer, gitUrlBase, inOptions): |
| 448 |
|
| 449 |
toolDir = toolName+"-"+toolVer |
| 450 |
|
| 451 |
print("\nDownloading the source for " + toolDir + " ...") |
| 452 |
|
| 453 |
outFile = toolDir+"-download.log" |
| 454 |
workingDir=scratch_dir |
| 455 |
toolSrcBaseDir = toolDir+"-base" |
| 456 |
targetToolSrcDir = workingDir+"/"+toolSrcBaseDir |
| 457 |
|
| 458 |
if os.path.exists(targetToolSrcDir): |
| 459 |
print("\nRemoving existing directory '" + targetToolSrcDir + "' ...") |
| 460 |
cmnd = "rm -rf "+targetToolSrcDir |
| 461 |
if not inOptions.skipOp: |
| 462 |
echoRunSysCmnd(cmnd) |
| 463 |
else: |
| 464 |
print("\nRunning: " + cmnd) |
| 465 |
|
| 466 |
cmnd = "git clone "+gitUrlBase+toolSrcBaseDir+" "+targetToolSrcDir |
| 467 |
if not inOptions.skipOp: |
| 468 |
echoRunSysCmnd(cmnd, workingDir=workingDir, outFile=outFile, timeCmnd=True) |
| 469 |
else: |
| 470 |
print("\nRunning: " + cmnd) |
| 471 |
print("\n Running in working directory: " + workingDir) |
| 472 |
print("\n Writing console output to file " + outFile) |
| 473 |
|
| 474 |
|
| 475 |
# |
| 476 |
# Install downloaded tool from source |
| 477 |
# |
| 478 |
def installToolFromSource(toolName, toolVer, installBaseDir, |
| 479 |
extraEnv, inOptions \ |
| 480 |
): |
| 481 |
|
| 482 |
toolDir = toolName+"-"+toolVer |
| 483 |
|
| 484 |
print("\nInstalling " + toolDir + " ...") |
| 485 |
|
| 486 |
outFile = toolDir+"-install.log" |
| 487 |
workingDir=scratch_dir |
| 488 |
toolInstallDir = installBaseDir+"/"+toolDir |
| 489 |
|
| 490 |
cmnd = devtools_install_dir+"/install-"+toolName+".py" \ |
| 491 |
+" --"+toolName+"-version="+toolVer \ |
| 492 |
+" --untar --configure --build --install --show-final-instructions" \ |
| 493 |
+" --install-dir="+toolInstallDir \ |
| 494 |
+" --parallel="+inOptions.parallelLevel \ |
| 495 |
+" --install-owner="+inOptions.installOwner \ |
| 496 |
+" --install-group="+inOptions.installGroup |
| 497 |
if inOptions.installForAll: |
| 498 |
cmnd += " --install-for-all" |
| 499 |
if not inOptions.skipOp: |
| 500 |
echoRunSysCmnd(cmnd, workingDir=workingDir, outFile=outFile, timeCmnd=True, |
| 501 |
extraEnv=extraEnv) |
| 502 |
else: |
| 503 |
print("\nRunning: " + cmnd) |
| 504 |
print("\n Running in working directory: " + workingDir) |
| 505 |
print("\n Appending environment: " + str(extraEnv)) |
| 506 |
print("\n Writing console output to file " + outFile) |
| 507 |
|
| 508 |
|
| 509 |
# |
| 510 |
# Main |
| 511 |
# |
| 512 |
|
| 513 |
def main(cmndLineArgs): |
| 514 |
|
| 515 |
# |
| 516 |
# Get the command-line options |
| 517 |
# |
| 518 |
|
| 519 |
inOptions = getCmndLineOptions(cmndLineArgs) |
| 520 |
|
| 521 |
if inOptions.skipOp: |
| 522 |
print("\n***") |
| 523 |
print("*** NOTE: --no-op provided, will only trace actions and not touch the filesystem!") |
| 524 |
print("***\n") |
| 525 |
|
| 526 |
commonToolsSelected = \ |
| 527 |
getToolsSelectedArray(inOptions.commonTools, commonToolsArray) |
| 528 |
print("\nSelected common tools = " + str(commonToolsSelected)) |
| 529 |
commonToolsSelectedSet = set(commonToolsSelected) |
| 530 |
|
| 531 |
compilerToolsetSelected = \ |
| 532 |
getToolsSelectedArray(inOptions.compilerToolset, compilerToolsetArray) |
| 533 |
print("\nSelected compiler toolset = " + str(compilerToolsetSelected)) |
| 534 |
compilerToolsetSelectedSet = set(compilerToolsetSelected) |
| 535 |
|
| 536 |
gccVersion=gcc_version_default #ToDo: Make variable! |
| 537 |
|
| 538 |
dev_env_base_dir = inOptions.installDir |
| 539 |
|
| 540 |
### |
| 541 |
print("\n\nA) Setup the install directory <dev_env_base> ='" + |
| 542 |
dev_env_base_dir + "':\n") |
| 543 |
### |
| 544 |
|
| 545 |
dev_env_base_exists = os.path.exists(dev_env_base_dir) |
| 546 |
|
| 547 |
common_tools_dir = os.path.join(dev_env_base_dir, "common_tools") |
| 548 |
common_tools_exists = os.path.exists(common_tools_dir) |
| 549 |
|
| 550 |
compiler_toolset_base_dir = os.path.join(dev_env_base_dir, "gcc-"+gccVersion) |
| 551 |
compiler_toolset_base_exists = os.path.exists(compiler_toolset_base_dir) |
| 552 |
|
| 553 |
compiler_toolset_dir = os.path.join(compiler_toolset_base_dir, "toolset") |
| 554 |
compiler_toolset_exists = os.path.exists(compiler_toolset_dir) |
| 555 |
|
| 556 |
if inOptions.doInitialSetup: |
| 557 |
|
| 558 |
if not dev_env_base_exists: |
| 559 |
print("Creating directory '" + dev_env_base_dir + "' ...") |
| 560 |
if not inOptions.skipOp: |
| 561 |
os.makedirs(dev_env_base_dir) |
| 562 |
|
| 563 |
if not common_tools_exists: |
| 564 |
print("Creating directory '" + common_tools_dir + "' ...") |
| 565 |
if not inOptions.skipOp: |
| 566 |
os.makedirs(common_tools_dir) |
| 567 |
|
| 568 |
# Always create this directory so we can write the load_dev_env.sh script! |
| 569 |
if not compiler_toolset_base_exists: |
| 570 |
print("Creating directory '" + compiler_toolset_base_dir + "' ...") |
| 571 |
if not inOptions.skipOp: |
| 572 |
os.makedirs(compiler_toolset_base_dir) |
| 573 |
|
| 574 |
if not compiler_toolset_exists: |
| 575 |
print("Creating directory '" + compiler_toolset_dir + "' ...") |
| 576 |
if not inOptions.skipOp: |
| 577 |
os.makedirs(compiler_toolset_dir) |
| 578 |
|
| 579 |
print("Writing new files " + inOptions.loadDevEnvFileBaseName + |
| 580 |
".[sh,csh] ...") |
| 581 |
if not inOptions.skipOp: |
| 582 |
writeLoadDevEnvFiles(dev_env_base_dir, compiler_toolset_base_dir, inOptions) |
| 583 |
|
| 584 |
else: |
| 585 |
|
| 586 |
print("Skipping setup of the install directory by request!") |
| 587 |
|
| 588 |
assertInstallDirExists(dev_env_base_dir, inOptions) |
| 589 |
assertInstallDirExists(common_tools_dir, inOptions) |
| 590 |
assertInstallDirExists(compiler_toolset_base_dir, inOptions) |
| 591 |
assertInstallDirExists(compiler_toolset_dir, inOptions) |
| 592 |
|
| 593 |
### |
| 594 |
print("\n\nB) Download all sources for each selected tool:\n") |
| 595 |
### |
| 596 |
|
| 597 |
if inOptions.doDownload: |
| 598 |
|
| 599 |
if "cmake" in commonToolsSelectedSet: |
| 600 |
downloadToolSource("cmake", cmake_version_default, |
| 601 |
inOptions.sourceGitUrlBase, inOptions) |
| 602 |
|
| 603 |
if "autoconf" in commonToolsSelectedSet: |
| 604 |
downloadToolSource("autoconf", autoconf_version_default, |
| 605 |
inOptions.sourceGitUrlBase, inOptions) |
| 606 |
|
| 607 |
if "gcc" in compilerToolsetSelectedSet: |
| 608 |
downloadToolSource("gcc", gcc_version_default, |
| 609 |
inOptions.sourceGitUrlBase, inOptions) |
| 610 |
|
| 611 |
if "mpich" in compilerToolsetSelectedSet: |
| 612 |
downloadToolSource("mpich", mpich_version_default, |
| 613 |
inOptions.sourceGitUrlBase, inOptions) |
| 614 |
|
| 615 |
else: |
| 616 |
|
| 617 |
print("Skipping download of the source for the tools on request!") |
| 618 |
if inOptions.doInstall: |
| 619 |
print("NOTE: The downloads had better be there for the install!") |
| 620 |
|
| 621 |
### |
| 622 |
print("\n\nC) Untar, configure, build and install each selected tool:\n") |
| 623 |
### |
| 624 |
|
| 625 |
if inOptions.doInstall: |
| 626 |
|
| 627 |
if "gitdist" in commonToolsSelectedSet: |
| 628 |
print("\nInstalling gitdist ...") |
| 629 |
echoRunSysCmnd("cp "+pythonUtilsDir+"/gitdist "+common_tools_dir+"/") |
| 630 |
InstallProgramDriver.fixupInstallPermissions(inOptions, common_tools_dir) |
| 631 |
|
| 632 |
if "cmake" in commonToolsSelectedSet: |
| 633 |
installToolFromSource("cmake", cmake_version_default, |
| 634 |
common_tools_dir, None, inOptions ) |
| 635 |
|
| 636 |
if "autoconf" in commonToolsSelectedSet: |
| 637 |
installToolFromSource("autoconf", autoconf_version_default, |
| 638 |
common_tools_dir, None, inOptions ) |
| 639 |
|
| 640 |
if "gcc" in compilerToolsetSelectedSet: |
| 641 |
installToolFromSource("gcc", gcc_version_default, |
| 642 |
compiler_toolset_dir, None, inOptions ) |
| 643 |
|
| 644 |
if "mpich" in compilerToolsetSelectedSet: |
| 645 |
gccInstallDir = compiler_toolset_dir+"/gcc-"+gcc_version_default |
| 646 |
if not os.path.exists(gccInstallDir) and not inOptions.skipOp: |
| 647 |
raise Exception("Error, gcc has not been installed yet." \ |
| 648 |
" Missing directory '"+gccInstallDir+"'") |
| 649 |
LD_LIBRARY_PATH = os.environ.get("LD_LIBRARY_PATH", "") |
| 650 |
installToolFromSource( |
| 651 |
"mpich", |
| 652 |
mpich_version_default, |
| 653 |
compiler_toolset_dir, |
| 654 |
{ |
| 655 |
"CC" : gccInstallDir+"/bin/gcc", |
| 656 |
"CXX" : gccInstallDir+"/bin/g++", |
| 657 |
"FC" : gccInstallDir+"/bin/gfortran", |
| 658 |
"LD_LIBRARY_PATH" : gccInstallDir+"/lib64:"+LD_LIBRARY_PATH |
| 659 |
}, |
| 660 |
inOptions |
| 661 |
) |
| 662 |
|
| 663 |
else: |
| 664 |
|
| 665 |
print("Skipping install of the tools on request!") |
| 666 |
|
| 667 |
### |
| 668 |
print("\n\nD) Final instructions for using installed dev env:") |
| 669 |
### |
| 670 |
|
| 671 |
if inOptions.showFinalInstructions: |
| 672 |
print("\nTo use the new dev env, just source the file:\n") |
| 673 |
print(" source " + compiler_toolset_base_dir + "/load_dev_env.sh\n") |
| 674 |
print("for sh or bash shells (or load_dev_env.csh for csh shell).\n") |
| 675 |
print("TIP: Add this source to your ~/.bash_profile!") |
| 676 |
else: |
| 677 |
print("Skipping on request ...") |
| 678 |
|
| 679 |
if inOptions.skipOp: |
| 680 |
print("\n***") |
| 681 |
print("*** NOTE: --no-op provided, only traced actions that would have been taken!") |
| 682 |
print("***") |
| 683 |
|
| 684 |
print("\n[End]") |
| 685 |
|
| 686 |
|
| 687 |
# |
| 688 |
# Script driver |
| 689 |
# |
| 690 |
|
| 691 |
if __name__ == '__main__': |
| 692 |
try: |
| 693 |
sys.exit(main(sys.argv[1:])) |
| 694 |
except Exception as e: |
| 695 |
print(e) |
| 696 |
print() |
| 697 |
printStackTrace() |
| 698 |
sys.exit(1) |