summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/jobs.h2
-rw-r--r--src/build.c19
-rw-r--r--src/jobs.c34
3 files changed, 47 insertions, 8 deletions
diff --git a/include/jobs.h b/include/jobs.h
index 66ddcec..37445c1 100644
--- a/include/jobs.h
+++ b/include/jobs.h
@@ -9,7 +9,7 @@ struct output {
};
struct job {
- char *name, *drv_path;
+ char *name, *drv_path, *attr;
bool transitive;
bool insubstituters;
diff --git a/src/build.c b/src/build.c
index 39750b5..87238e9 100644
--- a/src/build.c
+++ b/src/build.c
@@ -2,6 +2,7 @@
#include <pthread.h>
#include <stdbool.h>
#include <stdlib.h>
+#include <limits.h>
#include <string.h>
#include "build.h"
@@ -43,16 +44,29 @@ out:
static int build(struct queue *queue)
{
struct job *job;
- char *args[3];
+ char *args[5];
size_t argindex;
int ret;
+ char out_link[NAME_MAX] = "result";
+
ret = queue_pop(queue, &job, queue->htab);
if (ret < 0)
return ret;
+ if (job->attr) {
+ ret = snprintf(out_link, sizeof(out_link), "result-%s", job->attr);
+ if (ret < 0 || (size_t)ret > sizeof(out_link)) {
+ ret = -ENAMETOOLONG;
+ print_err("%s", strerror(-ret));
+ goto out_free_job;
+ }
+ }
+
argindex = 0;
args[argindex++] = "nix-build";
+ args[argindex++] = "--out-link";
+ args[argindex++] = out_link;
args[argindex++] = job->drv_path;
args[argindex++] = NULL;
@@ -64,9 +78,10 @@ static int build(struct queue *queue)
run("nix-build", args);
}
+out_free_job:
job_free(job);
- return 0;
+ return ret;
}
int build_thread_new(struct build_thread **build_thread, struct queue *q)
diff --git a/src/jobs.c b/src/jobs.c
index bda9ee2..4e3926a 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -11,7 +11,7 @@
#include "util.h"
static void output_free(struct output *output);
-static int job_new(struct job **j, char *name, char *drv_path,
+static int job_new(struct job **j, char *name, char *drv_path, char *attr,
struct job *parent);
static int job_output_insert(struct job *j, char *name, char *store_path);
static int job_read_inputdrvs(struct job *job, cJSON *input_drvs);
@@ -167,7 +167,7 @@ static int job_read_inputdrvs(struct job *job, cJSON *input_drvs)
int ret = 0;
for (cJSON *array = input_drvs; array != NULL; array = array->next) {
- ret = job_new(&dep_job, NULL, array->string, job);
+ ret = job_new(&dep_job, NULL, array->string, NULL, job);
if (ret < 0)
goto out_free_dep_job;
@@ -238,6 +238,7 @@ int job_read(FILE *stream, struct job **job)
char *drv_path = NULL;
struct job *j = NULL;
cJSON *root = NULL;
+ char *attr = NULL;
char *name = NULL;
int ret = 0;
@@ -271,6 +272,14 @@ int job_read(FILE *stream, struct job **job)
}
name = temp->valuestring;
+ temp = cJSON_GetObjectItemCaseSensitive(root, "attr");
+ if (!cJSON_IsString(temp)) {
+ ret = JOB_READ_JSON_INVAL;
+ goto out_free;
+ }
+ if (temp->valuestring[0] != '\0')
+ attr = temp->valuestring;
+
temp = cJSON_GetObjectItemCaseSensitive(root, "drvPath");
if (!cJSON_IsString(temp)) {
free(name);
@@ -279,7 +288,7 @@ int job_read(FILE *stream, struct job **job)
}
drv_path = temp->valuestring;
- ret = job_new(&j, name, drv_path, NULL);
+ ret = job_new(&j, name, drv_path, attr, NULL);
if (ret < 0)
goto out_free;
@@ -343,11 +352,12 @@ void job_free(struct job *job)
free(job->drv_path);
free(job->name);
+ free(job->attr);
free(job);
}
static int job_new(struct job **j, char *name, char *drv_path,
- struct job *parent)
+ char *attr, struct job *parent)
{
struct job *job;
int ret = 0;
@@ -371,12 +381,23 @@ static int job_new(struct job **j, char *name, char *drv_path,
job->parents_filled = 0;
job->parents = NULL;
+ if (attr != NULL) {
+ job->attr = strdup(attr);
+ if (job->attr == NULL) {
+ print_err("%s", strerror(errno));
+ ret = -errno;
+ goto out_free_job;
+ }
+ } else {
+ job->attr = NULL;
+ }
+
if (name != NULL) {
job->name = strdup(name);
if (job->name == NULL) {
print_err("%s", strerror(errno));
ret = -errno;
- goto out_free_job;
+ goto out_free_attr;
}
} else {
job->name = NULL;
@@ -401,6 +422,9 @@ out_free_drv_path:
out_free_name:
if (ret < 0)
free(job->name);
+out_free_attr:
+ if (ret < 0)
+ free(job->attr);
out_free_job:
if (ret < 0)
free(job);