Skip to content

[driver] Document what a "subcommand" is (NFC) #11940

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

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 8 additions & 4 deletions tools/driver/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ extern int modulewrap_main(ArrayRef<const char *> Args, const char *Argv0,
extern int swift_format_main(ArrayRef<const char *> Args, const char *Argv0,
void *MainAddr);

/// Determine if the given invocation should run as a subcommand.
/// Determine if the given invocation should run as a "subcommand".
/// Examples of "subcommands" are 'swift build' or 'swift-test', which are
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: please include a newline here in case anyone ever does run Doxygen on the Swift source.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also that should be "swift test", right?

/// usually used to invoke the Swift package manager executables 'swift-build'
/// and 'swift-test', respectively.
///
/// \param ExecName The name of the argv[0] we were invoked as.
/// \param SubcommandName On success, the full name of the subcommand to invoke.
Expand All @@ -72,9 +75,10 @@ static bool shouldRunAsSubcommand(StringRef ExecName,
SmallVectorImpl<const char *> &Args) {
assert(Args.size() > 0);

// If we are not run as 'swift', don't do anything special. This doesn't work
// with symlinks with alternate names, but we can't detect 'swift' vs 'swiftc'
// if we try and resolve using the actual executable path.
// We only recognize subcommands in the form of 'swift <name-of-subcommand>'.
// If we are being run as an executable named something other than 'swift',
// we do not run a subcommand. This means we do not recognize symlinks with
// alternate names, for example 'swiftc build', as subcommands.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not what the original text was getting at. We do want to distinguish "swift" vs. "swiftc", but ideally we wouldn't distinguish "swift" vs. "swift-4.1" (or similar).

if (ExecName != "swift")
return false;

Expand Down