Example #1
0
struct vrt_consumer *
vrt_consumer_new(const char *name, struct vrt_queue *q)
{
    struct vrt_consumer  *c = cork_new(struct vrt_consumer);
    memset(c, 0, sizeof(struct vrt_consumer));
    c->name = cork_strdup(name);
    cork_array_init(&c->dependencies);

    ei_check(vrt_queue_add_consumer(q, c));
    c->cursor.value = starting_value;
    c->last_available_id = starting_value;
    c->current_id = starting_value;
    c->eof_count = 0;
    c->batch_count = 0;
    c->yield_count = 0;
    return c;

error:
    if (c->name != NULL) {
        cork_strfree(c->name);
    }

    cork_array_done(&c->dependencies);
    cork_delete(struct vrt_consumer, c);
    return NULL;
}
Example #2
0
static int
save_bdd(struct save_data *save_data,
         struct ipset_node_cache *cache, ipset_node_id root)
{
    /* First, output the file header. */

    DEBUG("Writing file header");
    rii_check(save_data->write_header(save_data, cache, root));

    /* The serialized node IDs are different than the in-memory node
     * IDs.  This means that, for our nonterminal nodes, we need a
     * mapping from internal node ID to serialized node ID. */

    DEBUG("Creating file caches");
    save_data->serialized_ids = cork_pointer_hash_table_new(0, 0);
    save_data->next_serialized_id = -1;

    /* Trace down through the BDD tree, outputting each terminal and
     * nonterminal node as they're encountered. */

    DEBUG("Writing nodes");

    serialized_id  last_serialized_id;
    ei_check(save_visit_node(save_data, root, &last_serialized_id));

    /* Finally, output the file footer and cleanup. */

    DEBUG("Writing file footer");
    ei_check(save_data->write_footer(save_data, cache, root));

    DEBUG("Freeing file caches");
    cork_hash_table_free(save_data->serialized_ids);
    return 0;

  error:
    /* If there's an error, clean up the objects that we've created
     * before returning. */
    cork_hash_table_free(save_data->serialized_ids);
    return -1;
}
Example #3
0
int
cork_consume_file_from_path(struct cork_stream_consumer *consumer,
                            const char *path, int flags)
{
    int  fd;
    rii_check_posix(fd = open(path, flags));
    ei_check(cork_consume_fd(consumer, fd));
    rii_check_posix(close(fd));
    return 0;

error:
    rii_check_posix(close(fd));
    return -1;
}
Example #4
0
struct vrt_producer *
vrt_producer_new(const char *name, unsigned int batch_size,
                 struct vrt_queue *q)
{
    struct vrt_producer  *p;
    unsigned int  maximum_batch_size;

    p = cork_new(struct vrt_producer);
    memset(p, 0, sizeof(struct vrt_producer));

    p->name = cork_strdup(name);
    ei_check(vrt_queue_add_producer(q, p));

    if (batch_size == 0) {
        batch_size = DEFAULT_BATCH_SIZE;
    }
    maximum_batch_size = vrt_queue_size(q) / 4;
    if (batch_size > maximum_batch_size) {
        batch_size = maximum_batch_size;
    }
    clog_trace("<%s> Batch size is %u", name, batch_size);

    p->last_produced_id = starting_value;
    p->last_claimed_id = starting_value;
    p->batch_size = batch_size;
    p->yield = NULL;
    p->batch_count = 0;
    p->yield_count = 0;
    return p;

error:
    if (p->name != NULL) {
        cork_strfree(p->name);
    }

    cork_delete(struct vrt_producer, p);
    return NULL;
}
Example #5
0
File: rpm.c Project: dcreager/buzzy
static struct bz_version *
bz_version_from_rpm_any(const char *rpm_version)
{
    int  cs;
    const char  *p = rpm_version;
    const char  *pe = strchr(rpm_version, '\0');
    const char  *eof = pe;
    struct bz_version  *version;
    enum bz_version_part_kind  kind;
    const char  *start;
    struct cork_buffer  buf = CORK_BUFFER_INIT();

    clog_trace("Parse any RPM version \"%s\"", rpm_version);
    version = bz_version_new();

    
#line 560 "libbuzzy/distro/rpm.c"
static const int rpm_version_any_start = 1;

static const int rpm_version_any_en_main = 1;


#line 566 "libbuzzy/distro/rpm.c"
	{
	cs = rpm_version_any_start;
	}

#line 571 "libbuzzy/distro/rpm.c"
	{
	if ( p == pe )
		goto _test_eof;
	switch ( cs )
	{
case 1:
	if ( 48 <= (*p) && (*p) <= 57 )
		goto tr0;
	goto st0;
st0:
cs = 0;
	goto _out;
tr0:
#line 272 "libbuzzy/distro/rpm.c.rl"
	{
            kind = BZ_VERSION_RELEASE;
            start = p;
            clog_trace("  Create new release version part");
        }
	goto st2;
tr4:
#line 290 "libbuzzy/distro/rpm.c.rl"
	{
            size_t  size = p - start;
            clog_trace("    String value: %.*s", (int) size, start);
            ei_check(bz_version_add_part(version, kind, start, size));
        }
#line 272 "libbuzzy/distro/rpm.c.rl"
	{
            kind = BZ_VERSION_RELEASE;
            start = p;
            clog_trace("  Create new release version part");
        }
	goto st2;
st2:
	if ( ++p == pe )
		goto _test_eof2;
case 2:
#line 610 "libbuzzy/distro/rpm.c"
	switch( (*p) ) {
		case 43: goto tr2;
		case 45: goto tr3;
		case 46: goto tr2;
		case 95: goto tr2;
	}
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto tr4;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto tr5;
	} else
		goto tr5;
	goto st0;
tr2:
#line 290 "libbuzzy/distro/rpm.c.rl"
	{
            size_t  size = p - start;
            clog_trace("    String value: %.*s", (int) size, start);
            ei_check(bz_version_add_part(version, kind, start, size));
        }
	goto st3;
st3:
	if ( ++p == pe )
		goto _test_eof3;
case 3:
#line 638 "libbuzzy/distro/rpm.c"
	switch( (*p) ) {
		case 43: goto st3;
		case 46: goto st3;
		case 95: goto st3;
	}
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto tr7;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto tr8;
	} else
		goto tr8;
	goto st0;
tr7:
#line 272 "libbuzzy/distro/rpm.c.rl"
	{
            kind = BZ_VERSION_RELEASE;
            start = p;
            clog_trace("  Create new release version part");
        }
	goto st4;
tr18:
#line 290 "libbuzzy/distro/rpm.c.rl"
	{
            size_t  size = p - start;
            clog_trace("    String value: %.*s", (int) size, start);
            ei_check(bz_version_add_part(version, kind, start, size));
        }
#line 272 "libbuzzy/distro/rpm.c.rl"
	{
            kind = BZ_VERSION_RELEASE;
            start = p;
            clog_trace("  Create new release version part");
        }
	goto st4;
st4:
	if ( ++p == pe )
		goto _test_eof4;
case 4:
#line 679 "libbuzzy/distro/rpm.c"
	switch( (*p) ) {
		case 43: goto tr2;
		case 45: goto tr3;
		case 46: goto tr2;
		case 95: goto tr2;
	}
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto st4;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto tr5;
	} else
		goto tr5;
	goto st0;
tr3:
#line 290 "libbuzzy/distro/rpm.c.rl"
	{
            size_t  size = p - start;
            clog_trace("    String value: %.*s", (int) size, start);
            ei_check(bz_version_add_part(version, kind, start, size));
        }
	goto st5;
st5:
	if ( ++p == pe )
		goto _test_eof5;
case 5:
#line 707 "libbuzzy/distro/rpm.c"
	switch( (*p) ) {
		case 48: goto st6;
		case 49: goto tr11;
	}
	if ( 50 <= (*p) && (*p) <= 57 )
		goto tr12;
	goto st0;
st6:
	if ( ++p == pe )
		goto _test_eof6;
case 6:
	if ( (*p) == 46 )
		goto st7;
	goto st0;
st7:
	if ( ++p == pe )
		goto _test_eof7;
case 7:
	if ( 48 <= (*p) && (*p) <= 57 )
		goto tr14;
	goto st0;
tr21:
#line 290 "libbuzzy/distro/rpm.c.rl"
	{
            size_t  size = p - start;
            clog_trace("    String value: %.*s", (int) size, start);
            ei_check(bz_version_add_part(version, kind, start, size));
        }
#line 272 "libbuzzy/distro/rpm.c.rl"
	{
            kind = BZ_VERSION_RELEASE;
            start = p;
            clog_trace("  Create new release version part");
        }
	goto st10;
tr12:
#line 284 "libbuzzy/distro/rpm.c.rl"
	{
            kind = BZ_VERSION_POSTRELEASE;
            start = p;
            clog_trace("  Create new postrelease version part");
        }
	goto st10;
tr14:
#line 278 "libbuzzy/distro/rpm.c.rl"
	{
            kind = BZ_VERSION_PRERELEASE;
            start = p;
            clog_trace("  Create new prerelease version part");
        }
	goto st10;
st10:
	if ( ++p == pe )
		goto _test_eof10;
case 10:
#line 763 "libbuzzy/distro/rpm.c"
	switch( (*p) ) {
		case 43: goto tr20;
		case 46: goto tr20;
		case 95: goto tr20;
	}
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto tr21;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto tr22;
	} else
		goto tr22;
	goto st0;
tr20:
#line 290 "libbuzzy/distro/rpm.c.rl"
	{
            size_t  size = p - start;
            clog_trace("    String value: %.*s", (int) size, start);
            ei_check(bz_version_add_part(version, kind, start, size));
        }
	goto st8;
st8:
	if ( ++p == pe )
		goto _test_eof8;
case 8:
#line 790 "libbuzzy/distro/rpm.c"
	switch( (*p) ) {
		case 43: goto st8;
		case 46: goto st8;
		case 95: goto st8;
	}
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto tr16;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto tr17;
	} else
		goto tr17;
	goto st0;
tr16:
#line 272 "libbuzzy/distro/rpm.c.rl"
	{
            kind = BZ_VERSION_RELEASE;
            start = p;
            clog_trace("  Create new release version part");
        }
	goto st11;
tr24:
#line 290 "libbuzzy/distro/rpm.c.rl"
	{
            size_t  size = p - start;
            clog_trace("    String value: %.*s", (int) size, start);
            ei_check(bz_version_add_part(version, kind, start, size));
        }
#line 272 "libbuzzy/distro/rpm.c.rl"
	{
            kind = BZ_VERSION_RELEASE;
            start = p;
            clog_trace("  Create new release version part");
        }
	goto st11;
st11:
	if ( ++p == pe )
		goto _test_eof11;
case 11:
#line 831 "libbuzzy/distro/rpm.c"
	switch( (*p) ) {
		case 43: goto tr20;
		case 46: goto tr20;
		case 95: goto tr20;
	}
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto st11;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto tr22;
	} else
		goto tr22;
	goto st0;
tr17:
#line 272 "libbuzzy/distro/rpm.c.rl"
	{
            kind = BZ_VERSION_RELEASE;
            start = p;
            clog_trace("  Create new release version part");
        }
	goto st12;
tr22:
#line 290 "libbuzzy/distro/rpm.c.rl"
	{
            size_t  size = p - start;
            clog_trace("    String value: %.*s", (int) size, start);
            ei_check(bz_version_add_part(version, kind, start, size));
        }
#line 272 "libbuzzy/distro/rpm.c.rl"
	{
            kind = BZ_VERSION_RELEASE;
            start = p;
            clog_trace("  Create new release version part");
        }
	goto st12;
st12:
	if ( ++p == pe )
		goto _test_eof12;
case 12:
#line 872 "libbuzzy/distro/rpm.c"
	switch( (*p) ) {
		case 43: goto tr20;
		case 46: goto tr20;
		case 95: goto tr20;
	}
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto tr24;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto st12;
	} else
		goto st12;
	goto st0;
tr11:
#line 284 "libbuzzy/distro/rpm.c.rl"
	{
            kind = BZ_VERSION_POSTRELEASE;
            start = p;
            clog_trace("  Create new postrelease version part");
        }
	goto st13;
st13:
	if ( ++p == pe )
		goto _test_eof13;
case 13:
#line 899 "libbuzzy/distro/rpm.c"
	switch( (*p) ) {
		case 43: goto tr20;
		case 46: goto tr20;
		case 95: goto tr20;
	}
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto tr21;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto tr22;
	} else
		goto tr22;
	goto st0;
tr8:
#line 272 "libbuzzy/distro/rpm.c.rl"
	{
            kind = BZ_VERSION_RELEASE;
            start = p;
            clog_trace("  Create new release version part");
        }
	goto st9;
tr5:
#line 290 "libbuzzy/distro/rpm.c.rl"
	{
            size_t  size = p - start;
            clog_trace("    String value: %.*s", (int) size, start);
            ei_check(bz_version_add_part(version, kind, start, size));
        }
#line 272 "libbuzzy/distro/rpm.c.rl"
	{
            kind = BZ_VERSION_RELEASE;
            start = p;
            clog_trace("  Create new release version part");
        }
	goto st9;
st9:
	if ( ++p == pe )
		goto _test_eof9;
case 9:
#line 940 "libbuzzy/distro/rpm.c"
	switch( (*p) ) {
		case 43: goto tr2;
		case 45: goto tr3;
		case 46: goto tr2;
		case 95: goto tr2;
	}
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto tr18;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto st9;
	} else
		goto st9;
	goto st0;
	}
	_test_eof2: cs = 2; goto _test_eof; 
	_test_eof3: cs = 3; goto _test_eof; 
	_test_eof4: cs = 4; goto _test_eof; 
	_test_eof5: cs = 5; goto _test_eof; 
	_test_eof6: cs = 6; goto _test_eof; 
	_test_eof7: cs = 7; goto _test_eof; 
	_test_eof10: cs = 10; goto _test_eof; 
	_test_eof8: cs = 8; goto _test_eof; 
	_test_eof11: cs = 11; goto _test_eof; 
	_test_eof12: cs = 12; goto _test_eof; 
	_test_eof13: cs = 13; goto _test_eof; 
	_test_eof9: cs = 9; goto _test_eof; 

	_test_eof: {}
	if ( p == eof )
	{
	switch ( cs ) {
	case 10: 
	case 11: 
	case 12: 
#line 290 "libbuzzy/distro/rpm.c.rl"
	{
            size_t  size = p - start;
            clog_trace("    String value: %.*s", (int) size, start);
            ei_check(bz_version_add_part(version, kind, start, size));
        }
	break;
#line 984 "libbuzzy/distro/rpm.c"
	}
	}

	_out: {}
	}

#line 337 "libbuzzy/distro/rpm.c.rl"


    /* A hack to suppress some unused variable warnings */
    (void) rpm_version_any_en_main;

    if (CORK_UNLIKELY(cs < 
#line 998 "libbuzzy/distro/rpm.c"
10
#line 342 "libbuzzy/distro/rpm.c.rl"
)) {
        goto error;
    }

    bz_version_finalize(version);
    cork_buffer_done(&buf);
    return version;

error:
    cork_buffer_done(&buf);
    bz_version_free(version);
    return NULL;
}
Example #6
0
static int
bz_autotools__build(void *user_data)
{
    struct bz_env  *env = user_data;
    struct bz_value  *ctx = bz_env_as_value(env);
    const char  *package_name;
    struct cork_path  *build_dir;
    struct cork_path  *source_dir;
    struct cork_path  *configure;
    struct bz_value  *configure_args;
    const char  *pkgconfig_path;
    bool  exists;
    bool  verbose;
    struct cork_exec  *exec;
    struct cork_env  *exec_env;
    struct cork_buffer  buf = CORK_BUFFER_INIT();

    rii_check(bz_install_dependency_string("autoconf", ctx));
    rii_check(bz_install_dependency_string("automake", ctx));
    rii_check(bz_build_message(env, "autotools"));

    rip_check(package_name = bz_env_get_string(env, "name", true));
    rip_check(build_dir = bz_env_get_path(env, "build_dir", true));
    rip_check(source_dir = bz_env_get_path(env, "source_dir", true));
    rip_check(configure =
              bz_env_get_path(env, "autotools.configure.configure", true));
    rie_check(pkgconfig_path = bz_env_get_string(env, "pkgconfig.path", false));
    rie_check(verbose = bz_env_get_bool(env, "verbose", true));

    /* Create the build path */
    rii_check(bz_create_directory(cork_path_get(build_dir), 0750));

    clog_info("(%s) Configure using autotools", package_name);

    /* $ autoreconf -i */
    rii_check(bz_file_exists(cork_path_get(configure), &exists));
    if (!exists) {
        exec = cork_exec_new("autoreconf");
        cork_exec_add_param(exec, "autoreconf");
        cork_exec_add_param(exec, "-i");
        cork_exec_set_cwd(exec, cork_path_get(source_dir));
        ei_check(bz_subprocess_run_exec(verbose, NULL, exec));
    }

#define add_dir(buzzy_name, param_name) \
    do { \
        struct cork_path  *value; \
        ep_check(value = bz_env_get_path(env, buzzy_name, true)); \
        cork_buffer_printf(&buf, "--" param_name "=%s", cork_path_get(value)); \
        cork_exec_add_param(exec, buf.buf); \
    } while (0)

    /* $ ./configure ... */
    exec = cork_exec_new(cork_path_get(configure));
    exec_env = cork_env_clone_current();
    cork_exec_set_env(exec, exec_env);
    cork_exec_add_param(exec, cork_path_get(configure));
    add_dir("prefix", "prefix");
    add_dir("exec_prefix", "exec-prefix");
    add_dir("bin_dir", "bindir");
    add_dir("sbin_dir", "sbindir");
    add_dir("lib_dir", "libdir");
    add_dir("libexec_dir", "libexecdir");
    add_dir("share_dir", "datadir");
    add_dir("man_dir", "mandir");

    /* Add custom configure arguments, if given. */
    configure_args = bz_env_get_value(env, "autotools.configure.args");
    if (configure_args != NULL) {
        struct bz_configure_add_arg  state = { exec, env };

        switch (bz_value_kind(configure_args)) {
            case BZ_VALUE_SCALAR:
                ei_check(bz_configure_add_arg(&state, configure_args));
                break;

            case BZ_VALUE_ARRAY:
                ei_check(bz_array_value_map
                         (configure_args, &state, bz_configure_add_arg));
                break;

            case BZ_VALUE_MAP:
                bz_bad_config("autotools.configure.args cannot be a map");
                goto error;

            default:
                cork_unreachable();
        }
    }

    cork_exec_set_cwd(exec, cork_path_get(build_dir));
    if (pkgconfig_path != NULL) {
        cork_env_add(exec_env, "PKG_CONFIG_PATH", pkgconfig_path);
    }
    ei_check(bz_subprocess_run_exec(verbose, NULL, exec));

    /* $ make */
    clog_info("(%s) Build using autotools", package_name);
    exec = cork_exec_new("make");
    cork_exec_add_param(exec, "make");
    cork_exec_set_cwd(exec, cork_path_get(build_dir));
    ei_check(bz_subprocess_run_exec(verbose, NULL, exec));

    cork_buffer_done(&buf);
    return 0;

error:
    cork_buffer_done(&buf);
    return -1;
}
static int
cork_walk_one_directory(struct cork_dir_walker *w, struct cork_buffer *path,
                        size_t root_path_size)
{
    DIR  *dir = NULL;
    struct dirent  *entry;
    size_t  dir_path_size;

    rip_check_posix(dir = opendir(path->buf));

    cork_buffer_append(path, "/", 1);
    dir_path_size = path->size;
    errno = 0;
    while ((entry = readdir(dir)) != NULL) {
        struct stat  info;

        /* Skip the "." and ".." entries */
        if (strcmp(entry->d_name, ".") == 0 ||
            strcmp(entry->d_name, "..") == 0) {
            continue;
        }

        /* Stat the directory entry */
        cork_buffer_append_string(path, entry->d_name);
        ei_check_posix(stat(path->buf, &info));

        /* If the entry is a subdirectory, recurse into it. */
        if (S_ISDIR(info.st_mode)) {
            int  rc = cork_dir_walker_enter_directory
                (w, path->buf, path->buf + root_path_size,
                 path->buf + dir_path_size);
            if (rc != CORK_SKIP_DIRECTORY) {
                ei_check(cork_walk_one_directory(w, path, root_path_size));
                ei_check(cork_dir_walker_leave_directory
                         (w, path->buf, path->buf + root_path_size,
                          path->buf + dir_path_size));
            }
        } else if (S_ISREG(info.st_mode)) {
            ei_check(cork_dir_walker_file
                     (w, path->buf, path->buf + root_path_size,
                      path->buf + dir_path_size));
        }

        /* Remove this entry name from the path buffer. */
        cork_buffer_truncate(path, dir_path_size);

        /* We have to reset errno to 0 because of the ambiguous way
         * readdir uses a return value of NULL.  Other functions may
         * return normally yet set errno to a non-zero value.  dlopen
         * on Mac OS X is an ogreish example.  Since an error readdir
         * is indicated by returning NULL and setting errno to indicate
         * the error, then we need to reset it to zero before each call.
         * We shall assume, perhaps to our great misery, that functions
         * within this loop do proper error checking and act accordingly.
         */
        errno = 0;
    }

    /* Check errno immediately after the while loop terminates */
    if (CORK_UNLIKELY(errno != 0)) {
        cork_system_error_set();
        goto error;
    }

    /* Remove the trailing '/' from the path buffer. */
    cork_buffer_truncate(path, dir_path_size - 1);
    rii_check_posix(closedir(dir));
    return 0;

error:
    if (dir != NULL) {
        rii_check_posix(closedir(dir));
    }
    return -1;
}
Example #8
0
static int
bz_pacman__package(void *user_data)
{
    struct bz_env  *env = user_data;
    struct bz_value  *ctx = bz_env_as_value(env);
    struct cork_path  *staging_dir;
    struct cork_path  *binary_package_dir;
    struct cork_path  *package_build_dir;
    struct cork_path  *pkgbuild;
    struct cork_path  *package_file;
    const char  *package_name;
    const char  *version;
    const char  *pkgrel;
    const char  *pkgext;
    const char  *architecture;
    const char  *license;
    bool  verbose;

    struct cork_env  *exec_env;
    struct cork_exec  *exec;
    struct cork_buffer  buf = CORK_BUFFER_INIT();
    bool  staging_exists;

    rii_check(bz_install_dependency_string("pacman", ctx));
    rii_check(bz_package_message(env, "pacman"));

    rip_check(package_name = bz_env_get_string(env, "name", true));
    clog_info("(%s) Package using pacman", package_name);

    rip_check(staging_dir = bz_env_get_path(env, "staging_dir", true));
    rip_check(binary_package_dir =
              bz_env_get_path(env, "binary_package_dir", true));
    rip_check(package_build_dir =
              bz_env_get_path(env, "package_build_dir", true));
    rip_check(pkgbuild = bz_env_get_path(env, "pacman.pkgbuild", true));
    rip_check(package_file = bz_env_get_path(env, "pacman.package_file", true));
    rip_check(version = bz_env_get_string(env, "pacman.version", true));
    rip_check(pkgrel = bz_env_get_string(env, "pacman.pkgrel", true));
    rip_check(pkgext = bz_env_get_string(env, "pacman.pkgext", true));
    rip_check(architecture = bz_env_get_string(env, "pacman.arch", true));
    rip_check(license = bz_env_get_string(env, "license", true));
    rie_check(verbose = bz_env_get_bool(env, "verbose", true));

    rii_check(bz_file_exists(cork_path_get(staging_dir), &staging_exists));
    if (CORK_UNLIKELY(!staging_exists)) {
        cork_error_set_printf
            (ENOENT, "Staging directory %s does not exist",
             cork_path_get(staging_dir));
        return -1;
    }

    /* NOTE: pacman runs ldconfig automatically, so unlike the other packagers,
     * we do NOT need to add an ldconfig call to the post-install and
     * post-remove scripts. */

    /* Create the temporary directory and the packaging destination */
    rii_check(bz_create_directory(cork_path_get(package_build_dir), 0750));
    rii_check(bz_create_directory(cork_path_get(binary_package_dir), 0750));

    /* Create a PKGBUILD file for this package */
    cork_buffer_append_printf(&buf, "pkgname='%s'\n", package_name);
    cork_buffer_append_printf(&buf, "pkgver='%s'\n", version);
    cork_buffer_append_printf(&buf, "pkgrel='%s'\n", pkgrel);
    cork_buffer_append_printf(&buf, "arch=('%s')\n", architecture);
    cork_buffer_append_printf(&buf, "license=('%s')\n", license);
    rii_check(bz_pacman_fill_deps(env, &buf, "depends", "dependencies"));
    cork_buffer_append_printf(&buf,
        "package () {\n"
        "    rm -rf \"${pkgdir}\"\n"
        "    cp -a '%s' \"${pkgdir}\"\n"
        "}\n",
        cork_path_get(staging_dir)
    );

    /* Add pre- and post-install scripts, if necessary. */
    rii_check(bz_pacman_add_install_scripts(env, &buf));

    ei_check(bz_create_file(cork_path_get(pkgbuild), &buf, 0640));
    cork_buffer_done(&buf);

    exec_env = cork_env_clone_current();
    cork_env_add(exec_env, "PKGDEST", cork_path_get(binary_package_dir));
    cork_env_add(exec_env, "PKGEXT", pkgext);
    exec = cork_exec_new_with_params("makepkg", "-sf", NULL);
    cork_exec_set_cwd(exec, cork_path_get(package_build_dir));
    cork_exec_set_env(exec, exec_env);
    clog_info("(%s) Create %s using pacman",
              package_name, cork_path_get(package_file));
    return bz_subprocess_run_exec(verbose, NULL, exec);

error:
    cork_buffer_done(&buf);
    return -1;
}