OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/xcode_writer.h" | 5 #include "tools/gn/xcode_writer.h" |
6 | 6 |
7 #include <iomanip> | 7 #include <iomanip> |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 if (!XcodeWriter::FilterTargets(build_settings, all_targets, | 184 if (!XcodeWriter::FilterTargets(build_settings, all_targets, |
185 dir_filters_string, &targets, err)) { | 185 dir_filters_string, &targets, err)) { |
186 return false; | 186 return false; |
187 } | 187 } |
188 | 188 |
189 XcodeWriter workspace(workspace_name); | 189 XcodeWriter workspace(workspace_name); |
190 workspace.CreateProductsProject(targets, attributes, source_path, config_name, | 190 workspace.CreateProductsProject(targets, attributes, source_path, config_name, |
191 root_target_name, ninja_extra_args, | 191 root_target_name, ninja_extra_args, |
192 build_settings, target_os); | 192 build_settings, target_os); |
193 | 193 |
194 workspace.CreateSourcesProject(all_targets, build_settings->build_dir(), | 194 workspace.CreateSourcesProject( |
195 attributes, source_path, config_name, | 195 all_targets, build_settings->build_dir(), attributes, source_path, |
196 target_os); | 196 build_settings->root_path_utf8(), config_name, target_os); |
197 | 197 |
198 return workspace.WriteFiles(build_settings, err); | 198 return workspace.WriteFiles(build_settings, err); |
199 } | 199 } |
200 | 200 |
201 XcodeWriter::XcodeWriter(const std::string& name) : name_(name) { | 201 XcodeWriter::XcodeWriter(const std::string& name) : name_(name) { |
202 if (name_.empty()) | 202 if (name_.empty()) |
203 name_.assign("all"); | 203 name_.assign("all"); |
204 } | 204 } |
205 | 205 |
206 XcodeWriter::~XcodeWriter() {} | 206 XcodeWriter::~XcodeWriter() {} |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } | 314 } |
315 | 315 |
316 projects_.push_back(std::move(main_project)); | 316 projects_.push_back(std::move(main_project)); |
317 } | 317 } |
318 | 318 |
319 void XcodeWriter::CreateSourcesProject( | 319 void XcodeWriter::CreateSourcesProject( |
320 const std::vector<const Target*>& targets, | 320 const std::vector<const Target*>& targets, |
321 const SourceDir& root_build_dir, | 321 const SourceDir& root_build_dir, |
322 const PBXAttributes& attributes, | 322 const PBXAttributes& attributes, |
323 const std::string& source_path, | 323 const std::string& source_path, |
| 324 const std::string& absolute_source_path, |
324 const std::string& config_name, | 325 const std::string& config_name, |
325 TargetOsType target_os) { | 326 TargetOsType target_os) { |
326 std::vector<SourceFile> sources; | 327 std::vector<SourceFile> sources; |
327 for (const Target* target : targets) { | 328 for (const Target* target : targets) { |
328 for (const SourceFile& source : target->sources()) { | 329 for (const SourceFile& source : target->sources()) { |
329 if (source.is_system_absolute()) | |
330 continue; | |
331 | |
332 if (IsStringInOutputDir(root_build_dir, source.value())) | 330 if (IsStringInOutputDir(root_build_dir, source.value())) |
333 continue; | 331 continue; |
334 | 332 |
335 sources.push_back(source); | 333 sources.push_back(source); |
336 } | 334 } |
337 } | 335 } |
338 | 336 |
339 std::unique_ptr<PBXProject> sources_for_indexing( | 337 std::unique_ptr<PBXProject> sources_for_indexing( |
340 new PBXProject("sources", config_name, source_path, attributes)); | 338 new PBXProject("sources", config_name, source_path, attributes)); |
341 | 339 |
342 // Sort sources to ensure determinisn of the project file generation and | 340 // Sort sources to ensure determinisn of the project file generation and |
343 // remove duplicate reference to the source files (can happen due to the | 341 // remove duplicate reference to the source files (can happen due to the |
344 // bundle_data targets). | 342 // bundle_data targets). |
345 std::sort(sources.begin(), sources.end()); | 343 std::sort(sources.begin(), sources.end()); |
346 sources.erase(std::unique(sources.begin(), sources.end()), sources.end()); | 344 sources.erase(std::unique(sources.begin(), sources.end()), sources.end()); |
347 | 345 |
348 SourceDir source_dir("//"); | 346 SourceDir source_dir("//"); |
349 for (const SourceFile& source : sources) { | 347 for (const SourceFile& source : sources) { |
350 std::string source_file = RebasePath(source.value(), source_dir); | 348 std::string source_file = |
| 349 RebasePath(source.value(), source_dir, absolute_source_path); |
351 sources_for_indexing->AddSourceFile(source_file); | 350 sources_for_indexing->AddSourceFile(source_file); |
352 } | 351 } |
353 | 352 |
354 projects_.push_back(std::move(sources_for_indexing)); | 353 projects_.push_back(std::move(sources_for_indexing)); |
355 } | 354 } |
356 | 355 |
357 bool XcodeWriter::WriteFiles(const BuildSettings* build_settings, Err* err) { | 356 bool XcodeWriter::WriteFiles(const BuildSettings* build_settings, Err* err) { |
358 for (const auto& project : projects_) { | 357 for (const auto& project : projects_) { |
359 if (!WriteProjectFile(build_settings, project.get(), err)) | 358 if (!WriteProjectFile(build_settings, project.get(), err)) |
360 return false; | 359 return false; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 for (auto* object : pair.second) { | 421 for (auto* object : pair.second) { |
423 object->Print(out, 2); | 422 object->Print(out, 2); |
424 } | 423 } |
425 out << "/* End " << ToString(pair.first) << " section */\n"; | 424 out << "/* End " << ToString(pair.first) << " section */\n"; |
426 } | 425 } |
427 | 426 |
428 out << "\t};\n" | 427 out << "\t};\n" |
429 << "\trootObject = " << project->Reference() << ";\n" | 428 << "\trootObject = " << project->Reference() << ";\n" |
430 << "}\n"; | 429 << "}\n"; |
431 } | 430 } |
OLD | NEW |