OLD | NEW |
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 "tools/gn/command_format.h" | 5 #include "tools/gn/command_format.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 namespace commands { | 25 namespace commands { |
26 | 26 |
27 const char kSwitchDryRun[] = "dry-run"; | 27 const char kSwitchDryRun[] = "dry-run"; |
28 const char kSwitchDumpTree[] = "dump-tree"; | 28 const char kSwitchDumpTree[] = "dump-tree"; |
29 const char kSwitchStdin[] = "stdin"; | 29 const char kSwitchStdin[] = "stdin"; |
30 | 30 |
31 const char kFormat[] = "format"; | 31 const char kFormat[] = "format"; |
32 const char kFormat_HelpShort[] = | 32 const char kFormat_HelpShort[] = |
33 "format: Format .gn file."; | 33 "format: Format .gn file."; |
34 const char kFormat_Help[] = | 34 const char kFormat_Help[] = |
35 "gn format [--dump-tree] (--stdin | <build_file>)\n" | 35 R"(gn format [--dump-tree] (--stdin | <build_file>) |
36 "\n" | 36 |
37 " Formats .gn file to a standard format.\n" | 37 Formats .gn file to a standard format. |
38 "\n" | 38 |
39 " The contents of some lists ('sources', 'deps', etc.) will be sorted to\n" | 39 The contents of some lists ('sources', 'deps', etc.) will be sorted to a |
40 " a canonical order. To suppress this, you can add a comment of the form\n" | 40 canonical order. To suppress this, you can add a comment of the form "# |
41 " \"# NOSORT\" immediately preceeding the assignment. e.g.\n" | 41 NOSORT" immediately preceeding the assignment. e.g. |
42 "\n" | 42 |
43 " # NOSORT\n" | 43 # NOSORT |
44 " sources = [\n" | 44 sources = [ |
45 " \"z.cc\",\n" | 45 "z.cc", |
46 " \"a.cc\",\n" | 46 "a.cc", |
47 " ]\n" | 47 ] |
48 "\n" | 48 |
49 "Arguments\n" | 49 Arguments |
50 "\n" | 50 |
51 " --dry-run\n" | 51 --dry-run |
52 " Does not change or output anything, but sets the process exit code\n" | 52 Does not change or output anything, but sets the process exit code based |
53 " based on whether output would be different than what's on disk.\n" | 53 on whether output would be different than what's on disk. This is useful |
54 " This is useful for presubmit/lint-type checks.\n" | 54 for presubmit/lint-type checks. |
55 " - Exit code 0: successful format, matches on disk.\n" | 55 - Exit code 0: successful format, matches on disk. |
56 " - Exit code 1: general failure (parse error, etc.)\n" | 56 - Exit code 1: general failure (parse error, etc.) |
57 " - Exit code 2: successful format, but differs from on disk.\n" | 57 - Exit code 2: successful format, but differs from on disk. |
58 "\n" | 58 |
59 " --dump-tree\n" | 59 --dump-tree |
60 " For debugging, dumps the parse tree to stdout and does not update\n" | 60 For debugging, dumps the parse tree to stdout and does not update the |
61 " the file or print formatted output.\n" | 61 file or print formatted output. |
62 "\n" | 62 |
63 " --stdin\n" | 63 --stdin |
64 " Read input from stdin and write to stdout rather than update\n" | 64 Read input from stdin and write to stdout rather than update a file |
65 " a file in-place.\n" | 65 in-place. |
66 "\n" | 66 |
67 "Examples\n" | 67 Examples |
68 " gn format //some/BUILD.gn\n" | 68 gn format //some/BUILD.gn |
69 " gn format some\\BUILD.gn\n" | 69 gn format some\\BUILD.gn |
70 " gn format /abspath/some/BUILD.gn\n" | 70 gn format /abspath/some/BUILD.gn |
71 " gn format --stdin\n"; | 71 gn format --stdin |
| 72 )"; |
72 | 73 |
73 namespace { | 74 namespace { |
74 | 75 |
75 const int kIndentSize = 2; | 76 const int kIndentSize = 2; |
76 const int kMaximumWidth = 80; | 77 const int kMaximumWidth = 80; |
77 | 78 |
78 const int kPenaltyLineBreak = 500; | 79 const int kPenaltyLineBreak = 500; |
79 const int kPenaltyHorizontalSeparation = 100; | 80 const int kPenaltyHorizontalSeparation = 100; |
80 const int kPenaltyExcess = 10000; | 81 const int kPenaltyExcess = 10000; |
81 const int kPenaltyBrokenLineOnOneLiner = 5000; | 82 const int kPenaltyBrokenLineOnOneLiner = 5000; |
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 } | 1074 } |
1074 printf("Wrote formatted to '%s'.\n", to_write.AsUTF8Unsafe().c_str()); | 1075 printf("Wrote formatted to '%s'.\n", to_write.AsUTF8Unsafe().c_str()); |
1075 } | 1076 } |
1076 } | 1077 } |
1077 } | 1078 } |
1078 | 1079 |
1079 return 0; | 1080 return 0; |
1080 } | 1081 } |
1081 | 1082 |
1082 } // namespace commands | 1083 } // namespace commands |
OLD | NEW |