aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-09-01 15:11:52 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-09-01 15:11:52 -0400
commite01383da05d5cf03d080854ac048df37df4d1b9a (patch)
treebcbcde2dca685a6de30c0b05ef1ab9ffeadfaed5
parentee020c72d92c3807fa4afcd1e170d3df81688b97 (diff)
Change module install directory to PREFIX/lib/tomo_vX.Y/*
-rw-r--r--CHANGES.md3
-rw-r--r--Makefile2
-rw-r--r--docs/libraries.md4
-rw-r--r--docs/tomo.1.md2
-rw-r--r--docs/versions.md2
-rw-r--r--man/man1/tomo.14
-rw-r--r--src/compile/headers.c4
-rw-r--r--src/compile/statements.c4
-rw-r--r--src/modules.c44
-rw-r--r--src/stdlib/stacktrace.c2
-rw-r--r--src/tomo.c28
-rw-r--r--src/typecheck.c4
12 files changed, 48 insertions, 55 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 965a1aea..97c80bdb 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -3,7 +3,8 @@
## v0.3
- Added a versioning system based on `CHANGES.md` files and `modules.ini`
- configuration for module aliases.
+ configuration for module aliases (now installed to
+ `$TOMO_PREFIX/lib/tomo_vX.Y/module_vZ.W`).
- When attempting to run a program with a module that is not installed, Tomo
can prompt the user to automatically install it.
- Programs can use `--version` as a CLI flag to print a Tomo program's version
diff --git a/Makefile b/Makefile
index 983f41ae..ce05f76a 100644
--- a/Makefile
+++ b/Makefile
@@ -232,7 +232,7 @@ uninstall:
exit 0; \
fi; \
rm -rvf "$(PREFIX)/bin/tomo" "$(PREFIX)/bin/tomo"[0-9]* "$(PREFIX)/bin/tomo_v"* "$(PREFIX)/include/tomo_v"* \
- "$(PREFIX)/lib/libtomo_v*" "$(PREFIX)/share/tomo_$(TOMO_VERSION)"; \
+ "$(PREFIX)/lib/libtomo_v*" "$(PREFIX)/lib/tomo_$(TOMO_VERSION)"; \
sh link_versions.sh
endif
diff --git a/docs/libraries.md b/docs/libraries.md
index 69608ae3..79477070 100644
--- a/docs/libraries.md
+++ b/docs/libraries.md
@@ -151,7 +151,7 @@ that can be used by other Tomo projects. You can build a library by running
If you additionally add the `-I` flag, Tomo will copy the entire directory
(excluding files and directories that begin with `.` such as `.git`) into
-`~/.local/share/tomo_vX.Y/installed/` (where `X` and `Y` are the major/minor
+`~/.local/lib/tomo_vX.Y/` (where `X` and `Y` are the major/minor
version of the compiler).
### Using Shared Libraries
@@ -169,7 +169,7 @@ When you build and install a library, its version is determined from a
[Versions](versions.md)). The library's version number is added to the file
path where the library is installed, so if the library `foo` has version
`v1.2`, then it will be installed to
-`~/.local/share/tomo_vX.Y/installed/foo_v1.2/`. When using a library, you must
+`~/.local/lib/tomo_vX.Y/foo_v1.2/`. When using a library, you must
explicitly supply either the exact version in the `use` statement like this:
`use foo_v1.2`, or provide a `modules.ini` file that lists version information
and other details about modules being used. For each module, you should provide
diff --git a/docs/tomo.1.md b/docs/tomo.1.md
index 3bf5e779..feed98af 100644
--- a/docs/tomo.1.md
+++ b/docs/tomo.1.md
@@ -69,4 +69,4 @@ C code, which is then compiled using a C compiler of your choice.
: Print the Tomo installation prefix and exit.
`-r`, `--run`
-: Run an installed tomo program from `~/.local/share/tomo_vX.Y/installed`.
+: Run an installed tomo program from `~/.local/lib/tomo_vX.Y/`.
diff --git a/docs/versions.md b/docs/versions.md
index c68d1f81..eb617f43 100644
--- a/docs/versions.md
+++ b/docs/versions.md
@@ -49,7 +49,7 @@ The version for the Tomo language itself will come into play in a few ways:
(e.g. `~/.local/lib/libtomo_v1.2.so`) and headers (e.g.
`~/.local/include/tomo_v1.2/tomo.h`).
4. Tomo libraries will be installed to a separate subdirectory for each version
- of the compiler (e.g. `~/.local/share/tomo_v1.2/installed`).
+ of the compiler (e.g. `~/.local/lib/tomo_v1.2/`).
## Tomo Program Versions
diff --git a/man/man1/tomo.1 b/man/man1/tomo.1
index c3330175..ae2b08d2 100644
--- a/man/man1/tomo.1
+++ b/man/man1/tomo.1
@@ -1,4 +1,4 @@
-.\" Automatically generated by Pandoc 3.1.12.1
+.\" Automatically generated by Pandoc 3.1.13
.\"
.TH "TOMO" "1" "June 11, 2024" "" ""
.SH NAME
@@ -68,6 +68,6 @@ Print the Tomo installation prefix and exit.
.TP
\f[B]\-r\f[R], \f[B]\-\-run\f[R]
Run an installed tomo program from
-\f[B]\[ti]/.local/share/tomo_vX.Y/installed\f[R].
+\f[B]\[ti]/.local/lib/tomo_vX.Y/\f[R].
.SH AUTHORS
Bruce Hill (\f[I]bruce\[at]bruce\-hill.com\f[R]).
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]));
diff --git a/src/tomo.c b/src/tomo.c
index da10df87..0e455ec6 100644
--- a/src/tomo.c
+++ b/src/tomo.c
@@ -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);
}