onyx-pkg: added generating a single file to load
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 22 Feb 2023 01:44:40 +0000 (19:44 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 22 Feb 2023 01:44:40 +0000 (19:44 -0600)
scripts/onyx-pkg.onyx

index 7b1253bf55109ec58971cc68ccc3c4c0c17c84cc..a3f2a38ad5893bc488277ec4d18912e88f085661 100644 (file)
@@ -325,6 +325,8 @@ run_sync_command :: (args: [] cstr) {
         dependencies_installed[to_install.repo] = to_install.version;
     }
 
+    build_package_file_to_load();
+
     if options.clean {
         for os.list_directory(config.config.lib_source_directory) {
             if it.type != .Directory do continue;
@@ -616,6 +618,42 @@ run_command_and_forward_output :: (cmd: str) => {
     return os.process_wait(^run_proc);
 }
 
+build_package_file_to_load :: () {
+    filepath := tprintf("{}/{}", config.config.lib_source_directory, "packages.onyx");
+
+    if os.file_exists(filepath) {
+        os.remove_file(filepath);
+    }
+
+    for os.with_file(filepath, .Write) {
+        w := io.writer_make(it);
+        defer io.writer_free(^w);
+
+        io.write(^w, """
+//
+// THIS FILE WAS AUTOMATICALLY GENERATED BY onyx-pkg.
+// DO NOT MODIFY UNLESS YOU KNOW WHAT YOU ARE DOING.
+//
+
+// PACKAGE LOADING
+""");
+
+        for config.dependencies.dependencies->as_iter() {
+            dependency_repo := it.key;
+            dependency_folder := config.dependency_folders.folders[dependency_repo];
+
+            io.write_format(^w,
+                "#load \"./{}/module.onyx\"\n",
+                dependency_folder);
+        }
+
+        io.write(^w, "\n\n// NATIVE LIBRARY PATH\n");
+
+        io.write_format(^w, "#library_path \"{}\"\n", config.config.lib_bin_directory);
+    }
+}
+
+
 
 #tag conv.Custom_Parse.{parse}
 #tag conv.Custom_Format.{format}