Skip to content

Commit c312143

Browse files
authored
Merge pull request swiftlang#32543 from DougGregor/frontend-version-flag
2 parents 6a44443 + 46f9f21 commit c312143

File tree

6 files changed

+32
-3
lines changed

6 files changed

+32
-3
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class FrontendOptions {
134134
DumpPCM, ///< Dump information about a precompiled Clang module
135135

136136
ScanDependencies, ///< Scan dependencies of Swift source files
137+
PrintVersion, ///< Print version information.
137138
};
138139

139140
/// Indicates the action the user requested that the frontend perform.

include/swift/Option/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def help_hidden : Flag<["-", "--"], "help-hidden">,
213213

214214
def v : Flag<["-"], "v">, Flags<[DoesNotAffectIncrementalBuild]>,
215215
HelpText<"Show commands to run and use verbose output">;
216-
def version : Flag<["-", "--"], "version">,
216+
def version : Flag<["-", "--"], "version">, Flags<[FrontendOption]>,
217217
HelpText<"Print version information and exit">;
218218

219219
def parseable_output : Flag<["-"], "parseable-output">,

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ ArgsToFrontendOptionsConverter::determineRequestedAction(const ArgList &args) {
314314
// (Setting up module output will be handled below.)
315315
return FrontendOptions::ActionType::EmitModuleOnly;
316316
}
317+
318+
if (args.hasArg(OPT_version))
319+
return FrontendOptions::ActionType::PrintVersion;
320+
317321
return FrontendOptions::ActionType::NoneAction;
318322
}
319323
Option Opt = A->getOption();
@@ -386,7 +390,8 @@ bool ArgsToFrontendOptionsConverter::setUpInputKindAndImmediateArgs() {
386390
if (Opts.InputsAndOutputs.verifyInputs(
387391
Diags, treatAsSIL,
388392
Opts.RequestedAction == FrontendOptions::ActionType::REPL,
389-
Opts.RequestedAction == FrontendOptions::ActionType::NoneAction)) {
393+
(Opts.RequestedAction == FrontendOptions::ActionType::NoneAction ||
394+
Opts.RequestedAction == FrontendOptions::ActionType::PrintVersion))){
390395
return true;
391396
}
392397
if (Opts.RequestedAction == FrontendOptions::ActionType::Immediate) {

lib/Frontend/FrontendOptions.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ bool FrontendOptions::needsProperModuleName(ActionType action) {
5353
return true;
5454
case ActionType::Immediate:
5555
case ActionType::REPL:
56+
case ActionType::PrintVersion:
5657
return false;
5758
case ActionType::EmitAssembly:
5859
case ActionType::EmitIR:
@@ -75,6 +76,7 @@ bool FrontendOptions::shouldActionOnlyParse(ActionType action) {
7576
case FrontendOptions::ActionType::DumpInterfaceHash:
7677
case FrontendOptions::ActionType::EmitImportedModules:
7778
case FrontendOptions::ActionType::ScanDependencies:
79+
case FrontendOptions::ActionType::PrintVersion:
7880
return true;
7981
default:
8082
return false;
@@ -124,6 +126,7 @@ FrontendOptions::formatForPrincipalOutputFileForAction(ActionType action) {
124126
case ActionType::DumpTypeRefinementContexts:
125127
case ActionType::DumpTypeInfo:
126128
case ActionType::DumpPCM:
129+
case ActionType::PrintVersion:
127130
return TY_Nothing;
128131

129132
case ActionType::EmitPCH:
@@ -191,6 +194,7 @@ bool FrontendOptions::canActionEmitDependencies(ActionType action) {
191194
case ActionType::Immediate:
192195
case ActionType::REPL:
193196
case ActionType::DumpPCM:
197+
case ActionType::PrintVersion:
194198
return false;
195199
case ActionType::ResolveImports:
196200
case ActionType::Typecheck:
@@ -232,6 +236,7 @@ bool FrontendOptions::canActionEmitReferenceDependencies(ActionType action) {
232236
case ActionType::EmitPCM:
233237
case ActionType::DumpPCM:
234238
case ActionType::ScanDependencies:
239+
case ActionType::PrintVersion:
235240
return false;
236241
case ActionType::Typecheck:
237242
case ActionType::MergeModules:
@@ -279,6 +284,7 @@ bool FrontendOptions::canActionEmitObjCHeader(ActionType action) {
279284
case ActionType::EmitPCM:
280285
case ActionType::DumpPCM:
281286
case ActionType::ScanDependencies:
287+
case ActionType::PrintVersion:
282288
return false;
283289
case ActionType::Typecheck:
284290
case ActionType::MergeModules:
@@ -315,6 +321,7 @@ bool FrontendOptions::canActionEmitLoadedModuleTrace(ActionType action) {
315321
case ActionType::EmitPCM:
316322
case ActionType::DumpPCM:
317323
case ActionType::ScanDependencies:
324+
case ActionType::PrintVersion:
318325
return false;
319326
case ActionType::ResolveImports:
320327
case ActionType::Typecheck:
@@ -357,6 +364,7 @@ bool FrontendOptions::canActionEmitModule(ActionType action) {
357364
case ActionType::EmitPCM:
358365
case ActionType::DumpPCM:
359366
case ActionType::ScanDependencies:
367+
case ActionType::PrintVersion:
360368
return false;
361369
case ActionType::MergeModules:
362370
case ActionType::EmitModuleOnly:
@@ -410,6 +418,7 @@ bool FrontendOptions::canActionEmitInterface(ActionType action) {
410418
case ActionType::EmitBC:
411419
case ActionType::EmitAssembly:
412420
case ActionType::EmitObject:
421+
case ActionType::PrintVersion:
413422
return true;
414423
}
415424
llvm_unreachable("unhandled action");
@@ -449,6 +458,7 @@ bool FrontendOptions::doesActionProduceOutput(ActionType action) {
449458
case ActionType::NoneAction:
450459
case ActionType::Immediate:
451460
case ActionType::REPL:
461+
case ActionType::PrintVersion:
452462
return false;
453463
}
454464
llvm_unreachable("Unknown ActionType");
@@ -488,6 +498,7 @@ bool FrontendOptions::doesActionProduceTextualOutput(ActionType action) {
488498
case ActionType::DumpTypeInfo:
489499
case ActionType::DumpPCM:
490500
case ActionType::ScanDependencies:
501+
case ActionType::PrintVersion:
491502
return true;
492503
}
493504
llvm_unreachable("unhandled action");
@@ -512,6 +523,7 @@ bool FrontendOptions::doesActionGenerateSIL(ActionType action) {
512523
case ActionType::EmitPCM:
513524
case ActionType::DumpPCM:
514525
case ActionType::ScanDependencies:
526+
case ActionType::PrintVersion:
515527
return false;
516528
case ActionType::EmitSILGen:
517529
case ActionType::EmitSIBGen:
@@ -557,6 +569,7 @@ bool FrontendOptions::doesActionGenerateIR(ActionType action) {
557569
case ActionType::EmitPCM:
558570
case ActionType::DumpPCM:
559571
case ActionType::ScanDependencies:
572+
case ActionType::PrintVersion:
560573
return false;
561574
case ActionType::Immediate:
562575
case ActionType::REPL:

lib/FrontendTool/FrontendTool.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,13 @@ static bool performCompile(CompilerInstance &Instance,
12971297
return precompileClangModule(Instance);
12981298
if (Action == FrontendOptions::ActionType::DumpPCM)
12991299
return dumpPrecompiledClangModule(Instance);
1300-
1300+
if (Action == FrontendOptions::ActionType::PrintVersion) {
1301+
llvm::outs() << version::getSwiftFullVersion(
1302+
version::Version::getCurrentLanguageVersion()) << '\n';
1303+
llvm::outs() << "Target: "
1304+
<< Invocation.getLangOptions().Target.str() << '\n';
1305+
return false;
1306+
}
13011307
if (Action == FrontendOptions::ActionType::CompileModuleFromInterface)
13021308
return buildModuleFromInterface(Instance);
13031309

test/Frontend/version.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %target-swift-frontend --version | %FileCheck %s
2+
3+
// CHECK: Swift version
4+
// CHECK-NEXT: Target

0 commit comments

Comments
 (0)