You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.5 KiB

  1. From 90b92d8c73446bb50eee14ca8d88c5224002001a Mon Sep 17 00:00:00 2001
  2. From: Muh Muhten <muh.muhten@gmail.com>
  3. Date: Sun, 15 Oct 2017 01:57:17 -0400
  4. Subject: [PATCH 7/9] Add import metadata key "optional"
  5. A library marked is imported if found, but silently skipped if missing.
  6. This is the desired semantic for the auto-include at ~/.jq
  7. ---
  8. src/linker.c | 9 ++++++++-
  9. 1 file changed, 8 insertions(+), 1 deletion(-)
  10. --- a/src/linker.c
  11. +++ b/src/linker.c
  12. @@ -246,6 +246,9 @@ static int process_dependencies(jq_state
  13. jv v = jv_object_get(jv_copy(dep), jv_string("raw"));
  14. if (jv_get_kind(v) == JV_KIND_TRUE)
  15. raw = 1;
  16. + int optional = 0;
  17. + if (jv_get_kind(jv_object_get(jv_copy(dep), jv_string("optional"))) == JV_KIND_TRUE)
  18. + optional = 1;
  19. jv_free(v);
  20. jv relpath = validate_relpath(jv_object_get(jv_copy(dep), jv_string("relpath")));
  21. jv as = jv_object_get(jv_copy(dep), jv_string("as"));
  22. @@ -259,10 +262,14 @@ static int process_dependencies(jq_state
  23. jv resolved = find_lib(jq, relpath, search, is_data ? ".json" : ".jq", jv_copy(jq_origin), jv_copy(lib_origin));
  24. // XXX ...move the rest of this into a callback.
  25. if (!jv_is_valid(resolved)) {
  26. + jv_free(as);
  27. + if (optional) {
  28. + jv_free(resolved);
  29. + continue;
  30. + }
  31. jv emsg = jv_invalid_get_msg(resolved);
  32. jq_report_error(jq, jv_string_fmt("jq: error: %s\n",jv_string_value(emsg)));
  33. jv_free(emsg);
  34. - jv_free(as);
  35. jv_free(deps);
  36. jv_free(jq_origin);
  37. jv_free(lib_origin);