diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/compile/headers.c | 2 | ||||
| -rw-r--r-- | src/compile/statements.c | 2 | ||||
| -rw-r--r-- | src/modules.c | 26 | ||||
| -rw-r--r-- | src/modules.h | 4 | ||||
| -rw-r--r-- | src/tomo.c | 43 | ||||
| -rw-r--r-- | src/typecheck.c | 12 |
6 files changed, 47 insertions, 42 deletions
diff --git a/src/compile/headers.c b/src/compile/headers.c index 6dc69f03..33a979cf 100644 --- a/src/compile/headers.c +++ b/src/compile/headers.c @@ -171,7 +171,7 @@ Text_t compile_statement_type_header(env_t *env, Path_t header_path, ast_t *ast) Path_t build_dir = Path$resolved(Path$parent(header_path), Path$current_dir()); switch (use->what) { case USE_MODULE: { - module_info_t mod = get_module_info(ast); + module_info_t mod = get_used_module_info(ast); glob_t tm_files; const char *folder = mod.version ? String(mod.name, "_", mod.version) : mod.name; if (glob(String(TOMO_PATH, "/lib/tomo_" TOMO_VERSION "/", folder, "/[!._0-9]*.tm"), GLOB_TILDE, NULL, diff --git a/src/compile/statements.c b/src/compile/statements.c index bde9ae36..3fc44ac4 100644 --- a/src/compile/statements.c +++ b/src/compile/statements.c @@ -188,7 +188,7 @@ static Text_t _compile_statement(env_t *env, ast_t *ast) { Text_t suffix = get_id_suffix(Path$as_c_string(path)); return with_source_info(env, ast, Texts("$initialize", suffix, "();\n")); } else if (use->what == USE_MODULE) { - module_info_t mod = get_module_info(ast); + module_info_t mod = get_used_module_info(ast); glob_t tm_files; const char *folder = mod.version ? String(mod.name, "_", mod.version) : mod.name; if (glob(String(TOMO_PATH, "/lib/tomo_" TOMO_VERSION "/", folder, "/[!._0-9]*.tm"), GLOB_TILDE, NULL, diff --git a/src/modules.c b/src/modules.c index fafbbf86..9c562387 100644 --- a/src/modules.c +++ b/src/modules.c @@ -24,6 +24,28 @@ errx(1, "Failed to run command: %s", String(__VA_ARGS__)); \ }) +const char *get_library_version(Path_t lib_dir) { + Path_t changes_file = Path$child(lib_dir, Text("CHANGES.md")); + OptionalText_t changes = Path$read(changes_file); + if (changes.length <= 0) { + return "v0.0"; + } + const char *changes_str = Text$as_c_string(Texts(Text("\n"), changes)); + const char *version_line = strstr(changes_str, "\n## "); + if (version_line == NULL) + print_err("CHANGES.md in ", lib_dir, " does not have any valid versions starting with '## '"); + return String(string_slice(version_line + 4, strcspn(version_line + 4, "\r\n"))); +} + +Text_t get_library_name(Path_t lib_dir) { + Text_t name = Path$base_name(lib_dir); + name = Text$without_prefix(name, Text("tomo-")); + name = Text$without_suffix(name, Text("-tomo")); + Text_t suffix = Texts(Text("_"), Text$from_str(get_library_version(lib_dir))); + if (!Text$ends_with(name, suffix, NULL)) name = Texts(name, suffix); + return name; +} + bool install_from_modules_ini(Path_t ini_file, bool ask_confirmation) { OptionalClosure_t by_line = Path$by_line(ini_file); if (by_line.fn == NULL) return false; @@ -72,7 +94,7 @@ find_section:; } } -module_info_t get_module_info(ast_t *use) { +module_info_t get_used_module_info(ast_t *use) { static Table_t cache = {}; TypeInfo_t *cache_type = Table$info(Pointer$info("@", &Memory$info), Pointer$info("@", &Memory$info)); module_info_t **cached = Table$get(cache, &use, cache_type); @@ -90,6 +112,8 @@ bool try_install_module(module_info_t mod, bool ask_confirmation) { "_", Text$from_str(mod.version))); if (Path$exists(dest)) return true; + print("No such path: ", dest); + if (mod.git) { if (ask_confirmation) { OptionalText_t answer = diff --git a/src/modules.h b/src/modules.h index c36d96dd..98911ec9 100644 --- a/src/modules.h +++ b/src/modules.h @@ -10,6 +10,8 @@ typedef struct { const char *name, *version, *url, *git, *revision, *path; } module_info_t; -module_info_t get_module_info(ast_t *use); +Text_t get_library_name(Path_t lib_dir); +const char *get_library_version(Path_t lib_dir); +module_info_t get_used_module_info(ast_t *use); bool install_from_modules_ini(Path_t ini_file, bool ask_confirmation); bool try_install_module(module_info_t mod, bool ask_confirmation); @@ -411,26 +411,6 @@ Path_t build_file(Path_t path, const char *extension) { return Path$child(build_dir, Texts(Path$base_name(path), Text$from_str(extension))); } -static const char *get_version(Path_t lib_dir) { - Path_t changes_file = Path$child(lib_dir, Text("CHANGES.md")); - OptionalText_t changes = Path$read(changes_file); - if (changes.length <= 0) { - return "v0.0"; - } - const char *changes_str = Text$as_c_string(Texts(Text("\n"), changes)); - const char *version_line = strstr(changes_str, "\n## "); - if (version_line == NULL) - print_err("CHANGES.md in ", lib_dir, " does not have any valid versions starting with '## '"); - return String(string_slice(version_line + 4, strcspn(version_line + 4, "\r\n"))); -} - -static Path_t with_version_suffix(Path_t lib_dir) { - Text_t suffix = Texts(Text("_"), Text$from_str(get_version(lib_dir))); - return Text$ends_with(Path$base_name(lib_dir), suffix, NULL) - ? lib_dir - : Path$sibling(lib_dir, Texts(Path$base_name(lib_dir), suffix)); -} - void build_library(Path_t lib_dir) { lib_dir = Path$resolved(lib_dir, Path$current_dir()); if (!Path$is_directory(lib_dir, true)) print_err("Not a valid directory: ", lib_dir); @@ -441,8 +421,8 @@ void build_library(Path_t lib_dir) { compile_files(env, tm_files, &object_files, &extra_ldlibs); - Text_t versioned_dir = Path$base_name(with_version_suffix(lib_dir)); - Path_t shared_lib = Path$child(lib_dir, Texts(Text("lib"), versioned_dir, Text(SHARED_SUFFIX))); + Text_t lib_name = get_library_name(lib_dir); + Path_t shared_lib = Path$child(lib_dir, Texts(Text("lib"), lib_name, Text(SHARED_SUFFIX))); if (!is_stale_for_any(shared_lib, object_files, false)) { if (verbose) whisper("Unchanged: ", shared_lib); return; @@ -453,7 +433,7 @@ void build_library(Path_t lib_dir) { " -Wl,-install_name,@rpath/'lib", Path$base_name(lib_dir), version_suffix, SHARED_SUFFIX, "'" #else - " -Wl,-soname,'lib", versioned_dir, SHARED_SUFFIX, + " -Wl,-soname,'lib", lib_name, SHARED_SUFFIX, "'" #endif " -shared ", @@ -467,12 +447,11 @@ 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 versioned_dir = Path$base_name(with_version_suffix(lib_dir)); - Path_t dest = Path$child(Path$from_str(String(TOMO_PATH, "/lib/tomo_" TOMO_VERSION)), versioned_dir); + Text_t lib_name = get_library_name(lib_dir); + Path_t dest = Path$child(Path$from_str(String(TOMO_PATH, "/lib/tomo_" TOMO_VERSION)), lib_name); print("Installing ", lib_dir, " into ", dest); if (!Path$equal_values(lib_dir, dest)) { - if (verbose) whisper("Clearing out any pre-existing version of ", lib_dir_name); + if (verbose) whisper("Clearing out any pre-existing version of ", lib_name); xsystem(as_owner, "rm -rf '", dest, "'"); if (verbose) whisper("Moving files to ", dest); xsystem(as_owner, "mkdir -p '", dest, "'"); @@ -481,15 +460,15 @@ void install_library(Path_t lib_dir) { } // If we have `debugedit` on this system, use it to remap the debugging source information // to point to the installed version of the source file. Otherwise, fail silently. - if (verbose) whisper("Updating debug symbols for ", dest, "/lib", lib_dir_name, SHARED_SUFFIX); + if (verbose) whisper("Updating debug symbols for ", dest, "/lib", lib_name, SHARED_SUFFIX); int result = system(String(as_owner, "debugedit -b ", lib_dir, " -d '", dest, "'" " '", - dest, "/lib", versioned_dir, SHARED_SUFFIX, + dest, "/lib", lib_name, SHARED_SUFFIX, "' " ">/dev/null 2>/dev/null")); (void)result; - print("Installed \033[1m", lib_dir_name, "\033[m to ", TOMO_PATH, "/lib/tomo_" TOMO_VERSION "/", versioned_dir); + print("Installed \033[1m", lib_dir, "\033[m to ", TOMO_PATH, "/lib/tomo_" TOMO_VERSION "/", lib_name); } void compile_files(env_t *env, List_t to_compile, List_t *object_files, List_t *extra_ldlibs) { @@ -647,7 +626,7 @@ void build_file_dependency_graph(Path_t path, Table_t *to_compile, Table_t *to_l break; } case USE_MODULE: { - module_info_t mod = get_module_info(stmt_ast); + module_info_t mod = get_used_module_info(stmt_ast); const char *full_name = mod.version ? String(mod.name, "_", mod.version) : mod.name; Text_t lib = Texts("-Wl,-rpath,'", TOMO_PATH, "/lib/tomo_" TOMO_VERSION "/", Text$from_str(full_name), "' '", TOMO_PATH, "/lib/tomo_" TOMO_VERSION "/", Text$from_str(full_name), "/lib", @@ -802,7 +781,7 @@ void transpile_code(env_t *base_env, Path_t path) { Text$print(c_file, c_code); - const char *version = get_version(Path$parent(path)); + const char *version = get_library_version(Path$parent(path)); binding_t *main_binding = get_binding(module_env, "main"); if (main_binding && main_binding->type->tag == FunctionType) { type_t *ret = Match(main_binding->type, FunctionType)->ret; diff --git a/src/typecheck.c b/src/typecheck.c index 07f8aac4..89a21fc3 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -165,15 +165,15 @@ PUREFUNC type_t *get_math_type(env_t *env, ast_t *ast, type_t *lhs_t, type_t *rh return NULL; } -static env_t *load_module(env_t *env, ast_t *module_ast) { - DeclareMatch(use, module_ast, Use); +static env_t *load_module(env_t *env, ast_t *use_ast) { + DeclareMatch(use, use_ast, Use); switch (use->what) { case USE_LOCAL: { - Path_t source_path = Path$from_str(module_ast->file->filename); + Path_t source_path = Path$from_str(use_ast->file->filename); Path_t source_dir = Path$parent(source_path); Path_t used_path = Path$resolved(Path$from_str(use->path), source_dir); - if (!Path$exists(used_path)) code_err(module_ast, "No such file exists: ", quoted(use->path)); + if (!Path$exists(used_path)) code_err(use_ast, "No such file exists: ", quoted(use->path)); env_t *module_env = Table$str_get(*env->imports, String(used_path)); if (module_env) return module_env; @@ -183,12 +183,12 @@ static env_t *load_module(env_t *env, ast_t *module_ast) { return load_module_env(env, ast); } case USE_MODULE: { - module_info_t mod = get_module_info(module_ast); + module_info_t mod = get_used_module_info(use_ast); glob_t tm_files; const char *folder = mod.version ? String(mod.name, "_", mod.version) : mod.name; if (glob(String(TOMO_PATH, "/lib/tomo_" TOMO_VERSION "/", folder, "/[!._0-9]*.tm"), GLOB_TILDE, NULL, &tm_files) != 0) { - if (!try_install_module(mod, true)) code_err(module_ast, "Couldn't find or install library: ", folder); + if (!try_install_module(mod, true)) code_err(use_ast, "Couldn't find or install library: ", folder); } env_t *module_env = fresh_scope(env); |
