summaryrefslogtreecommitdiffstats
path: root/chromium/build/patches/chromium-gn-bootstrap-revert-4960.patch
blob: bb51adad610156f4e9f3e66036b342de0cdf1803 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
Description: revert https://gn.googlesource.com/gn/+/0d038c2e0a32a528713d3dfaf1f1e0cdfe87fd46, which breaks the chromium build

--- a/tools/gn/build/gen.py
+++ b/tools/gn/build/gen.py
@@ -522,6 +522,7 @@ def WriteGNNinja(path, platform, host, o
         'tools/gn/setup.cc',
         'tools/gn/source_dir.cc',
         'tools/gn/source_file.cc',
+        'tools/gn/source_file_type.cc',
         'tools/gn/standard_out.cc',
         'tools/gn/string_utils.cc',
         'tools/gn/substitution_list.cc',
--- a/tools/gn/tools/gn/c_tool.h
+++ b/tools/gn/tools/gn/c_tool.h
@@ -12,6 +12,7 @@
 #include "tools/gn/label.h"
 #include "tools/gn/label_ptr.h"
 #include "tools/gn/scope.h"
+#include "tools/gn/source_file_type.h"
 #include "tools/gn/substitution_list.h"
 #include "tools/gn/substitution_pattern.h"
 #include "tools/gn/tool.h"
--- a/tools/gn/tools/gn/compile_commands_writer.cc
+++ b/tools/gn/tools/gn/compile_commands_writer.cc
@@ -122,7 +122,7 @@ void WriteCommand(const Target* target,
                   const CompileFlags& flags,
                   std::vector<OutputFile>& tool_outputs,
                   PathOutput& path_output,
-                  SourceFile::Type source_type,
+                  SourceFileType source_type,
                   const char* tool_name,
                   EscapeOptions opts,
                   std::string* compile_commands) {
@@ -144,16 +144,16 @@ void WriteCommand(const Target* target,
     } else if (range.type == &CSubstitutionCFlags) {
       command_out << flags.cflags;
     } else if (range.type == &CSubstitutionCFlagsC) {
-      if (source_type == SourceFile::SOURCE_C)
+      if (source_type == SOURCE_C)
         command_out << flags.cflags_c;
     } else if (range.type == &CSubstitutionCFlagsCc) {
-      if (source_type == SourceFile::SOURCE_CPP)
+      if (source_type == SOURCE_CPP)
         command_out << flags.cflags_cc;
     } else if (range.type == &CSubstitutionCFlagsObjC) {
-      if (source_type == SourceFile::SOURCE_M)
+      if (source_type == SOURCE_M)
         command_out << flags.cflags_objc;
     } else if (range.type == &CSubstitutionCFlagsObjCc) {
-      if (source_type == SourceFile::SOURCE_MM)
+      if (source_type == SOURCE_MM)
         command_out << flags.cflags_objcc;
     } else if (range.type == &SubstitutionLabel ||
                range.type == &SubstitutionLabelName ||
@@ -222,11 +222,9 @@ void CompileCommandsWriter::RenderJSON(c
     for (const auto& source : target->sources()) {
       // If this source is not a C/C++/ObjC/ObjC++ source (not header) file,
       // continue as it does not belong in the compilation database.
-      SourceFile::Type source_type = source.type();
-      if (source_type != SourceFile::SOURCE_CPP &&
-          source_type != SourceFile::SOURCE_C &&
-          source_type != SourceFile::SOURCE_M &&
-          source_type != SourceFile::SOURCE_MM)
+      SourceFileType source_type = GetSourceFileType(source);
+      if (source_type != SOURCE_CPP && source_type != SOURCE_C &&
+          source_type != SOURCE_M && source_type != SOURCE_MM)
         continue;
 
       const char* tool_name = Tool::kToolNone;
@@ -324,4 +322,4 @@ void CompileCommandsWriter::VisitDeps(co
       VisitDeps(pair.ptr, visited);
     }
   }
-}
+}
\ No newline at end of file
--- a/tools/gn/tools/gn/general_tool.h
+++ b/tools/gn/tools/gn/general_tool.h
@@ -11,6 +11,7 @@
 #include "base/macros.h"
 #include "tools/gn/label.h"
 #include "tools/gn/label_ptr.h"
+#include "tools/gn/source_file_type.h"
 #include "tools/gn/substitution_list.h"
 #include "tools/gn/substitution_pattern.h"
 #include "tools/gn/tool.h"
--- a/tools/gn/tools/gn/header_checker.cc
+++ b/tools/gn/tools/gn/header_checker.cc
@@ -18,6 +18,7 @@
 #include "tools/gn/err.h"
 #include "tools/gn/filesystem_utils.h"
 #include "tools/gn/scheduler.h"
+#include "tools/gn/source_file_type.h"
 #include "tools/gn/target.h"
 #include "tools/gn/trace.h"
 #include "util/worker_pool.h"
@@ -151,10 +152,9 @@ void HeaderChecker::RunCheckOverFiles(co
 
   for (const auto& file : files) {
     // Only check C-like source files (RC files also have includes).
-    SourceFile::Type type = file.first.type();
-    if (type != SourceFile::SOURCE_CPP && type != SourceFile::SOURCE_H &&
-        type != SourceFile::SOURCE_C && type != SourceFile::SOURCE_M &&
-        type != SourceFile::SOURCE_MM && type != SourceFile::SOURCE_RC)
+    SourceFileType type = GetSourceFileType(file.first);
+    if (type != SOURCE_CPP && type != SOURCE_H && type != SOURCE_C &&
+        type != SOURCE_M && type != SOURCE_MM && type != SOURCE_RC)
       continue;
 
     if (!check_generated_) {
--- a/tools/gn/tools/gn/ninja_binary_target_writer.cc
+++ b/tools/gn/tools/gn/ninja_binary_target_writer.cc
@@ -23,23 +23,22 @@
 #include "tools/gn/ninja_utils.h"
 #include "tools/gn/scheduler.h"
 #include "tools/gn/settings.h"
+#include "tools/gn/source_file_type.h"
 #include "tools/gn/string_utils.h"
 #include "tools/gn/substitution_writer.h"
 #include "tools/gn/target.h"
 
 bool NinjaBinaryTargetWriter::SourceFileTypeSet::CSourceUsed() {
-  return Get(SourceFile::SOURCE_CPP) || Get(SourceFile::SOURCE_H) ||
-         Get(SourceFile::SOURCE_C) || Get(SourceFile::SOURCE_M) ||
-         Get(SourceFile::SOURCE_MM) || Get(SourceFile::SOURCE_RC) ||
-         Get(SourceFile::SOURCE_S);
+  return Get(SOURCE_CPP) || Get(SOURCE_H) || Get(SOURCE_C) || Get(SOURCE_M) ||
+         Get(SOURCE_MM) || Get(SOURCE_RC) || Get(SOURCE_S);
 }
 
 bool NinjaBinaryTargetWriter::SourceFileTypeSet::RustSourceUsed() {
-  return Get(SourceFile::SOURCE_RS);
+  return Get(SOURCE_RS);
 }
 
 bool NinjaBinaryTargetWriter::SourceFileTypeSet::GoSourceUsed() {
-  return Get(SourceFile::SOURCE_GO);
+  return Get(SOURCE_GO);
 }
 
 NinjaBinaryTargetWriter::NinjaBinaryTargetWriter(const Target* target,
@@ -50,6 +49,10 @@ NinjaBinaryTargetWriter::NinjaBinaryTarg
 NinjaBinaryTargetWriter::~NinjaBinaryTargetWriter() = default;
 
 void NinjaBinaryTargetWriter::Run() {
+  SourceFileTypeSet used_types;
+  for (const auto& source : target_->sources())
+    used_types.Set(GetSourceFileType(source));
+
   NinjaCBinaryTargetWriter writer(target_, out_);
   writer.Run();
 }
--- a/tools/gn/tools/gn/ninja_binary_target_writer.h
+++ b/tools/gn/tools/gn/ninja_binary_target_writer.h
@@ -23,12 +23,11 @@ class NinjaBinaryTargetWriter : public N
   class SourceFileTypeSet {
    public:
     SourceFileTypeSet() {
-      memset(flags_, 0,
-             sizeof(bool) * static_cast<int>(SourceFile::SOURCE_NUMTYPES));
+      memset(flags_, 0, sizeof(bool) * static_cast<int>(SOURCE_NUMTYPES));
     }
 
-    void Set(SourceFile::Type type) { flags_[static_cast<int>(type)] = true; }
-    bool Get(SourceFile::Type type) const {
+    void Set(SourceFileType type) { flags_[static_cast<int>(type)] = true; }
+    bool Get(SourceFileType type) const {
       return flags_[static_cast<int>(type)];
     }
 
@@ -37,7 +36,7 @@ class NinjaBinaryTargetWriter : public N
     bool GoSourceUsed();
 
    private:
-    bool flags_[static_cast<int>(SourceFile::SOURCE_NUMTYPES)];
+    bool flags_[static_cast<int>(SOURCE_NUMTYPES)];
   };
 
   NinjaBinaryTargetWriter(const Target* target, std::ostream& out);
--- a/tools/gn/tools/gn/ninja_c_binary_target_writer.cc
+++ b/tools/gn/tools/gn/ninja_c_binary_target_writer.cc
@@ -24,6 +24,7 @@
 #include "tools/gn/ninja_utils.h"
 #include "tools/gn/scheduler.h"
 #include "tools/gn/settings.h"
+#include "tools/gn/source_file_type.h"
 #include "tools/gn/string_utils.h"
 #include "tools/gn/substitution_writer.h"
 #include "tools/gn/target.h"
@@ -66,27 +67,27 @@ void AddSourceSetObjectFiles(const Targe
     if (source_set->GetOutputFilesForSource(source, &tool_name, &tool_outputs))
       obj_files->push_back(tool_outputs[0]);
 
-    used_types.Set(source.type());
+    used_types.Set(GetSourceFileType(source));
   }
 
   // Add MSVC precompiled header object files. GCC .gch files are not object
   // files so they are omitted.
   if (source_set->config_values().has_precompiled_headers()) {
-    if (used_types.Get(SourceFile::SOURCE_C)) {
+    if (used_types.Get(SOURCE_C)) {
       const CTool* tool = source_set->toolchain()->GetToolAsC(CTool::kCToolCc);
       if (tool && tool->precompiled_header_type() == CTool::PCH_MSVC) {
         GetPCHOutputFiles(source_set, CTool::kCToolCc, &tool_outputs);
         obj_files->Append(tool_outputs.begin(), tool_outputs.end());
       }
     }
-    if (used_types.Get(SourceFile::SOURCE_CPP)) {
+    if (used_types.Get(SOURCE_CPP)) {
       const CTool* tool = source_set->toolchain()->GetToolAsC(CTool::kCToolCxx);
       if (tool && tool->precompiled_header_type() == CTool::PCH_MSVC) {
         GetPCHOutputFiles(source_set, CTool::kCToolCxx, &tool_outputs);
         obj_files->Append(tool_outputs.begin(), tool_outputs.end());
       }
     }
-    if (used_types.Get(SourceFile::SOURCE_M)) {
+    if (used_types.Get(SOURCE_M)) {
       const CTool* tool =
           source_set->toolchain()->GetToolAsC(CTool::kCToolObjC);
       if (tool && tool->precompiled_header_type() == CTool::PCH_MSVC) {
@@ -94,7 +95,7 @@ void AddSourceSetObjectFiles(const Targe
         obj_files->Append(tool_outputs.begin(), tool_outputs.end());
       }
     }
-    if (used_types.Get(SourceFile::SOURCE_MM)) {
+    if (used_types.Get(SOURCE_MM)) {
       const CTool* tool =
           source_set->toolchain()->GetToolAsC(CTool::kCToolObjCxx);
       if (tool && tool->precompiled_header_type() == CTool::PCH_MSVC) {
@@ -118,7 +119,7 @@ void NinjaCBinaryTargetWriter::Run() {
   // Figure out what source types are needed.
   SourceFileTypeSet used_types;
   for (const auto& source : target_->sources())
-    used_types.Set(source.type());
+    used_types.Set(GetSourceFileType(source));
 
   WriteCompilerVars(used_types);
 
@@ -234,34 +235,31 @@ void NinjaCBinaryTargetWriter::WriteComp
       target_->config_values().has_precompiled_headers();
 
   EscapeOptions opts = GetFlagOptions();
-  if (used_types.Get(SourceFile::SOURCE_S) ||
-      used_types.Get(SourceFile::SOURCE_ASM)) {
+  if (used_types.Get(SOURCE_S) || used_types.Get(SOURCE_ASM)) {
     WriteOneFlag(target_, &CSubstitutionAsmFlags, false, Tool::kToolNone,
                  &ConfigValues::asmflags, opts, path_output_, out_);
   }
-  if (used_types.Get(SourceFile::SOURCE_C) ||
-      used_types.Get(SourceFile::SOURCE_CPP) ||
-      used_types.Get(SourceFile::SOURCE_M) ||
-      used_types.Get(SourceFile::SOURCE_MM)) {
+  if (used_types.Get(SOURCE_C) || used_types.Get(SOURCE_CPP) ||
+      used_types.Get(SOURCE_M) || used_types.Get(SOURCE_MM)) {
     WriteOneFlag(target_, &CSubstitutionCFlags, false, Tool::kToolNone,
                  &ConfigValues::cflags, opts, path_output_, out_);
   }
-  if (used_types.Get(SourceFile::SOURCE_C)) {
+  if (used_types.Get(SOURCE_C)) {
     WriteOneFlag(target_, &CSubstitutionCFlagsC, has_precompiled_headers,
                  CTool::kCToolCc, &ConfigValues::cflags_c, opts, path_output_,
                  out_);
   }
-  if (used_types.Get(SourceFile::SOURCE_CPP)) {
+  if (used_types.Get(SOURCE_CPP)) {
     WriteOneFlag(target_, &CSubstitutionCFlagsCc, has_precompiled_headers,
                  CTool::kCToolCxx, &ConfigValues::cflags_cc, opts, path_output_,
                  out_);
   }
-  if (used_types.Get(SourceFile::SOURCE_M)) {
+  if (used_types.Get(SOURCE_M)) {
     WriteOneFlag(target_, &CSubstitutionCFlagsObjC, has_precompiled_headers,
                  CTool::kCToolObjC, &ConfigValues::cflags_objc, opts,
                  path_output_, out_);
   }
-  if (used_types.Get(SourceFile::SOURCE_MM)) {
+  if (used_types.Get(SOURCE_MM)) {
     WriteOneFlag(target_, &CSubstitutionCFlagsObjCc, has_precompiled_headers,
                  CTool::kCToolObjCxx, &ConfigValues::cflags_objcc, opts,
                  path_output_, out_);
@@ -321,14 +319,14 @@ void NinjaCBinaryTargetWriter::WritePCHC
 
   const CTool* tool_c = target_->toolchain()->GetToolAsC(CTool::kCToolCc);
   if (tool_c && tool_c->precompiled_header_type() != CTool::PCH_NONE &&
-      used_types.Get(SourceFile::SOURCE_C)) {
+      used_types.Get(SOURCE_C)) {
     WritePCHCommand(&CSubstitutionCFlagsC, CTool::kCToolCc,
                     tool_c->precompiled_header_type(), input_dep,
                     order_only_deps, object_files, other_files);
   }
   const CTool* tool_cxx = target_->toolchain()->GetToolAsC(CTool::kCToolCxx);
   if (tool_cxx && tool_cxx->precompiled_header_type() != CTool::PCH_NONE &&
-      used_types.Get(SourceFile::SOURCE_CPP)) {
+      used_types.Get(SOURCE_CPP)) {
     WritePCHCommand(&CSubstitutionCFlagsCc, CTool::kCToolCxx,
                     tool_cxx->precompiled_header_type(), input_dep,
                     order_only_deps, object_files, other_files);
@@ -336,7 +334,7 @@ void NinjaCBinaryTargetWriter::WritePCHC
 
   const CTool* tool_objc = target_->toolchain()->GetToolAsC(CTool::kCToolObjC);
   if (tool_objc && tool_objc->precompiled_header_type() == CTool::PCH_GCC &&
-      used_types.Get(SourceFile::SOURCE_M)) {
+      used_types.Get(SOURCE_M)) {
     WritePCHCommand(&CSubstitutionCFlagsObjC, CTool::kCToolObjC,
                     tool_objc->precompiled_header_type(), input_dep,
                     order_only_deps, object_files, other_files);
@@ -345,7 +343,7 @@ void NinjaCBinaryTargetWriter::WritePCHC
   const CTool* tool_objcxx =
       target_->toolchain()->GetToolAsC(CTool::kCToolObjCxx);
   if (tool_objcxx && tool_objcxx->precompiled_header_type() == CTool::PCH_GCC &&
-      used_types.Get(SourceFile::SOURCE_MM)) {
+      used_types.Get(SOURCE_MM)) {
     WritePCHCommand(&CSubstitutionCFlagsObjCc, CTool::kCToolObjCxx,
                     tool_objcxx->precompiled_header_type(), input_dep,
                     order_only_deps, object_files, other_files);
@@ -478,7 +476,7 @@ void NinjaCBinaryTargetWriter::WriteSour
     deps.resize(0);
     const char* tool_name = Tool::kToolNone;
     if (!target_->GetOutputFilesForSource(source, &tool_name, &tool_outputs)) {
-      if (source.type() == SourceFile::SOURCE_DEF)
+      if (GetSourceFileType(source) == SOURCE_DEF)
         other_files->push_back(source);
       continue;  // No output for this source.
     }
@@ -599,7 +597,7 @@ void NinjaCBinaryTargetWriter::WriteLink
   const SourceFile* optional_def_file = nullptr;
   if (!other_files.empty()) {
     for (const SourceFile& src_file : other_files) {
-      if (src_file.type() == SourceFile::SOURCE_DEF) {
+      if (GetSourceFileType(src_file) == SOURCE_DEF) {
         optional_def_file = &src_file;
         implicit_deps.push_back(
             OutputFile(settings_->build_settings(), src_file));
--- a/tools/gn/tools/gn/source_file.cc
+++ b/tools/gn/tools/gn/source_file.cc
@@ -21,48 +21,18 @@ void AssertValueSourceFileString(const s
   DCHECK(!EndsWithSlash(s)) << s;
 }
 
-SourceFile::Type GetSourceFileType(const std::string& file) {
-  base::StringPiece extension = FindExtension(&file);
-  if (extension == "cc" || extension == "cpp" || extension == "cxx")
-    return SourceFile::SOURCE_CPP;
-  if (extension == "h" || extension == "hpp" || extension == "hxx" ||
-      extension == "hh" || extension == "inc")
-    return SourceFile::SOURCE_H;
-  if (extension == "c")
-    return SourceFile::SOURCE_C;
-  if (extension == "m")
-    return SourceFile::SOURCE_M;
-  if (extension == "mm")
-    return SourceFile::SOURCE_MM;
-  if (extension == "rc")
-    return SourceFile::SOURCE_RC;
-  if (extension == "S" || extension == "s" || extension == "asm")
-    return SourceFile::SOURCE_S;
-  if (extension == "o" || extension == "obj")
-    return SourceFile::SOURCE_O;
-  if (extension == "def")
-    return SourceFile::SOURCE_DEF;
-  if (extension == "rs")
-    return SourceFile::SOURCE_RS;
-  if (extension == "go")
-    return SourceFile::SOURCE_GO;
-
-  return SourceFile::SOURCE_UNKNOWN;
-}
-
 }  // namespace
 
-SourceFile::SourceFile() : type_(SOURCE_UNKNOWN) {}
+SourceFile::SourceFile() = default;
 
 SourceFile::SourceFile(const base::StringPiece& p)
-    : value_(p.data(), p.size()), type_(GetSourceFileType(value_)) {
+    : value_(p.data(), p.size()) {
   DCHECK(!value_.empty());
   AssertValueSourceFileString(value_);
   NormalizePath(&value_);
 }
 
-SourceFile::SourceFile(SwapIn, std::string* value)
-    : type_(GetSourceFileType(*value)) {
+SourceFile::SourceFile(SwapIn, std::string* value) {
   value_.swap(*value);
   DCHECK(!value_.empty());
   AssertValueSourceFileString(value_);
--- a/tools/gn/tools/gn/source_file.h
+++ b/tools/gn/tools/gn/source_file.h
@@ -20,28 +20,6 @@ class SourceDir;
 // ends in one.
 class SourceFile {
  public:
-  // This should be sequential integers starting from 0 so they can be used as
-  // array indices.
-  enum Type {
-    SOURCE_UNKNOWN = 0,
-    SOURCE_ASM,
-    SOURCE_C,
-    SOURCE_CPP,
-    SOURCE_H,
-    SOURCE_M,
-    SOURCE_MM,
-    SOURCE_S,
-    SOURCE_RC,
-    SOURCE_O,  // Object files can be inputs, too. Also counts .obj.
-    SOURCE_DEF,
-
-    SOURCE_RS,
-    SOURCE_GO,
-
-    // Must be last.
-    SOURCE_NUMTYPES,
-  };
-
   enum SwapIn { SWAP_IN };
 
   SourceFile();
@@ -58,7 +36,6 @@ class SourceFile {
 
   bool is_null() const { return value_.empty(); }
   const std::string& value() const { return value_; }
-  Type type() const { return type_; }
 
   // Returns everything after the last slash.
   std::string GetName() const;
@@ -103,7 +80,6 @@ class SourceFile {
   friend class SourceDir;
 
   std::string value_;
-  Type type_;
 
   // Copy & assign supported.
 };
--- /dev/null
+++ b/tools/gn/tools/gn/source_file_type.cc
@@ -0,0 +1,37 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "tools/gn/source_file_type.h"
+
+#include "tools/gn/filesystem_utils.h"
+#include "tools/gn/source_file.h"
+
+SourceFileType GetSourceFileType(const SourceFile& file) {
+  base::StringPiece extension = FindExtension(&file.value());
+  if (extension == "cc" || extension == "cpp" || extension == "cxx")
+    return SOURCE_CPP;
+  if (extension == "h" || extension == "hpp" || extension == "hxx" ||
+      extension == "hh")
+    return SOURCE_H;
+  if (extension == "c")
+    return SOURCE_C;
+  if (extension == "m")
+    return SOURCE_M;
+  if (extension == "mm")
+    return SOURCE_MM;
+  if (extension == "rc")
+    return SOURCE_RC;
+  if (extension == "S" || extension == "s" || extension == "asm")
+    return SOURCE_S;
+  if (extension == "o" || extension == "obj")
+    return SOURCE_O;
+  if (extension == "def")
+    return SOURCE_DEF;
+  if (extension == "rs")
+    return SOURCE_RS;
+  if (extension == "go")
+    return SOURCE_GO;
+
+  return SOURCE_UNKNOWN;
+}
--- /dev/null
+++ b/tools/gn/tools/gn/source_file_type.h
@@ -0,0 +1,34 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TOOLS_GN_SOURCE_FILE_TYPE_H_
+#define TOOLS_GN_SOURCE_FILE_TYPE_H_
+
+class SourceFile;
+
+// This should be sequential integers starting from 0 so they can be used as
+// array indices.
+enum SourceFileType {
+  SOURCE_UNKNOWN = 0,
+  SOURCE_ASM,
+  SOURCE_C,
+  SOURCE_CPP,
+  SOURCE_H,
+  SOURCE_M,
+  SOURCE_MM,
+  SOURCE_S,
+  SOURCE_RC,
+  SOURCE_O,  // Object files can be inputs, too. Also counts .obj.
+  SOURCE_DEF,
+
+  SOURCE_RS,
+  SOURCE_GO,
+
+  // Must be last.
+  SOURCE_NUMTYPES,
+};
+
+SourceFileType GetSourceFileType(const SourceFile& file);
+
+#endif  // TOOLS_GN_SOURCE_FILE_TYPE_H_
--- a/tools/gn/tools/gn/target.cc
+++ b/tools/gn/tools/gn/target.cc
@@ -16,6 +16,7 @@
 #include "tools/gn/filesystem_utils.h"
 #include "tools/gn/functions.h"
 #include "tools/gn/scheduler.h"
+#include "tools/gn/source_file_type.h"
 #include "tools/gn/substitution_writer.h"
 #include "tools/gn/tool.h"
 #include "tools/gn/toolchain.h"
@@ -486,10 +487,10 @@ bool Target::GetOutputFilesForSource(con
   outputs->clear();
   *computed_tool_type = Tool::kToolNone;
 
-  SourceFile::Type file_type = source.type();
-  if (file_type == SourceFile::SOURCE_UNKNOWN)
+  SourceFileType file_type = GetSourceFileType(source);
+  if (file_type == SOURCE_UNKNOWN)
     return false;
-  if (file_type == SourceFile::SOURCE_O) {
+  if (file_type == SOURCE_O) {
     // Object files just get passed to the output and not compiled.
     outputs->push_back(OutputFile(settings()->build_settings(), source));
     return true;
--- a/tools/gn/tools/gn/tool.cc
+++ b/tools/gn/tools/gn/tool.cc
@@ -261,27 +261,27 @@ std::unique_ptr<Tool> Tool::CreateTool(c
 }
 
 // static
-const char* Tool::GetToolTypeForSourceType(SourceFile::Type type) {
+const char* Tool::GetToolTypeForSourceType(SourceFileType type) {
   switch (type) {
-    case SourceFile::SOURCE_C:
+    case SOURCE_C:
       return CTool::kCToolCc;
-    case SourceFile::SOURCE_CPP:
+    case SOURCE_CPP:
       return CTool::kCToolCxx;
-    case SourceFile::SOURCE_M:
+    case SOURCE_M:
       return CTool::kCToolObjC;
-    case SourceFile::SOURCE_MM:
+    case SOURCE_MM:
       return CTool::kCToolObjCxx;
-    case SourceFile::SOURCE_ASM:
-    case SourceFile::SOURCE_S:
+    case SOURCE_ASM:
+    case SOURCE_S:
       return CTool::kCToolAsm;
-    case SourceFile::SOURCE_RC:
+    case SOURCE_RC:
       return CTool::kCToolRc;
-    case SourceFile::SOURCE_UNKNOWN:
-    case SourceFile::SOURCE_H:
-    case SourceFile::SOURCE_O:
-    case SourceFile::SOURCE_DEF:
-    case SourceFile::SOURCE_GO:
-    case SourceFile::SOURCE_RS:
+    case SOURCE_UNKNOWN:
+    case SOURCE_H:
+    case SOURCE_O:
+    case SOURCE_DEF:
+    case SOURCE_GO:
+    case SOURCE_RS:
       return kToolNone;
     default:
       NOTREACHED();
--- a/tools/gn/tools/gn/tool.h
+++ b/tools/gn/tools/gn/tool.h
@@ -12,7 +12,7 @@
 #include "tools/gn/label.h"
 #include "tools/gn/label_ptr.h"
 #include "tools/gn/scope.h"
-#include "tools/gn/source_file.h"
+#include "tools/gn/source_file_type.h"
 #include "tools/gn/substitution_list.h"
 #include "tools/gn/substitution_pattern.h"
 
@@ -171,7 +171,7 @@ class Tool {
                                           Toolchain* toolchain,
                                           Err* err);
 
-  static const char* GetToolTypeForSourceType(SourceFile::Type type);
+  static const char* GetToolTypeForSourceType(SourceFileType type);
   static const char* GetToolTypeForTargetFinalOutput(const Target* target);
 
  protected:
--- a/tools/gn/tools/gn/toolchain.cc
+++ b/tools/gn/tools/gn/toolchain.cc
@@ -88,16 +88,16 @@ void Toolchain::ToolchainSetupComplete()
   setup_complete_ = true;
 }
 
-const Tool* Toolchain::GetToolForSourceType(SourceFile::Type type) const {
+const Tool* Toolchain::GetToolForSourceType(SourceFileType type) const {
   return GetTool(Tool::GetToolTypeForSourceType(type));
 }
 
-const CTool* Toolchain::GetToolForSourceTypeAsC(SourceFile::Type type) const {
+const CTool* Toolchain::GetToolForSourceTypeAsC(SourceFileType type) const {
   return GetToolAsC(Tool::GetToolTypeForSourceType(type));
 }
 
 const GeneralTool* Toolchain::GetToolForSourceTypeAsGeneral(
-    SourceFile::Type type) const {
+    SourceFileType type) const {
   return GetToolAsGeneral(Tool::GetToolTypeForSourceType(type));
 }
 
--- a/tools/gn/tools/gn/toolchain.h
+++ b/tools/gn/tools/gn/toolchain.h
@@ -12,6 +12,7 @@
 #include "tools/gn/item.h"
 #include "tools/gn/label_ptr.h"
 #include "tools/gn/scope.h"
+#include "tools/gn/source_file_type.h"
 #include "tools/gn/substitution_type.h"
 #include "tools/gn/tool.h"
 #include "tools/gn/value.h"
@@ -87,9 +88,9 @@ class Toolchain : public Item {
   }
 
   // Returns the tool for compiling the given source file type.
-  const Tool* GetToolForSourceType(SourceFile::Type type) const;
-  const CTool* GetToolForSourceTypeAsC(SourceFile::Type type) const;
-  const GeneralTool* GetToolForSourceTypeAsGeneral(SourceFile::Type type) const;
+  const Tool* GetToolForSourceType(SourceFileType type) const;
+  const CTool* GetToolForSourceTypeAsC(SourceFileType type) const;
+  const GeneralTool* GetToolForSourceTypeAsGeneral(SourceFileType type) const;
 
   // Returns the tool that produces the final output for the given target type.
   // This isn't necessarily the tool you would expect. For copy target, this
--- a/tools/gn/tools/gn/visual_studio_writer.cc
+++ b/tools/gn/tools/gn/visual_studio_writer.cc
@@ -24,6 +24,7 @@
 #include "tools/gn/label_pattern.h"
 #include "tools/gn/parse_tree.h"
 #include "tools/gn/path_output.h"
+#include "tools/gn/source_file_type.h"
 #include "tools/gn/standard_out.h"
 #include "tools/gn/target.h"
 #include "tools/gn/variables.h"