Make CONFIGURATION_BUILD_DIR represent location of binaries

Generation of CONFIGURATION_BUILD_DIR was hardcoded before. Because of
it, if bundle or binary builds to another directory it cause an issue when we try to
run target from XCode.
In this CL we get the real path to bundle and store it in CONFIGURATION_BUILD_DIR

Change-Id: I0347e5ad8b27e1ab287d66960751306f2f42faad
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/7640
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Brett Wilson <brettw@chromium.org>
diff --git a/src/gn/bundle_data.cc b/src/gn/bundle_data.cc
index a72612d..4461168 100644
--- a/src/gn/bundle_data.cc
+++ b/src/gn/bundle_data.cc
@@ -187,3 +187,7 @@
     const Settings* settings) const {
   return SourceDir(GetBundleRootDirOutput(settings).value());
 }
+
+SourceDir BundleData::GetBundleDir(const Settings* settings) const{
+  return GetBundleRootDirOutput(settings).GetDir();
+}
diff --git a/src/gn/bundle_data.h b/src/gn/bundle_data.h
index 10a42b1..47e3d25 100644
--- a/src/gn/bundle_data.h
+++ b/src/gn/bundle_data.h
@@ -74,6 +74,9 @@
   // Performs GetBundleRootDirOutput but returns the result as a directory.
   SourceDir GetBundleRootDirOutputAsDir(const Settings* settings) const;
 
+  // Returns directory where bundle is
+  SourceDir GetBundleDir(const Settings* settings) const;
+
   // Returns the list of inputs for the compilation of the asset catalog.
   SourceFiles& assets_catalog_sources() { return assets_catalog_sources_; }
   const SourceFiles& assets_catalog_sources() const {
diff --git a/src/gn/xcode_object.cc b/src/gn/xcode_object.cc
index fe8b6e1..56b28a7 100644
--- a/src/gn/xcode_object.cc
+++ b/src/gn/xcode_object.cc
@@ -784,6 +784,7 @@
     const std::string& type,
     const std::string& output_name,
     const std::string& output_type,
+    const std::string& output_dir,
     const std::string& shell_script,
     const PBXAttributes& extra_attributes) {
   std::string_view ext = FindExtension(&output_name);
@@ -805,7 +806,8 @@
 
   PBXAttributes attributes = extra_attributes;
   attributes["CODE_SIGNING_REQUIRED"] = "NO";
-  attributes["CONFIGURATION_BUILD_DIR"] = ".";
+
+  attributes["CONFIGURATION_BUILD_DIR"] = output_dir;
   attributes["PRODUCT_NAME"] = product_name;
 
   targets_.push_back(std::make_unique<PBXNativeTarget>(
diff --git a/src/gn/xcode_object.h b/src/gn/xcode_object.h
index 1901366..c630177 100644
--- a/src/gn/xcode_object.h
+++ b/src/gn/xcode_object.h
@@ -352,6 +352,7 @@
   PBXNativeTarget* AddNativeTarget(
       const std::string& name,
       const std::string& type,
+      const std::string& output_dir,
       const std::string& output_name,
       const std::string& output_type,
       const std::string& shell_script,
diff --git a/src/gn/xcode_writer.cc b/src/gn/xcode_writer.cc
index 9dda504..7e9b7db 100644
--- a/src/gn/xcode_writer.cc
+++ b/src/gn/xcode_writer.cc
@@ -742,11 +742,15 @@
                                                Err* err) {
   DCHECK_EQ(target->output_type(), Target::EXECUTABLE);
 
+  const std::string output_dir = RebasePath(target->output_dir().value(),
+      build_settings_->build_dir());
+
   return project_.AddNativeTarget(
       target->label().name(), "compiled.mach-o.executable",
       target->output_name().empty() ? target->label().name()
                                     : target->output_name(),
       "com.apple.product-type.tool",
+      output_dir,
       GetBuildScript(target->label().name(), options_.ninja_executable,
                      options_.ninja_extra_args, env));
 }
@@ -769,9 +773,14 @@
   const std::string& target_output_name = RebasePath(
       target->bundle_data().GetBundleRootDirOutput(target->settings()).value(),
       build_settings_->build_dir());
+  const std::string output_dir = RebasePath(target->bundle_data()
+          .GetBundleDir(target->settings())
+          .value(),
+      build_settings_->build_dir());
   return project_.AddNativeTarget(
       pbxtarget_name, std::string(), target_output_name,
       target->bundle_data().product_type(),
+      output_dir,
       GetBuildScript(pbxtarget_name, options_.ninja_executable,
                      options_.ninja_extra_args, env),
       xcode_extra_attributes);