ide-build-target.c 5.14 KB
Newer Older
1 2
/* ide-build-target.c
 *
3
 * Copyright © 2016 Christian Hergert <chergert@redhat.com>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 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/>.
 */

#define G_LOG_DOMAIN "ide-build-target"

21 22
#include "config.h"

23
#include "buildsystem/ide-build-target.h"
24 25 26

G_DEFINE_INTERFACE (IdeBuildTarget, ide_build_target, IDE_TYPE_OBJECT)

27 28 29 30 31 32
static gchar*
ide_build_target_real_get_cwd (IdeBuildTarget *self)
{
  return NULL;
}

33 34 35 36 37 38 39
static gchar*
ide_build_target_real_get_language (IdeBuildTarget *self)
{
  return g_strdup ("asm");
}


40 41 42
static void
ide_build_target_default_init (IdeBuildTargetInterface *iface)
{
43
  iface->get_cwd = ide_build_target_real_get_cwd;
44
  iface->get_language = ide_build_target_real_get_language;
45 46 47 48 49
}

/**
 * ide_build_target_get_install_directory:
 *
50
 * Returns: (nullable) (transfer full): a #GFile or %NULL.
51 52 53 54 55 56 57 58 59 60 61
 */
GFile *
ide_build_target_get_install_directory (IdeBuildTarget *self)
{
  g_return_val_if_fail (IDE_IS_BUILD_TARGET (self), NULL);

  if (IDE_BUILD_TARGET_GET_IFACE (self)->get_install_directory)
    return IDE_BUILD_TARGET_GET_IFACE (self)->get_install_directory (self);

  return NULL;
}
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

/**
 * ide_build_target_get_name:
 *
 * Returns: (nullable) (transfer full): A filename or %NULL.
 */
gchar *
ide_build_target_get_name (IdeBuildTarget *self)
{
  g_return_val_if_fail (IDE_IS_BUILD_TARGET (self), NULL);

  if (IDE_BUILD_TARGET_GET_IFACE (self)->get_name)
    return IDE_BUILD_TARGET_GET_IFACE (self)->get_name (self);

  return NULL;
}
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

/**
 * ide_build_target_get_priority:
 * @self: an #IdeBuildTarget
 *
 * Gets the priority of the build target. This is used to sort build targets by
 * their importance. The lowest value (negative values are allowed) will be run
 * as the default run target by Builder.
 *
 * Returns: the priority of the build target
 *
 * Since: 3.28
 */
gint
ide_build_target_get_priority (IdeBuildTarget *self)
{
  g_return_val_if_fail (IDE_IS_BUILD_TARGET (self), 0);

  if (IDE_BUILD_TARGET_GET_IFACE (self)->get_priority)
    return IDE_BUILD_TARGET_GET_IFACE (self)->get_priority (self);
  return 0;
}

gint
ide_build_target_compare (const IdeBuildTarget *left,
                          const IdeBuildTarget *right)
{
  return ide_build_target_get_priority ((IdeBuildTarget *)left) -
         ide_build_target_get_priority ((IdeBuildTarget *)right);
}
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

/**
 * ide_build_target_get_argv:
 * @self: a #IdeBuildTarget
 *
 * Gets the arguments used to run the target.
 *
 * Returns: (transfer full): A #GStrv containing the arguments to
 *   run the target.
 *
 * Since: 3.28
 */
gchar **
ide_build_target_get_argv (IdeBuildTarget *self)
{
  g_autofree gchar *name = NULL;
  g_auto(GStrv) argv = NULL;

  g_return_val_if_fail (IDE_IS_BUILD_TARGET (self), NULL);

  if (IDE_BUILD_TARGET_GET_IFACE (self)->get_argv)
    argv = IDE_BUILD_TARGET_GET_IFACE (self)->get_argv (self);

  if (argv == NULL || *argv == NULL)
    {
      g_clear_pointer (&argv, g_strfreev);

      argv = g_new (gchar *, 2);
      argv[0] = ide_build_target_get_name (self);
      argv[1] = NULL;
    }

  return g_steal_pointer (&argv);
}
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

/**
 * ide_build_target_get_cwd:
 * @self: a #IdeBuildTarget
 *
 * For build systems and build target providers that insist to be run in
 * a specific place, this method gets the correct working directory.
 *
 * If this method returns %NULL, the runtime will pick a default working
 * directory for the spawned process (usually, the user home directory
 * in the host system, or the flatpak sandbox home under flatpak).
 *
 * Returns: (nullable) (transfer full): the working directory to use for this target
 *
 * Since: 3.28
 */
gchar *
ide_build_target_get_cwd (IdeBuildTarget *self)
{
  g_return_val_if_fail (IDE_IS_BUILD_TARGET (self), NULL);

  return IDE_BUILD_TARGET_GET_IFACE (self)->get_cwd (self);
}
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193

/**
 * ide_build_target_get_language:
 * @self: a #IdeBuildTarget
 *
 * Return the main programming language that was used to
 * write this build target.
 *
 * This method is primarily used to choose an appropriate
 * debugger. Therefore, if a build target is composed of
 * components in multiple language (eg. a GJS app with
 * GObject Introspection libraries, or a Java app with JNI
 * libraries), this should return the language that is
 * most likely to be appropriate for debugging.
 *
 * The default implementation returns "asm", which indicates
 * an unspecified language that compiles to native code.
 *
 * Returns: (transfer full): the programming language of this target
 *
 * Since: 3.28
 */
gchar *
ide_build_target_get_language (IdeBuildTarget *self)
{
  g_return_val_if_fail (IDE_IS_BUILD_TARGET (self), NULL);

  return IDE_BUILD_TARGET_GET_IFACE (self)->get_language (self);
}