@@ -27,6 +27,9 @@ public struct Driver {
2727 case unableToLoadOutputFileMap( String )
2828 case unableToDecodeFrontendTargetInfo
2929 case failedToRetrieveFrontendTargetInfo
30+ case missingProfilingData( String )
31+ case conditionalCompilationFlagHasRedundantPrefix( String )
32+ case conditionalCompilationFlagIsNotValidIdentifier( String )
3033 // Explicit Module Build Failures
3134 case malformedModuleDependency( String , String )
3235 case missingPCMArguments( String )
@@ -55,6 +58,12 @@ public struct Driver {
5558 return " could not decode frontend target info; compiler driver and frontend executables may be incompatible "
5659 case . failedToRetrieveFrontendTargetInfo:
5760 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) ') "
5867 // Explicit Module Build Failures
5968 case . malformedModuleDependency( let moduleName, let errorDescription) :
6069 return " Malformed Module Dependency: \( moduleName) , \( errorDescription) "
@@ -327,7 +336,13 @@ public struct Driver {
327336 self . numThreads = Self . determineNumThreads ( & parsedOptions, compilerMode: compilerMode, diagnosticsEngine: diagnosticEngine)
328337 self . numParallelJobs = Self . determineNumParallelJobs ( & parsedOptions, diagnosticsEngine: diagnosticEngine, env: env)
329338
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)
331346 Self . validateCoverageArgs ( & parsedOptions, diagnosticsEngine: diagnosticEngine)
332347 try toolchain. validateArgs ( & parsedOptions,
333348 targetTriple: self . frontendTargetInfo. target. triple,
@@ -1554,14 +1569,63 @@ extension Diagnostic.Message {
15541569 static var error_bridging_header_module_interface : Diagnostic . Message {
15551570 . error( " using bridging headers with module interfaces is unsupported " )
15561571 }
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+ }
15571578}
15581579
15591580// MARK: Miscellaneous Argument Validation
15601581extension Driver {
1561- static func validateWarningControlArgs( _ parsedOptions: inout ParsedOptions ) throws {
1582+ static func validateWarningControlArgs( _ parsedOptions: inout ParsedOptions ,
1583+ diagnosticEngine: DiagnosticsEngine ) {
15621584 if parsedOptions. hasArgument ( . suppressWarnings) &&
15631585 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+ }
15651629 }
15661630 }
15671631
0 commit comments