aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
authorEduardo Julian2021-11-29 17:53:01 -0400
committerEduardo Julian2021-11-29 17:53:01 -0400
commit13323c55a4d34ddb74b67fab684d4431f9624dd1 (patch)
tree2d5912a5a50640176507b8274293980c0376475b /stdlib/source
parentbd6ff5014b4d9fad6c6fa6ab3a2e30fc768687e1 (diff)
New packaging for Ruby programs.
Diffstat (limited to '')
-rw-r--r--stdlib/source/library/lux/tool/compiler/meta/packager.lux3
-rw-r--r--stdlib/source/library/lux/tool/compiler/meta/packager/ruby.lux140
-rw-r--r--stdlib/source/program/aedifex/command/build.lux7
-rw-r--r--stdlib/source/program/aedifex/command/test.lux50
-rw-r--r--stdlib/source/program/compositor.lux14
5 files changed, 185 insertions, 29 deletions
diff --git a/stdlib/source/library/lux/tool/compiler/meta/packager.lux b/stdlib/source/library/lux/tool/compiler/meta/packager.lux
index d57f52400..5d6fe712e 100644
--- a/stdlib/source/library/lux/tool/compiler/meta/packager.lux
+++ b/stdlib/source/library/lux/tool/compiler/meta/packager.lux
@@ -26,7 +26,8 @@
(-> (Dictionary file.Path Binary)
Archive
Context
- (Try Binary)))
+ (Try (Either Binary
+ (List [Text Binary])))))
(type: .public Order
(List [archive.ID (List artifact.ID)]))
diff --git a/stdlib/source/library/lux/tool/compiler/meta/packager/ruby.lux b/stdlib/source/library/lux/tool/compiler/meta/packager/ruby.lux
new file mode 100644
index 000000000..a375a908a
--- /dev/null
+++ b/stdlib/source/library/lux/tool/compiler/meta/packager/ruby.lux
@@ -0,0 +1,140 @@
+(.using
+ [library
+ [lux {"-" Module}
+ [type {"+" :sharing}]
+ [abstract
+ ["[0]" monad {"+" do}]]
+ [control
+ ["[0]" try {"+" Try}]]
+ [data
+ [binary {"+" Binary}]
+ ["[0]" product]
+ ["[0]" text
+ ["%" format {"+" format}]
+ [encoding
+ ["[0]" utf8]]]
+ [collection
+ ["[0]" sequence]
+ ["[0]" list ("[1]#[0]" functor mix)]
+ ["[0]" dictionary {"+" Dictionary}]
+ ["[0]" set {"+" Set}]]]
+ [math
+ [number
+ ["[0]" nat]]]
+ [target
+ ["_" ruby]]
+ [world
+ ["[0]" file]]]]
+ [program
+ [compositor
+ ["[0]" static {"+" Static}]]]
+ ["[0]" // {"+" Packager}
+ [//
+ ["[0]" archive {"+" Output}
+ ["[0]" descriptor {"+" Module Descriptor}]
+ ["[0]" artifact]
+ ["[0]" document {"+" Document}]
+ ["tree_shaking" dependency]]
+ [cache
+ ["[0]" dependency {"+" Order}]]
+ ["[0]" io "_"
+ ["[1]" archive]]
+ [//
+ [language
+ ["$" lux
+ [generation {"+" Context}]]]]]])
+
+(def: (bundle_module module module_id necessary_dependencies output)
+ (-> Module archive.ID (Set Context) Output (Try (Maybe _.Statement)))
+ (do [! try.monad]
+ []
+ (case (|> output
+ sequence.list
+ (list.only (function (_ [artifact_id custom content])
+ (set.member? necessary_dependencies [module_id artifact_id]))))
+ {.#End}
+ (in {.#None})
+
+ artifacts
+ (do !
+ [bundle (monad.mix !
+ (function (_ [artifact custom_name content] so_far)
+ (|> content
+ (# utf8.codec decoded)
+ (# ! each
+ (|>> :expected
+ (:sharing [directive]
+ directive
+ so_far
+
+ directive)
+ (_.then so_far)))))
+ (_.comment "Lux module"
+ (_.statement (_.string "")))
+ artifacts)]
+ (in {.#Some bundle})))))
+
+(def: module_file
+ (-> archive.ID file.Path)
+ (|>> %.nat (text.suffix ".rb")))
+
+(def: (write_module mapping necessary_dependencies [module [module_id [descriptor document output]]] sink)
+ (-> (Dictionary Module archive.ID) (Set Context)
+ [Module [archive.ID [Descriptor (Document .Module) Output]]]
+ (List [archive.ID [Text Binary]])
+ (Try (List [archive.ID [Text Binary]])))
+ (do [! try.monad]
+ [bundle (: (Try (Maybe _.Statement))
+ (..bundle_module module module_id necessary_dependencies output))]
+ (case bundle
+ {.#None}
+ (in sink)
+
+ {.#Some bundle}
+ (let [entry_content (|> (list)
+ (list#mix _.then bundle)
+ (: _.Statement)
+ _.code
+ (# utf8.codec encoded))]
+ (in (list& [module_id [(..module_file module_id) entry_content]]
+ sink))))))
+
+(def: .public main_file
+ "main.rb")
+
+(def: module_id_mapping
+ (-> Order (Dictionary Module archive.ID))
+ (|>> (list#each (function (_ [module [module_id [descriptor document output]]])
+ [module module_id]))
+ (dictionary.of_list text.hash)))
+
+(def: included_modules
+ (All (_ a) (-> (List [archive.ID a]) (Set archive.ID)))
+ (|>> (list#each product.left)
+ (list#mix set.has (set.empty nat.hash))))
+
+(def: .public (package host_dependencies archive program)
+ Packager
+ (do [! try.monad]
+ [.let [necessary_dependencies (tree_shaking.necessary_dependencies archive)]
+ order (dependency.load_order $.key archive)
+ entries (monad.mix ! (..write_module (module_id_mapping order) necessary_dependencies) {.#End} order)
+ .let [included_modules (..included_modules entries)
+ imports (|> order
+ (list.only (|>> product.right product.left (set.member? included_modules)))
+ list.reversed
+ (list#each (function (_ [module [module_id [descriptor document output]]])
+ (let [relative_path (_.do "gsub" (list (_.string main_file)
+ (_.string (..module_file module_id)))
+ {.#None}
+ (_.local "__FILE__"))]
+ (_.statement (_.require/1 relative_path)))))
+ (list#mix _.then (_.comment "Lux program"
+ (_.statement (_.string ""))))
+ (: _.Statement)
+ _.code
+ (# utf8.codec encoded))]]
+ (in (|> entries
+ (list#each product.right)
+ {.#Item [..main_file imports]}
+ {.#Right}))))
diff --git a/stdlib/source/program/aedifex/command/build.lux b/stdlib/source/program/aedifex/command/build.lux
index 9fbc34542..15a671615 100644
--- a/stdlib/source/program/aedifex/command/build.lux
+++ b/stdlib/source/program/aedifex/command/build.lux
@@ -23,6 +23,11 @@
[number
["n" nat]
["i" int]]]
+ [tool
+ [compiler
+ [meta
+ ["[0]" packager
+ ["[0]_[1]" ruby]]]]]
[world
["[0]" program {"+" Program}]
["[0]" file {"+" Path}]
@@ -291,7 +296,7 @@
([#JS ///.#js "program.js"]
[#Python ///.#java "program.py"]
[#Lua ///.#java "program.lua"]
- [#Ruby ///.#java "program.rb"]))
+ [#Ruby ///.#java (file.rooted fs "program" ruby_packager.main_file)]))
/ (# fs separator)
cache_directory (format working_directory / target)]
_ (console.write_line ..start console)
diff --git a/stdlib/source/program/aedifex/command/test.lux b/stdlib/source/program/aedifex/command/test.lux
index b2f67ba07..4aa1ecc54 100644
--- a/stdlib/source/program/aedifex/command/test.lux
+++ b/stdlib/source/program/aedifex/command/test.lux
@@ -1,28 +1,28 @@
(.using
- [library
- [lux "*"
- [abstract
- [monad {"+" do}]]
- [control
- [concurrency
- ["[0]" async {"+" Async} ("[1]#[0]" monad)]]]
- [math
- [number
- ["i" int]]]
- [world
- ["[0]" program {"+" Program}]
- ["[0]" file]
- ["[0]" shell {"+" Exit Shell}]
- ["[0]" console {"+" Console}]]]]
- ["[0]" // "_"
- ["[1][0]" build]
- ["/[1]" // "_"
- ["[1]" profile]
- ["[1][0]" action]
- ["[1][0]" command {"+" Command}]
- ["[1][0]" runtime]
- [dependency
- [resolution {"+" Resolution}]]]])
+ [library
+ [lux "*"
+ [abstract
+ [monad {"+" do}]]
+ [control
+ [concurrency
+ ["[0]" async {"+" Async} ("[1]#[0]" monad)]]]
+ [math
+ [number
+ ["i" int]]]
+ [world
+ ["[0]" program {"+" Program}]
+ ["[0]" file]
+ ["[0]" shell {"+" Exit Shell}]
+ ["[0]" console {"+" Console}]]]]
+ ["[0]" // "_"
+ ["[1][0]" build]
+ ["/[1]" // "_"
+ ["[1]" profile]
+ ["[1][0]" action]
+ ["[1][0]" command {"+" Command}]
+ ["[1][0]" runtime]
+ [dependency
+ [resolution {"+" Resolution}]]]])
(def: .public start "[TEST STARTED]")
(def: .public success "[TEST ENDED]")
@@ -46,7 +46,7 @@
(|> program
(///runtime.for (value@ ///.#java profile))
(//build.with_jvm_class_path host_dependencies))
-
+
(^template [<tag> <runtime>]
[{<tag> artifact}
(///runtime.for (value@ <runtime> profile)
diff --git a/stdlib/source/program/compositor.lux b/stdlib/source/program/compositor.lux
index 8e0077b4a..54fc903ad 100644
--- a/stdlib/source/program/compositor.lux
+++ b/stdlib/source/program/compositor.lux
@@ -5,7 +5,7 @@
["@" target]
["[0]" debug]
[abstract
- [monad {"+" do}]]
+ ["[0]" monad {"+" do}]]
[control
["[0]" io {"+" IO io}]
["[0]" try {"+" Try}]
@@ -87,7 +87,17 @@
(-> (file.System Async) (Dictionary file.Path Binary) [Packager file.Path] Static Archive Context (Async (Try Any)))
(case (packager host_dependencies archive context)
{try.#Success content}
- (# fs write content package)
+ (case content
+ {.#Left content}
+ (# fs write content package)
+
+ {.#Right content}
+ (do [! (try.with async.monad)]
+ [_ (# fs make_directory package)
+ _ (monad.each ! (function (_ [name content])
+ (# fs write content (file.rooted fs package name)))
+ content)]
+ (in [])))
{try.#Failure error}
(# async.monad in {try.#Failure error})))