@@ -1282,9 +1282,6 @@ struct BuildCommandTestCases {
12821282 }
12831283
12841284 @Test (
1285- . SWBINTTODO(
1286- " Implement get-task-allow entitlement for xcode build system "
1287- ) ,
12881285 . tags(
12891286 . Feature. CommandLineArguments. DisableGetTaskAllowEntitlement,
12901287 . Feature. CommandLineArguments. EnableGetTaskAllowEntitlement,
@@ -1293,131 +1290,127 @@ struct BuildCommandTestCases {
12931290 . tags(
12941291 . Feature. CommandLineArguments. BuildSystem,
12951292 ) ,
1296- arguments: getBuildData ( for: SupportedBuildSystemOnPlatform ) ,
1293+ arguments: getBuildData ( for: SupportedBuildSystemOnAllPlatforms ) ,
12971294 )
12981295 func getTaskAllowEntitlement(
12991296 data: BuildData ,
13001297 ) async throws {
13011298 let buildSystem = data. buildSystem
13021299 let buildConfiguration = data. config
1303- try await withKnownIssue ( isIntermittent: ProcessInfo . hostOperatingSystem == . linux) {
1304- try await fixture ( name: " ValidLayouts/SingleModule/ExecutableNew " ) { fixturePath in
1305- #if os(macOS)
1306- func codesignDisplay( execPath: AbsolutePath ) async throws
1307- -> ( AsyncProcessResult . ExitStatus , PropertyListItem ? )
1300+ try await fixture ( name: " ValidLayouts/SingleModule/ExecutableNew " ) { fixturePath in
1301+ #if os(macOS)
1302+ func codesignDisplay( execPath: AbsolutePath ) async throws
1303+ -> ( AsyncProcessResult . ExitStatus , PropertyListItem ? )
1304+ {
1305+ let args = [ " codesign " , " -d " , " --entitlements " , " - " , " --xml " , execPath. pathString]
1306+ let result = try await AsyncProcess . popen ( arguments: args)
1307+ let entitlements : PropertyListItem ? = if case . success( let output) = result. output,
1308+ !output. isEmpty
13081309 {
1309- let args = [ " codesign " , " -d " , " --entitlements " , " - " , " --xml " , execPath. pathString]
1310- let result = try await AsyncProcess . popen ( arguments: args)
1311- let entitlements : PropertyListItem ? = if case . success( let output) = result. output,
1312- !output. isEmpty
1313- {
1314- try PropertyList . fromBytes ( output)
1315- } else {
1316- nil
1317- }
1318-
1319- return ( result. exitStatus, entitlements)
1310+ try PropertyList . fromBytes ( output)
1311+ } else {
1312+ nil
13201313 }
13211314
1322- func verify( entitlements: PropertyListItem ? , getTaskAllowRequired: Bool ) {
1323- if getTaskAllowRequired {
1324- guard let entitlements, case . plDict( let dict) = entitlements else {
1325- Issue . record ( " Missing expected entitlements " )
1326- return
1327- }
1315+ return ( result. exitStatus, entitlements)
1316+ }
13281317
1329- #expect( dict [ " com.apple.security.get-task-allow " ] == . plBool( true ) )
1330- } else {
1331- #expect( entitlements == nil )
1318+ func verify( entitlements: PropertyListItem ? , getTaskAllowRequired: Bool ) {
1319+ guard let entitlements, case . plDict( let dict) = entitlements else {
1320+ if getTaskAllowRequired {
1321+ Issue . record ( " Missing expected entitlements " )
13321322 }
1323+ return
13331324 }
13341325
1335- let execName = " ExecutableNew "
1326+ if getTaskAllowRequired {
1327+ #expect( dict [ " com.apple.security.get-task-allow " ] == . plBool( true ) )
1328+ }
1329+ }
13361330
1337- var buildResult = try await build (
1338- [ " -v " ] ,
1339- packagePath: fixturePath,
1340- configuration: buildConfiguration,
1341- cleanAfterward: false ,
1342- buildSystem: buildSystem
1343- )
1344- var (
1345- exitStatus,
1346- entitlements
1347- ) = try await codesignDisplay ( execPath: buildResult. binPath. appending ( execName) )
1331+ let execName = " ExecutableNew "
13481332
1349- // codesign performs basic verification in display mode, which is enough to confirm ad-hoc signature
1350- // if verification fails (eg. no signature) termination code will be 1
1351- // though on Apple Silicon binary will always be signed because linker signs it by default
1352- #expect( exitStatus == . terminated( code: 0 ) )
1353- verify ( entitlements: entitlements, getTaskAllowRequired: buildConfiguration == . debug)
1333+ var buildResult = try await build (
1334+ [ " -v " ] ,
1335+ packagePath: fixturePath,
1336+ configuration: buildConfiguration,
1337+ cleanAfterward: false ,
1338+ buildSystem: buildSystem
1339+ )
1340+ var (
1341+ exitStatus,
1342+ entitlements
1343+ ) = try await codesignDisplay ( execPath: buildResult. binPath. appending ( execName) )
13541344
1355- try await executeSwiftPackage ( fixturePath, extraArgs: [ " clean " ] , buildSystem: buildSystem)
1345+ // codesign performs basic verification in display mode, which is enough to confirm ad-hoc signature
1346+ // if verification fails (eg. no signature) termination code will be 1
1347+ // though on Apple Silicon binary will always be signed because linker signs it by default
1348+ #expect( exitStatus == . terminated( code: 0 ) )
1349+ verify ( entitlements: entitlements, getTaskAllowRequired: buildConfiguration == . debug)
13561350
1357- buildResult = try await build (
1358- [ " --enable-get-task-allow-entitlement " ] ,
1359- packagePath: fixturePath,
1360- configuration: buildConfiguration,
1361- cleanAfterward: false ,
1362- buildSystem: buildSystem
1363- )
1364- (
1365- exitStatus,
1366- entitlements
1367- ) = try await codesignDisplay ( execPath: buildResult. binPath. appending ( execName) )
1351+ try await executeSwiftPackage ( fixturePath, extraArgs: [ " clean " ] , buildSystem: buildSystem)
13681352
1369- #expect( exitStatus == . terminated( code: 0 ) )
1370- verify ( entitlements: entitlements, getTaskAllowRequired: true )
1353+ buildResult = try await build (
1354+ [ " --enable-get-task-allow-entitlement " ] ,
1355+ packagePath: fixturePath,
1356+ configuration: buildConfiguration,
1357+ cleanAfterward: false ,
1358+ buildSystem: buildSystem
1359+ )
1360+ (
1361+ exitStatus,
1362+ entitlements
1363+ ) = try await codesignDisplay ( execPath: buildResult. binPath. appending ( execName) )
13711364
1372- try await executeSwiftPackage ( fixturePath, extraArgs: [ " clean " ] , buildSystem: buildSystem)
1365+ #expect( exitStatus == . terminated( code: 0 ) )
1366+ verify ( entitlements: entitlements, getTaskAllowRequired: true )
13731367
1374- buildResult = try await build (
1375- [ " --disable-get-task-allow-entitlement " ] ,
1376- packagePath: fixturePath,
1377- configuration: buildConfiguration,
1378- cleanAfterward: false ,
1379- buildSystem: buildSystem
1380- )
1381- (
1382- exitStatus,
1383- entitlements
1384- ) = try await codesignDisplay ( execPath: buildResult. binPath. appending ( execName) )
1385-
1386- #expect( exitStatus == . terminated( code: 0 ) )
1387- verify ( entitlements: entitlements, getTaskAllowRequired: false )
1388- #else
1389- var buildResult = try await build (
1390- [ " -v " ] ,
1391- packagePath: fixturePath,
1392- configuration: buildConfiguration,
1393- buildSystem: buildSystem
1394- )
1368+ try await executeSwiftPackage ( fixturePath, extraArgs: [ " clean " ] , buildSystem: buildSystem)
13951369
1396- #expect( !buildResult. stdout. contains ( " codesign --force --sign - --entitlements " ) )
1370+ buildResult = try await build (
1371+ [ " --disable-get-task-allow-entitlement " ] ,
1372+ packagePath: fixturePath,
1373+ configuration: buildConfiguration,
1374+ cleanAfterward: false ,
1375+ buildSystem: buildSystem
1376+ )
1377+ (
1378+ exitStatus,
1379+ entitlements
1380+ ) = try await codesignDisplay ( execPath: buildResult. binPath. appending ( execName) )
1381+
1382+ #expect( exitStatus == . terminated( code: 0 ) )
1383+ verify ( entitlements: entitlements, getTaskAllowRequired: false )
1384+ #else
1385+ var buildResult = try await build (
1386+ [ " -v " ] ,
1387+ packagePath: fixturePath,
1388+ configuration: buildConfiguration,
1389+ buildSystem: buildSystem
1390+ )
13971391
1398- buildResult = try await build (
1399- [ " --disable-get-task-allow-entitlement " , " -v " ] ,
1400- packagePath: fixturePath,
1401- configuration: buildConfiguration,
1402- buildSystem: buildSystem,
1403- )
1392+ #expect( !buildResult. stdout. contains ( " codesign --force --sign - --entitlements " ) )
14041393
1405- #expect( !buildResult. stdout. contains ( " codesign --force --sign - --entitlements " ) )
1406- #expect( buildResult. stderr. contains ( SwiftCommandState . entitlementsMacOSWarning) )
1394+ buildResult = try await build (
1395+ [ " --disable-get-task-allow-entitlement " , " -v " ] ,
1396+ packagePath: fixturePath,
1397+ configuration: buildConfiguration,
1398+ buildSystem: buildSystem,
1399+ )
14071400
1408- buildResult = try await build (
1409- [ " --enable-get-task-allow-entitlement " , " -v " ] ,
1410- packagePath: fixturePath,
1411- configuration: buildConfiguration,
1412- buildSystem: buildSystem,
1413- )
1401+ #expect( !buildResult. stdout. contains ( " codesign --force --sign - --entitlements " ) )
1402+ #expect( buildResult. stderr. contains ( SwiftCommandState . entitlementsMacOSWarning) )
14141403
1415- #expect( !buildResult. stdout. contains ( " codesign --force --sign - --entitlements " ) )
1416- #expect( buildResult. stderr. contains ( SwiftCommandState . entitlementsMacOSWarning) )
1417- #endif
1418- }
1419- } when: {
1420- [ . xcode] . contains ( buildSystem) && ProcessInfo . hostOperatingSystem != . linux
1404+ buildResult = try await build (
1405+ [ " --enable-get-task-allow-entitlement " , " -v " ] ,
1406+ packagePath: fixturePath,
1407+ configuration: buildConfiguration,
1408+ buildSystem: buildSystem,
1409+ )
1410+
1411+ #expect( !buildResult. stdout. contains ( " codesign --force --sign - --entitlements " ) )
1412+ #expect( buildResult. stderr. contains ( SwiftCommandState . entitlementsMacOSWarning) )
1413+ #endif
14211414 }
14221415 }
14231416
0 commit comments