@@ -320,53 +320,20 @@ end
320320
321321---- ----------------------------------------------------------------------------
322322
323- local function getCodesignScript ( entitlements , path , identity , developerBase )
324-
325- codesign_allocate = xcodetoolhelper [' codesign_allocate' ]
326- codesign = xcodetoolhelper [' codesign' ]
327-
328- -- Remove any extended macOS attributes from files in the bundle because
329- -- codesign doesn't like them
330- local removeXattrs = " /usr/bin/xattr -cr " .. quoteString (path ) .. " && "
331-
332- -- quote for spaces
333- codesign_allocate = quoteString (codesign_allocate )
334- codesign = quoteString (codesign )
335- developerBase = quoteString (developerBase )
336-
337- local devbase_shell = " DEVELOPER_BASE=" .. developerBase .. " \n "
338- local export_path = [==[
339- export PATH="$DEVELOPER_BASE/Platforms/iPhoneOS.platform/Developer/usr/bin:$DEVELOPER_BASE/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
340- ]==]
341-
342- local script = ' export CODESIGN_ALLOCATE=' .. codesign_allocate .. ' \n '
343-
344- local quotedpath = quoteString ( path )
345- local cmd = removeXattrs .. codesign .. " --verbose -f -s " .. quoteString (identity ).. " --entitlements " .. entitlements .. " " .. quotedpath
346-
347- -- print("getCodesignScript: codesign: ".. codesign)
348- -- print("getCodesignScript: codesign_allocate: ".. codesign_allocate)
349- -- print("getCodesignScript: ".. devbase_shell .. export_path .. script .. cmd)
350- return devbase_shell .. export_path .. script .. cmd
351- end
352-
353- local function getCodesignAPPXScriptAndPackage (path , identity , entitlements , developerBase , bundleId )
323+ local function getCodesignAPPXScriptAndPackage (path , identity , entitlements , developerBase , bundleId , isBuildForDistribution )
354324
355325 local codesign_allocate = xcodetoolhelper [' codesign_allocate' ]
356326 local codesign = xcodetoolhelper [' codesign' ]
357327
358328 -- Remove extended attributes that may interfere with codesign
359-
360329 local appxPath = path :gsub (' ["\' ]' , " " ) .. " /PlugIns"
361- local removeXattrs = " /usr/bin/xattr -cr " .. quoteString (appxPath )
330+ local removeXattrs = " /usr/bin/xattr -cr " .. quoteString (appxPath )
362331
363332 -- Quote paths to handle spaces
364333 codesign_allocate = quoteString (codesign_allocate )
365334 codesign = quoteString (codesign )
366335 developerBase = quoteString (developerBase )
367336
368-
369-
370337 -- Shell script setup
371338 local devbase_shell = " DEVELOPER_BASE=" .. developerBase .. " \n "
372339 local export_path = [==[
@@ -382,8 +349,6 @@ export PATH="$DEVELOPER_BASE/Platforms/iPhoneOS.platform/Developer/usr/bin:$DEVE
382349 if lfs .attributes (appxPath , " mode" ) == " directory" then
383350 for file in lfs .dir (appxPath ) do
384351 if file :match (" %.appex$" ) then
385- ---- Check if the mobile provision proflie file exists
386- --
387352 local appexPath = appxPath .. " /" .. file
388353 local infoPlist = quoteString (appexPath .. " /Info.plist" )
389354
@@ -395,24 +360,33 @@ export PATH="$DEVELOPER_BASE/Platforms/iPhoneOS.platform/Developer/usr/bin:$DEVE
395360 local setBundleIdCmd = " newBundleId=\" " .. bundleId .. " .$(" .. getBundleIdCmd .. " )\" && " ..
396361 " /usr/bin/plutil -replace CFBundleIdentifier -string \" $newBundleId\" " .. infoPlist
397362
398- local bundleIdOutput = io.popen (getBundleIdCmd ):read (" *a" ):gsub (" %s+" , " " ) -- Clean up any extra spaces
363+ local bundleIdOutput = io.popen (getBundleIdCmd ):read (" *a" ):gsub (" %s+" , " " ) -- Clean up any extra spaces
399364
400365 -- Run the command to update CFBundleIdentifier
401366 runScript (setBundleIdCmd )
402- local mobileProvisionPath = path :gsub (' ["\' ]' , " " ) .. " /iOSAppxFiles/" .. bundleIdOutput .. " /embedded.mobileprovision"
403- local mobileProvisionExists = lfs .attributes (mobileProvisionPath , " mode" ) == " file"
404- if ( not mobileProvisionExists ) then
405- print (" Warning: Cannot find mobile provision profile for " .. bundleIdOutput .. " at " .. " yourProject/iOSAppxFiles/" .. bundleIdOutput .. " /embedded.mobileprovision" .. " This may cause issues with your app." )
406- else
407- -- Copy the mobile provision profile to the .appex bundle and delete the old one
408- local copyMobileProvisionCmd = " cp " .. quoteString (mobileProvisionPath ) .. " " .. quoteString (appexPath .. " /embedded.mobileprovision" ) .. " && rm " .. quoteString (mobileProvisionPath )
409- runScript (copyMobileProvisionCmd )
410-
411- -- Append signing command for .appex
412- cmd = cmd .. " && " .. codesign .. " --verbose -f -s " .. quoteString (identity ) ..
413- " --entitlements " .. entitlements .. " " .. quoteString (appexPath )
414- end
415-
367+
368+ -- Determine which mobile provision profile to use based on `isBuildForDistribution`
369+ local mobileProvisionPath = path :gsub (' ["\' ]' , " " ) .. " /iOSAppxFiles/" .. bundleIdOutput .. " /"
370+ local selectedProvision = isBuildForDistribution and
371+ (mobileProvisionPath .. " embedded.mobileprovision" ) or
372+ (lfs .attributes (mobileProvisionPath .. " embedded_dev.mobileprovision" , " mode" ) == " file" and
373+ mobileProvisionPath .. " embedded_dev.mobileprovision" or
374+ mobileProvisionPath .. " embedded.mobileprovision" )
375+
376+ if not lfs .attributes (selectedProvision , " mode" ) then
377+ print (" Warning: Cannot find mobile provision profile for " .. bundleIdOutput ..
378+ " at " .. selectedProvision .. " This may cause issues with your app." )
379+ else
380+ -- Copy the mobile provision profile to the .appex bundle and delete the old one
381+ local copyMobileProvisionCmd = " cp " .. quoteString (selectedProvision ) .. " " ..
382+ quoteString (appexPath .. " /embedded.mobileprovision" ) ..
383+ " && rm -rf " .. quoteString (mobileProvisionPath )
384+ runScript (copyMobileProvisionCmd )
385+
386+ -- Append signing command for .appex
387+ cmd = cmd .. " && " .. codesign .. " --verbose -f -s " .. quoteString (identity ) ..
388+ " --entitlements " .. entitlements .. " " .. quoteString (appexPath )
389+ end
416390 end
417391 end
418392 end
@@ -1115,6 +1089,17 @@ local function packageApp( options )
11151089 local entitlements = quoteString ( options .tmpDir .. " /entitlements.xcent" )
11161090 setStatus (" Signing application with " .. tostring (options .signingIdentityName ))
11171091
1092+ -- codesign embedded appx (iOS Extension Files)
1093+ if (checkAppHasAPPX (options .appBundleFile )) then
1094+
1095+ local result , errMsg = runScript ( getCodesignAPPXScriptAndPackage ( options .appBundleFile :gsub (' ["\' ]' , " " ), options .signingIdentity , entitlements , iPhoneSDKRoot , options .bundleid , builtForAppStore ) )
1096+ if result ~= 0 then
1097+ errMsg = " ERROR: code signing embedded appx failed: " .. tostring (errMsg )
1098+ return errMsg
1099+ end
1100+ end
1101+
1102+
11181103 local result , errMsg = runScript ( getCodesignScript ( entitlements , appBundleFileUnquoted , options .signingIdentity , iPhoneSDKRoot ) )
11191104
11201105 if result ~= 0 then
@@ -1690,17 +1675,6 @@ function iPhonePostPackage( params )
16901675 return result
16911676 end
16921677
1693- -- codesign embedded appx (iOS Extension Files)
1694- if (checkAppHasAPPX (options .appBundleFile )) then
1695- local entitlements = quoteString ( options .tmpDir .. " /entitlements.xcent" )
1696- print (" Code signing embedded appx test/" , entitlements )
1697-
1698- local result , errMsg = runScript ( getCodesignAPPXScriptAndPackage ( options .appBundleFile :gsub (' ["\' ]' , " " ), options .signingIdentity , entitlements , iPhoneSDKRoot , options .bundleid ) )
1699- if result ~= 0 then
1700- errMsg = " ERROR: code signing embedded appx failed: " .. tostring (errMsg )
1701- return errMsg
1702- end
1703- end
17041678 end
17051679
17061680 return err
0 commit comments