Skip to content

Commit

Permalink
If jq filter wasn't an actual file, use $PWD as package root search path
Browse files Browse the repository at this point in the history
  • Loading branch information
joelpurra committed May 22, 2015
1 parent 89fd175 commit 41138d4
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion linker.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ static int load_library(jq_state *jq, jv lib_path, int is_data, int raw,
const char *as, block *out_block,
struct lib_loading_state *lib_state);

static jv get_package_root_search_start(jq_state *jq, jv lib_origin) {
// PROGRAM_ORIGIN is $PWD if PROGRAM_ORIGIN_FILE is not a PROGRAM_FROM_ACTUAL_FILE.
// Use PROGRAM_ORIGIN when getting the package root for PROGRAM_ORIGIN_FILE instead
// of lib_origin, but only in that specific case.
// file (more specifically a file in the same directory as the PROGRAM_ORIGIN file).
// TODO: pass the full file path, not just the directory path "lib_origin" to this
// function, then use PROGRAM_ORIGIN_FILE for comparison.
jv package_root_search_from;
if (jv_get_kind(jq_get_attr(jq, jv_string("PROGRAM_FROM_ACTUAL_FILE"))) == JV_KIND_FALSE
&& strcmp(jv_string_value(jq_get_attr(jq, jv_string("PROGRAM_ORIGIN"))),jv_string_value(lib_origin)) == 0) {
// It's a (named/anonymous) FIFO pipe; use PROGRAM_ORIGIN (which is $PWD) instead.
package_root_search_from = jv_copy(jq_get_prog_origin(jq));
} else {
package_root_search_from = jv_copy(lib_origin);
}
return package_root_search_from;
}


// Given a lib_path to search first, creates a chain of search paths
// in the following order:
Expand All @@ -48,14 +66,17 @@ static jv build_lib_search_chain(jq_state *jq, jv search_path, jv jq_origin, jv
jv_string_value(path) + sizeof ("$ORIGIN/") - 1);
} else if (jv_get_kind(lib_origin) == JV_KIND_STRING &&
strncmp("$PACKAGEROOT/",jv_string_value(path),sizeof("$PACKAGEROOT/")-1) == 0) {
jv package_root_search_from = get_package_root_search_start(jq, lib_origin);
jv package_root = jq_find_package_root(package_root_search_from);

// Could also use non-string package_root values as error message output.
jv package_root = jq_find_package_root(lib_origin);
if (jv_get_kind(package_root) == JV_KIND_STRING) {
expanded_elt = jv_string_fmt("%s/%s",
jv_string_value(package_root),
jv_string_value(path) + sizeof ("$PACKAGEROOT/") - 1);
}
jv_free(package_root);
jv_free(package_root_search_from);
} else {
expanded_elt = expand_path(path);
if (!jv_is_valid(expanded_elt)) {
Expand Down

0 comments on commit 41138d4

Please sign in to comment.