Пример #1
0
static void
ide_build_system_post_process_build_flags (IdeBuildSystem  *self,
                                           gchar          **flags)
{
  IdePipeline *pipeline;
  IdeBuildManager *build_manager;
  IdeContext *context;

  g_assert (IDE_IS_BUILD_SYSTEM (self));

  if (flags == NULL || flags[0] == NULL)
    return;

  context = ide_object_get_context (IDE_OBJECT (self));
  build_manager = ide_build_manager_from_context (context);
  pipeline = ide_build_manager_get_pipeline (build_manager);

  for (guint i = 0; flags[i] != NULL; i++)
    {
      gchar *flag = flags[i];
      gchar *translated;

      if (flag[0] != '-')
        continue;

      switch (flag[1])
        {
        case 'I':
          if (flag[2] == '\0')
            {
              if (flags[i+1] != NULL)
                {
                  translated = ide_build_system_translate (self, pipeline, "", flags[++i]);
                  flags[i] = translated;
                  g_free (flag);
                }
            }
          else
            {
              translated = ide_build_system_translate (self, pipeline, "-I", &flag[2]);
              flags[i] = translated;
              g_free (flag);
            }
          break;

        case 'D':
        case 'x':
          if (strlen (flag) == 2)
            i++;
          break;

        case 'f': /* -fPIC */
        case 'W': /* -Werror... */
        case 'm': /* -m64 -mtune=native */
        default:
          break;
        }
    }
}
Пример #2
0
static void
ide_build_system_real_get_build_flags_async (IdeBuildSystem      *self,
                                             GFile               *file,
                                             GCancellable        *cancellable,
                                             GAsyncReadyCallback  callback,
                                             gpointer             user_data)
{
  g_autoptr(IdeContext) context = NULL;
  g_autoptr(IdeTask) task = NULL;
  g_autoptr(GError) error = NULL;
  g_auto(GStrv) parsed_flags = NULL;
  IdeBuildManager *build_manager;
  IdeEnvironment *env;
  const gchar *flags = NULL;
  const gchar *path;
  IdePipeline *pipeline;
  IdeConfig *config;

  g_assert (IDE_IS_MAIN_THREAD ());
  g_assert (IDE_IS_BUILD_SYSTEM (self));
  g_assert (G_IS_FILE (file));
  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));

  task = ide_task_new (self, cancellable, callback, user_data);
  ide_task_set_source_tag (task, ide_build_system_real_get_build_flags_async);

  /* Avoid work immediately if we can */
  if (ide_task_return_error_if_cancelled (task))
    return;

  if (!g_file_is_native (file) || !(path = g_file_peek_path (file)))
    {
      ide_task_return_new_error (task,
                                 G_IO_ERROR,
                                 G_IO_ERROR_NOT_SUPPORTED,
                                 "Cannot get build flags for non-native file");
      return;
    }

  if (!(context = ide_object_ref_context (IDE_OBJECT (self))) ||
      !ide_context_has_project (context) ||
      !(build_manager = ide_build_manager_from_context (context)) ||
      !(pipeline = ide_build_manager_get_pipeline (build_manager)) ||
      !(config = ide_pipeline_get_config (pipeline)) ||
      !(env = ide_config_get_environment (config)))
    {
      ide_task_return_new_error (task,
                                 G_IO_ERROR,
                                 G_IO_ERROR_NOT_INITIALIZED,
                                 "Cannot access build flags without build config");
      return;
    }

  if (ide_path_is_cpp_like (path))
    {
      flags = ide_environment_getenv (env, "CXXFLAGS");
    }
  else if (ide_path_is_c_like (path))
    {
      if (!(flags = ide_environment_getenv (env, "CFLAGS")))
        flags = ide_environment_getenv (env, "CXXFLAGS");
    }
  else
    {
      ide_task_return_new_error (task,
                                 G_IO_ERROR,
                                 G_IO_ERROR_NOT_SUPPORTED,
                                 "Cannot extract build flags for unknown file type: \"%s\"",
                                 path);
      return;
    }

  if (flags == NULL)
    {
      ide_task_return_new_error (task,
                                 G_IO_ERROR,
                                 G_IO_ERROR_NOT_SUPPORTED,
                                 "No CFLAGS or CXXFLAGS environment variables were specified");
      return;
    }

  if (!g_shell_parse_argv (flags, NULL, &parsed_flags, &error))
    ide_task_return_error (task, g_steal_pointer (&error));
  else
    ide_task_return_pointer (task, g_steal_pointer (&parsed_flags), g_strfreev);
}
Пример #3
0
static void
gbp_flatpak_dependency_updater_update_async (IdeDependencyUpdater *updater,
                                             GCancellable         *cancellable,
                                             GAsyncReadyCallback   callback,
                                             gpointer              user_data)
{
  GbpFlatpakDependencyUpdater *self = (GbpFlatpakDependencyUpdater *)updater;
  GbpFlatpakDownloadStage *stage = NULL;
  g_autoptr(GTask) task = NULL;
  IdeBuildPipeline *pipeline;
  IdeBuildManager *manager;
  IdeContext *context;

  g_assert (GBP_IS_FLATPAK_DEPENDENCY_UPDATER (self));
  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));

  task = g_task_new (self, cancellable, callback, user_data);
  g_task_set_source_tag (task, gbp_flatpak_dependency_updater_update_async);
  g_task_set_priority (task, G_PRIORITY_LOW);

  context = ide_object_get_context (IDE_OBJECT (self));
  g_assert (IDE_IS_CONTEXT (context));

  manager = ide_context_get_build_manager (context);
  g_assert (IDE_IS_BUILD_MANAGER (manager));

  pipeline = ide_build_manager_get_pipeline (manager);
  g_assert (!pipeline || IDE_IS_BUILD_PIPELINE (pipeline));

  if (pipeline == NULL)
    {
      g_task_return_new_error (task,
                               G_IO_ERROR,
                               G_IO_ERROR_FAILED,
                               "Cannot update flatpak dependencies until build pipeline is initialized");
      return;
    }

  /* Find the downloads stage and tell it to download updates one time */
  ide_build_pipeline_foreach_stage (pipeline, find_download_stage_cb, &stage);

  if (stage == NULL)
    {
      /* Synthesize success if they weren't using flatpak. */
      g_task_return_boolean (task, TRUE);
      return;
    }

  gbp_flatpak_download_stage_force_update (stage);

  /* Ensure downloads and everything past it is invalidated */
  ide_build_pipeline_invalidate_phase (pipeline, IDE_BUILD_PHASE_DOWNLOADS);

  /* Start building all the way up to the project configure so that
   * the user knows if the updates broke their configuration or anything.
   */
  ide_build_manager_rebuild_async (manager,
                                   IDE_BUILD_PHASE_CONFIGURE,
                                   NULL,
                                   gbp_flatpak_dependency_updater_update_cb,
                                   g_steal_pointer (&task));
}