2015-04-16 13:58:01 +05:30
|
|
|
/*
|
|
|
|
* Copyright (c) 2010 The DragonFly Project. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The DragonFly Project
|
|
|
|
* by Matthew Dillon <dillon@backplane.com>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name of The DragonFly Project nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific, prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This is a derived version of DragonFly's BSD "fastbulk", adapted for xbps
|
2019-06-06 16:19:39 +05:30
|
|
|
* by Juan RP <xtraeme@gmail.com>.
|
2015-04-16 13:58:01 +05:30
|
|
|
*
|
|
|
|
* This program iterates all srcpkgs directories, runs './xbps-src show-build-deps',
|
|
|
|
* and builds a dependency tree on the fly.
|
|
|
|
*
|
2020-04-20 22:20:11 +05:30
|
|
|
* As the dependency tree is being built, terminal dependencies are built
|
2015-04-16 13:58:01 +05:30
|
|
|
* and packaged on the fly.
|
|
|
|
*
|
|
|
|
* As these builds complete additional dependencies may be satisfied and be
|
|
|
|
* added to the build order. Ultimately the entire tree is built.
|
|
|
|
*
|
|
|
|
* Only one attempt is made to build any given package, no matter how many
|
|
|
|
* other packages depend on it.
|
|
|
|
*/
|
2017-08-07 19:38:15 +05:30
|
|
|
#define _DEFAULT_SOURCE
|
|
|
|
#define _BSD_SOURCE
|
2015-04-16 13:58:01 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <errno.h>
|
2015-05-28 12:50:15 +05:30
|
|
|
#include <fcntl.h>
|
2015-04-16 13:58:01 +05:30
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/stat.h>
|
2017-08-07 19:38:15 +05:30
|
|
|
#include <sys/wait.h>
|
2015-06-20 15:48:45 +05:30
|
|
|
#include <getopt.h>
|
2015-04-16 13:58:01 +05:30
|
|
|
|
|
|
|
#include <xbps.h>
|
2020-02-22 20:21:07 +05:30
|
|
|
#include "uthash.h"
|
2015-04-16 13:58:01 +05:30
|
|
|
|
2020-04-13 04:48:06 +05:30
|
|
|
#ifndef __arraycount
|
|
|
|
#define __arraycount(x) (sizeof(x) / sizeof(*x))
|
|
|
|
#endif
|
|
|
|
|
2015-04-16 13:58:01 +05:30
|
|
|
struct item;
|
|
|
|
|
|
|
|
struct depn {
|
|
|
|
struct depn *dnext;
|
|
|
|
struct item *item;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct item {
|
2020-04-13 04:48:06 +05:30
|
|
|
enum { XWAITING, XDEPFAIL, XBUILD, XRUN, XDONE } status;
|
2015-04-16 13:58:01 +05:30
|
|
|
struct item *bnext; /* BuildList/RunList next */
|
|
|
|
struct depn *dbase; /* packages depending on us */
|
|
|
|
char *pkgn; /* package name */
|
|
|
|
int dcount; /* build completion for our dependencies */
|
|
|
|
int xcode; /* exit code from build */
|
|
|
|
pid_t pid; /* running build */
|
2020-02-22 20:21:07 +05:30
|
|
|
UT_hash_handle hh;
|
2015-04-16 13:58:01 +05:30
|
|
|
};
|
|
|
|
|
2020-04-13 04:48:06 +05:30
|
|
|
static struct item *hashtab;
|
2015-04-16 13:58:01 +05:30
|
|
|
static struct item *BuildList;
|
|
|
|
static struct item **BuildListP = &BuildList;
|
|
|
|
static struct item *RunList;
|
|
|
|
|
|
|
|
int NParallel = 1;
|
|
|
|
int VerboseOpt;
|
|
|
|
int NRunning;
|
2020-04-13 04:48:06 +05:30
|
|
|
unsigned int NBuilt = 0;
|
|
|
|
unsigned int NFinished = 0;
|
|
|
|
unsigned int NChecked = 0;
|
|
|
|
unsigned int NTotal = 0;
|
2015-04-16 13:58:01 +05:30
|
|
|
char *LogDir;
|
|
|
|
|
|
|
|
static struct item *
|
|
|
|
lookupItem(const char *pkgn)
|
|
|
|
{
|
2020-02-22 20:21:07 +05:30
|
|
|
struct item *item = NULL;
|
2015-04-16 13:58:01 +05:30
|
|
|
|
|
|
|
assert(pkgn);
|
|
|
|
|
2020-02-22 20:21:07 +05:30
|
|
|
HASH_FIND_STR(hashtab, pkgn, item);
|
|
|
|
return item;
|
2015-04-16 13:58:01 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static struct item *
|
|
|
|
addItem(const char *pkgn)
|
|
|
|
{
|
2020-02-22 20:21:07 +05:30
|
|
|
struct item *item = calloc(1, sizeof (struct item));
|
2015-04-16 13:58:01 +05:30
|
|
|
|
|
|
|
assert(pkgn);
|
2020-04-13 04:48:06 +05:30
|
|
|
assert(item);
|
2015-04-16 13:58:01 +05:30
|
|
|
|
|
|
|
item->status = XWAITING;
|
|
|
|
item->pkgn = strdup(pkgn);
|
2020-04-13 04:48:06 +05:30
|
|
|
assert(item->pkgn);
|
|
|
|
|
2020-02-22 20:21:07 +05:30
|
|
|
HASH_ADD_KEYPTR(hh, hashtab, item->pkgn, strlen(item->pkgn), item);
|
2015-04-16 13:58:01 +05:30
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2015-04-16 14:10:26 +05:30
|
|
|
static void __attribute__((noreturn))
|
2020-04-21 00:55:14 +05:30
|
|
|
usage(const char *progname, bool fail)
|
2015-04-16 13:58:01 +05:30
|
|
|
{
|
2020-04-20 22:25:44 +05:30
|
|
|
fprintf(stderr, "Usage: %s [OPTIONS] /path/to/void-packages [pkg pkg+N]\n\n"
|
2020-04-20 22:20:11 +05:30
|
|
|
"OPTIONS\n"
|
|
|
|
" -j, --jobs <N> Number of parallel builds\n"
|
|
|
|
" -l, --logdir <path> Path to store logs\n"
|
|
|
|
" -s, --system System rebuild mode\n"
|
|
|
|
" -V, --verbose Enable verbose mode\n"
|
|
|
|
" -v, --version Show XBPS version\n"
|
2020-04-20 22:25:44 +05:30
|
|
|
" -h, --help Show usage\n", progname);
|
2020-04-21 00:55:14 +05:30
|
|
|
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
|
2015-04-16 13:58:01 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the item to the build request list. This routine is called
|
|
|
|
* after all build dependencies have been satisfied for the item.
|
|
|
|
* runBuilds() will pick items off of BuildList to keep the parallel
|
|
|
|
* build pipeline full.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
addBuild(struct item *item)
|
|
|
|
{
|
|
|
|
assert(item);
|
|
|
|
|
|
|
|
*BuildListP = item;
|
|
|
|
BuildListP = &item->bnext;
|
|
|
|
item->status = XBUILD;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the build completion for an item.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
processCompletion(struct item *item)
|
|
|
|
{
|
|
|
|
struct depn *depn;
|
|
|
|
struct item *xitem;
|
2015-04-23 14:07:32 +05:30
|
|
|
const char *logdir;
|
2020-04-13 04:48:06 +05:30
|
|
|
char *logpath, *logpath2;
|
2015-04-16 13:58:01 +05:30
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
assert(item);
|
|
|
|
/*
|
|
|
|
* If XRUN we have to move the logfile to the correct directory.
|
2020-04-20 22:20:11 +05:30
|
|
|
* (If XDEPFAIL the logfile is already in the correct directory).
|
2015-04-16 13:58:01 +05:30
|
|
|
*/
|
|
|
|
if (item->status == XRUN) {
|
2020-04-13 05:05:07 +05:30
|
|
|
logpath = xbps_xasprintf("%s/run/%s.txt", LogDir, item->pkgn);
|
2020-04-13 04:48:06 +05:30
|
|
|
switch (item->xcode) {
|
|
|
|
case 0:
|
2015-04-23 14:07:32 +05:30
|
|
|
logdir = "good";
|
2020-04-13 04:48:06 +05:30
|
|
|
break;
|
|
|
|
case 2:
|
2015-04-23 14:07:32 +05:30
|
|
|
logdir = "skipped";
|
2020-04-13 04:48:06 +05:30
|
|
|
break;
|
|
|
|
default:
|
2015-04-23 14:07:32 +05:30
|
|
|
logdir = "bad";
|
2020-04-13 04:48:06 +05:30
|
|
|
break;
|
|
|
|
}
|
2020-04-13 05:05:07 +05:30
|
|
|
logpath2 = xbps_xasprintf("%s/%s/%s.txt", LogDir, logdir, item->pkgn);
|
2020-04-13 04:48:06 +05:30
|
|
|
(void)rename(logpath, logpath2);
|
|
|
|
free(logpath);
|
2015-04-16 13:58:01 +05:30
|
|
|
free(logpath2);
|
|
|
|
}
|
|
|
|
|
2020-04-20 22:20:11 +05:30
|
|
|
/*
|
|
|
|
* Make sure that item has already run (XRUN) or
|
|
|
|
* failed due to dependencies (XDEPFAIL).
|
|
|
|
*
|
|
|
|
* When XWAITING the item is waiting for its dependencies.
|
|
|
|
* When XBUILD the item is in the build list.
|
|
|
|
*/
|
2020-04-13 04:48:06 +05:30
|
|
|
assert(item->status == XRUN || item->status == XDEPFAIL);
|
2015-04-16 13:58:01 +05:30
|
|
|
|
2020-04-20 22:20:11 +05:30
|
|
|
/*
|
|
|
|
* Process reverse dependencies for the item.
|
|
|
|
*/
|
2015-04-16 13:58:01 +05:30
|
|
|
for (depn = item->dbase; depn; depn = depn->dnext) {
|
|
|
|
xitem = depn->item;
|
|
|
|
assert(xitem->dcount > 0);
|
|
|
|
--xitem->dcount;
|
2020-04-13 04:48:06 +05:30
|
|
|
|
|
|
|
if (xitem->status == XWAITING || xitem->status == XDEPFAIL) {
|
2015-04-16 13:58:01 +05:30
|
|
|
/*
|
|
|
|
* If our build went well add items dependent
|
|
|
|
* on us to the build, otherwise fail the items
|
|
|
|
* dependent on us.
|
|
|
|
*/
|
2020-04-13 04:48:06 +05:30
|
|
|
if (item->xcode == 0) {
|
|
|
|
if (xitem->dcount == 0) {
|
|
|
|
if (xitem->status == XWAITING) {
|
|
|
|
addBuild(xitem);
|
|
|
|
} else {
|
|
|
|
processCompletion(xitem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-04-16 13:58:01 +05:30
|
|
|
xitem->xcode = item->xcode;
|
|
|
|
xitem->status = XDEPFAIL;
|
2020-04-13 05:05:07 +05:30
|
|
|
logpath = xbps_xasprintf("%s/deps/%s.txt",
|
|
|
|
LogDir, xitem->pkgn);
|
2020-04-13 04:48:06 +05:30
|
|
|
fp = fopen(logpath, "a");
|
2015-04-20 22:14:06 +05:30
|
|
|
fprintf(fp, "%s\n", item->pkgn);
|
2015-04-16 13:58:01 +05:30
|
|
|
fclose(fp);
|
2020-04-13 04:48:06 +05:30
|
|
|
free(logpath);
|
|
|
|
processCompletion(xitem);
|
2015-04-16 13:58:01 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-20 22:20:11 +05:30
|
|
|
/*
|
|
|
|
* Item has been processed successfully.
|
|
|
|
*/
|
|
|
|
item->status = XDONE;
|
2020-04-13 04:48:06 +05:30
|
|
|
++NFinished;
|
|
|
|
|
|
|
|
printf("[%u/%u] Finished %s (PID: %u RET: %d)\n",
|
|
|
|
NFinished, NTotal, item->pkgn, item->pid, item->xcode);
|
2015-04-16 13:58:01 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for a running build to finish and process its completion.
|
|
|
|
* Return the build or NULL if no builds are pending.
|
|
|
|
*
|
|
|
|
* The caller should call runBuilds() in the loop to keep the build
|
|
|
|
* pipeline full until there is nothing left in the build list.
|
|
|
|
*/
|
|
|
|
static struct item *
|
|
|
|
waitRunning(int flags)
|
|
|
|
{
|
2020-04-13 04:48:06 +05:30
|
|
|
struct item *item = NULL;
|
2015-04-16 13:58:01 +05:30
|
|
|
struct item **itemp;
|
|
|
|
pid_t pid;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (RunList == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2020-04-13 04:48:06 +05:30
|
|
|
while (((pid = waitpid(0, &status, flags)) < 0) && !flags)
|
2015-04-16 13:58:01 +05:30
|
|
|
;
|
|
|
|
|
2020-04-20 22:20:11 +05:30
|
|
|
/*
|
|
|
|
* NOTE! The pid may be associated with one of our popen()'s
|
|
|
|
* so just ignore it if we cannot find it.
|
|
|
|
*/
|
2015-04-16 13:58:01 +05:30
|
|
|
if (pid > 0) {
|
|
|
|
status = WEXITSTATUS(status);
|
|
|
|
itemp = &RunList;
|
|
|
|
while ((item = *itemp) != NULL) {
|
|
|
|
if (item->pid == pid)
|
|
|
|
break;
|
|
|
|
itemp = &item->bnext;
|
|
|
|
}
|
|
|
|
if (item) {
|
|
|
|
*itemp = item->bnext;
|
|
|
|
item->bnext = NULL;
|
|
|
|
item->xcode = status;
|
|
|
|
--NRunning;
|
|
|
|
processCompletion(item);
|
|
|
|
}
|
2020-04-20 22:20:11 +05:30
|
|
|
} else {
|
|
|
|
item = NULL;
|
2015-04-16 13:58:01 +05:30
|
|
|
}
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start new builds from the build list and handle build completions,
|
|
|
|
* which can potentialy add new items to the build list.
|
|
|
|
*
|
2020-04-20 22:20:11 +05:30
|
|
|
* This routine will maintain up to NParallel builds. A new build is
|
|
|
|
* only started once its dependencies have completed successfully so
|
|
|
|
* when the bulk build starts it typically takes a little while before
|
|
|
|
* xbps-fbulk can keep the parallel pipeline full.
|
2015-04-16 13:58:01 +05:30
|
|
|
*/
|
|
|
|
static void
|
|
|
|
runBuilds(const char *bpath)
|
|
|
|
{
|
|
|
|
struct item *item;
|
|
|
|
char *logpath;
|
|
|
|
FILE *fp;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
assert(bpath);
|
|
|
|
/*
|
|
|
|
* Try to maintain up to NParallel builds
|
|
|
|
*/
|
|
|
|
while (NRunning < NParallel && BuildList) {
|
|
|
|
item = BuildList;
|
|
|
|
if ((BuildList = item->bnext) == NULL)
|
|
|
|
BuildListP = &BuildList;
|
|
|
|
|
2020-04-13 04:48:06 +05:30
|
|
|
item->status = XRUN;
|
2015-04-16 13:58:01 +05:30
|
|
|
/*
|
|
|
|
* When [re]running a build remove any bad log from prior
|
|
|
|
* attempts.
|
|
|
|
*/
|
2020-04-13 05:05:07 +05:30
|
|
|
logpath = xbps_xasprintf("%s/bad/%s.txt", LogDir, item->pkgn);
|
2015-07-26 11:51:46 +05:30
|
|
|
(void)remove(logpath);
|
2015-04-16 13:58:01 +05:30
|
|
|
free(logpath);
|
2020-04-13 05:05:07 +05:30
|
|
|
logpath = xbps_xasprintf("%s/deps/%s.txt", LogDir, item->pkgn);
|
2020-04-13 04:48:06 +05:30
|
|
|
(void)remove(logpath);
|
|
|
|
free(logpath);
|
2020-04-13 05:05:07 +05:30
|
|
|
logpath = xbps_xasprintf("%s/skipped/%s.txt", LogDir, item->pkgn);
|
2020-04-13 04:48:06 +05:30
|
|
|
(void)remove(logpath);
|
|
|
|
free(logpath);
|
2020-04-13 05:05:07 +05:30
|
|
|
logpath = xbps_xasprintf("%s/run/%s.txt", LogDir, item->pkgn);
|
2015-04-16 13:58:01 +05:30
|
|
|
|
|
|
|
item->pid = fork();
|
|
|
|
if (item->pid == 0) {
|
|
|
|
/*
|
|
|
|
* Child process - setup the log file and build
|
|
|
|
*/
|
|
|
|
if (chdir(bpath) < 0)
|
|
|
|
_exit(99);
|
|
|
|
|
|
|
|
fd = open(logpath, O_RDWR|O_CREAT|O_TRUNC, 0666);
|
|
|
|
if (fd != 1)
|
|
|
|
dup2(fd, 1);
|
|
|
|
if (fd != 2)
|
|
|
|
dup2(fd, 2);
|
|
|
|
if (fd != 1 && fd != 2)
|
|
|
|
close(fd);
|
|
|
|
fd = open("/dev/null", O_RDWR);
|
|
|
|
if (fd != 0) {
|
|
|
|
dup2(fd, 0);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
/* build the current pkg! */
|
2020-04-13 04:48:06 +05:30
|
|
|
execl("./xbps-src", "./xbps-src",
|
|
|
|
"-E", "-N", "-t", "pkg", item->pkgn, NULL);
|
2015-04-19 15:19:29 +05:30
|
|
|
|
2015-04-16 13:58:01 +05:30
|
|
|
_exit(99);
|
|
|
|
} else if (item->pid < 0) {
|
|
|
|
/*
|
|
|
|
* Parent fork() failed, log the problem and
|
|
|
|
* do completion processing.
|
|
|
|
*/
|
|
|
|
item->xcode = -98;
|
|
|
|
fp = fopen(logpath, "a");
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("xbps-fbulk: unable to fork/exec xbps-src\n");
|
2015-04-16 13:58:01 +05:30
|
|
|
fclose(fp);
|
|
|
|
processCompletion(item);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Parent is now tracking the running child,
|
|
|
|
* add the item to the RunList.
|
|
|
|
*/
|
|
|
|
item->bnext = RunList;
|
|
|
|
RunList = item;
|
|
|
|
++NRunning;
|
2020-04-13 04:48:06 +05:30
|
|
|
++NBuilt;
|
|
|
|
printf("[%u/%u] Building %s (PID: %u)\n",
|
2020-04-20 22:20:11 +05:30
|
|
|
NBuilt, NTotal, item->pkgn, item->pid);
|
2015-04-16 13:58:01 +05:30
|
|
|
}
|
|
|
|
free(logpath);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Process any completed builds (non-blocking)
|
|
|
|
*/
|
|
|
|
while (waitRunning(WNOHANG) != NULL)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a reverse dependency from the deepest point (xitem) to the
|
|
|
|
* packages that depend on xitem (item in this case).
|
|
|
|
*
|
|
|
|
* Caller will check dcount after it is through adding dependencies.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
addDepn(struct item *item, struct item *xitem)
|
|
|
|
{
|
2020-04-14 18:00:16 +05:30
|
|
|
struct depn *depn = malloc(sizeof(struct depn));
|
2020-04-20 22:20:11 +05:30
|
|
|
FILE *fp;
|
|
|
|
char *logpath;
|
2015-04-16 13:58:01 +05:30
|
|
|
|
|
|
|
assert(item);
|
|
|
|
assert(xitem);
|
|
|
|
assert(depn);
|
|
|
|
|
|
|
|
depn->item = item;
|
|
|
|
depn->dnext = xitem->dbase;
|
|
|
|
xitem->dbase = depn;
|
2020-04-20 22:20:11 +05:30
|
|
|
if (xitem->status == XDONE) {
|
|
|
|
if (xitem->xcode) {
|
|
|
|
/*
|
|
|
|
* If reverse dependency has failed,
|
|
|
|
* current item also failed!
|
|
|
|
*/
|
|
|
|
assert(item->status == XWAITING ||
|
|
|
|
item->status == XDEPFAIL);
|
|
|
|
item->xcode = xitem->xcode;
|
|
|
|
item->status = XDEPFAIL;
|
|
|
|
logpath = xbps_xasprintf("%s/deps/%s.txt",
|
|
|
|
LogDir, item->pkgn);
|
|
|
|
fp = fopen(logpath, "a");
|
|
|
|
fprintf(fp, "%s\n", xitem->pkgn);
|
|
|
|
fclose(fp);
|
|
|
|
free(logpath);
|
|
|
|
++NBuilt;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
++item->dcount;
|
|
|
|
}
|
2015-04-16 13:58:01 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-04-13 04:48:06 +05:30
|
|
|
* Recursively execute 'xbps-src show-build-deps' to calculate all required
|
2015-04-16 13:58:01 +05:30
|
|
|
* dependencies.
|
|
|
|
*/
|
|
|
|
static struct item *
|
|
|
|
ordered_depends(const char *bpath, const char *pkgn)
|
|
|
|
{
|
|
|
|
struct item *item, *xitem;
|
2020-04-13 04:48:06 +05:30
|
|
|
char buf[1024], cmd[PATH_MAX];
|
2015-04-16 13:58:01 +05:30
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
assert(bpath);
|
|
|
|
assert(pkgn);
|
|
|
|
|
|
|
|
item = addItem(pkgn);
|
|
|
|
/*
|
2020-04-20 22:20:11 +05:30
|
|
|
* Retrieve and process dependencies recursively. Note that
|
|
|
|
* addDepn() can modify item's status.
|
2015-04-16 13:58:01 +05:30
|
|
|
*/
|
2020-04-13 04:48:06 +05:30
|
|
|
++NChecked;
|
|
|
|
printf("[%u] Checking %s\n", NChecked, item->pkgn);
|
2015-04-19 15:19:29 +05:30
|
|
|
|
2020-04-13 04:48:06 +05:30
|
|
|
snprintf(cmd, sizeof(cmd)-1,
|
|
|
|
"%s/xbps-src show-build-deps %s 2>&1", bpath, pkgn);
|
2015-04-16 13:58:01 +05:30
|
|
|
fp = popen(cmd, "r");
|
|
|
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
2020-04-13 04:48:06 +05:30
|
|
|
char dpath[PATH_MAX];
|
2015-04-16 13:58:01 +05:30
|
|
|
size_t len;
|
2020-04-13 04:48:06 +05:30
|
|
|
struct stat st;
|
2015-04-16 13:58:01 +05:30
|
|
|
|
2020-04-13 04:48:06 +05:30
|
|
|
/* ignore xbps-src messages */
|
|
|
|
if (strncmp(buf, "=>", 2) == 0) {
|
2016-02-05 16:14:22 +05:30
|
|
|
continue;
|
2015-04-16 13:58:01 +05:30
|
|
|
}
|
2020-04-13 04:48:06 +05:30
|
|
|
|
2015-04-16 13:58:01 +05:30
|
|
|
len = strlen(buf);
|
|
|
|
if (len && buf[len-1] == '\n')
|
|
|
|
buf[--len] = 0;
|
|
|
|
|
2020-04-13 04:48:06 +05:30
|
|
|
snprintf(dpath, sizeof(dpath)-1,
|
|
|
|
"%s/srcpkgs/%s/template", bpath, buf);
|
|
|
|
if (stat(dpath, &st) == -1) {
|
|
|
|
/*
|
|
|
|
* Ignore unexistent dependencies, this
|
|
|
|
* might happen for virtual packages or
|
|
|
|
* autogenerated pkgs (-32bit, etc).
|
|
|
|
*
|
|
|
|
* We don't really care if the pkg has
|
|
|
|
* invalid dependencies, at build time they
|
|
|
|
* will be properly catched by xbps-src.
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
2015-04-16 13:58:01 +05:30
|
|
|
if (VerboseOpt)
|
2015-04-26 13:35:56 +05:30
|
|
|
printf("%s: depends on %s\n", pkgn, buf);
|
2015-04-16 13:58:01 +05:30
|
|
|
|
2015-04-26 13:35:56 +05:30
|
|
|
xitem = lookupItem(buf);
|
2015-04-16 13:58:01 +05:30
|
|
|
if (xitem == NULL)
|
2015-04-26 13:35:56 +05:30
|
|
|
xitem = ordered_depends(bpath, buf);
|
2020-04-13 04:48:06 +05:30
|
|
|
|
2015-04-16 13:58:01 +05:30
|
|
|
addDepn(item, xitem);
|
|
|
|
}
|
|
|
|
pclose(fp);
|
2020-04-13 04:48:06 +05:30
|
|
|
++NTotal;
|
2015-04-16 13:58:01 +05:30
|
|
|
/*
|
2020-04-20 22:20:11 +05:30
|
|
|
* If the item has no dependencies left either add it to the
|
|
|
|
* build list or do completion processing (i.e. if some of the
|
|
|
|
* dependencies failed).
|
2015-04-16 13:58:01 +05:30
|
|
|
*/
|
|
|
|
if (item->dcount == 0) {
|
2020-04-20 22:20:11 +05:30
|
|
|
switch (item->status) {
|
|
|
|
case XWAITING:
|
|
|
|
addBuild(item);
|
|
|
|
break;
|
|
|
|
case XDEPFAIL:
|
|
|
|
processCompletion(item);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Might happen due to excessive NParallel jobs!
|
|
|
|
* Error out because this is critical.
|
|
|
|
*/
|
|
|
|
printf("%s: item->xcode %d item->status %d\n",
|
|
|
|
item->pkgn, item->xcode, item->status);
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
2015-04-16 13:58:01 +05:30
|
|
|
} else {
|
|
|
|
if (VerboseOpt)
|
|
|
|
printf("Deferred package: %s\n", item->pkgn);
|
|
|
|
}
|
2020-04-20 22:20:11 +05:30
|
|
|
runBuilds(bpath);
|
2015-04-16 13:58:01 +05:30
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2020-04-20 22:20:11 +05:30
|
|
|
static int
|
|
|
|
pkgdb_get_pkgs_cb(struct xbps_handle *xhp UNUSED,
|
|
|
|
xbps_object_t obj, const char *key UNUSED,
|
|
|
|
void *arg, bool *done UNUSED)
|
|
|
|
{
|
|
|
|
xbps_array_t *array = arg;
|
2020-04-23 12:02:54 +05:30
|
|
|
const char *pkgname = NULL;
|
2020-04-20 22:20:11 +05:30
|
|
|
bool automatic = false;
|
|
|
|
|
|
|
|
xbps_dictionary_get_bool(obj, "automatic-install", &automatic);
|
|
|
|
if (automatic)
|
|
|
|
return 0;
|
|
|
|
|
2020-04-23 12:02:54 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname))
|
|
|
|
return EINVAL;
|
|
|
|
|
2020-04-20 22:20:11 +05:30
|
|
|
xbps_array_add_cstring_nocopy(*array, pkgname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-16 13:58:01 +05:30
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2020-04-20 22:20:11 +05:30
|
|
|
struct xbps_handle xh = {0};
|
|
|
|
xbps_array_t array;
|
2015-04-16 13:58:01 +05:30
|
|
|
DIR *dir;
|
|
|
|
struct dirent *den;
|
|
|
|
struct stat st;
|
|
|
|
const char *progname = argv[0];
|
2020-04-13 04:48:06 +05:30
|
|
|
const char *logdirs[] = { "good", "bad", "run", "deps", "skipped" };
|
|
|
|
char *bpath, *rpath, *tmp, cwd[PATH_MAX];
|
2015-04-16 13:58:01 +05:30
|
|
|
size_t blen;
|
2020-04-20 22:20:11 +05:30
|
|
|
int ch, NCores, rv;
|
|
|
|
bool RebuildSystem = false;
|
2015-06-20 15:48:45 +05:30
|
|
|
const struct option longopts[] = {
|
2020-04-20 22:20:11 +05:30
|
|
|
{ "system", no_argument, NULL, 's' },
|
|
|
|
{ "jobs", required_argument, NULL, 'j' },
|
|
|
|
{ "logdir", required_argument, NULL, 'l' },
|
|
|
|
{ "verbose", no_argument, NULL, 'v' },
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
2015-06-20 15:48:45 +05:30
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
};
|
2015-04-16 13:58:01 +05:30
|
|
|
|
2020-04-20 22:20:11 +05:30
|
|
|
while ((ch = getopt_long(argc, argv, "hj:l:svV", longopts, NULL)) != -1) {
|
2015-04-16 13:58:01 +05:30
|
|
|
switch (ch) {
|
2020-04-21 00:55:14 +05:30
|
|
|
case 'h':
|
|
|
|
usage(progname, false);
|
|
|
|
/* NOTREACHED */
|
2020-04-20 22:20:11 +05:30
|
|
|
case 's':
|
|
|
|
RebuildSystem = true;
|
|
|
|
break;
|
2015-04-16 13:58:01 +05:30
|
|
|
case 'j':
|
|
|
|
NParallel = strtol(optarg, NULL, 0);
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
VerboseOpt = 1;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
LogDir = optarg;
|
|
|
|
break;
|
2015-10-28 14:07:09 +05:30
|
|
|
case 'V':
|
|
|
|
printf("%s\n", XBPS_RELVER);
|
|
|
|
exit(EXIT_SUCCESS);
|
2020-04-21 00:55:14 +05:30
|
|
|
case '?':
|
2015-04-16 13:58:01 +05:30
|
|
|
default:
|
2020-04-21 00:55:14 +05:30
|
|
|
usage(progname, true);
|
|
|
|
/* NOTREACHED */
|
2015-04-16 13:58:01 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2015-05-04 21:42:52 +05:30
|
|
|
if (argc < 1) {
|
2020-04-21 00:55:14 +05:30
|
|
|
usage(progname, true);
|
|
|
|
/* NOTREACHED */
|
2015-04-16 13:58:01 +05:30
|
|
|
}
|
|
|
|
|
2020-04-20 22:20:11 +05:30
|
|
|
/*
|
|
|
|
* FIXME
|
|
|
|
* Limit NParallel to max cores, due to program design
|
|
|
|
* this won't work when it's higher, and we'd need to
|
|
|
|
* synchronize shared data!
|
|
|
|
*/
|
|
|
|
NCores = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
|
|
|
if (NParallel > NCores)
|
|
|
|
NParallel = NCores;
|
|
|
|
|
2020-04-13 04:48:06 +05:30
|
|
|
/*
|
|
|
|
* Check masterdir is properly initialized.
|
|
|
|
*/
|
2015-04-16 13:58:01 +05:30
|
|
|
if ((bpath = realpath(argv[0], NULL)) == NULL)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
blen = strlen(bpath) + strlen("/srcpkgs") + 1;
|
|
|
|
rpath = malloc(blen);
|
|
|
|
assert(rpath);
|
|
|
|
snprintf(rpath, blen, "%s/srcpkgs", bpath);
|
|
|
|
|
2020-04-13 04:48:06 +05:30
|
|
|
tmp = xbps_xasprintf("%s/masterdir/.xbps_chroot_init", bpath);
|
|
|
|
if (access(tmp, R_OK) == -1) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("%s/masterdir wasn't initialized, "
|
2015-04-16 13:58:01 +05:30
|
|
|
"run binary-bootstrap first.\n", bpath);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2020-04-13 04:48:06 +05:30
|
|
|
free(tmp);
|
|
|
|
|
2015-04-16 13:58:01 +05:30
|
|
|
/*
|
2020-04-13 04:48:06 +05:30
|
|
|
* Create Logdirs.
|
2015-04-16 13:58:01 +05:30
|
|
|
*/
|
|
|
|
if (LogDir == NULL) {
|
2020-04-13 04:48:06 +05:30
|
|
|
if (getcwd(cwd, sizeof(cwd)-1) == NULL) {
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
tmp = xbps_xasprintf("%s/fbulk-log.%u", cwd, (unsigned)getpid());
|
2015-04-16 13:58:01 +05:30
|
|
|
} else {
|
|
|
|
tmp = strdup(LogDir);
|
|
|
|
}
|
|
|
|
if (xbps_mkpath(tmp, 0755) != 0) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("failed to create %s logdir: %s\n",
|
2020-04-13 04:48:06 +05:30
|
|
|
tmp, strerror(errno));
|
2015-04-16 13:58:01 +05:30
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
LogDir = realpath(tmp, NULL);
|
|
|
|
free(tmp);
|
2020-04-13 04:48:06 +05:30
|
|
|
assert(LogDir);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < __arraycount(logdirs); i++) {
|
|
|
|
const char *p = logdirs[i];
|
|
|
|
tmp = xbps_xasprintf("%s/%s", LogDir, p);
|
|
|
|
if (xbps_mkpath(tmp, 0755) != 0) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("failed to create %s logdir: %s\n",
|
2020-04-13 04:48:06 +05:30
|
|
|
tmp, strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
free(tmp);
|
2015-04-16 13:58:01 +05:30
|
|
|
}
|
|
|
|
|
2020-04-20 22:20:11 +05:30
|
|
|
/*
|
|
|
|
* RebuildSystem: only rebuild packages that were installed
|
|
|
|
* manually.
|
|
|
|
*/
|
|
|
|
if (RebuildSystem) {
|
|
|
|
rv = xbps_init(&xh);
|
|
|
|
if (rv != 0) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("failed to initialize libxbps: %s", strerror(rv));
|
2020-04-20 22:20:11 +05:30
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
array = xbps_array_create();
|
|
|
|
rv = xbps_pkgdb_foreach_cb_multi(&xh, pkgdb_get_pkgs_cb, &array);
|
|
|
|
if (rv != 0) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("xbps_pkgdb_foreach_cb_multi: %s", strerror(rv));
|
2020-04-20 22:20:11 +05:30
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
for (unsigned int i = 0; i < xbps_array_count(array); i++) {
|
|
|
|
const char *pkgname = NULL;
|
|
|
|
|
|
|
|
xbps_array_get_cstring_nocopy(array, i, &pkgname);
|
|
|
|
if (pkgname && !lookupItem(pkgname)) {
|
|
|
|
ordered_depends(bpath, pkgname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xbps_end(&xh);
|
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
|
2015-04-16 13:58:01 +05:30
|
|
|
/*
|
2020-04-13 04:48:06 +05:30
|
|
|
* Generate dependency tree. This is done in two steps to know how
|
|
|
|
* many packages will be built.
|
2015-04-16 13:58:01 +05:30
|
|
|
*/
|
2019-07-06 12:07:47 +05:30
|
|
|
if (chdir(rpath) == -1) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("failed to chdir to %s: %s\n",
|
2020-04-13 04:48:06 +05:30
|
|
|
rpath, strerror(errno));
|
2019-07-06 12:07:47 +05:30
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2015-04-16 13:58:01 +05:30
|
|
|
|
|
|
|
if ((dir = opendir(rpath)) != NULL) {
|
|
|
|
while ((den = readdir(dir)) != NULL) {
|
2020-04-13 04:48:06 +05:30
|
|
|
char xpath[PATH_MAX];
|
2015-05-04 21:42:52 +05:30
|
|
|
bool found = false;
|
2015-04-16 13:58:01 +05:30
|
|
|
|
2020-04-13 04:48:06 +05:30
|
|
|
if (den->d_name[0] == '.' ||
|
|
|
|
(strcmp(den->d_name, "..") == 0))
|
2015-04-16 13:58:01 +05:30
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lstat(den->d_name, &st) == -1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!S_ISDIR(st.st_mode))
|
|
|
|
continue;
|
|
|
|
|
2015-05-04 21:42:52 +05:30
|
|
|
if (argc == 1) {
|
|
|
|
/* process all pkgs */
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
/* only process pkgs specified as arguments */
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
if (strcmp(argv[i], den->d_name) == 0) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
continue;
|
|
|
|
|
2020-04-13 04:48:06 +05:30
|
|
|
snprintf(xpath, sizeof(xpath)-1, "%s/template", den->d_name);
|
|
|
|
if ((stat(xpath, &st) == 0) && !lookupItem(den->d_name)) {
|
2015-04-16 13:58:01 +05:30
|
|
|
ordered_depends(bpath, den->d_name);
|
2020-04-13 04:48:06 +05:30
|
|
|
}
|
2015-04-16 13:58:01 +05:30
|
|
|
}
|
|
|
|
(void)closedir(dir);
|
|
|
|
}
|
2020-04-20 22:20:11 +05:30
|
|
|
start:
|
2015-04-16 13:58:01 +05:30
|
|
|
/*
|
2020-04-20 22:20:11 +05:30
|
|
|
* Wait for all current builds to finish running, keep the pipeline
|
|
|
|
* full until both the BuildList and RunList have been exhausted.
|
2015-04-16 13:58:01 +05:30
|
|
|
*/
|
2015-12-21 21:37:43 +05:30
|
|
|
free(rpath);
|
2015-04-16 13:58:01 +05:30
|
|
|
runBuilds(bpath);
|
|
|
|
while (waitRunning(0) != NULL)
|
|
|
|
runBuilds(bpath);
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|