Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate PSA into spago #955

Merged
merged 80 commits into from
May 3, 2023
Merged

Integrate PSA into spago #955

merged 80 commits into from
May 3, 2023

Conversation

JordanMartinez
Copy link
Contributor

@JordanMartinez JordanMartinez commented Mar 30, 2023

Description of the change

Fixes #904.

Summary of PR:

  1. psa and psa-utils were vendored into this codebase and modified/updated in the following ways:
    • using Dodo as its printer rather than its custom code. Moreover, a brighter red and yellow are used for warnings and errors than what was used previously.
    • using codec-argonaut as its Json encoder/decoder
    • removing unused/unexported declarations
    • replacing some declarations with pre-existing ones (e.g. replicate with power
    • cleaning up the imports
    • renaming PsaOptions to PsaOutputOptions because *Options in this codebase typically refers to values used in misc commands.
    • renaming output to buildOutput because output is already exported from Spago.Prelude
    • combining stash and stashFile into one argument
    • renaming the ansi arg to color (since Spago already has a similarly-named flag)
    • dropping the isLib arg as libraries can be determined via Spago
    • changing the Json printer to print to stdout rather than stderr. (I'm not sure if this is correct to do, but I'll clarify why in the PR via a code comment).
  2. psa was integrated into Spago in the following way:
    • logic in psa's main function was extracted out into Psa.psaCompile, which wraps Purs.compile
    • various logDebug statements were added to make it easier to see where problems arise (if any) in the future
    • Of the args that psa takes, I decided to keep all of them configurable via spago.yml except for:
      • json-errors: I assume this is only useful if being called by an IDE or if someone wants to run their own custom printer
      • ansi: this doesn't seem like something one should configure via spago.yml, only via CLI
      • libraryDirs: with Spago in control, we know what the library directories are.
    • Stashes are stored in one of three places:
      • when spago build -b pkgName is used: .spago/stashes/defaults/pkgName.stash
      • when spago build is used: .spago/stashes/defaults/entire-workspace.stash
      • when spago build --psa-stash-file "foo" is used: .spago/stashes/custom/foo.stash
      • when spago build --psa-stash-file "../foo" is used: .spago/stashes/custom/foo.stash

Checklist:

  • Added the change to the "Unreleased" section of the changelog
  • Added some example of the new feature to the README
  • Added a test for the contribution (if applicable)

P.S.: the above checks are not compulsory to get a change merged, so you may skip them. However, taking care of them will result in less work for the maintainers and will be much appreciated 😊

@JordanMartinez JordanMartinez mentioned this pull request Mar 30, 2023
3 tasks
@f-f
Copy link
Member

f-f commented Apr 5, 2023

Thanks Nate! If you have no preference on this then my personal preference is that we stick to this fork here so we can iterate quickly on the new Spago. Once things get more stable we can think about upstreaming improvements to your repo.

@JordanMartinez
Copy link
Contributor Author

As I've spent time on this, I'm actually wondering why this work isn't being done in the compiler itself as that would remove the underlying reason for why psa even exists. And then, this work wouldn't even be necessary and the IDE wouldn't need to depend on psa either. Thoughts?

@f-f
Copy link
Member

f-f commented Apr 12, 2023

@JordanMartinez indeed it would be nice if the compiler did all of this and psa would not have reason to exist - however the issue is not straightforward, so (as the linked thread shows) I am of the opinion that we'd be better off getting this to work in Spago first, and then eventually deprecate this functionality once the relevant things are merged in the compiler.

@@ -148,4 +190,9 @@ workspace:
output: "output"
# optional, Boolean, fail the build if `spago.yml` has redundant/missing packages
pedantic_packages: false
# optional, PsaOptions
# These options only take affect when
# a package is not selected (e.g. `spago build` vs `spago build -p pkgName`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see - these are fair points and they all makes sense but I'm still concerned about having the "build options" all scattered around the different config files.
I think the clarity of having only a single set of things to configure is a bigger advantage over being able to issue small tweaks to the different packages in the build.

It sounds like we can cover most of these concerns by having some more configuration flags for test code, and compiling that separately with different settings if these are specified.
The only thing that we'd not cover would be the "test code as package code" scenario of halogen-hooks, but I'd say it's acceptable, since it's a very niche use-case. If it becomes more common, then we can consider a way to support it.


censorBuildWarnings ∷ ArgParser (Maybe Core.CensorBuildWarnings)
censorBuildWarnings =
ArgParser.argument [ "---censor-build-warnings" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ArgParser.argument [ "---censor-build-warnings" ]
ArgParser.argument [ "--censor-build-warnings" ]

These flags now all have three hyphens

}

type PublishArgs =
{ selectedPackage :: Maybe String
, psaArgs :: PsaArgs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about the user being able to configure the build via flags. I don't think calling spago publish --strict makes much sense, but of course we can pick up the strict flag from the config file if specified.

stashFile ∷ ArgParser (Maybe (Either Boolean String))
stashFile = ArgParser.optional $ ArgParser.choose "stash"
[ ArgParser.argument [ "---stash-file" ] "Enable persistent warnings using a specific stash file"
# ArgParser.unformat "FILE" (Right <<< Right <<< Paths.mkLocalCachesCustomStashFile <<< Path.basename)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a comment in the previous review and I can't find it - I don't see the benefit of allowing custom stash files, since we already differentiate the stash locations per package in the build, so this just adds more complexity for no clear upside

@@ -148,4 +190,9 @@ workspace:
output: "output"
# optional, Boolean, fail the build if `spago.yml` has redundant/missing packages
pedantic_packages: false
# optional, PsaOptions
# These options only take affect when
# a package is not selected (e.g. `spago build` vs `spago build -p pkgName`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add that this is a fairly weak opinion because we don't have any real-world usage of this whole monorepo setup yet.
We can probably just ship the "workspace-only" version and then tweak later once folks need things.
I'd likely prefer the "workspace settings are the default ones, and package specific ones override" implementation, so we'd have to rework this anyways.

Copy link
Member

@f-f f-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge this now - thanks Jordan!

@f-f f-f merged commit 5dd06ae into master May 3, 2023
@f-f f-f deleted the jam/integrate-psa branch May 3, 2023 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate psa into Spago
3 participants