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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/gn/command_format_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/command_format.cc
diff --git a/tools/gn/command_format.cc b/tools/gn/command_format.cc
index d7301c92613b6e698908a7b7d7d3173c58000d93..ae36e37783e8792a0ced125f4b6b783ad8b3eab4 100644
--- a/tools/gn/command_format.cc
+++ b/tools/gn/command_format.cc
@@ -35,6 +35,16 @@ const char kFormat_Help[] =
"\n"
" Formats .gn file to a standard format.\n"
"\n"
+ " The contents of some lists ('sources', 'deps', etc.) will be sorted to\n"
+ " a canonical order. To suppress this, you can add a comment of the form\n"
+ " \"# NOSORT\" immediately preceeding the assignment. e.g.\n"
+ "\n"
+ " # NOSORT\n"
+ " sources = [\n"
+ " \"z.cc\",\n"
+ " \"a.cc\",\n"
+ " ]\n"
+ "\n"
"Arguments\n"
" --dry-run\n"
" Does not change or output anything, but sets the process exit code\n"
@@ -315,6 +325,12 @@ void Printer::AnnotatePreferredMultilineAssignment(const BinaryOpNode* binop) {
}
void Printer::SortIfSourcesOrDeps(const BinaryOpNode* binop) {
+ if (binop && binop->comments() && !binop->comments()->before().empty() &&
+ binop->comments()->before()[0].value().as_string() == "# NOSORT") {
+ // Allow disabling of sort for specific actions that might be
+ // order-sensitive.
+ return;
+ }
const IdentifierNode* ident = binop->left()->AsIdentifier();
const ListNode* list = binop->right()->AsList();
if ((binop->op().value() == "=" || binop->op().value() == "+=" ||
« 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