Index: tools/gn/xcode_writer.cc |
diff --git a/tools/gn/xcode_writer.cc b/tools/gn/xcode_writer.cc |
index 10624fa180d54a5d1df9067d8ca04ea720d5bb2d..275eefa01e7c24fef6c139cf95bd1a0ad0c9f623 100644 |
--- a/tools/gn/xcode_writer.cc |
+++ b/tools/gn/xcode_writer.cc |
@@ -22,6 +22,7 @@ |
#include "tools/gn/commands.h" |
#include "tools/gn/deps_iterator.h" |
#include "tools/gn/filesystem_utils.h" |
+#include "tools/gn/scope.h" |
#include "tools/gn/settings.h" |
#include "tools/gn/source_file.h" |
#include "tools/gn/target.h" |
@@ -31,34 +32,60 @@ |
namespace { |
-XcodeWriter::TargetOsType GetTargetOs(const Args& args) { |
- const Value* target_os_value = args.GetArgOverride(variables::kTargetOs); |
- if (target_os_value) { |
- if (target_os_value->type() == Value::STRING) { |
- if (target_os_value->string_value() == "ios") |
- return XcodeWriter::WRITER_TARGET_OS_IOS; |
+bool GetTargetOs(const Scope* scope, std::string* target_os, Err* err) { |
+ const char* variable_names[] = {variables::kTargetOs, variables::kHostOs}; |
+ for (size_t i = 0; i < arraysize(variable_names); ++i) { |
+ const Value* value = scope->GetValue(variable_names[i]); |
+ if (value && value->type() == Value::STRING && |
+ !value->string_value().empty()) { |
+ target_os->assign(value->string_value()); |
+ return true; |
} |
} |
- return XcodeWriter::WRITER_TARGET_OS_MACOS; |
+ *err = Err(nullptr, "cannot determine target_os"); |
+ return false; |
} |
-std::string GetArchs(const Args& args) { |
- const Value* target_cpu_value = args.GetArgOverride(variables::kTargetCpu); |
- if (target_cpu_value) { |
- if (target_cpu_value->type() == Value::STRING) { |
- if (target_cpu_value->string_value() == "x86") |
- return "i386"; |
- if (target_cpu_value->string_value() == "x64") |
- return "x86_64"; |
- if (target_cpu_value->string_value() == "arm") |
- return "armv7"; |
- if (target_cpu_value->string_value() == "armv7") |
- return "armv7"; |
- if (target_cpu_value->string_value() == "arm64") |
- return "armv64"; |
+bool GetTargetCpu(const Scope* scope, std::string* target_cpu, Err* err) { |
+ const char* variable_names[] = {variables::kTargetCpu, variables::kHostCpu}; |
+ for (size_t i = 0; i < arraysize(variable_names); ++i) { |
+ const Value* value = scope->GetValue(variable_names[i]); |
+ if (value && value->type() == Value::STRING && |
+ !value->string_value().empty()) { |
+ if (value->string_value() == "x86") { |
+ target_cpu->assign("i386"); |
+ return true; |
+ } |
+ if (value->string_value() == "x64") { |
+ target_cpu->assign("x86_64"); |
+ return true; |
+ } |
+ if (value->string_value() == "arm") { |
+ target_cpu->assign("armv7"); |
+ return true; |
+ } |
+ if (value->string_value() == "arm64") { |
+ target_cpu->assign("arm64"); |
+ return true; |
+ } |
} |
} |
- return "x86_64"; |
+ *err = Err(nullptr, "cannot determine target_cpu"); |
+ return false; |
+} |
+ |
+bool GetDeploymentTarget(const Scope* scope, |
+ const char* variable, |
+ std::string* deployment_target, |
+ Err* err) { |
+ const Value* value = scope->GetValue(variable); |
+ if (!value || value->type() != Value::STRING) { |
+ *err = Err(nullptr, "cannot determine deployment target"); |
+ return false; |
+ } |
+ |
+ deployment_target->assign(value->string_value()); |
+ return true; |
} |
std::string GetBuildScript(const std::string& target_name, |
@@ -147,20 +174,9 @@ bool XcodeWriter::RunAndWriteFiles(const std::string& workspace_name, |
const BuildSettings* build_settings, |
Builder* builder, |
Err* err) { |
- const XcodeWriter::TargetOsType target_os = |
- GetTargetOs(build_settings->build_args()); |
- |
PBXAttributes attributes; |
- switch (target_os) { |
- case XcodeWriter::WRITER_TARGET_OS_IOS: |
- attributes["SDKROOT"] = "iphoneos"; |
- attributes["TARGETED_DEVICE_FAMILY"] = "1,2"; |
- break; |
- case XcodeWriter::WRITER_TARGET_OS_MACOS: |
- attributes["ARCHS"] = GetArchs(build_settings->build_args()); |
- attributes["SDKROOT"] = "macosx10.11"; |
- break; |
- } |
+ if (!GetProjectsAttributes(build_settings, &attributes, err)) |
+ return false; |
const std::string source_path = |
base::FilePath::FromUTF8Unsafe( |
@@ -189,11 +205,10 @@ bool XcodeWriter::RunAndWriteFiles(const std::string& workspace_name, |
XcodeWriter workspace(workspace_name); |
workspace.CreateProductsProject(targets, attributes, source_path, config_name, |
root_target_name, ninja_extra_args, |
- build_settings, target_os); |
+ build_settings); |
workspace.CreateSourcesProject(all_targets, build_settings->build_dir(), |
- attributes, source_path, config_name, |
- target_os); |
+ attributes, source_path, config_name); |
return workspace.WriteFiles(build_settings, err); |
} |
@@ -206,6 +221,53 @@ XcodeWriter::XcodeWriter(const std::string& name) : name_(name) { |
XcodeWriter::~XcodeWriter() {} |
// static |
+bool XcodeWriter::GetProjectsAttributes(const BuildSettings* build_settings, |
+ PBXAttributes* attributes, |
+ Err* err) { |
+ Settings* null_settings = nullptr; |
sdefresne
2016/06/14 17:45:10
I'm not sure about this code. Previously the code
|
+ Scope global_scope(null_settings); |
+ Scope::KeyValueMap declared_arguments; |
+ build_settings->build_args().MergeDeclaredArguments(&declared_arguments); |
+ for (const auto& pair : declared_arguments) { |
+ global_scope.SetValue(pair.first, pair.second, nullptr); |
+ } |
+ build_settings->build_args().SetupRootScope(&global_scope, |
+ Scope::KeyValueMap()); |
+ |
+ std::string target_os; |
+ if (!GetTargetOs(&global_scope, &target_os, err)) |
+ return false; |
+ |
+ std::string target_cpu; |
+ if (!GetTargetCpu(&global_scope, &target_cpu, err)) |
+ return false; |
+ |
+ if (target_os == "ios") { |
+ std::string deployment_target; |
+ if (!GetDeploymentTarget(&global_scope, "ios_deployment_target", |
+ &deployment_target, err)) |
+ return false; |
+ |
+ attributes->insert(std::make_pair("SDKROOT", "iphoneos")); |
+ attributes->insert(std::make_pair("TARGETED_DEVICE_FAMILY", "1,2")); |
+ attributes->insert( |
+ std::make_pair("IPHONEOS_DEPLOYMENT_TARGET", deployment_target)); |
+ } else { |
+ std::string deployment_target; |
+ if (!GetDeploymentTarget(&global_scope, "mac_deployment_target", |
+ &deployment_target, err)) |
+ return false; |
+ |
+ attributes->insert(std::make_pair("ARCHS", target_cpu)); |
+ attributes->insert(std::make_pair("SDKROOT", "macosx")); |
+ attributes->insert( |
+ std::make_pair("MACOSX_DEPLOYMENT_TARGET", deployment_target)); |
+ } |
+ |
+ return true; |
+} |
+ |
+// static |
bool XcodeWriter::FilterTargets(const BuildSettings* build_settings, |
const std::vector<const Target*>& all_targets, |
const std::string& dir_filters_string, |
@@ -266,8 +328,7 @@ void XcodeWriter::CreateProductsProject( |
const std::string& config_name, |
const std::string& root_target, |
const std::string& ninja_extra_args, |
- const BuildSettings* build_settings, |
- TargetOsType target_os) { |
+ const BuildSettings* build_settings) { |
std::unique_ptr<PBXProject> main_project( |
new PBXProject("products", config_name, source_path, attributes)); |
@@ -278,10 +339,14 @@ void XcodeWriter::CreateProductsProject( |
main_project->AddAggregateTarget( |
"All", GetBuildScript(root_target, build_path, ninja_extra_args)); |
+ const auto iter = attributes.find("SDKROOT"); |
+ const bool skip_executable_targets = |
+ iter != attributes.end() && iter->second == "iphoneos"; |
+ |
for (const Target* target : targets) { |
switch (target->output_type()) { |
case Target::EXECUTABLE: |
- if (target_os == XcodeWriter::WRITER_TARGET_OS_IOS) |
+ if (skip_executable_targets) |
continue; |
main_project->AddNativeTarget( |
@@ -321,8 +386,7 @@ void XcodeWriter::CreateSourcesProject( |
const SourceDir& root_build_dir, |
const PBXAttributes& attributes, |
const std::string& source_path, |
- const std::string& config_name, |
- TargetOsType target_os) { |
+ const std::string& config_name) { |
std::vector<SourceFile> sources; |
for (const Target* target : targets) { |
if (!target->settings()->is_default()) |