File: plugin-distcc-build-addin.c

package info (click to toggle)
foundry 1.1~beta-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,552 kB
  • sloc: ansic: 167,487; xml: 417; makefile: 21; sh: 19; javascript: 10
file content (113 lines) | stat: -rw-r--r-- 3,586 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* plugin-distcc-build-addin.c
 *
 * Copyright 2025 Christian Hergert <chergert@redhat.com>
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of the
 * License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "config.h"

#include <glib/gi18n-lib.h>

#include "plugin-distcc-build-addin.h"

struct _PluginDistccBuildAddin
{
  FoundryBuildAddin parent_instance;
};

G_DEFINE_FINAL_TYPE (PluginDistccBuildAddin, plugin_distcc_build_addin, FOUNDRY_TYPE_BUILD_ADDIN)

static DexFuture *
plugin_distcc_build_addin_load_fiber (gpointer user_data)
{
  PluginDistccBuildAddin *self = user_data;
  g_autoptr(FoundryBuildPipeline) pipeline = NULL;
  g_autoptr(FoundrySettings) distcc_settings = NULL;
  g_autoptr(FoundryContext) context = NULL;
  g_autofree char *wrapper_path = NULL;
  g_autofree char *hosts_str = NULL;
  g_auto(GStrv) hosts = NULL;
  gboolean enabled;

  g_assert (PLUGIN_IS_DISTCC_BUILD_ADDIN (self));

  context = foundry_contextual_dup_context (FOUNDRY_CONTEXTUAL (self));
  pipeline = foundry_build_addin_dup_pipeline (FOUNDRY_BUILD_ADDIN (self));
  distcc_settings = foundry_context_load_settings (context, "org.gnome.foundry.distcc", NULL);
  enabled = foundry_settings_get_boolean (distcc_settings, "enabled");

  if (!enabled)
    return dex_future_new_true ();

  hosts = foundry_settings_get_strv (distcc_settings, "hosts");
  wrapper_path = foundry_settings_get_string (distcc_settings, "wrapper-path");

  if (foundry_str_empty0 (wrapper_path))
    {
      g_autofree char *distcc_path = dex_await_string (foundry_build_pipeline_contains_program (pipeline, "distcc"), NULL);

      if (distcc_path != NULL)
        g_set_str (&wrapper_path, distcc_path);
    }

  if (foundry_str_empty0 (wrapper_path))
    {
      FOUNDRY_CONTEXTUAL_MESSAGE (self, "%s: enabled but distcc not found", "distcc");
      return dex_future_new_true ();
    }

  if (hosts != NULL && hosts[0] != NULL)
    {
      hosts_str = g_strjoinv (",", hosts);
      foundry_build_pipeline_setenv (pipeline, "DISTCC_HOSTS", hosts_str);
    }

  foundry_build_pipeline_setenv (pipeline, "CCACHE_PREFIX", wrapper_path);

  return dex_future_new_true ();
}

static DexFuture *
plugin_distcc_build_addin_load (FoundryBuildAddin *addin)
{
  g_assert (PLUGIN_IS_DISTCC_BUILD_ADDIN (addin));

  return dex_scheduler_spawn (NULL, 0,
                              plugin_distcc_build_addin_load_fiber,
                              g_object_ref (addin),
                              g_object_unref);
}

static DexFuture *
plugin_distcc_build_addin_unload (FoundryBuildAddin *addin)
{
  return dex_future_new_true ();
}

static void
plugin_distcc_build_addin_class_init (PluginDistccBuildAddinClass *klass)
{
  FoundryBuildAddinClass *build_addin_class = FOUNDRY_BUILD_ADDIN_CLASS (klass);

  build_addin_class->load = plugin_distcc_build_addin_load;
  build_addin_class->unload = plugin_distcc_build_addin_unload;
}

static void
plugin_distcc_build_addin_init (PluginDistccBuildAddin *self)
{
}