Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS rendering changes #2263

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 101 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,52 @@ 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 GetTargetArmArch():
# Allows the arm architecture string to be overridden by
Expand All @@ -85,7 +126,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 +147,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 +171,17 @@ 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.targetIos:
sdkStr = GetCommandOutput('xcodebuild -showsdks')
sdkStrSpl = sdkStr.split()
for s in sdkStrSpl:
if s.startswith('iphoneos'):
s = s.replace('iphoneos', "")
context.iosVersion = s
break
else:
context.iosVersion = None
if context.targetUniversal and not SupportsMacOSUniversalBinaries():
self.targetUniversal = False
raise ValueError(
Expand All @@ -138,6 +192,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 +205,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