Some work on ostree-build
This commit is contained in:
1 parent
21c7ff74b6
commit
8bca739315
14 files changed
+749
-3
No files matched your search
+107
@@ -0,0 +1,107 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||
*
|
||||
* Copyright (C) 2011 Colin Walters <walters@verbum.org>
|
||||
*
|
||||
* 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Author: Colin Walters <walters@verbum.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "ob-builtins.h"
|
||||
|
||||
static OsbuildBuiltin builtins[] = {
|
||||
{ "buildone", osbuild_builtin_buildone, 0 },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static int
|
||||
usage (char **argv, gboolean is_error)
|
||||
{
|
||||
OsbuildBuiltin *builtin = builtins;
|
||||
void (*print_func) (const gchar *format, ...);
|
||||
|
||||
if (is_error)
|
||||
print_func = g_printerr;
|
||||
else
|
||||
print_func = g_print;
|
||||
|
||||
print_func ("usage: %s COMMAND [options]\n",
|
||||
argv[0]);
|
||||
print_func ("Builtin commands:\n");
|
||||
|
||||
while (builtin->name)
|
||||
{
|
||||
print_func (" %s\n", builtin->name);
|
||||
builtin++;
|
||||
}
|
||||
return (is_error ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char **argv)
|
||||
{
|
||||
OsbuildBuiltin *builtin;
|
||||
const char *cmd;
|
||||
|
||||
g_type_init ();
|
||||
|
||||
g_set_prgname (argv[0]);
|
||||
|
||||
builtin = builtins;
|
||||
|
||||
if (argc < 2)
|
||||
return usage (argv, 1);
|
||||
|
||||
cmd = argv[1];
|
||||
|
||||
while (builtin->name)
|
||||
{
|
||||
GError *error = NULL;
|
||||
if (strcmp (cmd, builtin->name) == 0)
|
||||
{
|
||||
int i;
|
||||
int tmp_argc;
|
||||
char **tmp_argv;
|
||||
|
||||
tmp_argc = argc - 1;
|
||||
tmp_argv = g_new0 (char *, tmp_argc + 1);
|
||||
|
||||
tmp_argv[0] = (char*)builtin->name;
|
||||
for (i = 0; i < tmp_argc; i++)
|
||||
tmp_argv[i+1] = argv[i+2];
|
||||
if (!builtin->fn (tmp_argc, tmp_argv, NULL, &error))
|
||||
{
|
||||
g_free (tmp_argv);
|
||||
g_printerr ("%s\n", error->message);
|
||||
g_clear_error (&error);
|
||||
return 1;
|
||||
}
|
||||
g_free (tmp_argv);
|
||||
return 0;
|
||||
}
|
||||
builtin++;
|
||||
}
|
||||
|
||||
g_printerr ("Unknown command '%s'\n", cmd);
|
||||
return usage (argv, 1);
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||
*
|
||||
* Copyright (C) 2011 Colin Walters <walters@verbum.org>
|
||||
*
|
||||
* 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Author: Colin Walters <walters@verbum.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "otutil.h"
|
||||
#include "ob-builtins.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static char *repo_path;
|
||||
static char *ref;
|
||||
static char *name;
|
||||
static char *generator;
|
||||
static char *resultdir;
|
||||
static gboolean raw;
|
||||
|
||||
static GOptionEntry options[] = {
|
||||
{ "repo", 0, 0, G_OPTION_ARG_FILENAME, &repo_path, "Repository path", "repo" },
|
||||
{ "rev", 'r', 0, G_OPTION_ARG_STRING, &ref, "Build using this tree", "rev" },
|
||||
{ "name", 0, 0, G_OPTION_ARG_STRING, &name, "Name of the source", "source" },
|
||||
{ "generator", 0, 0, G_OPTION_ARG_FILENAME, &generator, "Script to run on installed tree", "script" },
|
||||
{ "raw", 0, 0, G_OPTION_ARG_NONE, &raw, "Do not instantiate a tree, use current", NULL },
|
||||
{ "resultdir", 0, 0, G_OPTION_ARG_FILENAME, &resultdir, "Directory for output artifacts", "dir" },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static char *
|
||||
get_tmpdir (void)
|
||||
{
|
||||
char *tmp_prefix = g_strdup (g_getenv ("XDG_RUNTIME_DIR"));
|
||||
char *ret;
|
||||
|
||||
if (tmp_prefix)
|
||||
{
|
||||
ret = g_strdup_printf ("%s/osbuild", tmp_prefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_prefix = g_strdup_printf ("/tmp/osbuild-%d", getuid ());
|
||||
if (!g_file_test (tmp_prefix, G_FILE_TEST_IS_DIR))
|
||||
{
|
||||
if (!mkdir (tmp_prefix, 0755))
|
||||
{
|
||||
g_printerr ("Failed to make logging directory %s\n", tmp_prefix);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
ret = tmp_prefix;
|
||||
tmp_prefix = NULL;
|
||||
}
|
||||
g_free (tmp_prefix);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
open_log (const char *name,
|
||||
GOutputStream **out_log,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
char *tmpdir = NULL;
|
||||
char *path = NULL;
|
||||
GFile *logf = NULL;
|
||||
GFileOutputStream *ret_log = NULL;
|
||||
|
||||
path = g_strdup_printf ("%s/%s.log", tmpdir, name);
|
||||
logf = ot_util_new_file_for_path (path);
|
||||
|
||||
ret_log = g_file_replace (logf, NULL, FALSE, 0, NULL, error);
|
||||
if (!ret_log)
|
||||
goto out;
|
||||
|
||||
ret = TRUE;
|
||||
*out_log = (GOutputStream*)ret_log;
|
||||
ret_log = NULL;
|
||||
out:
|
||||
g_free (path);
|
||||
g_free (tmpdir);
|
||||
g_clear_object (&logf);
|
||||
g_clear_object (&ret_log);
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
osbuild_builtin_buildone (int argc, char **argv, const char *prefix, GError **error)
|
||||
{
|
||||
GOptionContext *context;
|
||||
gboolean ret = FALSE;
|
||||
char *tmpdir;
|
||||
|
||||
context = g_option_context_new ("- Build current directory");
|
||||
g_option_context_add_main_entries (context, options, NULL);
|
||||
|
||||
if (!g_option_context_parse (context, &argc, &argv, error))
|
||||
goto out;
|
||||
|
||||
if (!raw && !repo_path)
|
||||
{
|
||||
ot_util_usage_error (context, "A result directory must be specified with --resultdir", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!generator)
|
||||
generator = g_build_filename (LIBEXECDIR, "ostree", "generators", "default", NULL);
|
||||
|
||||
|
||||
|
||||
out:
|
||||
if (context)
|
||||
g_option_context_free (context);
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||
*
|
||||
* Copyright (C) 2011 Colin Walters <walters@verbum.org>
|
||||
*
|
||||
* 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Author: Colin Walters <walters@verbum.org>
|
||||
*/
|
||||
|
||||
#ifndef __OSBUILD_BUILTINS__
|
||||
#define __OSBUILD_BUILTINS__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum {
|
||||
OSBUILD_BUILTIN_FLAG_NONE = 0,
|
||||
} OsbuildBuiltinFlags;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
gboolean (*fn) (int argc, char **argv, const char *prefix, GError **error);
|
||||
int flags; /* OsbuildBuiltinFlags */
|
||||
} OsbuildBuiltin;
|
||||
|
||||
gboolean osbuild_builtin_buildone (int argc, char **argv, const char *prefix, GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,189 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||
*
|
||||
* Copyright (C) 2011 Colin Walters <walters@verbum.org>
|
||||
*
|
||||
* 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Author: Colin Walters <walters@verbum.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "otutil.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static const char *
|
||||
find_first_file (GFileTest test, const char *name, ...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
static const char *
|
||||
find_first_file (GFileTest test, const char *name, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start (args, name);
|
||||
|
||||
do
|
||||
{
|
||||
if (g_file_test (name, test))
|
||||
break;
|
||||
name = va_arg (args, const char *);
|
||||
}
|
||||
while (name != NULL);
|
||||
|
||||
va_end (args);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
static void
|
||||
split_configure_make_args (int argc,
|
||||
char **argv,
|
||||
GPtrArray **out_configure_args,
|
||||
GPtrArray **out_make_args,
|
||||
GPtrArray **out_makeinstall_args)
|
||||
{
|
||||
int i;
|
||||
|
||||
*out_configure_args = g_ptr_array_new ();
|
||||
*out_make_args = g_ptr_array_new ();
|
||||
*out_makeinstall_args = g_ptr_array_new ();
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if (g_str_has_prefix (argv[i], "--"))
|
||||
g_ptr_array_add (*out_configure_args, argv[i]);
|
||||
else if (g_str_has_prefix (argv[i], "DESTDIR="))
|
||||
g_ptr_array_add (*out_makeinstall_args, argv[i]);
|
||||
else
|
||||
g_ptr_array_add (*out_make_args, argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
spawn_sync_or_fatal (char **args, char **env, GSpawnFlags flags)
|
||||
{
|
||||
GError *error = NULL;
|
||||
int estatus;
|
||||
char **iter;
|
||||
|
||||
g_print ("osbuild: running: ");
|
||||
for (iter = args; *iter; iter++)
|
||||
g_print ("%s ", *iter);
|
||||
g_print ("\n");
|
||||
if (g_spawn_sync (NULL, args, env, flags, NULL, NULL, NULL, NULL, &estatus, &error))
|
||||
{
|
||||
if (WIFEXITED (estatus) && WEXITSTATUS (estatus) == 0)
|
||||
{
|
||||
g_message ("Subprocess %s exited successfully\n", args[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (WIFEXITED (estatus))
|
||||
g_error ("Subprocess %s exited with code %d\n", args[0], WEXITSTATUS (estatus));
|
||||
else if (WIFSIGNALED (estatus))
|
||||
g_error ("Subprocess %s killed by signal %d\n", args[0], WTERMSIG (estatus));
|
||||
else
|
||||
g_error ("Subprocess %s terminated with status %d\n", args[0], estatus);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_error ("Failed to execute %s: %s\n", args[0], error->message);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ptr_array_extend (GPtrArray *dest, GPtrArray *to_append)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < to_append->len; i++)
|
||||
g_ptr_array_add (dest, to_append->pdata[i]);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char **argv)
|
||||
{
|
||||
GPtrArray *config_args;
|
||||
GPtrArray *make_args;
|
||||
GPtrArray *makeinstall_args;
|
||||
GPtrArray *args;
|
||||
int i;
|
||||
char **subprocess_env;
|
||||
GError *error = NULL;
|
||||
|
||||
g_type_init ();
|
||||
|
||||
g_set_prgname (argv[0]);
|
||||
|
||||
args = g_ptr_array_new ();
|
||||
|
||||
subprocess_env = g_get_environ ();
|
||||
ot_g_environ_setenv (subprocess_env, "LANG", "C", TRUE);
|
||||
ot_g_environ_unsetenv (subprocess_env, "LC_ALL");
|
||||
|
||||
split_configure_make_args (argc, argv, &config_args, &make_args, &makeinstall_args);
|
||||
|
||||
if (!g_file_test ("./configure", G_FILE_TEST_IS_EXECUTABLE))
|
||||
{
|
||||
const char *autogen;
|
||||
char **autogen_env;
|
||||
|
||||
autogen = find_first_file (G_FILE_TEST_IS_EXECUTABLE, "./autogen", "./autogen.sh");
|
||||
if (!autogen)
|
||||
ot_util_fatal_literal ("No executable configure or autogen script found");
|
||||
|
||||
autogen_env = g_strdupv (subprocess_env);
|
||||
ot_g_environ_setenv (autogen_env, "NOCONFIGURE", "1", TRUE);
|
||||
|
||||
g_ptr_array_set_size (args, 0);
|
||||
g_ptr_array_add (args, (char*) autogen);
|
||||
g_ptr_array_add (args, NULL);
|
||||
spawn_sync_or_fatal ((char**)args->pdata, autogen_env, 0);
|
||||
}
|
||||
|
||||
if (!g_file_test ("./configure", G_FILE_TEST_IS_EXECUTABLE))
|
||||
ot_util_fatal_literal ("autogen script failed to generate a configure script");
|
||||
|
||||
g_ptr_array_set_size (args, 0);
|
||||
g_ptr_array_add (args, "./configure");
|
||||
ptr_array_extend (args, config_args);
|
||||
g_ptr_array_add (args, NULL);
|
||||
spawn_sync_or_fatal ((char**)args->pdata, subprocess_env, 0);
|
||||
|
||||
g_ptr_array_set_size (args, 0);
|
||||
g_ptr_array_add (args, "make");
|
||||
ptr_array_extend (args, make_args);
|
||||
g_ptr_array_add (args, NULL);
|
||||
spawn_sync_or_fatal ((char**)args->pdata, subprocess_env, G_SPAWN_SEARCH_PATH);
|
||||
|
||||
g_ptr_array_set_size (args, 0);
|
||||
g_ptr_array_add (args, "make");
|
||||
g_ptr_array_add (args, "install");
|
||||
ptr_array_extend (args, makeinstall_args);
|
||||
g_ptr_array_add (args, NULL);
|
||||
spawn_sync_or_fatal ((char**)args->pdata, subprocess_env, G_SPAWN_SEARCH_PATH);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user