From 456bafa82fd4a4154b2697fb36e9b3cdb76e0f92 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Sat, 30 Aug 2014 00:58:24 -0500 Subject: [PATCH] Drop the jq version directory from search path --- execute.c | 6 --- jq.h | 1 - linker.c | 68 ++++++++++----------------- tests/modules/{1.4-master => }/a.jq | 0 tests/modules/{1.4-master => }/b/b.jq | 0 5 files changed, 25 insertions(+), 50 deletions(-) rename tests/modules/{1.4-master => }/a.jq (100%) rename tests/modules/{1.4-master => }/b/b.jq (100%) diff --git a/execute.c b/execute.c index 97b33d3..acb42c5 100644 --- a/execute.c +++ b/execute.c @@ -992,12 +992,6 @@ jv jq_get_lib_dirs(jq_state *jq) { return jq_get_attr(jq, jv_string("LIB_DIRS")); } -jv jq_get_version_dir(jq_state *jq) { - jv d = jq_get_attr(jq, jv_string("VERSION_DIR")); - assert(jv_is_valid(d)); - return d; -} - void jq_set_attrs(jq_state *jq, jv attrs) { assert(jv_get_kind(attrs) == JV_KIND_OBJECT); jv_free(jq->attrs); diff --git a/jq.h b/jq.h index b517c52..3c9c7e3 100644 --- a/jq.h +++ b/jq.h @@ -26,7 +26,6 @@ void jq_set_attrs(jq_state *, jv); jv jq_get_attrs(jq_state *); jv jq_get_lib_origin(jq_state *); jv jq_get_lib_dirs(jq_state *); -jv jq_get_version_dir(jq_state *); void jq_set_attr(jq_state *, jv, jv); jv jq_get_attr(jq_state *, jv); #endif /* !_JQ_H_ */ diff --git a/linker.c b/linker.c index 1b152e6..bea1c30 100644 --- a/linker.c +++ b/linker.c @@ -76,7 +76,7 @@ static jv name2relpath(jv name) { return rp; } -static jv find_lib(jq_state *jq, jv lib_name, jv lib_search_path, int use_vers_dir) { +static jv find_lib(jq_state *jq, jv lib_name, jv lib_search_path) { assert(jv_get_kind(lib_search_path) == JV_KIND_STRING); assert(jv_get_kind(lib_name) == JV_KIND_STRING); @@ -86,54 +86,35 @@ static jv find_lib(jq_state *jq, jv lib_name, jv lib_search_path, int use_vers_d return rel_path; } - jv version_dirs; - if (use_vers_dir) { - jv vdir = jq_get_version_dir(jq); - assert(strchr(jv_string_value(vdir), '.') != NULL); - version_dirs = JV_ARRAY(jv_string(""), jv_string_concat(vdir, jv_string("/"))); - } else { - version_dirs = JV_ARRAY(jv_string("")); - } - struct stat st; int ret; jv lib_search_paths = build_lib_search_chain(jq, expand_path(lib_search_path)); jv_array_foreach(lib_search_paths, i, spath) { - jv vds = jv_copy(version_dirs); - jv_array_foreach(vds, k, vd) { - jv testpath = jq_realpath(jv_string_fmt("%s/%s%s.jq", - jv_string_value(spath), - jv_string_value(vd), - jv_string_value(rel_path))); - ret = stat(jv_string_value(testpath),&st); - if (ret == -1 && errno == ENOENT) { - jv_free(testpath); - testpath = jq_realpath(jv_string_fmt("%s/%s%s/%s.jq", - jv_string_value(spath), - jv_string_value(vd), - jv_string_value(rel_path), - jv_string_value(lib_name))); - ret = stat(jv_string_value(testpath),&st); - } - jv_free(vd); - if (ret == 0) { - jv_free(spath); - jv_free(vds); - jv_free(version_dirs); - jv_free(rel_path); - jv_free(lib_name); - jv_free(lib_search_paths); - return testpath; - } + jv testpath = jq_realpath(jv_string_fmt("%s/%s.jq", + jv_string_value(spath), + jv_string_value(rel_path))); + ret = stat(jv_string_value(testpath),&st); + if (ret == -1 && errno == ENOENT) { jv_free(testpath); + testpath = jq_realpath(jv_string_fmt("%s/%s/%s.jq", + jv_string_value(spath), + jv_string_value(rel_path), + jv_string_value(lib_name))); + ret = stat(jv_string_value(testpath),&st); + } + if (ret == 0) { + jv_free(spath); + jv_free(rel_path); + jv_free(lib_name); + jv_free(lib_search_paths); + return testpath; } - jv_free(vds); + jv_free(testpath); jv_free(spath); } jv output = jv_invalid_with_msg(jv_string_fmt("module not found: %s", jv_string_value(lib_name))); - jv_free(version_dirs); jv_free(rel_path); jv_free(lib_name); jv_free(lib_search_paths); @@ -161,13 +142,14 @@ static int process_dependencies(jq_state *jq, jv lib_origin, block *src_block, s jv_free(search); search = jv_string(""); } - int has_origin = (strncmp("$ORIGIN/",jv_string_value(search),8) == 0); - if (has_origin) { - jv tsearch = jv_string_fmt("%s/%s",jv_string_value(lib_origin),jv_string_value(search)+8); + if (strncmp("$ORIGIN/",jv_string_value(search),8) == 0) { + jv tsearch = jv_string_fmt("%s/%s", + jv_string_value(lib_origin), + jv_string_value(search) + sizeof ("$ORIGIN/") - 1); jv_free(search); search = tsearch; } - jv lib_path = find_lib(jq, name, search, !has_origin); + jv lib_path = find_lib(jq, name, search); if (!jv_is_valid(lib_path)) { jv emsg = jv_invalid_get_msg(lib_path); jq_report_error(jq, jv_string_fmt("jq: error: %s\n",jv_string_value(emsg))); @@ -238,7 +220,7 @@ static int load_library(jq_state *jq, jv lib_path, block *out_block, struct lib_ } jv load_module_meta(jq_state *jq, jv modname) { - jv lib_path = find_lib(jq, modname, jv_string(""), 1); + jv lib_path = find_lib(jq, modname, jv_string("")); jv meta = jv_null(); jv data = jv_load_file(jv_string_value(lib_path), 1); if (jv_is_valid(data)) { diff --git a/tests/modules/1.4-master/a.jq b/tests/modules/a.jq similarity index 100% rename from tests/modules/1.4-master/a.jq rename to tests/modules/a.jq diff --git a/tests/modules/1.4-master/b/b.jq b/tests/modules/b/b.jq similarity index 100% rename from tests/modules/1.4-master/b/b.jq rename to tests/modules/b/b.jq -- 2.40.0