Skip to content

Commit

Permalink
Add UT_LOCATE_REPO_ID for obtaining project repository identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Apr 30, 2019
1 parent 54bc343 commit a0a2e94
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 43 deletions.
9 changes: 3 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -987,13 +987,10 @@ int bake_run_template(
goto error;
}

/* Check temporary path, remove if already exists */
char *tmp_path = ut_envparse("$BAKE_HOME/temp/%s", path);
char ch, *ptr = tmp_path;
for (ptr = tmp_path; (ch = *ptr); ptr ++) {
if (ch == '.') *ptr = '-';
}
const char *repo_id = ut_locate(path, NULL, UT_LOCATE_REPO_ID);

/* Check temporary path, remove if already exists */
char *tmp_path = ut_envparse("$BAKE_HOME/temp/%s", repo_id);
if (ut_file_test(tmp_path) == 1) {
ut_rm(tmp_path);
}
Expand Down
3 changes: 2 additions & 1 deletion util/include/load.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ typedef enum ut_locate_kind {
UT_LOCATE_PROJECT, /* full path to project directory */
UT_LOCATE_SOURCE, /* full path to project source */
UT_LOCATE_DEVSRC, /* full path to project development source */
UT_LOCATE_TEMPLATE /* full path to templates directory */
UT_LOCATE_TEMPLATE,/* full path to templates directory */
UT_LOCATE_REPO_ID /* project repository identifier ('-' instead of '.') */
} ut_locate_kind;

/** Find project locations in the package hierarchy.
Expand Down
72 changes: 36 additions & 36 deletions util/src/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,54 +462,51 @@ const char* ut_locate(
}

if (loaded && loaded->tried_locating) {
/* Templates don't occupy the same namespace as ordinary projects */
if (!loaded->repo) {
ut_debug("locating project '%s' failed before", id);
goto error;
}
}

/* Test whether project or template project exists */
if (kind != UT_LOCATE_REPO_ID) {
if (kind != UT_LOCATE_TEMPLATE) {
if (!loaded->meta) {
ut_debug("locating project '%s' failed before", id);
goto error;
char *meta_path = ut_asprintf("%s"UT_OS_PS"%s", UT_META_PATH, id);
if (ut_file_test(meta_path) == 1) {
loaded->meta = meta_path;
} else {
ut_trace("project path '%s' not found", meta_path);
free(meta_path);
goto error;
}
}
} else {
if (!loaded->template) {
ut_debug("locating template '%s' failed before", id);
goto error;
char *tmpl_path = ut_asprintf("%s"UT_OS_PS"%s", UT_TEMPLATE_PATH, id);
if (ut_file_test(tmpl_path) == 1) {
loaded->template = tmpl_path;
} else {
ut_trace("template path '%s' not found", tmpl_path);
free(tmpl_path);
goto error;
}
}
}
}

/* Test whether project or template project exists */
if (kind == UT_LOCATE_TEMPLATE) {
if (!loaded->template) {
char *tmpl_path = ut_asprintf("%s"UT_OS_PS"%s", UT_TEMPLATE_PATH, id);
if (ut_file_test(tmpl_path) == 1) {
loaded->template = tmpl_path;
} else {
ut_trace("template path '%s' not found", tmpl_path);
free(tmpl_path);
goto error;
}
}
} else {
if (!loaded->meta) {
char *meta_path = ut_asprintf("%s"UT_OS_PS"%s", UT_META_PATH, id);
if (ut_file_test(meta_path) == 1) {
loaded->meta = meta_path;

/* Prepare repository identifier (replaces . with -) */
loaded->repo = ut_strdup(id);
char *ptr, ch;
for (ptr = loaded->repo; (ch = *ptr); ptr ++) {
if (ch == '.') {
*ptr = '-';
}
}
} else {
ut_trace("template path '%s' not found", meta_path);
free(meta_path);
goto error;

if (!loaded->repo) {
/* Prepare repository identifier (replaces . with -) */
loaded->repo = ut_strdup(id);
char *ptr, ch;
for (ptr = loaded->repo; (ch = *ptr); ptr ++) {
if (ch == '.') {
*ptr = '-';
}
}
}

/* Only try to locate packages once (until reset is called) */
loaded->tried_locating = true;

Expand Down Expand Up @@ -547,6 +544,9 @@ const char* ut_locate(
}
result = loaded->dev;
break;
case UT_LOCATE_REPO_ID:
result = loaded->repo;
break;
case UT_LOCATE_LIB:
case UT_LOCATE_STATIC:
case UT_LOCATE_APP:
Expand Down

0 comments on commit a0a2e94

Please sign in to comment.