JD2022-TU1/main/extern/gear4/buildfolder/generation/run_hg.py

103 lines
4.2 KiB
Python

import os
import platform
import sys
import subprocess
# Function to parse the ouput of xcodebuild on Mac and extract the sdk switch to be used depending on the target platform
def parseXcodebuild(targPlatform):
result=''
# Deduce pattern and subPattern from target platform
if targPlatform == 'mac':
patternStr = 'OS X SDKs'
subPatternStr = 'OS X'
elif targPlatform == 'ios':
patternStr = 'iOS SDKs'
subPatternStr = 'iOS'
else:
return result
# Ask xcodebuild for the supported SDKs list
p1 = subprocess.Popen(['xcodebuild', '-showsdks'], stdout=subprocess.PIPE, stderr=subprocess.PIPE);
stringList = p1.communicate()[0].splitlines()
patternFound = False
# Parse supported SDKs list
for s in stringList:
if not patternFound and s.find(patternStr) != -1: # Pattern must be found once and only once
patternFound = True
else:
if patternFound:
if s.find(subPatternStr) != -1: # Look for subpattern. Only the latest one is kept
# Next line should do something equivalent to what the 'tail -1|cut -f3' used to be doing in the shell script
result = s.split('-')[-1].split(' ')[-1]
if not s and result:
# Given the found sdk version, ask for the system path to xcodebuild
p2 = subprocess.Popen(['xcodebuild', '-version', '-sdk', result, 'Path'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = p2.communicate()[0].rstrip('\n') + '/usr/include'
return result
# If the sdk we look for is the last one in the list, we would end-up here
if result:
p2 = subprocess.Popen(['xcodebuild', '-version', '-sdk', result, 'Path'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = p2.communicate()[0].rstrip('\n') + '/usr/include'
return result
# Basically update paths and names depending on the platform we are running this script on
def adaptVariablesToHostPlatform(tgtPlatform, hgParams=[]):
# Default values for when we run this script on Windows
hgParams.append('\\')
hgParams.append('../../tools/HG')
hgParams.append('HG.exe')
hgParams.append("--msvcmode")
# Check for platform
platformName = platform.system()
if platformName == 'Darwin': # We are on Mac
hgParams[0] = '/'
hgParams[2] = './HG_mac'
hgParams[3] = ''
hgParams.append(parseXcodebuild(tgtPlatform))
elif platformName == 'Linux': # We are on Linux
hgParams[0] = '/'
hgParams[2] = './HG_linux'
hgParams[3] = ''
hgParams.append('/usr/include/')
else: # Assume we are on Windows
hgParams.append(os.getenv('VS100COMNTOOLS')+'..\\..\\VC\\include')
return hgParams
def runHG(targetPlatform):
print 'Running HG for platform ' + targetPlatform
# Adjust variables depending on the OS we are running
hgParam = adaptVariablesToHostPlatform(targetPlatform)
# Change working directory to the HG we are going to use
working_dir = os.getcwd()
os.chdir(hgParam[1])
# Run HG for each satellite folder
satellites = [ 'gear_core' ]
sep = hgParam[0]
root_dir = '..' + sep + '..'
for s in satellites:
# Create config hierarchy
config_path = root_dir + sep + s + sep + 'base' + sep + 'config' + sep
if not os.path.exists(config_path):
os.makedirs(config_path)
# Prepare HG command line
print 'Updating header for platform ' + targetPlatform
print 'Satellite ' + s
blob_file = s + '.cpp'
print 'Blobfile ' + blob_file
root_sat_dir = root_dir + sep + s + sep
eal_sources_dir = root_dir + sep + 'eal' + sep + 'sources'
module_root = root_dir + sep + s + sep + 'base'
cmdLine = hgParam[2] + ' ' + root_sat_dir + blob_file + ' --platform ' + targetPlatform + ' ' + hgParam[3] + ' -I \"' + hgParam[4] + '\"' + ' -I \"' + root_dir + '\"' + ' -I \"' + eal_sources_dir + '\"' + ' --moduleroot \"' + module_root + '\"'
print 'Running: ' + cmdLine
os.system(cmdLine)
# Change back directory
os.chdir(working_dir)
if __name__ == '__main__':
runHG(sys.argv[1])