OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/scheduler.h" | 5 #include "tools/gn/scheduler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "tools/gn/standard_out.h" | 10 #include "tools/gn/standard_out.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 void Scheduler::AddGenDependency(const base::FilePath& file) { | 101 void Scheduler::AddGenDependency(const base::FilePath& file) { |
102 base::AutoLock lock(lock_); | 102 base::AutoLock lock(lock_); |
103 gen_dependencies_.push_back(file); | 103 gen_dependencies_.push_back(file); |
104 } | 104 } |
105 | 105 |
106 std::vector<base::FilePath> Scheduler::GetGenDependencies() const { | 106 std::vector<base::FilePath> Scheduler::GetGenDependencies() const { |
107 base::AutoLock lock(lock_); | 107 base::AutoLock lock(lock_); |
108 return gen_dependencies_; | 108 return gen_dependencies_; |
109 } | 109 } |
110 | 110 |
| 111 void Scheduler::AddWrittenFile(const SourceFile& file) { |
| 112 base::AutoLock lock(lock_); |
| 113 written_files_.push_back(file); |
| 114 } |
| 115 |
| 116 void Scheduler::AddUnknownGeneratedInput(const Target* target, |
| 117 const SourceFile& file) { |
| 118 base::AutoLock lock(lock_); |
| 119 unknown_generated_inputs_.insert(std::make_pair(file, target)); |
| 120 } |
| 121 |
| 122 std::multimap<SourceFile, const Target*> |
| 123 Scheduler::GetUnknownGeneratedInputs() const { |
| 124 base::AutoLock lock(lock_); |
| 125 |
| 126 // Remove all unknown inputs that were written files. These are OK as inputs |
| 127 // to build steps since they were written as a side-effect of running GN. |
| 128 // |
| 129 // It's assumed that this function is called once during cleanup to check for |
| 130 // errors, so performing this work in the lock doesn't matter. |
| 131 std::multimap<SourceFile, const Target*> filtered = unknown_generated_inputs_; |
| 132 for (const SourceFile& file : written_files_) |
| 133 filtered.erase(file); |
| 134 |
| 135 return filtered; |
| 136 } |
| 137 |
| 138 void Scheduler::ClearUnknownGeneratedInputsAndWrittenFiles() { |
| 139 base::AutoLock lock(lock_); |
| 140 unknown_generated_inputs_.clear(); |
| 141 written_files_.clear(); |
| 142 } |
| 143 |
111 void Scheduler::IncrementWorkCount() { | 144 void Scheduler::IncrementWorkCount() { |
112 base::AtomicRefCountInc(&work_count_); | 145 base::AtomicRefCountInc(&work_count_); |
113 } | 146 } |
114 | 147 |
115 void Scheduler::DecrementWorkCount() { | 148 void Scheduler::DecrementWorkCount() { |
116 if (!base::AtomicRefCountDec(&work_count_)) { | 149 if (!base::AtomicRefCountDec(&work_count_)) { |
117 if (base::MessageLoop::current() == &main_loop_) { | 150 if (base::MessageLoop::current() == &main_loop_) { |
118 OnComplete(); | 151 OnComplete(); |
119 } else { | 152 } else { |
120 main_loop_.PostTask(FROM_HERE, | 153 main_loop_.PostTask(FROM_HERE, |
(...skipping 17 matching lines...) Expand all Loading... |
138 void Scheduler::DoWork(const base::Closure& closure) { | 171 void Scheduler::DoWork(const base::Closure& closure) { |
139 closure.Run(); | 172 closure.Run(); |
140 DecrementWorkCount(); | 173 DecrementWorkCount(); |
141 } | 174 } |
142 | 175 |
143 void Scheduler::OnComplete() { | 176 void Scheduler::OnComplete() { |
144 // Should be called on the main thread. | 177 // Should be called on the main thread. |
145 DCHECK(base::MessageLoop::current() == main_loop()); | 178 DCHECK(base::MessageLoop::current() == main_loop()); |
146 runner_.Quit(); | 179 runner_.Quit(); |
147 } | 180 } |
OLD | NEW |