install-build.py 3.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 43
# FreeBSD also likes to do things slightly different
if sys.platform == 'freebsd11':
44
	makeCommand = "gmake -j {cpuCount} install"
45

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

53 54 55 56 57
# Do we need to run update-mime-database?
# First let's determine the appropriate prefix...
# This will differ depending on whether we are diverting the install or not
installRoot = arguments.installTo
if arguments.divertTo != None:
Ben Cooksley's avatar
Ben Cooksley committed
58
	installRoot = os.path.join( arguments.divertTo, CommonUtils.makePathRelative(arguments.installTo) )
59 60 61 62 63 64 65 66 67 68 69 70

# Determine what mime directory we will have
# On most platforms this will be $prefix/share/mime
mimeDirectory = os.path.join( installRoot, 'share', 'mime' )
# Except on Windows... where it is bin/data/mime/
if sys.platform == 'win32':
	mimeDirectory = os.path.join( installRoot, 'bin', 'data', 'mime' )

# Make sure the mime directory exists - otherwise there is no point to running update-mime-database
if os.path.exists( mimeDirectory ):
	# Let's run update-mime-database
	commandToRun = BuildSystem.substituteCommandTokens( 'update-mime-database "' + mimeDirectory + '"'  )
71
	subprocess.check_call( commandToRun, stdout=sys.stdout, stderr=sys.stderr, shell=True, env=buildEnvironment )
72

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