andyarvanitis / purescript-native

A native compiler backend for PureScript (via C++ or Golang)
http://purescript.org
Other
629 stars 40 forks source link

feat: support 'spago run' and 'spago test' #60

Closed knight9999 closed 3 years ago

knight9999 commented 3 years ago

This PR is to resolve #45 .

Namely, this PR resolves

% spago run

and

% spago test

respectively.


The latest spago 0.16.0 calls alternative backend command as

% psgo --run Main.main

when running spago run, and

% psgo --run Test.Main.main

when running spago test.

Then this PR is checking the command-line parameters trickily as follows.

  1. if --run option is specified, then check the first string parameter following --run.
  2. if the first string parameter is Main.main or Test.Main.main, set moduleName as Main (for Main.main) or Test.Main (for Test.Main.main), and set files as the rest parameters.

Using this defined moduleName, call go command as

callProcess "go" ["run", T.unpack project </> modPrefix' </> fromMaybe "Main" moduleName]

The corresponding command is

% go project.localhost/purescript-native/output/Main

(for spago run) or

% go project.localhost/purescript-native/output/Test.Main

(for spago test)

On the other hand, in the Printer.hs, Test_Main module (more precisely Test.Main in implHeaderSource and Test.Main in implFooterSource) is improved likeMain` module.

andyarvanitis commented 3 years ago

That'll work, thanks!

knight9999 commented 3 years ago

Thanks @andyarvanitis ! This project is great! I am so happy!

i-am-the-slime commented 3 years ago

@knight9999 Thank you also from me! Sorry that I didn't manage to do it myself 👎