ostbuild: Rename osbuild to ostbuild, clean up old C files

This commit is contained in:
Colin Walters 2011-11-25 12:00:16 -05:00
parent 3c025e526f
commit fa06a4dcea
11 changed files with 37 additions and 504 deletions

View File

@ -15,7 +15,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
bin_SCRIPTS += src/osbuild/ostree-buildone \
src/osbuild/ostree-buildone-make \
src/osbuild/ostree-buildone-makeinstall-split-artifacts \
bin_SCRIPTS += src/ostbuild/ostbuild-one \
src/ostbuild/ostbuild-one-make \
src/ostbuild/ostbuild-one-makeinstall-split-artifacts \
$(NULL)

View File

@ -33,5 +33,5 @@ include Makefile-daemon.am
include Makefile-otutil.am
include Makefile-libostree.am
include Makefile-ostree.am
include Makefile-osbuild.am
include Makefile-ostbuild.am
include Makefile-triggers.am

View File

@ -1,108 +0,0 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2011 Colin Walters <walters@verbum.org>
*
* 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 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 Lesser General Public
* License along with this library; 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);
}

View File

@ -1,142 +0,0 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2011 Colin Walters <walters@verbum.org>
*
* 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 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 Lesser General Public
* License along with this library; 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) G_GNUC_UNUSED;
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) G_GNUC_UNUSED;
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_gfile_new_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;
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;
}

View File

@ -1,44 +0,0 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2011 Colin Walters <walters@verbum.org>
*
* 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 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 Lesser General Public
* License along with this library; 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

View File

@ -1,188 +0,0 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2011 Colin Walters <walters@verbum.org>
*
* 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 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 Lesser General Public
* License along with this library; 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;
char **subprocess_env;
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", NULL);
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;
}

13
src/ostbuild/ostbuild-chroot Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/python
import os,sys,re,subprocess
chroot_path=sys.argv[1]
proc_path=os.path.join(chroot_path, 'proc')
subprocess.check_call(['mount', '-t', 'proc', 'proc', proc_path])
subprocess.call(['chroot', chroot_path])
subprocess.check_call(['umount', proc_path])

8
src/ostbuild/ostbuild-fetch Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/python
#
# Copyright 2011 Colin Walters <walters@verbum.org>
# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
import os,sys,subprocess,tempfile,re
for

View File

@ -1,18 +1,11 @@
#!/usr/bin/python
#
# ostree-buildone:
# Copyright 2010, 2011 Colin Walters <walters@verbum.org>
# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
# The build output is automatically logged to $TMPDIR/build-$(PWD).log.
# For example, invoking metabuild in a directory named "foo" will log
# to /tmp/build-foo.log
#
# You can pass arguments to metabuild; if they start with '--', they're
# given to configure. Otherwise, they're passed to make.
#
# $ metabuild --enable-libfoo # passed to configure
# $ metabuild -j 1 # passed to make
import os,sys,subprocess,tempfile,re
import select,time,stat,fcntl
@ -38,7 +31,7 @@ except OSError, e:
pass
warning_re = re.compile(r'(: ((warning)|(error)|(fatal error)): )|(make(\[[0-9]+\])?: \*\*\*)')
output_whitelist_re = re.compile(r'^(make(\[[0-9]+\])?: Entering directory)|(ostree-build )')
output_whitelist_re = re.compile(r'^(make(\[[0-9]+\])?: Entering directory)|(ostbuild )')
_bold_sequence = None
_normal_sequence = None
@ -179,7 +172,7 @@ class OutputFilter(object):
f = open(logfile_path)
lines = []
for line in f:
if line.startswith('ostree-build '):
if line.startswith('ostbuild '):
continue
lines.append(line)
if len(lines) > _last_line_limit:
@ -218,15 +211,15 @@ class OutputFilter(object):
if not successful:
self._write_last_log_lines()
pass
self.output.write("ostree-build %s: %d warnings\n" % ('success' if successful else _bold('failed'),
self.output.write("ostbuild %s: %d warnings\n" % ('success' if successful else _bold('failed'),
self._warning_count, ))
self.output.write("ostree-build: full log path: %s\n" % (logfile_path, ))
self.output.write("ostbuild: full log path: %s\n" % (logfile_path, ))
if successful:
for f in os.listdir('_build'):
path = os.path.join('_build', f)
if f.startswith('artifact-'):
self.output.write("ostree-build: created artifact: %s\n" % (f, ))
self.output.write("ostbuild: created artifact: %s\n" % (f, ))
sys.exit(0 if successful else 1)
def _on_makeinstall_exit(pid, estatus):
@ -235,7 +228,7 @@ def _on_makeinstall_exit(pid, estatus):
def _on_make_exit(pid, estatus):
if estatus == 0:
args = list(subprocess_nice_args)
args.append('ostree-buildone-makeinstall-split-artifacts')
args.append('ostbuild-one-makeinstall-split-artifacts')
_logfile_f.write("Running: %r\n" % (args, ))
_logfile_f.flush()
proc = subprocess.Popen(args, stdin=devnull, stdout=logfile_write_fd, stderr=logfile_write_fd)
@ -245,7 +238,7 @@ def _on_make_exit(pid, estatus):
def _get_version():
if not os.path.isdir('.git'):
sys.stderr.write("ostree-buildone: error: Couldn't find .git directory")
sys.stderr.write("ostbuild-one: error: Couldn't find .git directory")
sys.exit(1)
proc = subprocess.Popen(['git', 'describe'], stdout=subprocess.PIPE)
@ -253,7 +246,7 @@ def _get_version():
if proc.wait() != 0:
proc = subprocess.Popen(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE)
if proc.wait() != 0:
sys.stderr.write("ostree-buildone: error: git rev-parse HEAD failed")
sys.stderr.write("ostbuild-one: error: git rev-parse HEAD failed")
sys.exit(1)
output = proc.communicate()[0].strip()
return output
@ -263,7 +256,7 @@ if __name__ == '__main__':
if user_tmpdir is None:
user_tmpdir = os.path.join(os.environ.get('TMPDIR', '/tmp'), 'metabuild-%s' % (os.getuid(), ))
else:
user_tmpdir = os.path.join(user_tmpdir, 'ostree-build')
user_tmpdir = os.path.join(user_tmpdir, 'ostbuild')
os.environ['OSBUILD_VERSION'] = _get_version()
@ -283,7 +276,7 @@ if __name__ == '__main__':
logfile_write_fd = os.open(logfile_path, os.O_WRONLY | os.O_CREAT | os.O_EXCL)
global _logfile_f
_logfile_f = os.fdopen(logfile_write_fd, "w")
sys.stdout.write('ostree-build: logging to %r\n' % (logfile_path, ))
sys.stdout.write('ostbuild: logging to %r\n' % (logfile_path, ))
sys.stdout.flush()
global _output_filter
@ -291,7 +284,7 @@ if __name__ == '__main__':
_output_filter.start()
args = list(subprocess_nice_args)
args.append('ostree-buildone-make')
args.append('ostbuild-one-make')
args.extend(sys.argv[1:])
devnull=open('/dev/null')
_logfile_f.write("Running: %r\n" % (args, ))

View File

View File

@ -91,6 +91,7 @@ def make_artifact(name, from_files):
tempfiles.append(filelist_temp)
f = open(filelist_temp, 'w')
for filename in from_files:
assert ('\n' not in filename)
f.write(filename)
f.write('\n')
f.close()