[xcode] Refer to target by their long name in generate Xcode project According to NinjaBuildWriter::WritePhonyAndAllRules() documentation, gn only generate a phony target with the short target name if it is either an executable or unambiguous. Recently a "chrome" target was added in a third-party repository which broke the compilation of Chrome on iOS from the genrated Xcode project since the "chrome" name was no longer unambiguous. Since the target is a bundle and not an executable, the phony target with the short name was not created. Change the Xcode generator to use the long name for the target for which the phony target is always generated. User don't need to care about collision when using Xcode to build. Bug: chromium/1383100 Change-Id: I5e1b43f4e675cc1967744e80194eb7fe7f8ae310 Reviewed-on: https://gn-review.googlesource.com/c/gn/+/14840 Reviewed-by: David Turner <digit@google.com> Reviewed-by: Justin Cohen <justincohen@google.com> Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
diff --git a/src/gn/xcode_writer.cc b/src/gn/xcode_writer.cc index 8216aa4..2673d3c 100644 --- a/src/gn/xcode_writer.cc +++ b/src/gn/xcode_writer.cc
@@ -117,6 +117,15 @@ return buffer.str(); } +std::string GetBuildScript(const Label& target_label, + const std::string& ninja_executable, + const std::string& build_dir, + base::Environment* environment) { + std::string target_name = target_label.GetUserVisibleName(false); + base::TrimString(target_name, "/", &target_name); + return GetBuildScript(target_name, ninja_executable, build_dir, environment); +} + bool IsApplicationTarget(const Target* target) { return target->output_type() == Target::CREATE_BUNDLE && target->bundle_data().product_type() == @@ -968,7 +977,7 @@ target->output_name().empty() ? target->label().name() : target->output_name(), "com.apple.product-type.tool", GetConfigOutputDir(output_dir), - GetBuildScript(target->label().name(), options_.ninja_executable, + GetBuildScript(target->label(), options_.ninja_executable, GetConfigOutputDir("."), env)); } @@ -1001,7 +1010,7 @@ return project_.AddNativeTarget( pbxtarget_name, std::string(), target_output_name, target->bundle_data().product_type(), GetConfigOutputDir(output_dir), - GetBuildScript(pbxtarget_name, options_.ninja_executable, + GetBuildScript(target->label(), options_.ninja_executable, GetConfigOutputDir("."), env), xcode_extra_attributes); }