[gnome-builder] cmake: Fix build issues when using CMakeLists.txt in a subdirectory



commit bd4102b9a40f8519fd0c9866e4fdf852ad8808d8
Author: Ryan Gonzalez <rymg19 gmail com>
Date:   Mon Sep 17 14:13:05 2018 -0500

    cmake: Fix build issues when using CMakeLists.txt in a subdirectory
    
    The configure code was using the VCS root directory when it should have been
    using the project directory, and the build code was using the project directory
    when it should have been using the VCS root directory.

 src/plugins/cmake/gbp-cmake-pipeline-addin.c | 13 +++++++++++--
 src/plugins/flatpak/gbp-flatpak-runtime.c    | 27 ++++-----------------------
 2 files changed, 15 insertions(+), 25 deletions(-)
---
diff --git a/src/plugins/cmake/gbp-cmake-pipeline-addin.c b/src/plugins/cmake/gbp-cmake-pipeline-addin.c
index fd646e8d2..b6a0d7f62 100644
--- a/src/plugins/cmake/gbp-cmake-pipeline-addin.c
+++ b/src/plugins/cmake/gbp-cmake-pipeline-addin.c
@@ -77,6 +77,9 @@ gbp_cmake_pipeline_addin_load (IdeBuildPipelineAddin *addin,
   g_autofree gchar *prefix_option = NULL;
   g_autofree gchar *build_ninja = NULL;
   g_autofree gchar *crossbuild_file = NULL;
+  GFile *project_file;
+  g_autofree gchar *project_file_name = NULL;
+  g_autofree gchar *srcdir = NULL;
   IdeBuildSystem *build_system;
   IdeConfiguration *configuration;
   IdeContext *context;
@@ -85,7 +88,6 @@ gbp_cmake_pipeline_addin_load (IdeBuildPipelineAddin *addin,
   const gchar *ninja = NULL;
   const gchar *config_opts;
   const gchar *prefix;
-  const gchar *srcdir;
   const gchar *cmake;
   guint id;
   gint parallelism;
@@ -101,10 +103,17 @@ gbp_cmake_pipeline_addin_load (IdeBuildPipelineAddin *addin,
   if (!GBP_IS_CMAKE_BUILD_SYSTEM (build_system))
     IDE_GOTO (failure);
 
+  project_file = ide_context_get_project_file (context);
+  project_file_name = g_file_get_basename (project_file);
+
   configuration = ide_build_pipeline_get_configuration (pipeline);
   runtime = ide_build_pipeline_get_runtime (pipeline);
   toolchain = ide_build_pipeline_get_toolchain (pipeline);
-  srcdir = ide_build_pipeline_get_srcdir (pipeline);
+
+  if (g_strcmp0 (project_file_name, "CMakeLists.txt") == 0)
+    srcdir = g_dirname (g_file_peek_path (project_file));
+  else
+    srcdir = g_strdup (ide_build_pipeline_get_srcdir (pipeline));
 
   g_assert (IDE_IS_CONFIGURATION (configuration));
   g_assert (IDE_IS_RUNTIME (runtime));
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime.c b/src/plugins/flatpak/gbp-flatpak-runtime.c
index 88ea16316..9536eb9ce 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime.c
+++ b/src/plugins/flatpak/gbp-flatpak-runtime.c
@@ -161,17 +161,16 @@ gbp_flatpak_runtime_create_launcher (IdeRuntime  *runtime,
 
   if (ret != NULL)
     {
-      g_autofree gchar *project_name = NULL;
-      g_autofree gchar *project_path = NULL;
       g_autofree gchar *build_path = NULL;
       g_autofree gchar *ccache_dir = NULL;
       g_auto(GStrv) new_environ = NULL;
       const gchar *builddir = NULL;
+      const gchar *project_path = NULL;
       const gchar * const *build_args = NULL;
-      GFile *project_file;
       IdeContext *context;
       IdeConfigurationManager *config_manager;
       IdeConfiguration *configuration;
+      IdeVcs *vcs;
 
       context = ide_object_get_context (IDE_OBJECT (self));
       config_manager = ide_context_get_configuration_manager (context);
@@ -181,26 +180,8 @@ gbp_flatpak_runtime_create_launcher (IdeRuntime  *runtime,
       builddir = get_builddir (self);
 
       /* Find the project directory path */
-      project_file = ide_context_get_project_file (context);
-      if (project_file != NULL)
-        {
-          g_autofree gchar *project_file_path = NULL;
-
-          project_file_path = g_file_get_path (project_file);
-          if (g_file_test (project_file_path, G_FILE_TEST_IS_DIR))
-            {
-              project_path = g_file_get_path (project_file);
-              project_name = g_file_get_basename (project_file);
-            }
-          else
-            {
-              g_autoptr(GFile) project_dir = NULL;
-
-              project_dir = g_file_get_parent (project_file);
-              project_path = g_file_get_path (project_dir);
-              project_name = g_file_get_basename (project_dir);
-            }
-        }
+      vcs = ide_context_get_vcs (context);
+      project_path = g_file_peek_path (ide_vcs_get_working_directory (vcs));
 
       /* Add 'flatpak build' and the specified arguments to the launcher */
       ide_subprocess_launcher_push_argv (ret, "flatpak");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]