Skip to content

Commit

Permalink
Merge pull request PixarAnimationStudios#210 from autodesk-forks/adsk…
Browse files Browse the repository at this point in the history
…-dev-ios

Merge PR PixarAnimationStudios#2035 APPLE: iOS Build script minimal
  • Loading branch information
rsanthanam authored and GitHub Enterprise committed Jan 5, 2023
2 parents 14414fe + 6494b5b commit 1379965
Show file tree
Hide file tree
Showing 38 changed files with 132,133 additions and 182 deletions.
126 changes: 108 additions & 18 deletions build_scripts/apple_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,20 @@
import platform
import shlex
import subprocess
import re

TARGET_NATIVE = "native"
TARGET_X86 = "x86_64"
TARGET_ARM64 = "arm64"
TARGET_UNIVERSAL = "universal"
TARGET_IOS = "ios"

def GetBuildTargets():
return [TARGET_NATIVE,
TARGET_X86,
TARGET_ARM64,
TARGET_UNIVERSAL]
TARGET_UNIVERSAL,
TARGET_IOS]

def GetBuildTargetDefault():
return TARGET_NATIVE;
Expand All @@ -57,14 +60,69 @@ def GetLocale():
return sys.stdout.encoding or locale.getdefaultlocale()[1] or "UTF-8"

def GetCommandOutput(command):
"""Executes the specified command and returns output or None."""
"""Executes the specified command and returns output or None.
If command contains pipes (i.e '|'s), creates a subprocess for
each pipe in command, returning the output from the last subcommand
or None if any of the subcommands result in a CalledProcessError"""

result = None

args = shlex.split(command)
commands = []
cmd_args = []
while args:
arg = args.pop(0)
if arg == '|':
commands.append((cmd_args))
cmd_args = []
else:
cmd_args.append(arg)
commands.append((cmd_args))

pipes = []
while len(commands) > 1:
# We have some pipes
command = commands.pop(0)
stdin = pipes[-1].stdout if pipes else None
try:
pipe = subprocess.Popen(command, stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
pipes.append(pipe)
except subprocess.CalledProcessError:
return None

# The last command actually returns a result
command = commands[0]
try:
return subprocess.check_output(
shlex.split(command),
stderr=subprocess.STDOUT).decode(GetLocale(), 'replace').strip()
stdin = pipes[-1].stdout if pipes else None
result = subprocess.check_output(
command,
stdin = stdin,
stderr=subprocess.STDOUT).decode('utf-8').strip()
except subprocess.CalledProcessError:
pass
return None

# clean-up
for pipe in pipes:
pipe.wait()

return result

def GetFrameworkRoot():
pathWithFramework = next(path for path in sys.path if (
"Python.framework" in path or "Python3.framework" in path))
splitPath = pathWithFramework.split('/')
index = 0
for p in range(0, len(splitPath)):
if splitPath[index] == "Python.framework" or \
splitPath[index] == "Python3.framework":
break
index = index+1
if index == len(splitPath):
raise Exception("Could not find Python framework")
#This should get Python.framework/Version/3.x
frameworkSplitPath = splitPath[0:index+3]
frameworkPath = "/".join(frameworkSplitPath)
return frameworkPath

def GetTargetArmArch():
# Allows the arm architecture string to be overridden by
Expand All @@ -85,7 +143,7 @@ def GetTargetArch(context):
else:
if context.targetX86:
macTargets = TARGET_X86
if context.targetARM64:
if context.targetARM64 or context.targetIos:
macTargets = GetTargetArmArch()
if context.targetUniversal:
macTargets = TARGET_X86 + ";" + GetTargetArmArch()
Expand All @@ -106,6 +164,8 @@ def GetTargetArchPair(context):
primaryArch = TARGET_X86
if context.targetARM64:
primaryArch = GetTargetArmArch()
if context.targetIos:
primaryArch = TARGET_IOS
if context.targetUniversal:
primaryArch = GetHostArch()
if (primaryArch == TARGET_X86):
Expand All @@ -128,6 +188,7 @@ def SetTarget(context, targetName):
context.targetX86 = (targetName == TARGET_X86)
context.targetARM64 = (targetName == GetTargetArmArch())
context.targetUniversal = (targetName == TARGET_UNIVERSAL)
context.targetIos = (targetName == TARGET_IOS)
if context.targetUniversal and not SupportsMacOSUniversalBinaries():
self.targetUniversal = False
raise ValueError(
Expand All @@ -138,6 +199,7 @@ def GetTargetName(context):
TARGET_X86 if context.targetX86 else
GetTargetArmArch() if context.targetARM64 else
TARGET_UNIVERSAL if context.targetUniversal else
TARGET_IOS if context.targetIos else
"")

devout = open(os.devnull, 'w')
Expand All @@ -150,26 +212,54 @@ def ExtractFilesRecursive(path, cond):
files.append(os.path.join(r, file))
return files

def CodesignFiles(files):
SDKVersion = subprocess.check_output(
['xcodebuild', '-version']).strip()[6:10]
codeSignIDs = subprocess.check_output(
['security', 'find-identity', '-vp', 'codesigning'])
def _GetCodeSignStringFromTerminal():
codeSignIDs = subprocess.check_output(['security',
'find-identity', '-vp', 'codesigning'])
return codeSignIDs

def GetCodeSignID():
codeSignIDs = _GetCodeSignStringFromTerminal()
codeSignID = "-"
if os.environ.get('CODE_SIGN_ID'):
codeSignID = os.environ.get('CODE_SIGN_ID')
elif float(SDKVersion) >= 11.0 and \
codeSignIDs.find(b'Apple Development') != -1:
codeSignID = "Apple Development"
elif codeSignIDs.find(b'Mac Developer') != -1:
codeSignID = "Mac Developer"
else:
try:
codeSignID = codeSignIDs.decode("utf-8").split()[1]
except:
raise Exception("Unable to parse codesign ID")
return codeSignID

def GetCodeSignIDHash():
codeSignIDs = _GetCodeSignStringFromTerminal()
try:
return re.findall(r'\(.*?\)', codeSignIDs.decode("utf-8"))[0][1:-1]
except:
raise Exception("Unable to parse codesign ID hash")

def GetDevelopmentTeamID():
if os.environ.get("DEVELOPMENT_TEAM"):
return os.environ.get("DEVELOPMENT_TEAM")
codesignID = GetCodeSignIDHash()
x509subject = GetCommandOutput('security find-certificate -c {}'
' -p | openssl x509 -subject | head -1'.format(codesignID)).strip()
# Extract the Organizational Unit (OU field) from the cert
try:
team = [elm for elm in x509subject.split(
'/') if elm.startswith('OU')][0].split('=')[1]
if team is not None and team != "":
return team
except Exception as ex:
raise Exception("No development team found with exception " + ex)

def CodesignFiles(files):
codeSignID = GetCodeSignID()

for f in files:
subprocess.call(['codesign', '-f', '-s', '{codesignid}'
.format(codesignid=codeSignID), f],
.format(codesignid=codeSignID), f],
stdout=devout, stderr=devout)


def Codesign(install_path, verbose_output=False):
if not MacOS():
return False
Expand Down
Loading

0 comments on commit 1379965

Please sign in to comment.