Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: tools/gn/command_gyp.cc

Issue 137713007: Check for GN args using the union of all rather than individually. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/command_args.cc ('k') | tools/gn/setup.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <iostream> 5 #include <iostream>
6 #include <map> 6 #include <map>
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 i != grouped_targets.end(); ++i) { 310 i != grouped_targets.end(); ++i) {
311 GypTargetWriter::WriteFile(i->first, i->second, debug_toolchain, err); 311 GypTargetWriter::WriteFile(i->first, i->second, debug_toolchain, err);
312 if (err->has_error()) 312 if (err->has_error())
313 return std::make_pair(0, 0); 313 return std::make_pair(0, 0);
314 } 314 }
315 315
316 return std::make_pair(target_count, 316 return std::make_pair(target_count,
317 static_cast<int>(grouped_targets.size())); 317 static_cast<int>(grouped_targets.size()));
318 } 318 }
319 319
320 // Verifies that all build argument overrides are used by at least one of the
321 // build types.
322 void VerifyAllOverridesUsed(const Setups& setups) {
323 // Collect all declared args from all builds.
324 Scope::KeyValueMap declared;
325 setups.debug->build_settings().build_args().MergeDeclaredArguments(
326 &declared);
327 setups.release->build_settings().build_args().MergeDeclaredArguments(
328 &declared);
329 if (setups.debug64 && setups.release64) {
330 setups.debug64->build_settings().build_args().MergeDeclaredArguments(
331 &declared);
332 setups.release64->build_settings().build_args().MergeDeclaredArguments(
333 &declared);
334 }
335 if (setups.xcode_debug && setups.xcode_release) {
336 setups.xcode_debug->build_settings().build_args().MergeDeclaredArguments(
337 &declared);
338 setups.xcode_release->build_settings().build_args().MergeDeclaredArguments(
339 &declared);
340 }
341
342 Scope::KeyValueMap used =
343 setups.debug->build_settings().build_args().GetAllOverrides();
344
345 Err err;
346 if (!Args::VerifyAllOverridesUsed(used, declared, &err)) {
347 // TODO(brettw) implement a system of warnings. Until we have a better
348 // system, print the error but don't cause a failure.
349 err.PrintToStdout();
350 }
351 }
352
320 } // namespace 353 } // namespace
321 354
322 // Suppress output on success. 355 // Suppress output on success.
323 const char kSwitchQuiet[] = "q"; 356 const char kSwitchQuiet[] = "q";
324 357
325 const char kGyp[] = "gyp"; 358 const char kGyp[] = "gyp";
326 const char kGyp_HelpShort[] = 359 const char kGyp_HelpShort[] =
327 "gyp: Make GYP files from GN."; 360 "gyp: Make GYP files from GN.";
328 const char kGyp_Help[] = 361 const char kGyp_Help[] =
329 "gyp: Make GYP files from GN.\n" 362 "gyp: Make GYP files from GN.\n"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 " executable(\"my_app\") {\n" 417 " executable(\"my_app\") {\n"
385 " deps = [ \":gyp_target\" ]\n" 418 " deps = [ \":gyp_target\" ]\n"
386 " gyp_file = \"//foo/myapp.gyp\"\n" 419 " gyp_file = \"//foo/myapp.gyp\"\n"
387 " sources = ...\n" 420 " sources = ...\n"
388 " }\n"; 421 " }\n";
389 422
390 int RunGyp(const std::vector<std::string>& args) { 423 int RunGyp(const std::vector<std::string>& args) {
391 base::ElapsedTimer timer; 424 base::ElapsedTimer timer;
392 Setups setups; 425 Setups setups;
393 426
394 // Deliberately leaked to avoid expensive process teardown. 427 // Deliberately leaked to avoid expensive process teardown. We also turn off
428 // unused override checking since we want to merge all declared arguments and
429 // check those, rather than check each build individually. Otherwise, you
430 // couldn't have an arg that was used in only one build type. This comes up
431 // because some args are build-type specific.
395 setups.debug = new Setup; 432 setups.debug = new Setup;
433 setups.debug->set_check_for_unused_overrides(false);
396 if (!setups.debug->DoSetup()) 434 if (!setups.debug->DoSetup())
397 return 1; 435 return 1;
398 const char kIsDebug[] = "is_debug"; 436 const char kIsDebug[] = "is_debug";
399 437
400 SourceDir base_build_dir = setups.debug->build_settings().build_dir(); 438 SourceDir base_build_dir = setups.debug->build_settings().build_dir();
401 setups.debug->build_settings().SetBuildDir( 439 setups.debug->build_settings().SetBuildDir(
402 AppendDirSuffix(base_build_dir, ".Debug")); 440 AppendDirSuffix(base_build_dir, ".Debug"));
403 441
404 // Make a release build based on the debug one. We use a new directory for 442 // Make a release build based on the debug one. We use a new directory for
405 // the build output so that they don't stomp on each other. 443 // the build output so that they don't stomp on each other.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 return 1; 497 return 1;
460 if (setups.debug64 && !setups.debug64->RunPostMessageLoop()) 498 if (setups.debug64 && !setups.debug64->RunPostMessageLoop())
461 return 1; 499 return 1;
462 if (setups.release64 && !setups.release64->RunPostMessageLoop()) 500 if (setups.release64 && !setups.release64->RunPostMessageLoop())
463 return 1; 501 return 1;
464 if (setups.xcode_debug && !setups.xcode_debug->RunPostMessageLoop()) 502 if (setups.xcode_debug && !setups.xcode_debug->RunPostMessageLoop())
465 return 1; 503 return 1;
466 if (setups.xcode_release && !setups.xcode_release->RunPostMessageLoop()) 504 if (setups.xcode_release && !setups.xcode_release->RunPostMessageLoop())
467 return 1; 505 return 1;
468 506
507 VerifyAllOverridesUsed(setups);
508
469 Err err; 509 Err err;
470 std::pair<int, int> counts = WriteGypFiles(setups, &err); 510 std::pair<int, int> counts = WriteGypFiles(setups, &err);
471 if (err.has_error()) { 511 if (err.has_error()) {
472 err.PrintToStdout(); 512 err.PrintToStdout();
473 return 1; 513 return 1;
474 } 514 }
475 515
476 base::TimeDelta elapsed_time = timer.Elapsed(); 516 base::TimeDelta elapsed_time = timer.Elapsed();
477 517
478 if (!CommandLine::ForCurrentProcess()->HasSwitch(kSwitchQuiet)) { 518 if (!CommandLine::ForCurrentProcess()->HasSwitch(kSwitchQuiet)) {
479 OutputString("Done. ", DECORATION_GREEN); 519 OutputString("Done. ", DECORATION_GREEN);
480 520
481 std::string stats = "Wrote " + 521 std::string stats = "Wrote " +
482 base::IntToString(counts.first) + " targets to " + 522 base::IntToString(counts.first) + " targets to " +
483 base::IntToString(counts.second) + " GYP files read from " + 523 base::IntToString(counts.second) + " GYP files read from " +
484 base::IntToString( 524 base::IntToString(
485 setups.debug->scheduler().input_file_manager()->GetInputFileCount()) 525 setups.debug->scheduler().input_file_manager()->GetInputFileCount())
486 + " GN files in " + 526 + " GN files in " +
487 base::IntToString(elapsed_time.InMilliseconds()) + "ms\n"; 527 base::IntToString(elapsed_time.InMilliseconds()) + "ms\n";
488 528
489 OutputString(stats); 529 OutputString(stats);
490 } 530 }
491 531
492 return 0; 532 return 0;
493 } 533 }
494 534
495 } // namespace commands 535 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/command_args.cc ('k') | tools/gn/setup.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698