Skip to content

Commit bb963d9

Browse files
committed
Move --envlog switch to gn gen command
1 parent 0897755 commit bb963d9

File tree

5 files changed

+32
-32
lines changed

5 files changed

+32
-32
lines changed

tools/gn/command_gen.cc

+22-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace commands {
2929
namespace {
3030

3131
const char kSwitchCheck[] = "check";
32+
const char kSwitchEnvlog[] = "envlog";
3233
const char kSwitchFilters[] = "filters";
3334
const char kSwitchIde[] = "ide";
3435
const char kSwitchIdeValueEclipse[] = "eclipse";
@@ -278,7 +279,7 @@ const char kGen_HelpShort[] = "gen: Generate ninja files.";
278279
const char kGen_Help[] =
279280
R"(gn gen: Generate ninja files.
280281
281-
gn gen [--check] [<ide options>] <out_dir>
282+
gn gen [--check] [--envlog=<file_name>] [<ide options>] <out_dir>
282283
283284
Generates ninja files from the current tree and puts them in the given output
284285
directory.
@@ -293,6 +294,13 @@ const char kGen_Help[] =
293294
294295
See "gn help switches" for the common command-line switches.
295296
297+
Options
298+
299+
--envlog=<file_name>
300+
Writes a list of environment variables to the given file. The env log
301+
will show a list of environment variables referenced in gn files as
302+
well as their values.
303+
296304
IDE options
297305
298306
GN optionally generates files for IDE. Possibilities for <ide options>
@@ -396,13 +404,16 @@ int RunGen(const std::vector<std::string>& args) {
396404
return 1;
397405
}
398406

407+
const base::CommandLine* command_line =
408+
base::CommandLine::ForCurrentProcess();
409+
bool env_logging = command_line->HasSwitch(kSwitchEnvlog);
410+
399411
// Deliberately leaked to avoid expensive process teardown.
400412
Setup* setup = new Setup();
413+
setup->scheduler().set_env_logging(env_logging);
401414
if (!setup->DoSetup(args[0], true))
402415
return 1;
403416

404-
const base::CommandLine* command_line =
405-
base::CommandLine::ForCurrentProcess();
406417
if (command_line->HasSwitch(kSwitchCheck))
407418
setup->set_check_public_headers(true);
408419

@@ -435,6 +446,14 @@ int RunGen(const std::vector<std::string>& args) {
435446
return 1;
436447
}
437448

449+
if (env_logging) {
450+
std::string file_name = command_line->GetSwitchValueASCII(kSwitchEnvlog);
451+
SourceFile envlog = setup->build_settings().build_dir().ResolveRelativeFile(
452+
Value(nullptr, file_name), &err);
453+
base::FilePath envlog_path = setup->build_settings().GetFullPath(envlog);
454+
setup->scheduler().SaveEnvLog(envlog_path);
455+
}
456+
438457
if (!WriteRuntimeDepsFilesIfNecessary(setup->builder(), &err)) {
439458
err.PrintToStdout();
440459
return 1;

tools/gn/docs/reference.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@
631631
### <a name="gen:"></a>**gn gen**: Generate ninja files.
632632

633633
```
634-
gn gen [--check] [<ide options>] <out_dir>
634+
gn gen [--check] [--envlog=<file_name>] [<ide options>] <out_dir>
635635
636636
Generates ninja files from the current tree and puts them in the given output
637637
directory.
@@ -647,6 +647,15 @@
647647
See "gn help switches" for the common command-line switches.
648648
```
649649

650+
#### **Options**
651+
652+
```
653+
--envlog=<file_name>
654+
Writes a list of environment variables to the given file. The env log
655+
will show a list of environment variables referenced in gn files as
656+
well as their values.
657+
```
658+
650659
#### **IDE options**
651660

652661
```
@@ -7028,7 +7037,6 @@
70287037
* [--args: Specifies build arguments overrides.](#--args)
70297038
* [--color: Force colored output.](#--color)
70307039
* [--dotfile: Override the name of the ".gn" file.](#--dotfile)
7031-
* [--envlog: Writes a list of environment variables to the given file.](#--envlog)
70327040
* [--fail-on-unused-args: Treat unused build args as fatal errors.](#--fail-on-unused-args)
70337041
* [--markdown: Write help output in the Markdown format.](#--markdown)
70347042
* [--nocolor: Force non-colored output.](#--nocolor)

tools/gn/setup.cc

-8
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ bool Setup::DoSetup(const std::string& build_dir, bool force_create) {
298298

299299
scheduler_.set_verbose_logging(cmdline->HasSwitch(switches::kVerbose));
300300
scheduler_.set_verbose_log(cmdline->GetSwitchValuePath(switches::kVerbose));
301-
scheduler_.set_env_logging(cmdline->HasSwitch(switches::kEnvlog));
302301
if (cmdline->HasSwitch(switches::kTime) ||
303302
cmdline->HasSwitch(switches::kTracelog))
304303
EnableTracing();
@@ -399,13 +398,6 @@ bool Setup::RunPostMessageLoop() {
399398
PrintLongHelp(SummarizeTraces());
400399
if (cmdline->HasSwitch(switches::kTracelog))
401400
SaveTraces(cmdline->GetSwitchValuePath(switches::kTracelog));
402-
if (cmdline->HasSwitch(switches::kEnvlog)) {
403-
std::string file_name = cmdline->GetSwitchValueASCII(switches::kEnvlog);
404-
SourceFile logfile = build_settings_.build_dir().ResolveRelativeFile(
405-
Value(nullptr, file_name), &err);
406-
base::FilePath logfile_path = build_settings_.GetFullPath(logfile);
407-
scheduler_.SaveEnvLog(logfile_path);
408-
}
409401

410402
return true;
411403
}

tools/gn/switches.cc

-15
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,6 @@ const char kDotfile_Help[] =
7070
It would be nice to test the edge cases and document or fix.
7171
)";
7272

73-
const char kEnvlog[] = "envlog";
74-
const char kEnvlog_HelpShort[] =
75-
"--envlog: Writes a list of environment variables to the given file.";
76-
const char kEnvlog_Help[] =
77-
R"(--envlog: Writes a list of environment variables to the given file.
78-
79-
The env log will show a list of environment variables used referenced
80-
in gn files as well their values.
81-
82-
Examples
83-
84-
gn gen out/Default --envlog=myenv.log
85-
)";
86-
8773
const char kFailOnUnusedArgs[] = "fail-on-unused-args";
8874
const char kFailOnUnusedArgs_HelpShort[] =
8975
"--fail-on-unused-args: Treat unused build args as fatal errors.";
@@ -289,7 +275,6 @@ const SwitchInfoMap& GetSwitches() {
289275
INSERT_VARIABLE(Args)
290276
INSERT_VARIABLE(Color)
291277
INSERT_VARIABLE(Dotfile)
292-
INSERT_VARIABLE(Envlog)
293278
INSERT_VARIABLE(FailOnUnusedArgs)
294279
INSERT_VARIABLE(Markdown)
295280
INSERT_VARIABLE(NoColor)

tools/gn/switches.h

-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ extern const char kDotfile[];
4040
extern const char kDotfile_HelpShort[];
4141
extern const char kDotfile_Help[];
4242

43-
extern const char kEnvlog[];
44-
extern const char kEnvlog_HelpShort[];
45-
extern const char kEnvlog_Help[];
46-
4743
extern const char kFailOnUnusedArgs[];
4844
extern const char kFailOnUnusedArgs_HelpShort[];
4945
extern const char kFailOnUnusedArgs_Help[];

0 commit comments

Comments
 (0)