@@ -27,6 +27,9 @@ public struct Driver {
27
27
case unableToLoadOutputFileMap( String )
28
28
case unableToDecodeFrontendTargetInfo
29
29
case failedToRetrieveFrontendTargetInfo
30
+ case missingProfilingData( String )
31
+ case conditionalCompilationFlagHasRedundantPrefix( String )
32
+ case conditionalCompilationFlagIsNotValidIdentifier( String )
30
33
// Explicit Module Build Failures
31
34
case malformedModuleDependency( String , String )
32
35
case missingPCMArguments( String )
@@ -55,6 +58,12 @@ public struct Driver {
55
58
return " could not decode frontend target info; compiler driver and frontend executables may be incompatible "
56
59
case . failedToRetrieveFrontendTargetInfo:
57
60
return " failed to retrieve frontend target info "
61
+ case . missingProfilingData( let arg) :
62
+ return " no profdata file exists at ' \( arg) ' "
63
+ case . conditionalCompilationFlagHasRedundantPrefix( let name) :
64
+ return " invalid argument '-D \( name) '; did you provide a redundant '-D' in your build settings? "
65
+ case . conditionalCompilationFlagIsNotValidIdentifier( let name) :
66
+ return " conditional compilation flags must be valid Swift identifiers (rather than ' \( name) ') "
58
67
// Explicit Module Build Failures
59
68
case . malformedModuleDependency( let moduleName, let errorDescription) :
60
69
return " Malformed Module Dependency: \( moduleName) , \( errorDescription) "
@@ -327,7 +336,13 @@ public struct Driver {
327
336
self . numThreads = Self . determineNumThreads ( & parsedOptions, compilerMode: compilerMode, diagnosticsEngine: diagnosticEngine)
328
337
self . numParallelJobs = Self . determineNumParallelJobs ( & parsedOptions, diagnosticsEngine: diagnosticEngine, env: env)
329
338
330
- try Self . validateWarningControlArgs ( & parsedOptions)
339
+ Self . validateWarningControlArgs ( & parsedOptions, diagnosticEngine: diagnosticEngine)
340
+ Self . validateProfilingArgs ( & parsedOptions,
341
+ fileSystem: fileSystem,
342
+ workingDirectory: workingDirectory,
343
+ diagnosticEngine: diagnosticEngine)
344
+ Self . validateCompilationConditionArgs ( & parsedOptions, diagnosticEngine: diagnosticEngine)
345
+ Self . validateFrameworkSearchPathArgs ( & parsedOptions, diagnosticEngine: diagnosticEngine)
331
346
Self . validateCoverageArgs ( & parsedOptions, diagnosticsEngine: diagnosticEngine)
332
347
try toolchain. validateArgs ( & parsedOptions,
333
348
targetTriple: self . frontendTargetInfo. target. triple,
@@ -1554,14 +1569,63 @@ extension Diagnostic.Message {
1554
1569
static var error_bridging_header_module_interface : Diagnostic . Message {
1555
1570
. error( " using bridging headers with module interfaces is unsupported " )
1556
1571
}
1572
+ static func warning_cannot_assign_to_compilation_condition( name: String ) -> Diagnostic . Message {
1573
+ . warning( " conditional compilation flags do not have values in Swift; they are either present or absent (rather than ' \( name) ') " )
1574
+ }
1575
+ static func warning_framework_search_path_includes_extension( path: String ) -> Diagnostic . Message {
1576
+ . warning( " framework search path ends in \" .framework \" ; add directory containing framework instead: \( path) " )
1577
+ }
1557
1578
}
1558
1579
1559
1580
// MARK: Miscellaneous Argument Validation
1560
1581
extension Driver {
1561
- static func validateWarningControlArgs( _ parsedOptions: inout ParsedOptions ) throws {
1582
+ static func validateWarningControlArgs( _ parsedOptions: inout ParsedOptions ,
1583
+ diagnosticEngine: DiagnosticsEngine ) {
1562
1584
if parsedOptions. hasArgument ( . suppressWarnings) &&
1563
1585
parsedOptions. hasFlag ( positive: . warningsAsErrors, negative: . noWarningsAsErrors, default: false ) {
1564
- throw Error . conflictingOptions ( . warningsAsErrors, . suppressWarnings)
1586
+ diagnosticEngine. emit ( Error . conflictingOptions ( . warningsAsErrors, . suppressWarnings) )
1587
+ }
1588
+ }
1589
+
1590
+ static func validateProfilingArgs( _ parsedOptions: inout ParsedOptions ,
1591
+ fileSystem: FileSystem ,
1592
+ workingDirectory: AbsolutePath ? ,
1593
+ diagnosticEngine: DiagnosticsEngine ) {
1594
+ if parsedOptions. hasArgument ( . profileGenerate) &&
1595
+ parsedOptions. hasArgument ( . profileUse) {
1596
+ diagnosticEngine. emit ( Error . conflictingOptions ( . profileGenerate, . profileUse) )
1597
+ }
1598
+
1599
+ if let profileArgs = parsedOptions. getLastArgument ( . profileUse) ? . asMultiple,
1600
+ let workingDirectory = workingDirectory ?? fileSystem. currentWorkingDirectory {
1601
+ for profilingData in profileArgs {
1602
+ if !fileSystem. exists ( AbsolutePath ( profilingData,
1603
+ relativeTo: workingDirectory) ) {
1604
+ diagnosticEngine. emit ( Error . missingProfilingData ( profilingData) )
1605
+ }
1606
+ }
1607
+ }
1608
+ }
1609
+
1610
+ static func validateCompilationConditionArgs( _ parsedOptions: inout ParsedOptions ,
1611
+ diagnosticEngine: DiagnosticsEngine ) {
1612
+ for arg in parsedOptions. arguments ( for: . D) . map ( \. argument. asSingle) {
1613
+ if arg. contains ( " = " ) {
1614
+ diagnosticEngine. emit ( . warning_cannot_assign_to_compilation_condition( name: arg) )
1615
+ } else if arg. hasPrefix ( " -D " ) {
1616
+ diagnosticEngine. emit ( Error . conditionalCompilationFlagHasRedundantPrefix ( arg) )
1617
+ } else if !arg. sd_isSwiftIdentifier {
1618
+ diagnosticEngine. emit ( Error . conditionalCompilationFlagIsNotValidIdentifier ( arg) )
1619
+ }
1620
+ }
1621
+ }
1622
+
1623
+ static func validateFrameworkSearchPathArgs( _ parsedOptions: inout ParsedOptions ,
1624
+ diagnosticEngine: DiagnosticsEngine ) {
1625
+ for arg in parsedOptions. arguments ( for: . F, . Fsystem) . map ( \. argument. asSingle) {
1626
+ if arg. hasSuffix ( " .framework " ) || arg. hasSuffix ( " .framework/ " ) {
1627
+ diagnosticEngine. emit ( . warning_framework_search_path_includes_extension( path: arg) )
1628
+ }
1565
1629
}
1566
1630
}
1567
1631
0 commit comments