@@ -29,6 +29,7 @@ namespace commands {
29
29
namespace {
30
30
31
31
const char kSwitchCheck [] = " check" ;
32
+ const char kSwitchEnvlog [] = " envlog" ;
32
33
const char kSwitchFilters [] = " filters" ;
33
34
const char kSwitchIde [] = " ide" ;
34
35
const char kSwitchIdeValueEclipse [] = " eclipse" ;
@@ -278,7 +279,7 @@ const char kGen_HelpShort[] = "gen: Generate ninja files.";
278
279
const char kGen_Help [] =
279
280
R"( gn gen: Generate ninja files.
280
281
281
- gn gen [--check] [<ide options>] <out_dir>
282
+ gn gen [--check] [--envlog=<file_name>] [ <ide options>] <out_dir>
282
283
283
284
Generates ninja files from the current tree and puts them in the given output
284
285
directory.
@@ -293,6 +294,13 @@ const char kGen_Help[] =
293
294
294
295
See "gn help switches" for the common command-line switches.
295
296
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
+
296
304
IDE options
297
305
298
306
GN optionally generates files for IDE. Possibilities for <ide options>
@@ -396,13 +404,16 @@ int RunGen(const std::vector<std::string>& args) {
396
404
return 1 ;
397
405
}
398
406
407
+ const base::CommandLine* command_line =
408
+ base::CommandLine::ForCurrentProcess ();
409
+ bool env_logging = command_line->HasSwitch (kSwitchEnvlog );
410
+
399
411
// Deliberately leaked to avoid expensive process teardown.
400
412
Setup* setup = new Setup ();
413
+ setup->scheduler ().set_env_logging (env_logging);
401
414
if (!setup->DoSetup (args[0 ], true ))
402
415
return 1 ;
403
416
404
- const base::CommandLine* command_line =
405
- base::CommandLine::ForCurrentProcess ();
406
417
if (command_line->HasSwitch (kSwitchCheck ))
407
418
setup->set_check_public_headers (true );
408
419
@@ -435,6 +446,14 @@ int RunGen(const std::vector<std::string>& args) {
435
446
return 1 ;
436
447
}
437
448
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
+
438
457
if (!WriteRuntimeDepsFilesIfNecessary (setup->builder (), &err)) {
439
458
err.PrintToStdout ();
440
459
return 1 ;
0 commit comments