| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 std::vector<const Target*> targets; | 182 std::vector<const Target*> targets; |
| 183 std::vector<const Target*> all_targets = builder->GetAllResolvedTargets(); | 183 std::vector<const Target*> all_targets = builder->GetAllResolvedTargets(); |
| 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 target_os); | 192 build_settings, target_os); |
| 193 | 193 |
| 194 workspace.CreateSourcesProject(all_targets, build_settings->build_dir(), | 194 workspace.CreateSourcesProject(all_targets, build_settings->build_dir(), |
| 195 attributes, source_path, config_name, | 195 attributes, source_path, config_name, |
| 196 target_os); | 196 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()) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 return true; | 259 return true; |
| 260 } | 260 } |
| 261 | 261 |
| 262 void XcodeWriter::CreateProductsProject( | 262 void XcodeWriter::CreateProductsProject( |
| 263 const std::vector<const Target*>& targets, | 263 const std::vector<const Target*>& targets, |
| 264 const PBXAttributes& attributes, | 264 const PBXAttributes& attributes, |
| 265 const std::string& source_path, | 265 const std::string& source_path, |
| 266 const std::string& config_name, | 266 const std::string& config_name, |
| 267 const std::string& root_target, | 267 const std::string& root_target, |
| 268 const std::string& ninja_extra_args, | 268 const std::string& ninja_extra_args, |
| 269 const BuildSettings* build_settings, |
| 269 TargetOsType target_os) { | 270 TargetOsType target_os) { |
| 270 std::unique_ptr<PBXProject> main_project( | 271 std::unique_ptr<PBXProject> main_project( |
| 271 new PBXProject("products", config_name, source_path, attributes)); | 272 new PBXProject("products", config_name, source_path, attributes)); |
| 272 | 273 |
| 273 std::string build_path; | 274 std::string build_path; |
| 274 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 275 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| 275 env->GetVar("PATH", &build_path); | 276 env->GetVar("PATH", &build_path); |
| 276 | 277 |
| 277 main_project->AddAggregateTarget( | 278 main_project->AddAggregateTarget( |
| 278 "All", GetBuildScript(root_target, build_path, ninja_extra_args)); | 279 "All", GetBuildScript(root_target, build_path, ninja_extra_args)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 291 GetBuildScript(target->label().name(), build_path, | 292 GetBuildScript(target->label().name(), build_path, |
| 292 ninja_extra_args)); | 293 ninja_extra_args)); |
| 293 break; | 294 break; |
| 294 | 295 |
| 295 case Target::CREATE_BUNDLE: | 296 case Target::CREATE_BUNDLE: |
| 296 if (target->bundle_data().product_type().empty()) | 297 if (target->bundle_data().product_type().empty()) |
| 297 continue; | 298 continue; |
| 298 | 299 |
| 299 main_project->AddNativeTarget( | 300 main_project->AddNativeTarget( |
| 300 target->label().name(), std::string(), | 301 target->label().name(), std::string(), |
| 301 target->bundle_data() | 302 RebasePath(target->bundle_data() |
| 302 .GetBundleRootDirOutput(target->settings()) | 303 .GetBundleRootDirOutput(target->settings()) |
| 303 .Resolve(base::FilePath()) | 304 .value(), |
| 304 .AsUTF8Unsafe(), | 305 build_settings->build_dir()), |
| 305 target->bundle_data().product_type(), | 306 target->bundle_data().product_type(), |
| 306 GetBuildScript(target->label().name(), build_path, | 307 GetBuildScript(target->label().name(), build_path, |
| 307 ninja_extra_args)); | 308 ninja_extra_args)); |
| 308 break; | 309 break; |
| 309 | 310 |
| 310 default: | 311 default: |
| 311 break; | 312 break; |
| 312 } | 313 } |
| 313 } | 314 } |
| 314 | 315 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 340 | 341 |
| 341 std::unique_ptr<PBXProject> sources_for_indexing( | 342 std::unique_ptr<PBXProject> sources_for_indexing( |
| 342 new PBXProject("sources", config_name, source_path, attributes)); | 343 new PBXProject("sources", config_name, source_path, attributes)); |
| 343 | 344 |
| 344 // Sort sources to ensure determinisn of the project file generation and | 345 // Sort sources to ensure determinisn of the project file generation and |
| 345 // remove duplicate reference to the source files (can happen due to the | 346 // remove duplicate reference to the source files (can happen due to the |
| 346 // bundle_data targets). | 347 // bundle_data targets). |
| 347 std::sort(sources.begin(), sources.end()); | 348 std::sort(sources.begin(), sources.end()); |
| 348 sources.erase(std::unique(sources.begin(), sources.end()), sources.end()); | 349 sources.erase(std::unique(sources.begin(), sources.end()), sources.end()); |
| 349 | 350 |
| 351 SourceDir source_dir("//"); |
| 350 for (const SourceFile& source : sources) { | 352 for (const SourceFile& source : sources) { |
| 351 base::FilePath source_path = source.Resolve(base::FilePath()); | 353 std::string source_file = RebasePath(source.value(), source_dir); |
| 352 sources_for_indexing->AddSourceFile(source_path.AsUTF8Unsafe()); | 354 sources_for_indexing->AddSourceFile(source_file); |
| 353 } | 355 } |
| 354 | 356 |
| 355 projects_.push_back(std::move(sources_for_indexing)); | 357 projects_.push_back(std::move(sources_for_indexing)); |
| 356 } | 358 } |
| 357 | 359 |
| 358 bool XcodeWriter::WriteFiles(const BuildSettings* build_settings, Err* err) { | 360 bool XcodeWriter::WriteFiles(const BuildSettings* build_settings, Err* err) { |
| 359 for (const auto& project : projects_) { | 361 for (const auto& project : projects_) { |
| 360 if (!WriteProjectFile(build_settings, project.get(), err)) | 362 if (!WriteProjectFile(build_settings, project.get(), err)) |
| 361 return false; | 363 return false; |
| 362 } | 364 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 for (const auto& object : pair.second) { | 425 for (const auto& object : pair.second) { |
| 424 object->Print(out, 2); | 426 object->Print(out, 2); |
| 425 } | 427 } |
| 426 out << "/* End " << ToString(pair.first) << " section */\n"; | 428 out << "/* End " << ToString(pair.first) << " section */\n"; |
| 427 } | 429 } |
| 428 | 430 |
| 429 out << "\t};\n" | 431 out << "\t};\n" |
| 430 << "\trootObject = " << project->Reference() << ";\n" | 432 << "\trootObject = " << project->Reference() << ";\n" |
| 431 << "}\n"; | 433 << "}\n"; |
| 432 } | 434 } |
| OLD | NEW |