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

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

Issue 1766163002: gn format: Support # NOSORT to disable sorting of blocks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 9 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
« no previous file with comments | « no previous file | tools/gn/command_format_unittest.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 17 matching lines...) Expand all
28 const char kSwitchStdin[] = "stdin"; 28 const char kSwitchStdin[] = "stdin";
29 29
30 const char kFormat[] = "format"; 30 const char kFormat[] = "format";
31 const char kFormat_HelpShort[] = 31 const char kFormat_HelpShort[] =
32 "format: Format .gn file."; 32 "format: Format .gn file.";
33 const char kFormat_Help[] = 33 const char kFormat_Help[] =
34 "gn format [--dump-tree] [--in-place] [--stdin] BUILD.gn\n" 34 "gn format [--dump-tree] [--in-place] [--stdin] BUILD.gn\n"
35 "\n" 35 "\n"
36 " Formats .gn file to a standard format.\n" 36 " Formats .gn file to a standard format.\n"
37 "\n" 37 "\n"
38 " The contents of some lists ('sources', 'deps', etc.) will be sorted to\n"
39 " a canonical order. To suppress this, you can add a comment of the form\n"
40 " \"# NOSORT\" immediately preceeding the assignment. e.g.\n"
41 "\n"
42 " # NOSORT\n"
43 " sources = [\n"
44 " \"z.cc\",\n"
45 " \"a.cc\",\n"
46 " ]\n"
47 "\n"
38 "Arguments\n" 48 "Arguments\n"
39 " --dry-run\n" 49 " --dry-run\n"
40 " Does not change or output anything, but sets the process exit code\n" 50 " Does not change or output anything, but sets the process exit code\n"
41 " based on whether output would be different than what's on disk.\n" 51 " based on whether output would be different than what's on disk.\n"
42 " This is useful for presubmit/lint-type checks.\n" 52 " This is useful for presubmit/lint-type checks.\n"
43 " - Exit code 0: successful format, matches on disk.\n" 53 " - Exit code 0: successful format, matches on disk.\n"
44 " - Exit code 1: general failure (parse error, etc.)\n" 54 " - Exit code 1: general failure (parse error, etc.)\n"
45 " - Exit code 2: successful format, but differs from on disk.\n" 55 " - Exit code 2: successful format, but differs from on disk.\n"
46 "\n" 56 "\n"
47 " --dump-tree\n" 57 " --dump-tree\n"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 const base::StringPiece lhs = ident->value().value(); 318 const base::StringPiece lhs = ident->value().value();
309 if (lhs == "data" || lhs == "datadeps" || lhs == "data_deps" || 319 if (lhs == "data" || lhs == "datadeps" || lhs == "data_deps" ||
310 lhs == "deps" || lhs == "inputs" || lhs == "outputs" || 320 lhs == "deps" || lhs == "inputs" || lhs == "outputs" ||
311 lhs == "public" || lhs == "public_deps" || lhs == "sources") { 321 lhs == "public" || lhs == "public_deps" || lhs == "sources") {
312 const_cast<ListNode*>(list)->set_prefer_multiline(true); 322 const_cast<ListNode*>(list)->set_prefer_multiline(true);
313 } 323 }
314 } 324 }
315 } 325 }
316 326
317 void Printer::SortIfSourcesOrDeps(const BinaryOpNode* binop) { 327 void Printer::SortIfSourcesOrDeps(const BinaryOpNode* binop) {
328 if (binop && binop->comments() && !binop->comments()->before().empty() &&
329 binop->comments()->before()[0].value().as_string() == "# NOSORT") {
330 // Allow disabling of sort for specific actions that might be
331 // order-sensitive.
332 return;
333 }
318 const IdentifierNode* ident = binop->left()->AsIdentifier(); 334 const IdentifierNode* ident = binop->left()->AsIdentifier();
319 const ListNode* list = binop->right()->AsList(); 335 const ListNode* list = binop->right()->AsList();
320 if ((binop->op().value() == "=" || binop->op().value() == "+=" || 336 if ((binop->op().value() == "=" || binop->op().value() == "+=" ||
321 binop->op().value() == "-=") && 337 binop->op().value() == "-=") &&
322 ident && list) { 338 ident && list) {
323 const base::StringPiece lhs = ident->value().value(); 339 const base::StringPiece lhs = ident->value().value();
324 if (lhs == "sources") 340 if (lhs == "sources")
325 const_cast<ListNode*>(list)->SortAsStringsList(); 341 const_cast<ListNode*>(list)->SortAsStringsList();
326 else if (lhs == "deps" || lhs == "public_deps") 342 else if (lhs == "deps" || lhs == "public_deps")
327 const_cast<ListNode*>(list)->SortAsDepsList(); 343 const_cast<ListNode*>(list)->SortAsDepsList();
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 } 1068 }
1053 } else { 1069 } else {
1054 printf("%s", output_string.c_str()); 1070 printf("%s", output_string.c_str());
1055 } 1071 }
1056 } 1072 }
1057 1073
1058 return 0; 1074 return 0;
1059 } 1075 }
1060 1076
1061 } // namespace commands 1077 } // namespace commands
OLDNEW
« no previous file with comments | « no previous file | tools/gn/command_format_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698