aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/command
diff options
context:
space:
mode:
authorEduardo Julian2021-06-24 03:42:57 -0400
committerEduardo Julian2021-06-24 03:42:57 -0400
commitce1a7a131f7c4df8eae5c019eba2893b56f04d46 (patch)
tree645c4b42c4b9bff141b7390d9f33f3f1fe4aeea1 /stdlib/source/program/aedifex/command
parenta82bd1eabe94763162c2b0707d9c198fbe9835e3 (diff)
Added a macro for type-casting JVM objects.
Diffstat (limited to 'stdlib/source/program/aedifex/command')
-rw-r--r--stdlib/source/program/aedifex/command/auto.lux16
-rw-r--r--stdlib/source/program/aedifex/command/build.lux128
-rw-r--r--stdlib/source/program/aedifex/command/test.lux6
3 files changed, 87 insertions, 63 deletions
diff --git a/stdlib/source/program/aedifex/command/auto.lux b/stdlib/source/program/aedifex/command/auto.lux
index afce4d6ff..000384ccd 100644
--- a/stdlib/source/program/aedifex/command/auto.lux
+++ b/stdlib/source/program/aedifex/command/auto.lux
@@ -42,13 +42,17 @@
(#try.Failure error)
(wrap (list)))))
-(def: (pause _)
- (-> Any (Promise (Try Any)))
- (promise.delay 1,000 (#try.Success [])))
+(def: #export delay
+ Nat
+ 1,000)
-(def: #export (do! watcher command)
+(def: (pause delay)
+ (-> Nat (Promise (Try Any)))
+ (promise.delay delay (#try.Success [])))
+
+(def: #export (do! delay watcher command)
(All [a]
- (-> (Watcher Promise)
+ (-> Nat (Watcher Promise)
(-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command a))
(-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command Any))))
(function (_ console program fs shell resolution)
@@ -65,7 +69,7 @@
_ <call>]
(loop [_ []]
(do !
- [_ (..pause [])
+ [_ (..pause delay)
events (\ watcher poll [])
_ (case events
(#.Cons _)
diff --git a/stdlib/source/program/aedifex/command/build.lux b/stdlib/source/program/aedifex/command/build.lux
index 7052109fb..e2d6f78b8 100644
--- a/stdlib/source/program/aedifex/command/build.lux
+++ b/stdlib/source/program/aedifex/command/build.lux
@@ -132,66 +132,82 @@
(def: #export failure "[BUILD FAILED]")
(template [<name> <capability>]
- [(def: (<name> console process)
+ [(def: #export (<name> console process)
(-> (Console Promise) (Process Promise) (Promise (Try Any)))
- (do {! promise.monad}
- [?line (!.use (\ process <capability>) [])]
- (case ?line
- (#try.Failure error)
- (if (exception.match? shell.no_more_output error)
- (wrap (#try.Success []))
- (console.write_line error console))
-
- (#try.Success line)
- (do (try.with !)
- [_ (console.write_line line console)]
- (log_output! console process)))))]
+ ## This is a very odd way of implementing this function.
+ ## But it's written this way because the more straightforward way (i.e. by using (try.with promise.monad))
+ ## eventually led to the function hanging/freezing.
+ ## I'm not sure why it happened, but I got this weirder implementation to work.
+ (let [[read! write!] (: [(Promise (Try Any))
+ (promise.Resolver (Try Any))]
+ (promise.promise []))
+ _ (|> (!.use (\ process <capability>) [])
+ (promise.await (function (recur ?line)
+ (case ?line
+ (#try.Failure error)
+ (if (exception.match? shell.no_more_output error)
+ (write! (#try.Success []))
+ (promise.await write! (console.write_line error console)))
+
+ (#try.Success line)
+ (promise.await (function (_ outcome)
+ (case outcome
+ (#try.Failure error)
+ (write! (#try.Failure error))
+
+ (#try.Success _)
+ (promise.await recur
+ (!.use (\ process <capability>) []))))
+ (console.write_line line console)))))
+ io.run)]
+ read!))]
[log_output! read]
[log_error! error]
)
-(def: #export (do! console program fs shell resolution profile)
+(def: #export (do! console program fs shell resolution)
(-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command [Compiler Path]))
- (case [(get@ #///.program profile)
- (get@ #///.target profile)]
- [#.None _]
- (promise\wrap (exception.throw ..no_specified_program []))
-
- [_ #.None]
- (promise\wrap (exception.throw ..no_specified_target []))
-
- [(#.Some program_module) (#.Some target)]
- (do promise.monad
- [environment (\ program environment [])
- home (\ program home [])
- working_directory (\ program directory [])]
- (do ///action.monad
- [[resolution compiler] (promise\wrap (..compiler resolution))
- #let [[[command compiler_params] output] (case compiler
- (#JVM dependency) [(///runtime.java (..path fs home dependency))
- "program.jar"]
- (#JS dependency) [(///runtime.node (..path fs home dependency))
- "program.js"])
- / (\ fs separator)
- cache_directory (format working_directory / target)]
- _ (console.write_line ..start console)
- process (!.use (\ shell execute)
- [environment
- working_directory
- command
- (list.concat (list compiler_params
- (list "build")
- (..plural "--library" (..libraries fs home resolution))
- (..plural "--source" (set.to_list (get@ #///.sources profile)))
- (..singular "--target" cache_directory)
- (..singular "--module" program_module)))])
- _ (..log_output! console process)
- _ (..log_error! console process)
- exit (!.use (\ process await) [])
- _ (console.write_line (if (i.= shell.normal exit)
- ..success
- ..failure)
- console)]
- (wrap [compiler
- (format cache_directory / output)])))))
+ (function (_ profile)
+ (case [(get@ #///.program profile)
+ (get@ #///.target profile)]
+ [#.None _]
+ (promise\wrap (exception.throw ..no_specified_program []))
+
+ [_ #.None]
+ (promise\wrap (exception.throw ..no_specified_target []))
+
+ [(#.Some program_module) (#.Some target)]
+ (do promise.monad
+ [environment (\ program environment [])
+ home (\ program home [])
+ working_directory (\ program directory [])]
+ (do ///action.monad
+ [[resolution compiler] (promise\wrap (..compiler resolution))
+ #let [[[command compiler_params] output] (case compiler
+ (#JVM dependency) [(///runtime.java (..path fs home dependency))
+ "program.jar"]
+ (#JS dependency) [(///runtime.node (..path fs home dependency))
+ "program.js"])
+ / (\ fs separator)
+ cache_directory (format working_directory / target)]
+ _ (console.write_line ..start console)
+ process (!.use (\ shell execute)
+ [environment
+ working_directory
+ command
+ (list.concat (list compiler_params
+ (list "build")
+ (..plural "--library" (..libraries fs home resolution))
+ (..plural "--source" (set.to_list (get@ #///.sources profile)))
+ (..singular "--target" cache_directory)
+ (..singular "--module" program_module)))])
+ _ (..log_output! console process)
+ _ (..log_error! console process)
+ exit (!.use (\ process await) [])
+ _ (console.write_line (if (i.= shell.normal exit)
+ ..success
+ ..failure)
+ console)]
+ (wrap [compiler
+ (format cache_directory / output)]))))))
diff --git a/stdlib/source/program/aedifex/command/test.lux b/stdlib/source/program/aedifex/command/test.lux
index c3b517437..e717b7cd6 100644
--- a/stdlib/source/program/aedifex/command/test.lux
+++ b/stdlib/source/program/aedifex/command/test.lux
@@ -21,6 +21,7 @@
["." // #_
["#." build]
["/#" // #_
+ ["#" profile]
["#." action]
["#." command (#+ Command)]
["#." runtime]
@@ -37,7 +38,8 @@
[environment (\ program environment [])
working_directory (\ program directory [])]
(do ///action.monad
- [[compiler program] (//build.do! console program fs shell resolution profile)
+ [[compiler program] (//build.do! console program fs shell resolution
+ (set@ #///.program (get@ #///.test profile) profile))
_ (console.write_line ..start console)
#let [[compiler_command compiler_parameters] (case compiler
(#//build.JVM artifact) (///runtime.java program)
@@ -47,6 +49,8 @@
working_directory
compiler_command
compiler_parameters])
+ _ (//build.log_output! console process)
+ _ (//build.log_error! console process)
exit (!.use (\ process await) [])
_ (console.write_line (if (i.= shell.normal exit)
..success