aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/command/build.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/program/aedifex/command/build.lux')
-rw-r--r--stdlib/source/program/aedifex/command/build.lux128
1 files changed, 72 insertions, 56 deletions
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)]))))))