Skip to content

Commit

Permalink
update macos targets
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansson committed Apr 3, 2022
1 parent e0e00ff commit f2b3c49
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 24 deletions.
4 changes: 2 additions & 2 deletions build/ninja/clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def initialize(self, project, archs, configs, includepaths, dependlibs, libpaths
self.cxxcmd = '$toolchain$cxx -MMD -MT $out -MF $out.d $includepaths $moreincludepaths $cxxflags $carchflags $cconfigflags $cmoreflags $cxxenvflags -c $in -o $out'
self.ccdeps = 'gcc'
self.ccdepfile = '$out.d'
self.arcmd = self.rmcmd('$out') + ' && $toolchain$ar crs $ararchflags $arflags $arenvflags $out $in'
self.arcmd = self.rmcmd('$out') + ' && $toolchain$ar crsD $ararchflags $arflags $arenvflags $out $in'
if self.target.is_windows():
self.linkcmd = '$toolchain$link $libpaths $configlibpaths $linkflags $linkarchflags $linkconfigflags $linkenvflags /debug /nologo /subsystem:console /dynamicbase /nxcompat /manifest /manifestuac:\"level=\'asInvoker\' uiAccess=\'false\'\" /tlbid:1 /pdb:$pdbpath /out:$out $in $libs $archlibs $oslibs $frameworks'
self.dllcmd = self.linkcmd + ' /dll'
Expand All @@ -51,7 +51,7 @@ def initialize(self, project, archs, configs, includepaths, dependlibs, libpaths
'-fno-math-errno','-ffinite-math-only', '-funsafe-math-optimizations',
'-fno-trapping-math', '-ffast-math']
self.cwarnflags = ['-W', '-Werror', '-pedantic', '-Wall', '-Weverything',
'-Wno-c++98-compat', '-Wno-padded', '-Wno-documentation-unknown-command', '-Wno-declaration-after-statement',
'-Wno-c++98-compat', '-Wno-padded', '-Wno-documentation-unknown-command',
'-Wno-implicit-fallthrough', '-Wno-static-in-inline', '-Wno-reserved-id-macro', '-Wno-disabled-macro-expansion']
self.cmoreflags = []
self.mflags = []
Expand Down
22 changes: 16 additions & 6 deletions build/ninja/codesign.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
parser.add_argument('--config', type=str,
help = 'Build configuration',
default = '')
parser.add_argument('--entitlements', type=str,
help = 'Entitlements file',
default = '')
options = parser.parse_args()

androidprefs = {}
Expand Down Expand Up @@ -93,13 +96,13 @@ def codesign_ios():
if not 'provisioning' in iosprefs:
iosprefs['provisioning'] = options.provisioning

sdkdir = subprocess.check_output( [ 'xcrun', '--sdk', 'iphoneos', '--show-sdk-path' ] ).strip()
sdkdir = subprocess.check_output( [ 'xcrun', '--sdk', 'iphoneos', '--show-sdk-path' ] ).decode().strip().splitlines()[-1]
entitlements = os.path.join( sdkdir, 'Entitlements.plist' )
plistpath = os.path.join( options.builddir, 'Entitlements.xcent' )

platformpath = subprocess.check_output( [ 'xcrun', '--sdk', 'iphoneos', '--show-sdk-platform-path' ] ).strip()
platformpath = subprocess.check_output( [ 'xcrun', '--sdk', 'iphoneos', '--show-sdk-platform-path' ] ).decode().strip().splitlines()[-1]
localpath = platformpath + "/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
plutil = "PATH=" + localpath + " " + subprocess.check_output( [ 'xcrun', '--sdk', 'iphoneos', '-f', 'plutil' ] ).strip()
plutil = "PATH=" + localpath + " " + subprocess.check_output( [ 'xcrun', '--sdk', 'iphoneos', '-f', 'plutil' ] ).decode().strip().splitlines()[-1]

shutil.copyfile( entitlements, plistpath )
os.system( plutil + ' -convert xml1 ' + plistpath )
Expand Down Expand Up @@ -142,16 +145,23 @@ def codesign_macos():
macosprefs['bundleidentifier'] = options.bundle
if not 'provisioning' in macosprefs:
macosprefs['provisioning'] = options.provisioning
if not 'entitlements' in macosprefs:
macosprefs['entitlements'] = options.entitlements

codesign_allocate = subprocess.check_output( [ 'xcrun', '--sdk', 'macosx', '-f', 'codesign_allocate' ] ).strip()
sdkdir = subprocess.check_output( [ 'xcrun', '--sdk', 'macosx', '--show-sdk-path' ] ).strip()
codesign_allocate = subprocess.check_output( [ 'xcrun', '--sdk', 'macosx', '-f', 'codesign_allocate' ] ).decode().strip().splitlines()[-1]
sdkdir = subprocess.check_output( [ 'xcrun', '--sdk', 'macosx', '--show-sdk-path' ] ).decode().strip().splitlines()[-1]
entitlements = os.path.join( sdkdir, 'Entitlements.plist' )

if os.path.isfile( os.path.join( options.file, 'Contents', '_CodeSignature', 'CodeResources' ) ):
os.remove( os.path.join( options.file, 'Contents', '_CodeSignature', 'CodeResources' ) )

if 'signature' in macosprefs:
os.system( 'export CODESIGN_ALLOCATE=' + codesign_allocate + '; /usr/bin/codesign --force --sign ' + macosprefs['signature'] + ' ' + options.file )
command = 'export CODESIGN_ALLOCATE=' + codesign_allocate + '; /usr/bin/codesign --force --sign "' + macosprefs['signature'] + '" -o runtime '
if ('entitlements' in macosprefs) and (macosprefs['entitlements'] != '') and (macosprefs['entitlements'] != 'none'):
command = command + '--entitlements ' + macosprefs['entitlements'] + ' --generate-entitlement-der '
command = command + options.file
# print(command)
os.system(command)

if os.path.isfile( os.path.join( options.file, 'Contents', '_CodeSignature', 'CodeResources' ) ):
os.utime( os.path.join( options.file, 'Contents', '_CodeSignature', 'CodeResources' ), None )
Expand Down
2 changes: 1 addition & 1 deletion build/ninja/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def initialize(self, project, archs, configs, includepaths, dependlibs, libpaths
self.cxxcmd = '$toolchain$cxx -MMD -MT $out -MF $out.d $includepaths $moreincludepaths $cxxflags $carchflags $cconfigflags $cmoreflags $cxxenvflags -c $in -o $out'
self.ccdeps = 'gcc'
self.ccdepfile = '$out.d'
self.arcmd = self.rmcmd('$out') + ' && $toolchain$ar crs $ararchflags $arflags $arenvflags $out $in'
self.arcmd = self.rmcmd('$out') + ' && $toolchain$ar crsD $ararchflags $arflags $arenvflags $out $in'
self.linkcmd = '$toolchain$link $libpaths $configlibpaths $linkflags $linkarchflags $linkconfigflags $linkenvflags -o $out $in $libs $archlibs $oslibs'

#Base flags
Expand Down
25 changes: 16 additions & 9 deletions build/ninja/plist.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import unicodedata

def normalize_char(c):
try:
UNICODE_EXISTS = bool(type(unicode))
except NameError:
unicode = lambda s: str(s)
try:
cname = unicodedata.name( unicode(c) )
cname = cname[:cname.index( ' WITH' )]
Expand All @@ -29,7 +33,7 @@ def replace_var( str, var, val ):

parser = argparse.ArgumentParser( description = 'PList utility for Ninja builds' )
parser.add_argument( 'files',
metavar = 'file', type=file, nargs='+',
metavar = 'file', type=open, nargs='+',
help = 'Source plist file' )
parser.add_argument( '--exename', type=str,
help = 'Executable name',
Expand Down Expand Up @@ -59,15 +63,18 @@ def replace_var( str, var, val ):
options.target = 'macos'
if not options.deploymenttarget:
if options.target == 'macos':
options.deploymenttarget = '10.7'
options.deploymenttarget = '12.0'
else:
options.deploymenttarget = '6.0'
options.deploymenttarget = '10.0'

buildversion = subprocess.check_output( [ 'sw_vers', '-buildVersion' ] ).strip()
buildversion = subprocess.check_output( [ 'sw_vers', '-buildVersion' ] ).decode().strip()

#Merge inputs using first file as base
#Merge input plists using first file as base
lines = []
for f in options.files:
_, extension = os.path.splitext(f.name)
if extension != '.plist':
continue
if lines == []:
lines += [ line.strip( '\n\r' ) for line in f ]
else:
Expand Down Expand Up @@ -171,8 +178,8 @@ def replace_var( str, var, val ):

#run plutil -convert binary1
sdk = 'iphoneos'
platformpath = subprocess.check_output( [ 'xcrun', '--sdk', sdk, '--show-sdk-platform-path' ] ).strip()
platformpath = subprocess.check_output( [ 'xcrun', '--sdk', sdk, '--show-sdk-platform-path' ] ).decode().strip()
localpath = platformpath + "/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
plutil = "PATH=" + localpath + " " + subprocess.check_output( [ 'xcrun', '--sdk', sdk, '-f', 'plutil' ] ).strip()
os.system( plutil + ' -convert binary1 ' + options.output )

plutil = "PATH=" + localpath + " " + subprocess.check_output( [ 'xcrun', '--sdk', sdk, '-f', 'plutil' ] ).decode().strip()
plcommand = plutil + ' -convert binary1 ' + options.output
os.system( plcommand )
5 changes: 5 additions & 0 deletions build/ninja/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def check_output(args):
import subprocess
return subprocess.check_output(args).decode().strip()

def check_last_output(args):
import subprocess
output = subprocess.check_output(args).decode().strip()
return output.splitlines()[-1]

def supported_toolchains():
return ['msvc', 'gcc', 'clang', 'intel']

Expand Down
18 changes: 12 additions & 6 deletions build/ninja/xcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def build_toolchain(self):
sdk = 'iphoneos'
deploytarget = 'IPHONEOS_DEPLOYMENT_TARGET=' + self.deploymenttarget

platformpath = toolchain.check_output(['xcrun', '--sdk', sdk, '--show-sdk-platform-path'])
platformpath = toolchain.check_last_output(['xcrun', '--sdk', sdk, '--show-sdk-platform-path'])
localpath = platformpath + "/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"

self.plist = "PATH=" + localpath + " " + toolchain.check_output(['xcrun', '--sdk', sdk, '-f', 'plutil'])
self.xcassets = "PATH=" + localpath + " " + toolchain.check_output(['xcrun', '--sdk', sdk, '-f', 'actool'])
self.xib = "PATH=" + localpath + " " + toolchain.check_output(['xcrun', '--sdk', sdk, '-f', 'ibtool'])
self.dsymutil = "PATH=" + localpath + " " + toolchain.check_output(['xcrun', '--sdk', sdk, '-f', 'dsymutil'])
self.plist = "PATH=" + localpath + " " + toolchain.check_last_output(['xcrun', '--sdk', sdk, '-f', 'plutil'])
self.xcassets = "PATH=" + localpath + " " + toolchain.check_last_output(['xcrun', '--sdk', sdk, '-f', 'actool'])
self.xib = "PATH=" + localpath + " " + toolchain.check_last_output(['xcrun', '--sdk', sdk, '-f', 'ibtool'])
self.dsymutil = "PATH=" + localpath + " " + toolchain.check_last_output(['xcrun', '--sdk', sdk, '-f', 'dsymutil'])

self.plistcmd = 'build/ninja/plist.py --exename $exename --prodname $prodname --bundle $bundleidentifier --target $target --deploymenttarget $deploymenttarget --output $outpath $in'
if self.target.is_macos():
Expand All @@ -58,7 +58,7 @@ def build_toolchain(self):
' --output-partial-info-plist $outplist --auto-activate-custom-fonts' \
' --output-format human-readable-text --compile $outpath $in &> /dev/null '
self.dsymutilcmd = '$dsymutil $in -o $outpath'
self.codesigncmd = 'build/ninja/codesign.py --target $target --prefs codesign.json --builddir $builddir --binname $binname --config $config $outpath'
self.codesigncmd = 'build/ninja/codesign.py --target $target --prefs codesign.json --builddir $builddir --binname $binname --config $config --entitlements $entitlements $outpath'

def parse_default_variables(self, variables):
if not variables:
Expand Down Expand Up @@ -106,6 +106,7 @@ def write_variables(self, writer):
writer.variable('dsymutil', self.dsymutil)
writer.variable('bundleidentifier', syntax.escape(self.bundleidentifier))
writer.variable('deploymenttarget', self.deploymenttarget)
writer.variable('entitlements', 'none')

def write_rules(self, writer):
writer.rule('dsymutil', command = self.dsymutilcmd, description = 'DSYMUTIL $outpath')
Expand Down Expand Up @@ -147,6 +148,7 @@ def app(self, toolchain, writer, module, archbins, outpath, binname, basepath, c
plists = []
assetsplists = []
xibplists = []
entitlements = []

#All resource output files
outfiles = []
Expand Down Expand Up @@ -183,6 +185,8 @@ def app(self, toolchain, writer, module, archbins, outpath, binname, basepath, c
has_resources = True
elif resource.endswith('.plist'):
plists += [os.path.join(basepath, module, resource)]
elif resource.endswith('.entitlements'):
entitlements += [os.path.join(basepath, module, resource)]

#Extra output files/directories
outfiles = []
Expand Down Expand Up @@ -213,6 +217,8 @@ def app(self, toolchain, writer, module, archbins, outpath, binname, basepath, c
elif self.target.is_macos():
if self.provisioning != '':
codesignvars += [('provisioning', self.provisioning)]
if len(entitlements) > 0:
codesignvars += [('entitlements', entitlements[0])]
writer.build([os.path.join(apppath, 'Contents', '_CodeSignature', 'CodeResources'), os.path.join(apppath, 'Contents', '_CodeSignature'), os.path.join(apppath, 'Contents'), apppath], 'codesign', builtbin, implicit = builtres + [os.path.join('build', 'ninja', 'codesign.py')], variables = codesignvars)

return builtbin + builtsym + builtres

0 comments on commit f2b3c49

Please sign in to comment.