~chromium-team/chromium-browser/disco-stable

« back to all changes in this revision

Viewing changes to debian/patches/revert-gn-4960.patch

  • Committer: Olivier Tilloy
  • Date: 2019-05-22 08:15:38 UTC
  • Revision ID: olivier.tilloy@canonical.com-20190522081538-k8o272t0mvnydu7d
* Upstream release: 74.0.3729.169
* debian/patches/revert-gn-4960.patch: added
* debian/patches/revert-gn-4980.patch: added

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: revert https://gn.googlesource.com/gn/+/0d038c2e0a32a528713d3dfaf1f1e0cdfe87fd46, which breaks the chromium build
 
2
 
 
3
--- a/tools/gn/build/gen.py
 
4
+++ b/tools/gn/build/gen.py
 
5
@@ -522,6 +522,7 @@ def WriteGNNinja(path, platform, host, o
 
6
         'tools/gn/setup.cc',
 
7
         'tools/gn/source_dir.cc',
 
8
         'tools/gn/source_file.cc',
 
9
+        'tools/gn/source_file_type.cc',
 
10
         'tools/gn/standard_out.cc',
 
11
         'tools/gn/string_utils.cc',
 
12
         'tools/gn/substitution_list.cc',
 
13
--- a/tools/gn/tools/gn/c_tool.h
 
14
+++ b/tools/gn/tools/gn/c_tool.h
 
15
@@ -12,6 +12,7 @@
 
16
 #include "tools/gn/label.h"
 
17
 #include "tools/gn/label_ptr.h"
 
18
 #include "tools/gn/scope.h"
 
19
+#include "tools/gn/source_file_type.h"
 
20
 #include "tools/gn/substitution_list.h"
 
21
 #include "tools/gn/substitution_pattern.h"
 
22
 #include "tools/gn/tool.h"
 
23
--- a/tools/gn/tools/gn/compile_commands_writer.cc
 
24
+++ b/tools/gn/tools/gn/compile_commands_writer.cc
 
25
@@ -122,7 +122,7 @@ void WriteCommand(const Target* target,
 
26
                   const CompileFlags& flags,
 
27
                   std::vector<OutputFile>& tool_outputs,
 
28
                   PathOutput& path_output,
 
29
-                  SourceFile::Type source_type,
 
30
+                  SourceFileType source_type,
 
31
                   const char* tool_name,
 
32
                   EscapeOptions opts,
 
33
                   std::string* compile_commands) {
 
34
@@ -144,16 +144,16 @@ void WriteCommand(const Target* target,
 
35
     } else if (range.type == &CSubstitutionCFlags) {
 
36
       command_out << flags.cflags;
 
37
     } else if (range.type == &CSubstitutionCFlagsC) {
 
38
-      if (source_type == SourceFile::SOURCE_C)
 
39
+      if (source_type == SOURCE_C)
 
40
         command_out << flags.cflags_c;
 
41
     } else if (range.type == &CSubstitutionCFlagsCc) {
 
42
-      if (source_type == SourceFile::SOURCE_CPP)
 
43
+      if (source_type == SOURCE_CPP)
 
44
         command_out << flags.cflags_cc;
 
45
     } else if (range.type == &CSubstitutionCFlagsObjC) {
 
46
-      if (source_type == SourceFile::SOURCE_M)
 
47
+      if (source_type == SOURCE_M)
 
48
         command_out << flags.cflags_objc;
 
49
     } else if (range.type == &CSubstitutionCFlagsObjCc) {
 
50
-      if (source_type == SourceFile::SOURCE_MM)
 
51
+      if (source_type == SOURCE_MM)
 
52
         command_out << flags.cflags_objcc;
 
53
     } else if (range.type == &SubstitutionLabel ||
 
54
                range.type == &SubstitutionLabelName ||
 
55
@@ -222,11 +222,9 @@ void CompileCommandsWriter::RenderJSON(c
 
56
     for (const auto& source : target->sources()) {
 
57
       // If this source is not a C/C++/ObjC/ObjC++ source (not header) file,
 
58
       // continue as it does not belong in the compilation database.
 
59
-      SourceFile::Type source_type = source.type();
 
60
-      if (source_type != SourceFile::SOURCE_CPP &&
 
61
-          source_type != SourceFile::SOURCE_C &&
 
62
-          source_type != SourceFile::SOURCE_M &&
 
63
-          source_type != SourceFile::SOURCE_MM)
 
64
+      SourceFileType source_type = GetSourceFileType(source);
 
65
+      if (source_type != SOURCE_CPP && source_type != SOURCE_C &&
 
66
+          source_type != SOURCE_M && source_type != SOURCE_MM)
 
67
         continue;
 
68
 
 
69
       const char* tool_name = Tool::kToolNone;
 
70
@@ -324,4 +322,4 @@ void CompileCommandsWriter::VisitDeps(co
 
71
       VisitDeps(pair.ptr, visited);
 
72
     }
 
73
   }
 
74
-}
 
75
+}
 
76
\ No newline at end of file
 
77
--- a/tools/gn/tools/gn/general_tool.h
 
78
+++ b/tools/gn/tools/gn/general_tool.h
 
79
@@ -11,6 +11,7 @@
 
80
 #include "base/macros.h"
 
81
 #include "tools/gn/label.h"
 
82
 #include "tools/gn/label_ptr.h"
 
83
+#include "tools/gn/source_file_type.h"
 
84
 #include "tools/gn/substitution_list.h"
 
85
 #include "tools/gn/substitution_pattern.h"
 
86
 #include "tools/gn/tool.h"
 
87
--- a/tools/gn/tools/gn/header_checker.cc
 
88
+++ b/tools/gn/tools/gn/header_checker.cc
 
89
@@ -18,6 +18,7 @@
 
90
 #include "tools/gn/err.h"
 
91
 #include "tools/gn/filesystem_utils.h"
 
92
 #include "tools/gn/scheduler.h"
 
93
+#include "tools/gn/source_file_type.h"
 
94
 #include "tools/gn/target.h"
 
95
 #include "tools/gn/trace.h"
 
96
 #include "util/worker_pool.h"
 
97
@@ -151,10 +152,9 @@ void HeaderChecker::RunCheckOverFiles(co
 
98
 
 
99
   for (const auto& file : files) {
 
100
     // Only check C-like source files (RC files also have includes).
 
101
-    SourceFile::Type type = file.first.type();
 
102
-    if (type != SourceFile::SOURCE_CPP && type != SourceFile::SOURCE_H &&
 
103
-        type != SourceFile::SOURCE_C && type != SourceFile::SOURCE_M &&
 
104
-        type != SourceFile::SOURCE_MM && type != SourceFile::SOURCE_RC)
 
105
+    SourceFileType type = GetSourceFileType(file.first);
 
106
+    if (type != SOURCE_CPP && type != SOURCE_H && type != SOURCE_C &&
 
107
+        type != SOURCE_M && type != SOURCE_MM && type != SOURCE_RC)
 
108
       continue;
 
109
 
 
110
     if (!check_generated_) {
 
111
--- a/tools/gn/tools/gn/ninja_binary_target_writer.cc
 
112
+++ b/tools/gn/tools/gn/ninja_binary_target_writer.cc
 
113
@@ -23,23 +23,22 @@
 
114
 #include "tools/gn/ninja_utils.h"
 
115
 #include "tools/gn/scheduler.h"
 
116
 #include "tools/gn/settings.h"
 
117
+#include "tools/gn/source_file_type.h"
 
118
 #include "tools/gn/string_utils.h"
 
119
 #include "tools/gn/substitution_writer.h"
 
120
 #include "tools/gn/target.h"
 
121
 
 
122
 bool NinjaBinaryTargetWriter::SourceFileTypeSet::CSourceUsed() {
 
123
-  return Get(SourceFile::SOURCE_CPP) || Get(SourceFile::SOURCE_H) ||
 
124
-         Get(SourceFile::SOURCE_C) || Get(SourceFile::SOURCE_M) ||
 
125
-         Get(SourceFile::SOURCE_MM) || Get(SourceFile::SOURCE_RC) ||
 
126
-         Get(SourceFile::SOURCE_S);
 
127
+  return Get(SOURCE_CPP) || Get(SOURCE_H) || Get(SOURCE_C) || Get(SOURCE_M) ||
 
128
+         Get(SOURCE_MM) || Get(SOURCE_RC) || Get(SOURCE_S);
 
129
 }
 
130
 
 
131
 bool NinjaBinaryTargetWriter::SourceFileTypeSet::RustSourceUsed() {
 
132
-  return Get(SourceFile::SOURCE_RS);
 
133
+  return Get(SOURCE_RS);
 
134
 }
 
135
 
 
136
 bool NinjaBinaryTargetWriter::SourceFileTypeSet::GoSourceUsed() {
 
137
-  return Get(SourceFile::SOURCE_GO);
 
138
+  return Get(SOURCE_GO);
 
139
 }
 
140
 
 
141
 NinjaBinaryTargetWriter::NinjaBinaryTargetWriter(const Target* target,
 
142
@@ -50,6 +49,10 @@ NinjaBinaryTargetWriter::NinjaBinaryTarg
 
143
 NinjaBinaryTargetWriter::~NinjaBinaryTargetWriter() = default;
 
144
 
 
145
 void NinjaBinaryTargetWriter::Run() {
 
146
+  SourceFileTypeSet used_types;
 
147
+  for (const auto& source : target_->sources())
 
148
+    used_types.Set(GetSourceFileType(source));
 
149
+
 
150
   NinjaCBinaryTargetWriter writer(target_, out_);
 
151
   writer.Run();
 
152
 }
 
153
--- a/tools/gn/tools/gn/ninja_binary_target_writer.h
 
154
+++ b/tools/gn/tools/gn/ninja_binary_target_writer.h
 
155
@@ -23,12 +23,11 @@ class NinjaBinaryTargetWriter : public N
 
156
   class SourceFileTypeSet {
 
157
    public:
 
158
     SourceFileTypeSet() {
 
159
-      memset(flags_, 0,
 
160
-             sizeof(bool) * static_cast<int>(SourceFile::SOURCE_NUMTYPES));
 
161
+      memset(flags_, 0, sizeof(bool) * static_cast<int>(SOURCE_NUMTYPES));
 
162
     }
 
163
 
 
164
-    void Set(SourceFile::Type type) { flags_[static_cast<int>(type)] = true; }
 
165
-    bool Get(SourceFile::Type type) const {
 
166
+    void Set(SourceFileType type) { flags_[static_cast<int>(type)] = true; }
 
167
+    bool Get(SourceFileType type) const {
 
168
       return flags_[static_cast<int>(type)];
 
169
     }
 
170
 
 
171
@@ -37,7 +36,7 @@ class NinjaBinaryTargetWriter : public N
 
172
     bool GoSourceUsed();
 
173
 
 
174
    private:
 
175
-    bool flags_[static_cast<int>(SourceFile::SOURCE_NUMTYPES)];
 
176
+    bool flags_[static_cast<int>(SOURCE_NUMTYPES)];
 
177
   };
 
178
 
 
179
   NinjaBinaryTargetWriter(const Target* target, std::ostream& out);
 
180
--- a/tools/gn/tools/gn/ninja_c_binary_target_writer.cc
 
181
+++ b/tools/gn/tools/gn/ninja_c_binary_target_writer.cc
 
182
@@ -24,6 +24,7 @@
 
183
 #include "tools/gn/ninja_utils.h"
 
184
 #include "tools/gn/scheduler.h"
 
185
 #include "tools/gn/settings.h"
 
186
+#include "tools/gn/source_file_type.h"
 
187
 #include "tools/gn/string_utils.h"
 
188
 #include "tools/gn/substitution_writer.h"
 
189
 #include "tools/gn/target.h"
 
190
@@ -66,27 +67,27 @@ void AddSourceSetObjectFiles(const Targe
 
191
     if (source_set->GetOutputFilesForSource(source, &tool_name, &tool_outputs))
 
192
       obj_files->push_back(tool_outputs[0]);
 
193
 
 
194
-    used_types.Set(source.type());
 
195
+    used_types.Set(GetSourceFileType(source));
 
196
   }
 
197
 
 
198
   // Add MSVC precompiled header object files. GCC .gch files are not object
 
199
   // files so they are omitted.
 
200
   if (source_set->config_values().has_precompiled_headers()) {
 
201
-    if (used_types.Get(SourceFile::SOURCE_C)) {
 
202
+    if (used_types.Get(SOURCE_C)) {
 
203
       const CTool* tool = source_set->toolchain()->GetToolAsC(CTool::kCToolCc);
 
204
       if (tool && tool->precompiled_header_type() == CTool::PCH_MSVC) {
 
205
         GetPCHOutputFiles(source_set, CTool::kCToolCc, &tool_outputs);
 
206
         obj_files->Append(tool_outputs.begin(), tool_outputs.end());
 
207
       }
 
208
     }
 
209
-    if (used_types.Get(SourceFile::SOURCE_CPP)) {
 
210
+    if (used_types.Get(SOURCE_CPP)) {
 
211
       const CTool* tool = source_set->toolchain()->GetToolAsC(CTool::kCToolCxx);
 
212
       if (tool && tool->precompiled_header_type() == CTool::PCH_MSVC) {
 
213
         GetPCHOutputFiles(source_set, CTool::kCToolCxx, &tool_outputs);
 
214
         obj_files->Append(tool_outputs.begin(), tool_outputs.end());
 
215
       }
 
216
     }
 
217
-    if (used_types.Get(SourceFile::SOURCE_M)) {
 
218
+    if (used_types.Get(SOURCE_M)) {
 
219
       const CTool* tool =
 
220
           source_set->toolchain()->GetToolAsC(CTool::kCToolObjC);
 
221
       if (tool && tool->precompiled_header_type() == CTool::PCH_MSVC) {
 
222
@@ -94,7 +95,7 @@ void AddSourceSetObjectFiles(const Targe
 
223
         obj_files->Append(tool_outputs.begin(), tool_outputs.end());
 
224
       }
 
225
     }
 
226
-    if (used_types.Get(SourceFile::SOURCE_MM)) {
 
227
+    if (used_types.Get(SOURCE_MM)) {
 
228
       const CTool* tool =
 
229
           source_set->toolchain()->GetToolAsC(CTool::kCToolObjCxx);
 
230
       if (tool && tool->precompiled_header_type() == CTool::PCH_MSVC) {
 
231
@@ -118,7 +119,7 @@ void NinjaCBinaryTargetWriter::Run() {
 
232
   // Figure out what source types are needed.
 
233
   SourceFileTypeSet used_types;
 
234
   for (const auto& source : target_->sources())
 
235
-    used_types.Set(source.type());
 
236
+    used_types.Set(GetSourceFileType(source));
 
237
 
 
238
   WriteCompilerVars(used_types);
 
239
 
 
240
@@ -234,34 +235,31 @@ void NinjaCBinaryTargetWriter::WriteComp
 
241
       target_->config_values().has_precompiled_headers();
 
242
 
 
243
   EscapeOptions opts = GetFlagOptions();
 
244
-  if (used_types.Get(SourceFile::SOURCE_S) ||
 
245
-      used_types.Get(SourceFile::SOURCE_ASM)) {
 
246
+  if (used_types.Get(SOURCE_S) || used_types.Get(SOURCE_ASM)) {
 
247
     WriteOneFlag(target_, &CSubstitutionAsmFlags, false, Tool::kToolNone,
 
248
                  &ConfigValues::asmflags, opts, path_output_, out_);
 
249
   }
 
250
-  if (used_types.Get(SourceFile::SOURCE_C) ||
 
251
-      used_types.Get(SourceFile::SOURCE_CPP) ||
 
252
-      used_types.Get(SourceFile::SOURCE_M) ||
 
253
-      used_types.Get(SourceFile::SOURCE_MM)) {
 
254
+  if (used_types.Get(SOURCE_C) || used_types.Get(SOURCE_CPP) ||
 
255
+      used_types.Get(SOURCE_M) || used_types.Get(SOURCE_MM)) {
 
256
     WriteOneFlag(target_, &CSubstitutionCFlags, false, Tool::kToolNone,
 
257
                  &ConfigValues::cflags, opts, path_output_, out_);
 
258
   }
 
259
-  if (used_types.Get(SourceFile::SOURCE_C)) {
 
260
+  if (used_types.Get(SOURCE_C)) {
 
261
     WriteOneFlag(target_, &CSubstitutionCFlagsC, has_precompiled_headers,
 
262
                  CTool::kCToolCc, &ConfigValues::cflags_c, opts, path_output_,
 
263
                  out_);
 
264
   }
 
265
-  if (used_types.Get(SourceFile::SOURCE_CPP)) {
 
266
+  if (used_types.Get(SOURCE_CPP)) {
 
267
     WriteOneFlag(target_, &CSubstitutionCFlagsCc, has_precompiled_headers,
 
268
                  CTool::kCToolCxx, &ConfigValues::cflags_cc, opts, path_output_,
 
269
                  out_);
 
270
   }
 
271
-  if (used_types.Get(SourceFile::SOURCE_M)) {
 
272
+  if (used_types.Get(SOURCE_M)) {
 
273
     WriteOneFlag(target_, &CSubstitutionCFlagsObjC, has_precompiled_headers,
 
274
                  CTool::kCToolObjC, &ConfigValues::cflags_objc, opts,
 
275
                  path_output_, out_);
 
276
   }
 
277
-  if (used_types.Get(SourceFile::SOURCE_MM)) {
 
278
+  if (used_types.Get(SOURCE_MM)) {
 
279
     WriteOneFlag(target_, &CSubstitutionCFlagsObjCc, has_precompiled_headers,
 
280
                  CTool::kCToolObjCxx, &ConfigValues::cflags_objcc, opts,
 
281
                  path_output_, out_);
 
282
@@ -321,14 +319,14 @@ void NinjaCBinaryTargetWriter::WritePCHC
 
283
 
 
284
   const CTool* tool_c = target_->toolchain()->GetToolAsC(CTool::kCToolCc);
 
285
   if (tool_c && tool_c->precompiled_header_type() != CTool::PCH_NONE &&
 
286
-      used_types.Get(SourceFile::SOURCE_C)) {
 
287
+      used_types.Get(SOURCE_C)) {
 
288
     WritePCHCommand(&CSubstitutionCFlagsC, CTool::kCToolCc,
 
289
                     tool_c->precompiled_header_type(), input_dep,
 
290
                     order_only_deps, object_files, other_files);
 
291
   }
 
292
   const CTool* tool_cxx = target_->toolchain()->GetToolAsC(CTool::kCToolCxx);
 
293
   if (tool_cxx && tool_cxx->precompiled_header_type() != CTool::PCH_NONE &&
 
294
-      used_types.Get(SourceFile::SOURCE_CPP)) {
 
295
+      used_types.Get(SOURCE_CPP)) {
 
296
     WritePCHCommand(&CSubstitutionCFlagsCc, CTool::kCToolCxx,
 
297
                     tool_cxx->precompiled_header_type(), input_dep,
 
298
                     order_only_deps, object_files, other_files);
 
299
@@ -336,7 +334,7 @@ void NinjaCBinaryTargetWriter::WritePCHC
 
300
 
 
301
   const CTool* tool_objc = target_->toolchain()->GetToolAsC(CTool::kCToolObjC);
 
302
   if (tool_objc && tool_objc->precompiled_header_type() == CTool::PCH_GCC &&
 
303
-      used_types.Get(SourceFile::SOURCE_M)) {
 
304
+      used_types.Get(SOURCE_M)) {
 
305
     WritePCHCommand(&CSubstitutionCFlagsObjC, CTool::kCToolObjC,
 
306
                     tool_objc->precompiled_header_type(), input_dep,
 
307
                     order_only_deps, object_files, other_files);
 
308
@@ -345,7 +343,7 @@ void NinjaCBinaryTargetWriter::WritePCHC
 
309
   const CTool* tool_objcxx =
 
310
       target_->toolchain()->GetToolAsC(CTool::kCToolObjCxx);
 
311
   if (tool_objcxx && tool_objcxx->precompiled_header_type() == CTool::PCH_GCC &&
 
312
-      used_types.Get(SourceFile::SOURCE_MM)) {
 
313
+      used_types.Get(SOURCE_MM)) {
 
314
     WritePCHCommand(&CSubstitutionCFlagsObjCc, CTool::kCToolObjCxx,
 
315
                     tool_objcxx->precompiled_header_type(), input_dep,
 
316
                     order_only_deps, object_files, other_files);
 
317
@@ -478,7 +476,7 @@ void NinjaCBinaryTargetWriter::WriteSour
 
318
     deps.resize(0);
 
319
     const char* tool_name = Tool::kToolNone;
 
320
     if (!target_->GetOutputFilesForSource(source, &tool_name, &tool_outputs)) {
 
321
-      if (source.type() == SourceFile::SOURCE_DEF)
 
322
+      if (GetSourceFileType(source) == SOURCE_DEF)
 
323
         other_files->push_back(source);
 
324
       continue;  // No output for this source.
 
325
     }
 
326
@@ -599,7 +597,7 @@ void NinjaCBinaryTargetWriter::WriteLink
 
327
   const SourceFile* optional_def_file = nullptr;
 
328
   if (!other_files.empty()) {
 
329
     for (const SourceFile& src_file : other_files) {
 
330
-      if (src_file.type() == SourceFile::SOURCE_DEF) {
 
331
+      if (GetSourceFileType(src_file) == SOURCE_DEF) {
 
332
         optional_def_file = &src_file;
 
333
         implicit_deps.push_back(
 
334
             OutputFile(settings_->build_settings(), src_file));
 
335
--- a/tools/gn/tools/gn/source_file.cc
 
336
+++ b/tools/gn/tools/gn/source_file.cc
 
337
@@ -21,48 +21,18 @@ void AssertValueSourceFileString(const s
 
338
   DCHECK(!EndsWithSlash(s)) << s;
 
339
 }
 
340
 
 
341
-SourceFile::Type GetSourceFileType(const std::string& file) {
 
342
-  base::StringPiece extension = FindExtension(&file);
 
343
-  if (extension == "cc" || extension == "cpp" || extension == "cxx")
 
344
-    return SourceFile::SOURCE_CPP;
 
345
-  if (extension == "h" || extension == "hpp" || extension == "hxx" ||
 
346
-      extension == "hh" || extension == "inc")
 
347
-    return SourceFile::SOURCE_H;
 
348
-  if (extension == "c")
 
349
-    return SourceFile::SOURCE_C;
 
350
-  if (extension == "m")
 
351
-    return SourceFile::SOURCE_M;
 
352
-  if (extension == "mm")
 
353
-    return SourceFile::SOURCE_MM;
 
354
-  if (extension == "rc")
 
355
-    return SourceFile::SOURCE_RC;
 
356
-  if (extension == "S" || extension == "s" || extension == "asm")
 
357
-    return SourceFile::SOURCE_S;
 
358
-  if (extension == "o" || extension == "obj")
 
359
-    return SourceFile::SOURCE_O;
 
360
-  if (extension == "def")
 
361
-    return SourceFile::SOURCE_DEF;
 
362
-  if (extension == "rs")
 
363
-    return SourceFile::SOURCE_RS;
 
364
-  if (extension == "go")
 
365
-    return SourceFile::SOURCE_GO;
 
366
-
 
367
-  return SourceFile::SOURCE_UNKNOWN;
 
368
-}
 
369
-
 
370
 }  // namespace
 
371
 
 
372
-SourceFile::SourceFile() : type_(SOURCE_UNKNOWN) {}
 
373
+SourceFile::SourceFile() = default;
 
374
 
 
375
 SourceFile::SourceFile(const base::StringPiece& p)
 
376
-    : value_(p.data(), p.size()), type_(GetSourceFileType(value_)) {
 
377
+    : value_(p.data(), p.size()) {
 
378
   DCHECK(!value_.empty());
 
379
   AssertValueSourceFileString(value_);
 
380
   NormalizePath(&value_);
 
381
 }
 
382
 
 
383
-SourceFile::SourceFile(SwapIn, std::string* value)
 
384
-    : type_(GetSourceFileType(*value)) {
 
385
+SourceFile::SourceFile(SwapIn, std::string* value) {
 
386
   value_.swap(*value);
 
387
   DCHECK(!value_.empty());
 
388
   AssertValueSourceFileString(value_);
 
389
--- a/tools/gn/tools/gn/source_file.h
 
390
+++ b/tools/gn/tools/gn/source_file.h
 
391
@@ -20,28 +20,6 @@ class SourceDir;
 
392
 // ends in one.
 
393
 class SourceFile {
 
394
  public:
 
395
-  // This should be sequential integers starting from 0 so they can be used as
 
396
-  // array indices.
 
397
-  enum Type {
 
398
-    SOURCE_UNKNOWN = 0,
 
399
-    SOURCE_ASM,
 
400
-    SOURCE_C,
 
401
-    SOURCE_CPP,
 
402
-    SOURCE_H,
 
403
-    SOURCE_M,
 
404
-    SOURCE_MM,
 
405
-    SOURCE_S,
 
406
-    SOURCE_RC,
 
407
-    SOURCE_O,  // Object files can be inputs, too. Also counts .obj.
 
408
-    SOURCE_DEF,
 
409
-
 
410
-    SOURCE_RS,
 
411
-    SOURCE_GO,
 
412
-
 
413
-    // Must be last.
 
414
-    SOURCE_NUMTYPES,
 
415
-  };
 
416
-
 
417
   enum SwapIn { SWAP_IN };
 
418
 
 
419
   SourceFile();
 
420
@@ -58,7 +36,6 @@ class SourceFile {
 
421
 
 
422
   bool is_null() const { return value_.empty(); }
 
423
   const std::string& value() const { return value_; }
 
424
-  Type type() const { return type_; }
 
425
 
 
426
   // Returns everything after the last slash.
 
427
   std::string GetName() const;
 
428
@@ -103,7 +80,6 @@ class SourceFile {
 
429
   friend class SourceDir;
 
430
 
 
431
   std::string value_;
 
432
-  Type type_;
 
433
 
 
434
   // Copy & assign supported.
 
435
 };
 
436
--- /dev/null
 
437
+++ b/tools/gn/tools/gn/source_file_type.cc
 
438
@@ -0,0 +1,37 @@
 
439
+// Copyright 2014 The Chromium Authors. All rights reserved.
 
440
+// Use of this source code is governed by a BSD-style license that can be
 
441
+// found in the LICENSE file.
 
442
+
 
443
+#include "tools/gn/source_file_type.h"
 
444
+
 
445
+#include "tools/gn/filesystem_utils.h"
 
446
+#include "tools/gn/source_file.h"
 
447
+
 
448
+SourceFileType GetSourceFileType(const SourceFile& file) {
 
449
+  base::StringPiece extension = FindExtension(&file.value());
 
450
+  if (extension == "cc" || extension == "cpp" || extension == "cxx")
 
451
+    return SOURCE_CPP;
 
452
+  if (extension == "h" || extension == "hpp" || extension == "hxx" ||
 
453
+      extension == "hh")
 
454
+    return SOURCE_H;
 
455
+  if (extension == "c")
 
456
+    return SOURCE_C;
 
457
+  if (extension == "m")
 
458
+    return SOURCE_M;
 
459
+  if (extension == "mm")
 
460
+    return SOURCE_MM;
 
461
+  if (extension == "rc")
 
462
+    return SOURCE_RC;
 
463
+  if (extension == "S" || extension == "s" || extension == "asm")
 
464
+    return SOURCE_S;
 
465
+  if (extension == "o" || extension == "obj")
 
466
+    return SOURCE_O;
 
467
+  if (extension == "def")
 
468
+    return SOURCE_DEF;
 
469
+  if (extension == "rs")
 
470
+    return SOURCE_RS;
 
471
+  if (extension == "go")
 
472
+    return SOURCE_GO;
 
473
+
 
474
+  return SOURCE_UNKNOWN;
 
475
+}
 
476
--- /dev/null
 
477
+++ b/tools/gn/tools/gn/source_file_type.h
 
478
@@ -0,0 +1,34 @@
 
479
+// Copyright 2014 The Chromium Authors. All rights reserved.
 
480
+// Use of this source code is governed by a BSD-style license that can be
 
481
+// found in the LICENSE file.
 
482
+
 
483
+#ifndef TOOLS_GN_SOURCE_FILE_TYPE_H_
 
484
+#define TOOLS_GN_SOURCE_FILE_TYPE_H_
 
485
+
 
486
+class SourceFile;
 
487
+
 
488
+// This should be sequential integers starting from 0 so they can be used as
 
489
+// array indices.
 
490
+enum SourceFileType {
 
491
+  SOURCE_UNKNOWN = 0,
 
492
+  SOURCE_ASM,
 
493
+  SOURCE_C,
 
494
+  SOURCE_CPP,
 
495
+  SOURCE_H,
 
496
+  SOURCE_M,
 
497
+  SOURCE_MM,
 
498
+  SOURCE_S,
 
499
+  SOURCE_RC,
 
500
+  SOURCE_O,  // Object files can be inputs, too. Also counts .obj.
 
501
+  SOURCE_DEF,
 
502
+
 
503
+  SOURCE_RS,
 
504
+  SOURCE_GO,
 
505
+
 
506
+  // Must be last.
 
507
+  SOURCE_NUMTYPES,
 
508
+};
 
509
+
 
510
+SourceFileType GetSourceFileType(const SourceFile& file);
 
511
+
 
512
+#endif  // TOOLS_GN_SOURCE_FILE_TYPE_H_
 
513
--- a/tools/gn/tools/gn/target.cc
 
514
+++ b/tools/gn/tools/gn/target.cc
 
515
@@ -16,6 +16,7 @@
 
516
 #include "tools/gn/filesystem_utils.h"
 
517
 #include "tools/gn/functions.h"
 
518
 #include "tools/gn/scheduler.h"
 
519
+#include "tools/gn/source_file_type.h"
 
520
 #include "tools/gn/substitution_writer.h"
 
521
 #include "tools/gn/tool.h"
 
522
 #include "tools/gn/toolchain.h"
 
523
@@ -486,10 +487,10 @@ bool Target::GetOutputFilesForSource(con
 
524
   outputs->clear();
 
525
   *computed_tool_type = Tool::kToolNone;
 
526
 
 
527
-  SourceFile::Type file_type = source.type();
 
528
-  if (file_type == SourceFile::SOURCE_UNKNOWN)
 
529
+  SourceFileType file_type = GetSourceFileType(source);
 
530
+  if (file_type == SOURCE_UNKNOWN)
 
531
     return false;
 
532
-  if (file_type == SourceFile::SOURCE_O) {
 
533
+  if (file_type == SOURCE_O) {
 
534
     // Object files just get passed to the output and not compiled.
 
535
     outputs->push_back(OutputFile(settings()->build_settings(), source));
 
536
     return true;
 
537
--- a/tools/gn/tools/gn/tool.cc
 
538
+++ b/tools/gn/tools/gn/tool.cc
 
539
@@ -261,27 +261,27 @@ std::unique_ptr<Tool> Tool::CreateTool(c
 
540
 }
 
541
 
 
542
 // static
 
543
-const char* Tool::GetToolTypeForSourceType(SourceFile::Type type) {
 
544
+const char* Tool::GetToolTypeForSourceType(SourceFileType type) {
 
545
   switch (type) {
 
546
-    case SourceFile::SOURCE_C:
 
547
+    case SOURCE_C:
 
548
       return CTool::kCToolCc;
 
549
-    case SourceFile::SOURCE_CPP:
 
550
+    case SOURCE_CPP:
 
551
       return CTool::kCToolCxx;
 
552
-    case SourceFile::SOURCE_M:
 
553
+    case SOURCE_M:
 
554
       return CTool::kCToolObjC;
 
555
-    case SourceFile::SOURCE_MM:
 
556
+    case SOURCE_MM:
 
557
       return CTool::kCToolObjCxx;
 
558
-    case SourceFile::SOURCE_ASM:
 
559
-    case SourceFile::SOURCE_S:
 
560
+    case SOURCE_ASM:
 
561
+    case SOURCE_S:
 
562
       return CTool::kCToolAsm;
 
563
-    case SourceFile::SOURCE_RC:
 
564
+    case SOURCE_RC:
 
565
       return CTool::kCToolRc;
 
566
-    case SourceFile::SOURCE_UNKNOWN:
 
567
-    case SourceFile::SOURCE_H:
 
568
-    case SourceFile::SOURCE_O:
 
569
-    case SourceFile::SOURCE_DEF:
 
570
-    case SourceFile::SOURCE_GO:
 
571
-    case SourceFile::SOURCE_RS:
 
572
+    case SOURCE_UNKNOWN:
 
573
+    case SOURCE_H:
 
574
+    case SOURCE_O:
 
575
+    case SOURCE_DEF:
 
576
+    case SOURCE_GO:
 
577
+    case SOURCE_RS:
 
578
       return kToolNone;
 
579
     default:
 
580
       NOTREACHED();
 
581
--- a/tools/gn/tools/gn/tool.h
 
582
+++ b/tools/gn/tools/gn/tool.h
 
583
@@ -12,7 +12,7 @@
 
584
 #include "tools/gn/label.h"
 
585
 #include "tools/gn/label_ptr.h"
 
586
 #include "tools/gn/scope.h"
 
587
-#include "tools/gn/source_file.h"
 
588
+#include "tools/gn/source_file_type.h"
 
589
 #include "tools/gn/substitution_list.h"
 
590
 #include "tools/gn/substitution_pattern.h"
 
591
 
 
592
@@ -171,7 +171,7 @@ class Tool {
 
593
                                           Toolchain* toolchain,
 
594
                                           Err* err);
 
595
 
 
596
-  static const char* GetToolTypeForSourceType(SourceFile::Type type);
 
597
+  static const char* GetToolTypeForSourceType(SourceFileType type);
 
598
   static const char* GetToolTypeForTargetFinalOutput(const Target* target);
 
599
 
 
600
  protected:
 
601
--- a/tools/gn/tools/gn/toolchain.cc
 
602
+++ b/tools/gn/tools/gn/toolchain.cc
 
603
@@ -88,16 +88,16 @@ void Toolchain::ToolchainSetupComplete()
 
604
   setup_complete_ = true;
 
605
 }
 
606
 
 
607
-const Tool* Toolchain::GetToolForSourceType(SourceFile::Type type) const {
 
608
+const Tool* Toolchain::GetToolForSourceType(SourceFileType type) const {
 
609
   return GetTool(Tool::GetToolTypeForSourceType(type));
 
610
 }
 
611
 
 
612
-const CTool* Toolchain::GetToolForSourceTypeAsC(SourceFile::Type type) const {
 
613
+const CTool* Toolchain::GetToolForSourceTypeAsC(SourceFileType type) const {
 
614
   return GetToolAsC(Tool::GetToolTypeForSourceType(type));
 
615
 }
 
616
 
 
617
 const GeneralTool* Toolchain::GetToolForSourceTypeAsGeneral(
 
618
-    SourceFile::Type type) const {
 
619
+    SourceFileType type) const {
 
620
   return GetToolAsGeneral(Tool::GetToolTypeForSourceType(type));
 
621
 }
 
622
 
 
623
--- a/tools/gn/tools/gn/toolchain.h
 
624
+++ b/tools/gn/tools/gn/toolchain.h
 
625
@@ -12,6 +12,7 @@
 
626
 #include "tools/gn/item.h"
 
627
 #include "tools/gn/label_ptr.h"
 
628
 #include "tools/gn/scope.h"
 
629
+#include "tools/gn/source_file_type.h"
 
630
 #include "tools/gn/substitution_type.h"
 
631
 #include "tools/gn/tool.h"
 
632
 #include "tools/gn/value.h"
 
633
@@ -87,9 +88,9 @@ class Toolchain : public Item {
 
634
   }
 
635
 
 
636
   // Returns the tool for compiling the given source file type.
 
637
-  const Tool* GetToolForSourceType(SourceFile::Type type) const;
 
638
-  const CTool* GetToolForSourceTypeAsC(SourceFile::Type type) const;
 
639
-  const GeneralTool* GetToolForSourceTypeAsGeneral(SourceFile::Type type) const;
 
640
+  const Tool* GetToolForSourceType(SourceFileType type) const;
 
641
+  const CTool* GetToolForSourceTypeAsC(SourceFileType type) const;
 
642
+  const GeneralTool* GetToolForSourceTypeAsGeneral(SourceFileType type) const;
 
643
 
 
644
   // Returns the tool that produces the final output for the given target type.
 
645
   // This isn't necessarily the tool you would expect. For copy target, this
 
646
--- a/tools/gn/tools/gn/visual_studio_writer.cc
 
647
+++ b/tools/gn/tools/gn/visual_studio_writer.cc
 
648
@@ -24,6 +24,7 @@
 
649
 #include "tools/gn/label_pattern.h"
 
650
 #include "tools/gn/parse_tree.h"
 
651
 #include "tools/gn/path_output.h"
 
652
+#include "tools/gn/source_file_type.h"
 
653
 #include "tools/gn/standard_out.h"
 
654
 #include "tools/gn/target.h"
 
655
 #include "tools/gn/variables.h"