Skip to content
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

Add version output to CLI #1352

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions CLI/Analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ static bool reportModuleResult(Luau::Frontend& frontend, const Luau::ModuleName&

static void displayHelp(const char* argv0)
{
printf("%s\n", LUAU_VERSION);
printf("Usage: %s [--mode] [options] [file list]\n", argv0);
printf("\n");
printf("Available modes:\n");
Expand Down Expand Up @@ -304,6 +305,11 @@ int main(int argc, char** argv)
return 0;
}

if (argc >= 2 && (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)) {
printf("%s\n", LUAU_VERSION);
return 0;
}

ReportFormat format = ReportFormat::Default;
Luau::Mode mode = Luau::Mode::Nonstrict;
bool annotate = false;
Expand Down
6 changes: 6 additions & 0 deletions CLI/Ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

static void displayHelp(const char* argv0)
{
printf("%s\n", LUAU_VERSION);
printf("Usage: %s [file]\n", argv0);
}

Expand All @@ -34,6 +35,11 @@ int main(int argc, char** argv)
displayHelp(argv[0]);
return 0;
}
else if (argc >= 2 && (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0))
{
printf("%s\n", LUAU_VERSION);
return 0;
}
else if (argc < 2)
{
displayHelp(argv[0]);
Expand Down
6 changes: 6 additions & 0 deletions CLI/Bytecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ static Luau::CompileOptions copts()

static void displayHelp(const char* argv0)
{
printf("%s\n", LUAU_VERSION);
printf("Usage: %s [options] [file list]\n", argv0);
printf("\n");
printf("Available options:\n");
printf(" -h, --help: Display this usage message.\n");
printf(" -v, --version: Display Luau version.");
printf(" -O<n>: compile with optimization level n (default 1, n should be between 0 and 2).\n");
printf(" -g<n>: compile with debug level n (default 1, n should be between 0 and 2).\n");
printf(" --fflags=<fflags>: flags to be enabled.\n");
Expand All @@ -52,6 +54,10 @@ static bool parseArgs(int argc, char** argv, std::string& summaryFile)
{
displayHelp(argv[0]);
}
else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
{
printf("%s\n", LUAU_VERSION);
}
else if (strncmp(argv[i], "-O", 2) == 0)
{
int level = atoi(argv[i] + 2);
Expand Down
7 changes: 7 additions & 0 deletions CLI/Compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,15 @@ static bool compileFile(const char* name, CompileFormat format, Luau::CodeGen::A

static void displayHelp(const char* argv0)
{
printf("%s\n", LUAU_VERSION);
printf("Usage: %s [--mode] [options] [file list]\n", argv0);
printf("\n");
printf("Available modes:\n");
printf(" binary, text, remarks, codegen\n");
printf("\n");
printf("Available options:\n");
printf(" -h, --help: Display this usage message.\n");
printf(" -v, --version: Display version.\n");
printf(" -O<n>: compile with optimization level n (default 1, n should be between 0 and 2).\n");
printf(" -g<n>: compile with debug level n (default 1, n should be between 0 and 2).\n");
printf(" --target=<target>: compile code for specific architecture (a64, x64, a64_nf, x64_ms).\n");
Expand Down Expand Up @@ -470,6 +472,11 @@ int main(int argc, char** argv)
displayHelp(argv[0]);
return 0;
}
else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
{
printf("%s\n", LUAU_VERSION);
return 0;
}
else if (strncmp(argv[i], "-O", 2) == 0)
{
int level = atoi(argv[i] + 2);
Expand Down
4 changes: 4 additions & 0 deletions CLI/Reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ struct Reducer

[[noreturn]] void help(const std::vector<std::string_view>& args)
{
printf("%s\n", LUAU_VERSION);
printf("Syntax: %s script command \"search text\"\n", args[0].data());
printf(" Within command, use {} as a stand-in for the script being reduced\n");
exit(1);
Expand All @@ -482,6 +483,9 @@ int main(int argc, char** argv)
if (args.size() != 4)
help(args);

if (args[1] == "-v" || args[1] == "--version")
printf("%s\n", LUAU_VERSION);

for (size_t i = 1; i < args.size(); ++i)
{
if (args[i] == "--help")
Expand Down
7 changes: 7 additions & 0 deletions CLI/Repl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ static bool runFile(const char* name, lua_State* GL, bool repl)

static void displayHelp(const char* argv0)
{
printf("%s\n", LUAU_VERSION);
printf("Usage: %s [options] [file list] [-a] [arg list]\n", argv0);
printf("\n");
printf("When file list is omitted, an interactive REPL is started instead.\n");
Expand All @@ -664,6 +665,7 @@ static void displayHelp(const char* argv0)
printf(" --coverage: collect code coverage while running the code and output results to coverage.out\n");
printf(" -h, --help: Display this usage message.\n");
printf(" -i, --interactive: Run an interactive REPL after executing the last script specified.\n");
printf(" -v, --version: Display version.\n");
printf(" -O<n>: compile with optimization level n (default 1, n should be between 0 and 2).\n");
printf(" -g<n>: compile with debug level n (default 1, n should be between 0 and 2).\n");
printf(" --profile[=N]: profile the code using N Hz sampling (default 10000) and output results to profile.out\n");
Expand Down Expand Up @@ -705,6 +707,11 @@ int replMain(int argc, char** argv)
{
interactive = true;
}
else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
{
printf("%s\n", LUAU_VERSION);
return 0;
}
else if (strncmp(argv[i], "-O", 2) == 0)
{
int level = atoi(argv[i] + 2);
Expand Down
2 changes: 2 additions & 0 deletions Common/include/Luau/Common.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#pragma once

#define LUAU_VERSION "Luau 0.636"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't love the idea of just having a hardcoded version string like this, particularly because it means that we'll have to manually update this string every time.

I think the "right" way to do this might be something like... resolving the version by finding the most recent git release tag at build-time, which is kind of awful in-and-of-itself. Similarly, it would be nice to include the slug for the git hash in the release string as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

cc @andyfriesen do you have some thoughts on a good way to do this beyond hard-coding the version string?

Copy link
Contributor

@alexmccord alexmccord Jul 31, 2024

Choose a reason for hiding this comment

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

If only there was a tool that we ran each time we sync code that we could modify to handle this.


// Compiler codegen control macros
#ifdef _MSC_VER
#define LUAU_NORETURN __declspec(noreturn)
Expand Down
Loading