install-build.py 2.43 KB
Newer Older
1 2 3 4
#!/usr/bin/python3
import os
import sys
import argparse
Ben Cooksley's avatar
Ben Cooksley committed
5
import subprocess
6 7 8 9
from helperslib import BuildSpecs, BuildSystem, CommonUtils, EnvironmentHandler

# Parse the command line arguments we've been given
parser = argparse.ArgumentParser(description='Utility to install a project, diverting the installation for later capture if requested.')
10
parser.add_argument('--product', type=str, required=True)
11 12 13
parser.add_argument('--project', type=str, required=True)
parser.add_argument('--branchGroup', type=str, required=True)
parser.add_argument('--platform', type=str, required=True)
14
parser.add_argument('--installTo', type=str, required=True)
15 16 17 18
parser.add_argument('--divertTo', type=str)
arguments = parser.parse_args()

# Load our build specification, which governs how we handle this build
19
buildSpecification = BuildSpecs.Loader( product=arguments.product, project=arguments.project, branchGroup=arguments.branchGroup, platform=arguments.platform )
20 21

# Determine the environment we need to provide for the installation process
22
buildEnvironment = EnvironmentHandler.generateFor( installPrefix=arguments.installTo )
23 24 25 26 27 28 29 30 31 32 33 34

# Determine where our source code is checked out to and where we will be building it
# We'll assume that the directory we're running from is where the sources are located
sourcesLocation = os.getcwd()
buildLocation = CommonUtils.buildDirectoryForSources( sources=sourcesLocation, inSourceBuild=buildSpecification['in-source-build'] )

# Do we need to divert the installation?
if arguments.divertTo != None:
	# Set the appropriate environment variables to ensure we can capture make install's output later on
	buildEnvironment['DESTDIR'] = arguments.divertTo
	buildEnvironment['INSTALL_ROOT'] = arguments.divertTo

35 36 37 38 39 40
# Determine the build command we want to use
# Just about all of our platforms support standard "make" so that is our default...
makeCommand = "make -j {cpuCount} -l {maximumLoad} install"
# Windows is a bit special though
if sys.platform == 'win32':
	# We use NMake on Windows at the moment
41
	makeCommand = "jom install"
42
# FreeBSD also likes to do things slightly different
43
if sys.platform == 'freebsd12':
44
	makeCommand = "gmake -j {cpuCount} install"
45

46 47
# Install the project
try:
48
	commandToRun = BuildSystem.substituteCommandTokens( makeCommand )
49 50 51 52 53
	subprocess.check_call( commandToRun, stdout=sys.stdout, stderr=sys.stderr, shell=True, cwd=buildLocation, env=buildEnvironment )
except Exception:
	sys.exit(1)

# The project was installed successfully
54
sys.exit(0)