diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-09-01 15:11:52 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-09-01 15:11:52 -0400 |
| commit | e01383da05d5cf03d080854ac048df37df4d1b9a (patch) | |
| tree | bcbcde2dca685a6de30c0b05ef1ab9ffeadfaed5 /src | |
| parent | ee020c72d92c3807fa4afcd1e170d3df81688b97 (diff) | |
Change module install directory to PREFIX/lib/tomo_vX.Y/*
Diffstat (limited to 'src')
| -rw-r--r-- | src/compile/headers.c | 4 | ||||
| -rw-r--r-- | src/compile/statements.c | 4 | ||||
| -rw-r--r-- | src/modules.c | 44 | ||||
| -rw-r--r-- | src/stdlib/stacktrace.c | 2 | ||||
| -rw-r--r-- | src/tomo.c | 28 | ||||
| -rw-r--r-- | src/typecheck.c | 4 |
6 files changed, 39 insertions, 47 deletions
diff --git a/src/compile/headers.c b/src/compile/headers.c index 8c0863ee..be564144 100644 --- a/src/compile/headers.c +++ b/src/compile/headers.c @@ -174,8 +174,8 @@ Text_t compile_statement_type_header(env_t *env, Path_t header_path, ast_t *ast) module_info_t mod = get_module_info(ast); glob_t tm_files; const char *folder = mod.version ? String(mod.name, "_", mod.version) : mod.name; - if (glob(String(TOMO_PREFIX "/share/tomo_" TOMO_VERSION "/installed/", folder, "/[!._0-9]*.tm"), GLOB_TILDE, - NULL, &tm_files) + if (glob(String(TOMO_PREFIX "/lib/tomo_" TOMO_VERSION "/", folder, "/[!._0-9]*.tm"), GLOB_TILDE, NULL, + &tm_files) != 0) { if (!try_install_module(mod)) code_err(ast, "Could not find library"); } diff --git a/src/compile/statements.c b/src/compile/statements.c index e296795b..82a91a5e 100644 --- a/src/compile/statements.c +++ b/src/compile/statements.c @@ -204,8 +204,8 @@ static Text_t _compile_statement(env_t *env, ast_t *ast) { module_info_t mod = get_module_info(ast); glob_t tm_files; const char *folder = mod.version ? String(mod.name, "_", mod.version) : mod.name; - if (glob(String(TOMO_PREFIX "/share/tomo_" TOMO_VERSION "/installed/", folder, "/[!._0-9]*.tm"), GLOB_TILDE, - NULL, &tm_files) + if (glob(String(TOMO_PREFIX "/lib/tomo_" TOMO_VERSION "/", folder, "/[!._0-9]*.tm"), GLOB_TILDE, NULL, + &tm_files) != 0) { if (!try_install_module(mod)) code_err(ast, "Could not find library"); } diff --git a/src/modules.c b/src/modules.c index 40b3daf3..67b09fdb 100644 --- a/src/modules.c +++ b/src/modules.c @@ -50,34 +50,25 @@ module_info_t get_module_info(ast_t *use) { if (cached) return **cached; const char *name = Match(use, Use)->path; module_info_t *info = new (module_info_t, .name = name); - if (streq(name, "commands")) info->version = "v1.0"; - else if (streq(name, "random")) info->version = "v1.0"; - else if (streq(name, "base64")) info->version = "v1.0"; - else if (streq(name, "core")) info->version = "v1.0"; - else if (streq(name, "patterns")) info->version = "v1.1"; - else if (streq(name, "json")) info->version = "v1.0"; - else if (streq(name, "pthreads")) info->version = "v1.0"; - else if (streq(name, "shell")) info->version = "v1.0"; - else if (streq(name, "time")) info->version = "v1.0"; - else if (streq(name, "uuid")) info->version = "v1.0"; - else { - read_modules_ini(Path$sibling(Path$from_str(use->file->filename), Text("modules.ini")), info); - read_modules_ini(Path$with_extension(Path$from_str(use->file->filename), Text(":modules.ini"), false), info); - } + read_modules_ini(Path$sibling(Path$from_str(use->file->filename), Text("modules.ini")), info); + read_modules_ini(Path$with_extension(Path$from_str(use->file->filename), Text(":modules.ini"), false), info); Table$set(&cache, &use, &info, cache_type); return *info; } bool try_install_module(module_info_t mod) { if (mod.git) { - OptionalText_t answer = ask(Texts(Text("The module \""), Text$from_str(mod.name), - Text("\" is not installed.\nDo you want to install it from git URL "), - Text$from_str(mod.git), Text("? [Y/n] ")), + OptionalText_t answer = ask(Texts("The module \"", Text$from_str(mod.name), "\" ", Text$from_str(mod.version), + " is not installed.\nDo you want to install it from git URL ", + Text$from_str(mod.git), "? [Y/n] "), true, true); if (!(answer.length == 0 || Text$equal_values(answer, Text("Y")) || Text$equal_values(answer, Text("y")))) return false; print("Installing ", mod.name, " from git..."); Path_t tmpdir = Path$unique_directory(Path("/tmp/tomo-module-XXXXXX")); + tmpdir = Path$child(tmpdir, Text$from_str(mod.name)); + Path$create_directory(tmpdir, 0755); + if (mod.revision) xsystem("git clone --depth=1 --revision ", mod.revision, " ", mod.git, " ", tmpdir); else xsystem("git clone --depth=1 ", mod.git, " ", tmpdir); if (mod.path) xsystem("tomo -IL ", tmpdir, "/", mod.path); @@ -85,10 +76,10 @@ bool try_install_module(module_info_t mod) { Path$remove(tmpdir, true); return true; } else if (mod.url) { - OptionalText_t answer = ask(Texts(Text("The module "), Text$from_str(mod.name), - Text(" is not installed.\nDo you want to install it from URL "), - Text$from_str(mod.url), Text("? [Y/n] ")), - true, true); + OptionalText_t answer = + ask(Texts("The module \"", Text$from_str(mod.name), "\" ", Text$from_str(mod.version), + " is not installed.\nDo you want to install it from URL ", Text$from_str(mod.url), "? [Y/n] "), + true, true); if (!(answer.length == 0 || Text$equal_values(answer, Text("Y")) || Text$equal_values(answer, Text("y")))) return false; @@ -101,6 +92,9 @@ bool try_install_module(module_info_t mod) { if (!p) return false; const char *extension = p + 1; Path_t tmpdir = Path$unique_directory(Path("/tmp/tomo-module-XXXXXX")); + tmpdir = Path$child(tmpdir, Text$from_str(mod.name)); + Path$create_directory(tmpdir, 0755); + xsystem("curl ", mod.url, " -o ", tmpdir); if (streq(extension, ".zip")) xsystem("unzip ", tmpdir, "/", filename); else if (streq(extension, ".tar.gz") || streq(extension, ".tar")) xsystem("tar xf ", tmpdir, "/", filename); @@ -111,10 +105,10 @@ bool try_install_module(module_info_t mod) { Path$remove(tmpdir, true); return true; } else if (mod.path) { - OptionalText_t answer = ask(Texts(Text("The module "), Text$from_str(mod.name), - Text(" is not installed.\nDo you want to install it from path "), - Text$from_str(mod.path), Text("? [Y/n] ")), - true, true); + OptionalText_t answer = + ask(Texts("The module \"", Text$from_str(mod.name), "\" ", Text$from_str(mod.version), + " is not installed.\nDo you want to install it from path ", Text$from_str(mod.path), "? [Y/n] "), + true, true); if (!(answer.length == 0 || Text$equal_values(answer, Text("Y")) || Text$equal_values(answer, Text("y")))) return false; diff --git a/src/stdlib/stacktrace.c b/src/stdlib/stacktrace.c index 266dc4ef..c7ec54d3 100644 --- a/src/stdlib/stacktrace.c +++ b/src/stdlib/stacktrace.c @@ -98,7 +98,7 @@ void print_stacktrace(FILE *out, int offset) { cwd[cwd_len++] = '/'; cwd[cwd_len] = '\0'; - const char *install_dir = TOMO_PREFIX "/share/tomo_" TOMO_VERSION "/installed/"; + const char *install_dir = TOMO_PREFIX "/lib/tomo_" TOMO_VERSION "/"; static void *stack[1024]; int64_t size = (int64_t)backtrace(stack, sizeof(stack) / sizeof(stack[0])); @@ -87,8 +87,8 @@ static OptionalText_t show_codegen = NONE_TEXT, " -D_BSD_SOURCE" #endif " -DGC_THREADS" - " -I'" TOMO_PREFIX "/include' -I'" TOMO_PREFIX "/share/tomo_" TOMO_VERSION - "/installed' -I/usr/local/include"), + " -I'" TOMO_PREFIX "/include' -I'" TOMO_PREFIX "/lib/tomo_" TOMO_VERSION + "' -I/usr/local/include"), ldlibs = Text("-lgc -lm -lgmp -lunistring -ltomo_" TOMO_VERSION), ldflags = Text("-Wl,-rpath,'" TOMO_PREFIX "/lib',-rpath,/usr/local/lib" " -L/usr/local/lib"), @@ -163,8 +163,7 @@ int main(int argc, char *argv[]) { // Run a tool: if ((streq(argv[1], "-r") || streq(argv[1], "--run")) && argc >= 3) { if (strcspn(argv[2], "/;$") == strlen(argv[2])) { - const char *program = - String("'" TOMO_PREFIX "'/share/tomo_" TOMO_VERSION "/installed/", argv[2], "/", argv[2]); + const char *program = String("'" TOMO_PREFIX "'/lib/tomo_" TOMO_VERSION "/", argv[2], "/", argv[2]); execv(program, &argv[2]); } print_err("This is not an installed tomo program: ", argv[2]); @@ -183,7 +182,7 @@ int main(int argc, char *argv[]) { " --parse|-p: show parse tree\n" " --install|-I: install the executable or library\n" " --optimization|-O <level>: set optimization level\n" - " --run|-r: run a program from " TOMO_PREFIX "/share/tomo_" TOMO_VERSION "/installed\n"); + " --run|-r: run a program from " TOMO_PREFIX "/lib/tomo_" TOMO_VERSION "\n"); Text_t help = Texts(Text("\x1b[1mtomo\x1b[m: a compiler for the Tomo programming language"), Text("\n\n"), usage); tomo_parse_args( argc, argv, usage, help, TOMO_VERSION, {"files", true, List$info(&Path$info), &files}, @@ -248,7 +247,7 @@ int main(int argc, char *argv[]) { for (int64_t i = 0; i < uninstall.length; i++) { Text_t *u = (Text_t *)(uninstall.data + i * uninstall.stride); - xsystem(as_owner, "rm -rvf '" TOMO_PREFIX "'/share/tomo_" TOMO_VERSION "/installed/", *u); + xsystem(as_owner, "rm -rvf '" TOMO_PREFIX "'/lib/tomo_" TOMO_VERSION "/", *u); print("Uninstalled ", *u); } @@ -410,8 +409,7 @@ void build_library(Path_t lib_dir) { void install_library(Path_t lib_dir) { Text_t lib_dir_name = Path$base_name(lib_dir); Text_t version_suffix = get_version_suffix(lib_dir); - Path_t dest = Path$child(Path$from_str(TOMO_PREFIX "/share/tomo_" TOMO_VERSION "/installed"), - Texts(lib_dir_name, version_suffix)); + Path_t dest = Path$child(Path$from_str(TOMO_PREFIX "/lib/tomo_" TOMO_VERSION), Texts(lib_dir_name, version_suffix)); if (!Path$equal_values(lib_dir, dest)) { if (verbose) whisper("Clearing out any pre-existing version of ", lib_dir_name); xsystem(as_owner, "rm -rf '", dest, "'"); @@ -430,8 +428,8 @@ void install_library(Path_t lib_dir) { "' " ">/dev/null 2>/dev/null")); (void)result; - print("Installed \033[1m", lib_dir_name, "\033[m to " TOMO_PREFIX "/share/tomo_" TOMO_VERSION "/installed/", - lib_dir_name, version_suffix); + print("Installed \033[1m", lib_dir_name, "\033[m to " TOMO_PREFIX "/lib/tomo_" TOMO_VERSION "/", lib_dir_name, + version_suffix); } void compile_files(env_t *env, List_t to_compile, List_t *object_files, List_t *extra_ldlibs) { @@ -592,13 +590,13 @@ void build_file_dependency_graph(Path_t path, Table_t *to_compile, Table_t *to_l module_info_t mod = get_module_info(stmt_ast); const char *full_name = mod.version ? String(mod.name, "_", mod.version) : mod.name; Text_t lib = - Texts(Text("-Wl,-rpath,'"), Text(TOMO_PREFIX "/share/tomo_" TOMO_VERSION "/installed/"), - Text$from_str(full_name), Text("' '" TOMO_PREFIX "/share/tomo_" TOMO_VERSION "/installed/"), - Text$from_str(full_name), Text("/lib"), Text$from_str(full_name), Text(SHARED_SUFFIX "'")); + Texts(Text("-Wl,-rpath,'"), Text(TOMO_PREFIX "/lib/tomo_" TOMO_VERSION "/"), Text$from_str(full_name), + Text("' '" TOMO_PREFIX "/lib/tomo_" TOMO_VERSION "/"), Text$from_str(full_name), Text("/lib"), + Text$from_str(full_name), Text(SHARED_SUFFIX "'")); Table$set(to_link, &lib, NULL, Table$info(&Text$info, &Void$info)); - List_t children = Path$glob(Path$from_str( - String(TOMO_PREFIX "/share/tomo_" TOMO_VERSION "/installed/", full_name, "/[!._0-9]*.tm"))); + List_t children = + Path$glob(Path$from_str(String(TOMO_PREFIX "/lib/tomo_" TOMO_VERSION "/", full_name, "/[!._0-9]*.tm"))); for (int64_t i = 0; i < children.length; i++) { Path_t *child = (Path_t *)(children.data + i * children.stride); Table_t discarded = {.fallback = to_compile}; diff --git a/src/typecheck.c b/src/typecheck.c index 07970bd9..adb267df 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -186,8 +186,8 @@ static env_t *load_module(env_t *env, ast_t *module_ast) { module_info_t mod = get_module_info(module_ast); glob_t tm_files; const char *folder = mod.version ? String(mod.name, "_", mod.version) : mod.name; - if (glob(String(TOMO_PREFIX "/share/tomo_" TOMO_VERSION "/installed/", folder, "/[!._0-9]*.tm"), GLOB_TILDE, - NULL, &tm_files) + if (glob(String(TOMO_PREFIX "/lib/tomo_" TOMO_VERSION "/", folder, "/[!._0-9]*.tm"), GLOB_TILDE, NULL, + &tm_files) != 0) { if (!try_install_module(mod)) code_err(module_ast, "Couldn't find or install library: ", folder); } |
