Use original folder names more
This commit is contained in:
parent
6caf6f9131
commit
62745cda95
13
compile.c
13
compile.c
@ -1374,17 +1374,16 @@ CORD compile_statement(env_t *env, ast_t *ast)
|
||||
} else if (use->what == USE_C_CODE) {
|
||||
return CORD_all("#include \"", use->path, "\"\n");
|
||||
} else if (use->what == USE_MODULE) {
|
||||
const char *libname = Text$as_c_string(
|
||||
Text$replace(Text$from_str(use->path), Pattern("{1+ !alphanumeric}"), Text("_"), Pattern(""), false));
|
||||
|
||||
glob_t tm_files;
|
||||
if (glob(heap_strf("~/.local/share/tomo/installed/%s/[!._0-9]*.tm", libname), GLOB_TILDE, NULL, &tm_files) != 0)
|
||||
if (glob(heap_strf("~/.local/share/tomo/installed/%s/[!._0-9]*.tm", use->path), GLOB_TILDE, NULL, &tm_files) != 0)
|
||||
code_err(ast, "Could not find library");
|
||||
|
||||
const char *lib_id = Text$as_c_string(
|
||||
Text$replace(Text$from_str(use->path), Pattern("{1+ !alphanumeric}"), Text("_"), Pattern(""), false));
|
||||
for (size_t i = 0; i < tm_files.gl_pathc; i++) {
|
||||
const char *filename = tm_files.gl_pathv[i];
|
||||
env->code->variable_initializers = CORD_all(
|
||||
env->code->variable_initializers, use->path, "$", file_base_name(filename), "$$initialize();\n");
|
||||
env->code->variable_initializers, lib_id, "$", file_base_name(filename), "$$initialize();\n");
|
||||
}
|
||||
globfree(&tm_files);
|
||||
}
|
||||
@ -3794,9 +3793,7 @@ CORD compile_statement_header(env_t *env, ast_t *ast)
|
||||
auto use = Match(ast, Use);
|
||||
switch (use->what) {
|
||||
case USE_MODULE: {
|
||||
const char *libname = Text$as_c_string(
|
||||
Text$replace(Text$from_str(use->path), Pattern("{1+ !alphanumeric}"), Text("_"), Pattern(""), false));
|
||||
return CORD_all("#include <", libname, "/", libname, ".h>\n");
|
||||
return CORD_all("#include <", use->path, "/", use->path, ".h>\n");
|
||||
}
|
||||
case USE_LOCAL:
|
||||
return CORD_all("#include \"", use->path, ".h\"\n");
|
||||
|
29
tomo.c
29
tomo.c
@ -38,7 +38,7 @@ static void compile_object_file(const char *filename, bool force_recompile);
|
||||
static const char *compile_executable(env_t *base_env, const char *filename, CORD object_files, CORD extra_ldlibs);
|
||||
static void build_file_dependency_graph(const char *filename, Table_t *to_compile, Table_t *to_link);
|
||||
static const char *escape_lib_name(const char *lib_name);
|
||||
static void build_library(const char *lib_base_name);
|
||||
static void build_library(const char *lib_dir_name);
|
||||
static void compile_files(env_t *env, int filec, const char **filev, bool only_compile_arguments, CORD *object_files, CORD *ldlibs);
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wstack-protector"
|
||||
@ -235,7 +235,7 @@ static void _compile_file_header_for_library(env_t *env, const char *filename, T
|
||||
CORD_fprintf(output, "void %r$initialize(void);\n", namespace_prefix(module_env->libname, module_env->namespace));
|
||||
}
|
||||
|
||||
void build_library(const char *lib_base_name)
|
||||
void build_library(const char *lib_dir_name)
|
||||
{
|
||||
glob_t tm_files;
|
||||
char *library_directory = get_current_dir_name();
|
||||
@ -247,11 +247,11 @@ void build_library(const char *lib_base_name)
|
||||
|
||||
// Library name replaces all stretchs of non-alphanumeric chars with an underscore
|
||||
// So e.g. https://github.com/foo/baz --> https_github_com_foo_baz
|
||||
const char *libname = escape_lib_name(lib_base_name);
|
||||
env->libname = &libname;
|
||||
const char *lib_id = escape_lib_name(lib_dir_name);
|
||||
env->libname = &lib_id;
|
||||
|
||||
// Build a "whatever.h" header that loads all the headers:
|
||||
FILE *header_prog = CORD_RUN(autofmt ? autofmt : "cat", " 2>/dev/null >", libname, ".h");
|
||||
FILE *header_prog = CORD_RUN(autofmt ? autofmt : "cat", " 2>/dev/null >'", lib_dir_name, ".h'");
|
||||
fputs("#pragma once\n", header_prog);
|
||||
fputs("#include <tomo/tomo.h>\n", header_prog);
|
||||
Table_t visited_files = {};
|
||||
@ -269,7 +269,7 @@ void build_library(const char *lib_base_name)
|
||||
FILE *prog;
|
||||
for (size_t i = 0; i < tm_files.gl_pathc; i++) {
|
||||
const char *filename = tm_files.gl_pathv[i];
|
||||
prog = CORD_RUN("nm -Ug -fjust-symbols ", filename, ".o | sed 's/.*/\\0 ", libname, "$\\0/' >>symbol_renames.txt");
|
||||
prog = CORD_RUN("nm -Ug -fjust-symbols ", filename, ".o | sed 's/.*/\\0 ", lib_id, "$\\0/' >>symbol_renames.txt");
|
||||
int status = pclose(prog);
|
||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
errx(WEXITSTATUS(status), "Failed to create symbol rename table with `nm` and `sed`");
|
||||
@ -277,19 +277,20 @@ void build_library(const char *lib_base_name)
|
||||
|
||||
globfree(&tm_files);
|
||||
|
||||
prog = CORD_RUN(cc, " ", cflags, " ", ldflags, " ", ldlibs, " ", extra_ldlibs, " -Wl,-soname=lib", libname, ".so -shared ", object_files, " -o lib", libname, ".so");
|
||||
prog = CORD_RUN(cc, " ", cflags, " ", ldflags, " ", ldlibs, " ", extra_ldlibs, " '-Wl,-soname=lib", lib_dir_name, ".so' -shared ",
|
||||
object_files, " -o 'lib", lib_dir_name, ".so'");
|
||||
int status = pclose(prog);
|
||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
errx(WEXITSTATUS(status), "Failed to compile shared library file");
|
||||
if (verbose)
|
||||
CORD_printf("Compiled to lib%s.so\n", libname);
|
||||
CORD_printf("Compiled to lib%s.so\n", lib_dir_name);
|
||||
|
||||
prog = CORD_RUN("objcopy --redefine-syms=symbol_renames.txt lib", libname, ".so");
|
||||
prog = CORD_RUN("objcopy --redefine-syms=symbol_renames.txt 'lib", lib_dir_name, ".so'");
|
||||
status = pclose(prog);
|
||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
errx(WEXITSTATUS(status), "Failed to run `objcopy` to add library prefix to symbols");
|
||||
|
||||
prog = CORD_RUN("patchelf --rename-dynamic-symbols symbol_renames.txt lib", libname, ".so");
|
||||
prog = CORD_RUN("patchelf --rename-dynamic-symbols symbol_renames.txt 'lib", lib_dir_name, ".so'");
|
||||
status = pclose(prog);
|
||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
errx(WEXITSTATUS(status), "Failed to run `patchelf` to rename dynamic symbols with library prefix");
|
||||
@ -300,14 +301,14 @@ void build_library(const char *lib_base_name)
|
||||
unlink("symbol_renames.txt");
|
||||
|
||||
if (should_install) {
|
||||
const char *dest = heap_strf("%s/.local/share/tomo/installed/%s", getenv("HOME"), lib_base_name);
|
||||
const char *dest = heap_strf("%s/.local/share/tomo/installed/%s", getenv("HOME"), lib_dir_name);
|
||||
if (!streq(library_directory, dest)) {
|
||||
system(heap_strf("rm -rvf '%s'", dest));
|
||||
system(heap_strf("mkdir -p '%s'", dest));
|
||||
system(heap_strf("cp -rv * '%s/'", dest));
|
||||
}
|
||||
system("mkdir -p ~/.local/share/tomo/lib/");
|
||||
system(heap_strf("ln -fv -s ../installed/'%s'/lib%s.so ~/.local/share/tomo/lib/lib%s.so", lib_base_name, libname, libname));
|
||||
system(heap_strf("ln -fv -s ../installed/'%s'/lib'%s'.so ~/.local/share/tomo/lib/lib'%s'.so", lib_dir_name, lib_dir_name, lib_dir_name));
|
||||
}
|
||||
|
||||
free(library_directory);
|
||||
@ -418,9 +419,9 @@ void build_file_dependency_graph(const char *filename, Table_t *to_compile, Tabl
|
||||
break;
|
||||
}
|
||||
case USE_MODULE: {
|
||||
const char *lib_name = escape_lib_name(use->path);
|
||||
// const char *lib_name = escape_lib_name(use->path);
|
||||
// const char *lib = heap_strf("-l:'lib%s.so'", lib_name);
|
||||
const char *lib = heap_strf("'%s/.local/share/tomo/installed/%s/lib%s.so'", getenv("HOME"), lib_name, lib_name);
|
||||
const char *lib = heap_strf("'%s/.local/share/tomo/installed/%s/lib%s.so'", getenv("HOME"), use->path, use->path);
|
||||
Table$str_set(to_link, lib, lib);
|
||||
break;
|
||||
}
|
||||
|
12
typecheck.c
12
typecheck.c
@ -153,20 +153,14 @@ static env_t *load_module(env_t *env, ast_t *module_ast)
|
||||
return load_module_env(env, ast);
|
||||
}
|
||||
case USE_MODULE: {
|
||||
const char *libname = Text$as_c_string(
|
||||
Text$replace(Text$from_str(use->path), Pattern("{1+ !alphanumeric}"), Text("_"), Pattern(""), false));
|
||||
|
||||
glob_t tm_files;
|
||||
if (glob(heap_strf("~/.local/share/tomo/installed/%s/[!._0-9]*.tm", libname), GLOB_TILDE, NULL, &tm_files) != 0)
|
||||
if (glob(heap_strf("~/.local/share/tomo/installed/%s/[!._0-9]*.tm", use->path), GLOB_TILDE, NULL, &tm_files) != 0)
|
||||
code_err(module_ast, "Could not find library");
|
||||
|
||||
env_t *module_env = fresh_scope(env);
|
||||
Table$str_set(env->imports, use->path, module_env);
|
||||
char *libname_id = GC_strdup(libname);
|
||||
for (char *c = libname_id; *c; c++) {
|
||||
if (!isalnum(*c) && *c != '_')
|
||||
*c = '_';
|
||||
}
|
||||
char *libname_id = Text$as_c_string(
|
||||
Text$replace(Text$from_str(use->path), Pattern("{1+ !alphanumeric}"), Text("_"), Pattern(""), false));
|
||||
module_env->libname = new(CORD);
|
||||
*module_env->libname = (CORD)libname_id;
|
||||
for (size_t i = 0; i < tm_files.gl_pathc; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user