Skip to content

Driver: diagnose options that are only supported in the new driver #37375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/swift/AST/DiagnosticsDriver.def
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,7 @@ WARNING(warn_drv_darwin_sdk_invalid_settings, none,
"SDK settings were ignored because 'SDKSettings.json' could not be parsed",
())

WARNING(warning_unsupported_driver_option,none,
"option '%0' is ony supported in swift-driver", (StringRef))
#define UNDEFINE_DIAGNOSTIC_MACROS
#include "DefineDiagnosticMacros.h"
1 change: 1 addition & 0 deletions include/swift/Option/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace options {
SwiftAPIExtractOption = (1 << 15),
SwiftSymbolGraphExtractOption = (1 << 16),
SwiftAPIDigesterOption = (1 << 17),
NewDriverOnlyOption = (1 << 18),
};

enum ID {
Expand Down
5 changes: 4 additions & 1 deletion include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def SwiftSymbolGraphExtractOption : OptionFlag;
// The option should be accepted by swift-api-digester.
def SwiftAPIDigesterOption : OptionFlag;

// The option only functions in the new driver.
def NewDriverOnlyOption : OptionFlag;

/////////
// Options

Expand Down Expand Up @@ -1181,7 +1184,7 @@ def working_directory_EQ : Joined<["-"], "working-directory=">,
Alias<working_directory>;

def user_module_version : Separate<["-"], "user-module-version">,
Flags<[FrontendOption, ModuleInterfaceOption]>,
Flags<[FrontendOption, ModuleInterfaceOption, NewDriverOnlyOption]>,
HelpText<"Module version specified from Swift module authors">,
MetaVarName<"<vers>">;

Expand Down
3 changes: 3 additions & 0 deletions test/Driver/diagnose-new-driver-flags.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// RUN: %swiftc_driver -emit-module -user-module-version 999.999 %s -### 2>&1 | %FileCheck %s

// CHECK: warning: option '-user-module-version' is ony supported in swift-driver
7 changes: 7 additions & 0 deletions tools/driver/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ static int run_driver(StringRef ExecName,
if (Diags.hadAnyError())
return 1;

for (auto arg: ArgList->getArgs()) {
if (arg->getOption().hasFlag(options::NewDriverOnlyOption)) {
Diags.diagnose(SourceLoc(), diag::warning_unsupported_driver_option,
arg->getSpelling());
}
}

std::unique_ptr<Compilation> C =
TheDriver.buildCompilation(*TC, std::move(ArgList));

Expand Down