summaryrefslogtreecommitdiffstats
path: root/tools/gen_northbound_callbacks.c
diff options
context:
space:
mode:
authorRafael Zalamena <rzalamena@opensourcerouting.org>2019-07-29 23:59:20 +0200
committerRafael Zalamena <rzalamena@opensourcerouting.org>2019-07-29 23:59:20 +0200
commit88292d69599db37fe42e72d677c38370befbe471 (patch)
tree9b10b57d7d0eef4b6b23a141bb6fc544af5c7d88 /tools/gen_northbound_callbacks.c
parentMerge pull request #4728 from ton31337/fix/next-hop-self_force_alias_for_ipv6 (diff)
downloadfrr-88292d69599db37fe42e72d677c38370befbe471.tar.xz
frr-88292d69599db37fe42e72d677c38370befbe471.zip
tools: allow YANG model path specification
This allows developer to set a temporary YANG model directory path for generating northbound for models not yet installed. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to 'tools/gen_northbound_callbacks.c')
-rw-r--r--tools/gen_northbound_callbacks.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/tools/gen_northbound_callbacks.c b/tools/gen_northbound_callbacks.c
index f6c757f5d..e9a4e39bb 100644
--- a/tools/gen_northbound_callbacks.c
+++ b/tools/gen_northbound_callbacks.c
@@ -28,7 +28,8 @@
static void __attribute__((noreturn)) usage(int status)
{
- fprintf(stderr, "usage: gen_northbound_callbacks [-h] MODULE\n");
+ extern const char *__progname;
+ fprintf(stderr, "usage: %s [-h] [-p path] MODULE\n", __progname);
exit(status);
}
@@ -254,15 +255,32 @@ static int generate_nb_nodes(const struct lys_node *snode, void *arg)
int main(int argc, char *argv[])
{
+ const char *search_path = NULL;
struct yang_module *module;
char module_name_underscores[64];
+ struct stat st;
int opt;
- while ((opt = getopt(argc, argv, "h")) != -1) {
+ while ((opt = getopt(argc, argv, "hp:")) != -1) {
switch (opt) {
case 'h':
usage(EXIT_SUCCESS);
/* NOTREACHED */
+ case 'p':
+ if (stat(optarg, &st) == -1) {
+ fprintf(stderr,
+ "error: invalid search path '%s': %s\n",
+ optarg, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ if (S_ISDIR(st.st_mode) == 0) {
+ fprintf(stderr,
+ "error: search path is not directory");
+ exit(EXIT_FAILURE);
+ }
+
+ search_path = optarg;
+ break;
default:
usage(EXIT_FAILURE);
/* NOTREACHED */
@@ -275,6 +293,9 @@ int main(int argc, char *argv[])
yang_init();
+ if (search_path)
+ ly_ctx_set_searchdir(ly_native_ctx, search_path);
+
/* Load all FRR native models to ensure all augmentations are loaded. */
yang_module_load_all();
module = yang_module_find(argv[0]);