configure-build.py 2.54 KB
Newer Older
1
#!/usr/bin/python3
Ben Cooksley's avatar
Ben Cooksley committed
2
import os
3 4
import sys
import argparse
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 configure a project to be built.')
10
parser.add_argument('--product', type=str, required=True)
11 12 13 14 15 16 17
parser.add_argument('--project', type=str, required=True)
parser.add_argument('--branchGroup', type=str, required=True)
parser.add_argument('--platform', type=str, required=True)
parser.add_argument('--installTo', type=str, required=True)
arguments = parser.parse_args()

# Load our build specification, which governs how we handle this build
18
buildSpecification = BuildSpecs.Loader( product=arguments.product, project=arguments.project, branchGroup=arguments.branchGroup, platform=arguments.platform )
19 20 21 22 23 24 25 26 27 28 29

# Determine the environment we need to provide to any configure system (like CMake or Autotools)
buildEnvironment = EnvironmentHandler.generateFor( installPrefix=arguments.installTo )

# 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'] )

# Make sure the build location exists
if not os.path.isdir(buildLocation):
30
	os.makedirs(buildLocation)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

# Detect the appropriate build system to use
# We always do this even if the build specification says not to in order to keep the code cleaner
buildSystemHandler = BuildSystem.detect( sourcesLocation )

# Are we allowed to configure the build system using the handler?
if buildSpecification['detect-build-system'] and buildSystemHandler is not None:
	# Ask the build system handler to configure the project
	if not buildSystemHandler.configure( buildLocation, sourcesLocation, arguments.installTo, buildSpecification, buildEnvironment ):
		# Looks like the handler failed to configure the project - let's bail!
		sys.exit(1)

# Now we run any additional configure commands specified in the build specification
for configureCommand in buildSpecification['configure-commands']:
	# Now run it
	try:
		commandToRun = BuildSystem.substituteCommandTokens( configureCommand, sources=sourcesLocation, installPrefix=arguments.installTo )
		subprocess.check_call( commandToRun, stdout=sys.stdout, stderr=sys.stderr, shell=True, cwd=buildLocation, env=buildEnvironment )
	except Exception:
		sys.exit(1)

# All done!
sys.exit(0)