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

Unified Diff: tools/gn/parse_tree.cc

Issue 1496653002: Sort "deps" and "public_deps" when running the "gn format" command. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
« tools/gn/format_test_data/063.gn ('K') | « tools/gn/format_test_data/063.golden ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/parse_tree.cc
diff --git a/tools/gn/parse_tree.cc b/tools/gn/parse_tree.cc
index d22adca5c4b5f2d380d1f7167a769e1ec6bb985c..f7e7ce5838a2c17e20091d446ee1d2852b0b045e 100644
--- a/tools/gn/parse_tree.cc
+++ b/tools/gn/parse_tree.cc
@@ -16,6 +16,26 @@
namespace {
+enum DepsCategory {
+ kDepsCategoryRelative = 0,
+ kDepsCategoryLocal = 1,
+ kDepsCategoryAbsolute = 2,
+ kDepsCategoryOther = 3,
+};
+
+DepsCategory GetDepsCategory(base::StringPiece deps) {
+ if (deps.length() < 2 || deps[0] != '"' || deps[deps.size() - 1] != '"')
+ return kDepsCategoryOther;
+
+ if (deps[1] == ':')
+ return kDepsCategoryLocal;
+
+ if (deps[1] == '/')
+ return kDepsCategoryAbsolute;
+
+ return kDepsCategoryRelative;
+}
+
std::tuple<base::StringPiece, base::StringPiece> SplitAtFirst(
base::StringPiece str,
char c) {
@@ -590,7 +610,8 @@ void ListNode::SortAsDepsList() {
SortList([](const ParseNode* a, const ParseNode* b) {
base::StringPiece astr = GetStringRepresentation(a);
base::StringPiece bstr = GetStringRepresentation(b);
- return SplitAtFirst(astr, ':') < SplitAtFirst(bstr, ':');
+ return std::make_pair(GetDepsCategory(astr), SplitAtFirst(astr, ':')) <
+ std::make_pair(GetDepsCategory(bstr), SplitAtFirst(bstr, ':'));
});
}
« tools/gn/format_test_data/063.gn ('K') | « tools/gn/format_test_data/063.golden ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698