Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ New features:
- Add `--open` flag to `spago docs` which opens generated docs in browser (#379)
- Support building for alternate backends (#355). E.g: Use `backend = "psgo"` entry in `spago.dhall` to compile with `psgo`
- Add `--no-comments` flag to `spago init` which strips comments from the generated `spago.dhall` and `packages.dhall` configs (#417)
- Make `spago verify-set` compile everything, to detect duplicate module names (#438)
- Add shared output folder to reduce build duplication. Pass `--no-share-output` flag to `spago build` to disable (#377)
- Fix confusing warning when trying to `spago install` a package already present in project dependencies list (#436)

Expand Down
11 changes: 6 additions & 5 deletions app/Spago.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Spago.DryRun (DryRun (..))
import qualified Spago.GitHub
import Spago.GlobalCache (CacheFlag (..))
import Spago.Messages as Messages
import Spago.Packages (JsonFlag (..), PackagesFilter (..))
import Spago.Packages (CheckModulesUnique (..), JsonFlag (..), PackagesFilter (..))
import qualified Spago.Packages
import qualified Spago.Purs as Purs
import Spago.Types
Expand Down Expand Up @@ -60,7 +60,7 @@ data Command
| Verify (Maybe CacheFlag) PackageName

-- | Verify that the Package Set is correct
| VerifySet (Maybe CacheFlag)
| VerifySet (Maybe CacheFlag) CheckModulesUnique

-- | Test the project with some module, default Test.Main
| Test (Maybe ModuleName) BuildOptions [ExtraArg]
Expand Down Expand Up @@ -143,6 +143,7 @@ parser = do
openDocs = bool NoOpenDocs DoOpenDocs <$> CLI.switch "open" 'o' "Open generated documentation in browser (for HTML format only)"
noComments = bool WithComments NoComments <$> CLI.switch "no-comments" 'C' "Generate package.dhall and spago.dhall files without tutorial comments"
configPath = CLI.optional $ CLI.optText "config" 'x' "Optional config path to be used instead of the default spago.dhall"
chkModsUniq = bool DoCheckModulesUnique NoCheckModulesUnique <$> CLI.switch "no-check-modules-unique" 'M' "Skip checking whether modules names are unique across all packages."

mainModule = CLI.optional $ CLI.opt (Just . ModuleName) "main" 'm' "Module to be used as the application's entry point"
toTarget = CLI.optional $ CLI.opt (Just . TargetPath) "to" 't' "The target file path"
Expand Down Expand Up @@ -264,7 +265,7 @@ parser = do
verifySet =
( "verify-set"
, "Verify that the whole Package Set builds correctly"
, VerifySet <$> cacheFlag
, VerifySet <$> cacheFlag <*> chkModsUniq
)

upgradeSet =
Expand Down Expand Up @@ -338,8 +339,8 @@ main = do
Install cacheConfig packageNames -> Spago.Packages.install cacheConfig packageNames
ListPackages packagesFilter jsonFlag -> Spago.Packages.listPackages packagesFilter jsonFlag
Sources -> Spago.Packages.sources
Verify cacheConfig package -> Spago.Packages.verify cacheConfig (Just package)
VerifySet cacheConfig -> Spago.Packages.verify cacheConfig Nothing
Verify cacheConfig package -> Spago.Packages.verify cacheConfig NoCheckModulesUnique (Just package)
VerifySet cacheConfig chkModsUniq -> Spago.Packages.verify cacheConfig chkModsUniq Nothing
PackageSetUpgrade -> Spago.Packages.upgradePackageSet
Freeze -> Spago.Packages.freeze Spago.Packages.packagesPath
Build buildOptions -> Spago.Build.build buildOptions Nothing
Expand Down
22 changes: 19 additions & 3 deletions src/Spago/Packages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Spago.Packages
, PackageSet.freeze
, PackageSet.packagesPath
, PackagesFilter(..)
, CheckModulesUnique(..)
, JsonFlag(..)
, DepsOnly(..)
) where
Expand Down Expand Up @@ -306,13 +307,16 @@ sources = do
pure ()


verify :: Spago m => Maybe CacheFlag -> Maybe PackageName -> m ()
verify cacheFlag maybePackage = do
data CheckModulesUnique = DoCheckModulesUnique | NoCheckModulesUnique

verify :: Spago m => Maybe CacheFlag -> CheckModulesUnique -> Maybe PackageName -> m ()
verify cacheFlag chkModsUniq maybePackage = do
echoDebug "Running `spago verify`"
Config{ packageSet = packageSet@PackageSet{..}, ..} <- Config.ensureConfig
case maybePackage of
-- If no package is specified, verify all of them
Nothing -> verifyPackages packageSet (Map.toList packagesDB)
Nothing -> do
verifyPackages packageSet (Map.toList packagesDB)
-- In case we have a package, search in the package set for it
Just packageName -> do
case Map.lookup packageName packagesDB of
Expand All @@ -325,6 +329,9 @@ verify cacheFlag maybePackage = do
reverseDeps <- liftIO $ getReverseDeps packageSet packageName
let toVerify = [(packageName, package)] <> reverseDeps
verifyPackages packageSet toVerify
case chkModsUniq of
DoCheckModulesUnique -> compileEverything packageSet
NoCheckModulesUnique -> pure ()
where
verifyPackages :: Spago m => PackageSet -> [(PackageName, Package)] -> m ()
verifyPackages packageSet packages = do
Expand All @@ -340,3 +347,12 @@ verify cacheFlag maybePackage = do
echo $ "Verifying package " <> quotedName
Purs.compile globs []
echo $ "Successfully verified " <> quotedName

compileEverything :: Spago m => PackageSet -> m ()
compileEverything PackageSet{..} = do
let deps = Map.toList packagesDB
globs = getGlobs deps DepsOnly []
Fetch.fetchPackages cacheFlag deps packagesMinPursVersion
echo "Compiling everything (will fail if module names conflict)"
Purs.compile globs []
echo "Successfully compiled everything"