From cb8f2b36352948108446c7e3b270faa97589bf7a Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 25 Oct 2020 23:16:14 -0400 Subject: Some small refactoring. --- stdlib/source/program/aedifex.lux | 10 ++--- stdlib/source/program/aedifex/command/build.lux | 14 +++---- stdlib/source/program/aedifex/command/deploy.lux | 2 +- stdlib/source/program/aedifex/local.lux | 49 ++++++++---------------- stdlib/source/program/compositor.lux | 4 +- stdlib/source/program/licentia.lux | 4 +- stdlib/source/program/scriptum.lux | 2 +- 7 files changed, 35 insertions(+), 50 deletions(-) (limited to 'stdlib/source/program') diff --git a/stdlib/source/program/aedifex.lux b/stdlib/source/program/aedifex.lux index 76db24a47..485277d88 100644 --- a/stdlib/source/program/aedifex.lux +++ b/stdlib/source/program/aedifex.lux @@ -50,7 +50,7 @@ (def: (install! profile) (-> /.Profile (Promise Any)) (do promise.monad - [outcome (/local.install (file.async file.system) profile)] + [outcome (/local.install (file.async file.default) profile)] (wrap (case outcome (#try.Success _) (log! "Successfully installed locally!") @@ -63,14 +63,14 @@ (-> /.Profile (Promise Any)) (do promise.monad [outcome (do (try.with promise.monad) - [cache (/local.all-cached (file.async file.system) + [cache (/local.all-cached (file.async file.default) (set.to-list (get@ #/.dependencies profile)) /dependency.empty) resolution (promise.future (/dependency.resolve-all (set.to-list (get@ #/.repositories profile)) (set.to-list (get@ #/.dependencies profile)) cache))] - (/local.cache-all (file.async file.system) + (/local.cache-all (file.async file.default) resolution))] (wrap (case outcome (#try.Success _) @@ -82,12 +82,12 @@ (program: [{[profile operation] /cli.command}] (do {@ io.monad} - [?profile (/input.read io.monad file.system profile)] + [?profile (/input.read io.monad file.default profile)] (case ?profile (#try.Success profile) (case operation #/cli.POM - (exec (/command/pom.do! (file.async file.system) profile) + (exec (/command/pom.do! (file.async file.default) profile) (wrap [])) #/cli.Dependencies diff --git a/stdlib/source/program/aedifex/command/build.lux b/stdlib/source/program/aedifex/command/build.lux index 6a1ab93d4..2d8ffb763 100644 --- a/stdlib/source/program/aedifex/command/build.lux +++ b/stdlib/source/program/aedifex/command/build.lux @@ -89,7 +89,7 @@ (-> Resolution (List Path)) (|>> dictionary.keys (list.filter (|>> (get@ #///dependency.type) (text@= ///artifact/type.lux-library))) - (list@map (|>> (get@ #///dependency.artifact) (///local.path file.system))))) + (list@map (|>> (get@ #///dependency.artifact) (///local.path file.default))))) (import: java/lang/String) @@ -124,24 +124,24 @@ [(#.Some program) (#.Some target)] (do ///action.monad - [cache (///local.all-cached (file.async file.system) + [cache (///local.all-cached (file.async file.default) (set.to-list (get@ #///.dependencies profile)) ///dependency/resolution.empty) resolution (promise.future (///dependency/resolution.resolve-all (set.to-list (get@ #///.repositories profile)) (set.to-list (get@ #///.dependencies profile)) cache)) - _ (///local.cache-all (file.async file.system) + _ (///local.cache-all (file.async file.default) resolution) [resolution compiler] (promise@wrap (..compiler resolution)) working-directory (promise.future ..working-directory) #let [libraries (..libraries resolution) [prefix output] (case compiler - (#JVM artifact) [(format "java -jar " (///local.path file.system artifact)) + (#JVM artifact) [(format "java -jar " (///local.path file.default artifact)) "program.jar"] - (#JS artifact) [(format "node --stack_size=8192 " (///local.path file.system artifact)) + (#JS artifact) [(format "node --stack_size=8192 " (///local.path file.default artifact)) "program.js"]) - cache-directory (format working-directory (:: file.system separator) target) + cache-directory (format working-directory (:: file.default separator) target) command (format prefix " build" " " (..plural-parameter "--library" libraries) " " (..plural-parameter "--source" (set.to-list (get@ #///.sources profile))) @@ -151,5 +151,5 @@ outcome (///shell.execute command working-directory) #let [_ (log! "[BUILD ENDED]")]] (wrap [compiler - (format cache-directory (:: file.system separator) output)])) + (format cache-directory (:: file.default separator) output)])) )) diff --git a/stdlib/source/program/aedifex/command/deploy.lux b/stdlib/source/program/aedifex/command/deploy.lux index d7c7802b7..b8ac5c97c 100644 --- a/stdlib/source/program/aedifex/command/deploy.lux +++ b/stdlib/source/program/aedifex/command/deploy.lux @@ -65,7 +65,7 @@ content))))] (do {@ ///action.monad} [library (:: @ map (binary.run tar.writer) - (export.library (file.async file.system) + (export.library (file.async file.default) (set.to-list (get@ #/.sources profile)))) pom (promise@wrap (///pom.write profile)) _ (deploy! ///artifact/type.pom (|> pom (:: xml.codec encode) encoding.to-utf8)) diff --git a/stdlib/source/program/aedifex/local.lux b/stdlib/source/program/aedifex/local.lux index c7c72c827..674d99f04 100644 --- a/stdlib/source/program/aedifex/local.lux +++ b/stdlib/source/program/aedifex/local.lux @@ -26,7 +26,9 @@ ["." tar] ["." xml]]] [world - ["." file (#+ Path File Directory)]]] + ["." file (#+ Path File Directory)] + [net + ["." uri]]]] [program [compositor ["." export]]] @@ -40,31 +42,17 @@ ["#." dependency (#+ Dependency) ["#/." resolution (#+ Package Resolution)]]]) -(def: (local system) - (All [a] (-> (file.System a) Path)) - (format "~" (:: system separator) ".m2")) - (def: (repository system) (All [a] (-> (file.System a) Path)) - (format (..local system) (:: system separator) "repository")) + (let [/ (:: system separator)] + (format "~" / ".m2" / "repository"))) -(def: (guarantee-repository! system artifact) - (-> (file.System Promise) Artifact (Promise (Try Path))) - (do {@ (try.with promise.monad)} - [_ (: (Promise (Try (Directory Promise))) - (file.get-directory promise.monad system (..local system))) - #let [root (..repository system)] - _ (: (Promise (Try (Directory Promise))) - (file.get-directory promise.monad system root))] - (monad.fold @ - (function (_ child parent) - (do @ - [#let [path (format parent (:: system separator) child)] - _ (: (Promise (Try (Directory Promise))) - (file.get-directory promise.monad system path))] - (wrap path))) - root - (//artifact.local artifact)))) +(def: #export (path system artifact) + (All [a] (-> (file.System a) Artifact Path)) + (format (..repository system) + (:: system separator) + (text.replace-all uri.separator (:: system separator) + (//artifact.path artifact)))) (def: (save! system content file) (-> (file.System Promise) Binary Path (Promise (Try Any))) @@ -78,7 +66,8 @@ (case (get@ #/.identity profile) (#.Some identity) (do (try.with promise.monad) - [repository (..guarantee-repository! system identity) + [repository (: (Promise (Try Path)) + (file.make-directories promise.monad system (..path system identity))) #let [artifact-name (format repository (:: system separator) (//artifact.identity identity))] package (export.library system (set.to-list (get@ #/.sources profile))) _ (..save! system (binary.run tar.writer package) @@ -93,7 +82,8 @@ (def: #export (cache system [artifact type] package) (-> (file.System Promise) Dependency Package (Promise (Try Any))) (do (try.with promise.monad) - [directory (..guarantee-repository! system artifact) + [directory (: (Promise (Try Path)) + (file.make-directories promise.monad system (..path system artifact))) #let [prefix (format directory (:: system separator) (//artifact.identity artifact))] directory (: (Promise (Try (Directory Promise))) (file.get-directory promise.monad system directory)) @@ -129,7 +119,8 @@ (def: #export (cached system [artifact type]) (-> (file.System Promise) Dependency (Promise (Try Package))) (do (try.with promise.monad) - [directory (..guarantee-repository! system artifact) + [directory (: (Promise (Try Path)) + (file.make-directories promise.monad system (..path system artifact))) #let [prefix (format directory (:: system separator) (//artifact.identity artifact))] pom (..read! system (format prefix //artifact/extension.pom)) [pom dependencies] (:: promise.monad wrap @@ -175,9 +166,3 @@ (#try.Failure error) ))))) - -(def: #export (path system artifact) - (All [a] (-> (file.System a) Artifact Path)) - (format (..repository system) - (:: system separator) - (//artifact.identity artifact))) diff --git a/stdlib/source/program/compositor.lux b/stdlib/source/program/compositor.lux index 1b17a4de8..3bc870f9b 100644 --- a/stdlib/source/program/compositor.lux +++ b/stdlib/source/program/compositor.lux @@ -142,7 +142,7 @@ (:assume (platform.compile import static expander platform compilation [archive state]))}) _ (ioW.freeze (get@ #platform.&file-system platform) static archive) program-context (promise@wrap ($/program.context archive)) - _ (promise.future (..package! io.monad file.system packager,package static archive program-context))] + _ (promise.future (..package! io.monad file.default packager,package static archive program-context))] (wrap (log! "Compilation complete!")))) (#/cli.Export export) @@ -157,7 +157,7 @@ (undefined) ## (<| (or-crash! "Interpretation failed:") ## (do {@ promise.monad} - ## [console (|> console.system + ## [console (|> console.default ## promise.future ## (:: @ map (|>> try.assume console.async)))] ## (interpreter.run (try.with promise.monad) console platform interpretation generation-bundle))) diff --git a/stdlib/source/program/licentia.lux b/stdlib/source/program/licentia.lux index 7eab5b444..244e28223 100644 --- a/stdlib/source/program/licentia.lux +++ b/stdlib/source/program/licentia.lux @@ -57,7 +57,7 @@ (do io.monad [?done (: (IO (Try Any)) (do (try.with io.monad) - [file (!.use (:: file.system file) input) + [file (!.use (:: file.default file) input) blob (!.use (:: file content) []) document (io;wrap (do try.monad [raw-json (encoding.from-utf8 blob) @@ -69,7 +69,7 @@ license (json.run json /input.license)] (wrap (/output.license license)))) output-file (: (IO (Try (File IO))) - (file.get-file io.monad file.system output))] + (file.get-file io.monad file.default output))] (!.use (:: output-file over-write) (encoding.to-utf8 document))))] (case ?done (#try.Success _) diff --git a/stdlib/source/program/scriptum.lux b/stdlib/source/program/scriptum.lux index bf12da1cd..1cb0ee21a 100644 --- a/stdlib/source/program/scriptum.lux +++ b/stdlib/source/program/scriptum.lux @@ -489,7 +489,7 @@ (do io.monad [outcome (do (try.with io.monad) [target (: (IO (Try (File IO))) - (file.get-file io.monad file.system path))] + (file.get-file io.monad file.default path))] (!.use (:: target over-write) (encoding.to-utf8 (md.markdown documentation))))] (case outcome (#try.Failure error) -- cgit v1.2.3