forked from cory/tildefriends
core: As an experiment, handle running from a subdirectory (generally out/debug or out/release, since people tend to do that). Remove unused File.stat().
This commit is contained in:
65
src/main.c
65
src/main.c
@ -1256,6 +1256,47 @@ static int _tf_run_task(const tf_run_args_t* args, int index)
|
||||
snprintf(db_path_buffer, sizeof(db_path_buffer), "%s.%d", args->db_path, index);
|
||||
db_path = db_path_buffer;
|
||||
}
|
||||
|
||||
char* cwd = NULL;
|
||||
if (!args->zip)
|
||||
{
|
||||
size_t cwd_size = 1;
|
||||
uv_cwd((char[1]) { 0 }, &cwd_size);
|
||||
cwd = alloca(cwd_size);
|
||||
if (uv_cwd(cwd, &cwd_size) == 0)
|
||||
{
|
||||
size_t test_path_size = cwd_size + strlen("/core/core.js");
|
||||
char* test_path = alloca(test_path_size);
|
||||
|
||||
uv_loop_t* loop = tf_task_get_loop(task);
|
||||
uv_fs_t req = { 0 };
|
||||
while (true)
|
||||
{
|
||||
snprintf(test_path, test_path_size, "%s/core/core.js", cwd);
|
||||
int r = uv_fs_access(loop, &req, test_path, 0000, NULL);
|
||||
uv_fs_req_cleanup(&req);
|
||||
if (r != UV_ENOENT)
|
||||
{
|
||||
break;
|
||||
}
|
||||
char* slash = strrchr(cwd, '/');
|
||||
if (slash)
|
||||
{
|
||||
*slash = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
tf_printf("Using %s as the working directory.\n", cwd);
|
||||
}
|
||||
if (!*cwd)
|
||||
{
|
||||
cwd = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
tf_task_set_db_path(task, db_path);
|
||||
tf_task_activate(task);
|
||||
tf_ssb_set_verbose(tf_task_get_ssb(task), args->verbose);
|
||||
@ -1266,13 +1307,33 @@ static int _tf_run_task(const tf_run_args_t* args, int index)
|
||||
{
|
||||
tf_ssb_import_from_zip(tf_task_get_ssb(task), args->zip, "core", "apps");
|
||||
}
|
||||
else if (cwd)
|
||||
{
|
||||
size_t apps_path_size = strlen(cwd) + strlen("/apps") + 1;
|
||||
char* apps_path = alloca(apps_path_size);
|
||||
snprintf(apps_path, apps_path_size, "%s/apps", cwd);
|
||||
tf_ssb_import(tf_task_get_ssb(task), "core", apps_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
tf_ssb_import(tf_task_get_ssb(task), "core", "apps");
|
||||
}
|
||||
}
|
||||
tf_ssb_set_main_thread(tf_task_get_ssb(task), true);
|
||||
if (tf_task_execute(task, args->script))
|
||||
const char* script = args->script;
|
||||
if (!script && cwd)
|
||||
{
|
||||
size_t script_size = strlen(cwd) + strlen("/core/core.js") + 1;
|
||||
char* script_buffer = alloca(script_size);
|
||||
snprintf(script_buffer, script_size, "%s/core/core.js", cwd);
|
||||
script = script_buffer;
|
||||
}
|
||||
else if (!script)
|
||||
{
|
||||
script = "core/core.js";
|
||||
}
|
||||
tf_task_set_root_path(task, cwd);
|
||||
if (tf_task_execute(task, script))
|
||||
{
|
||||
tf_task_run(task);
|
||||
result = 0;
|
||||
@ -1356,7 +1417,6 @@ static int _tf_command_run(const char* file, int argc, char* argv[])
|
||||
const char* default_db_path = _get_db_path();
|
||||
tf_run_args_t args = {
|
||||
.count = 1,
|
||||
.script = "core/core.js",
|
||||
.http_port = 12345,
|
||||
.https_port = 12346,
|
||||
.ssb_port = 8008,
|
||||
@ -1787,7 +1847,6 @@ void tf_run_thread_start(const char* zip_path)
|
||||
tf_run_thread_data_t* data = tf_malloc(sizeof(tf_run_thread_data_t));
|
||||
tf_run_args_t args = {
|
||||
.count = 1,
|
||||
.script = "core/core.js",
|
||||
.http_port = 12345,
|
||||
.https_port = 12346,
|
||||
.ssb_port = 8008,
|
||||
|
Reference in New Issue
Block a user