From df42c3099025bee7c79c7af49e6fb76e932308b7 Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Sun, 22 Sep 2019 13:48:29 +0100 Subject: [PATCH 1/8] Add --sharedOutput flag to Spago build command --- README.md | 2 ++ app/Spago.hs | 8 +++--- src/Spago/Build.hs | 54 ++++++++++++++++++++++++++++------------- src/Spago/PackageSet.hs | 29 +++++++++++++++++++++- test/SpagoSpec.hs | 43 ++++++++++++++++++++++++++++++++ 5 files changed, 114 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 909416840..af8ba707e 100644 --- a/README.md +++ b/README.md @@ -637,6 +637,8 @@ in upstream // overrides } ``` +To avoid building the same packages over and over, use `--sharedOutput` in `spago build` to use one `output` folder in the location of your root `packages.dhall` to speed up builds. + ### `devDependencies`, `testDependencies`, or in general a situation with many configurations You might have a simpler situation than a monorepo, where e.g. you just want to "split" dependencies. diff --git a/app/Spago.hs b/app/Spago.hs index 7d6be03bc..0d82e47dd 100644 --- a/app/Spago.hs +++ b/app/Spago.hs @@ -12,8 +12,8 @@ import qualified Turtle as CLI import Spago.Build (BuildOptions (..), DepsOnly (..), ExtraArg (..), ModuleName (..), NoBuild (..), NoInstall (..), NoSearch (..), - OpenDocs (..), SourcePath (..), TargetPath (..), Watch (..), - WithMain (..)) + OpenDocs (..), SourcePath (..), TargetPath (..), + UseSharedOutputFolder (..), Watch (..), WithMain (..)) import qualified Spago.Build import qualified Spago.Config as Config import Spago.Dhall (TemplateComments (..)) @@ -155,8 +155,8 @@ parser = do packageName = CLI.arg (Just . PackageName) "package" "Specify a package name. You can list them with `list-packages`" packageNames = many $ CLI.arg (Just . PackageName) "package" "Package name to add as dependency" pursArgs = many $ CLI.opt (Just . ExtraArg) "purs-args" 'u' "Argument to pass to purs" - - buildOptions = BuildOptions <$> cacheFlag <*> watch <*> clearScreen <*> sourcePaths <*> noInstall <*> pursArgs <*> depsOnly + useSharedOutput = bool NoSharedOutput UseSharedOutputFolder <$> CLI.switch "sharedOutput" 'S' "Use shared output folder in location of packages.dhall" + buildOptions = BuildOptions <$> cacheFlag <*> watch <*> clearScreen <*> sourcePaths <*> noInstall <*> pursArgs <*> depsOnly <*> useSharedOutput -- Note: by default we limit concurrency to 20 globalOptions = GlobalOptions <$> verbose <*> usePsa <*> fmap (fromMaybe 20) jobsLimit <*> fmap (fromMaybe Config.defaultPath) configPath diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index bd7a455c6..d738bdca8 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -10,6 +10,7 @@ module Spago.Build , Watch (..) , NoBuild (..) , NoInstall (..) + , UseSharedOutputFolder (..) , BuildOptions (..) , Packages.DepsOnly (..) , NoSearch (..) @@ -43,8 +44,8 @@ import qualified Spago.Purs as Purs import qualified Spago.Templates as Templates import qualified Spago.Watch as Watch -import Spago.Types as PackageSet - +import qualified Spago.PackageSet as PackageSet +import Spago.Types as Types data Watch = Watch | BuildOnce @@ -55,14 +56,18 @@ data NoBuild = NoBuild | DoBuild -- | Flag to skip the automatic installation of libraries on build data NoInstall = NoInstall | DoInstall +-- | Flag to use shared output folder if possible +data UseSharedOutputFolder = UseSharedOutputFolder | NoSharedOutput + data BuildOptions = BuildOptions - { cacheConfig :: Maybe GlobalCache.CacheFlag - , shouldWatch :: Watch - , shouldClear :: Watch.ClearScreen - , sourcePaths :: [Purs.SourcePath] - , noInstall :: NoInstall - , pursArgs :: [Purs.ExtraArg] - , depsOnly :: Packages.DepsOnly + { cacheConfig :: Maybe GlobalCache.CacheFlag + , shouldWatch :: Watch + , shouldClear :: Watch.ClearScreen + , sourcePaths :: [Purs.SourcePath] + , noInstall :: NoInstall + , pursArgs :: [Purs.ExtraArg] + , depsOnly :: Packages.DepsOnly + , sharedOutput :: UseSharedOutputFolder } prepareBundleDefaults @@ -74,25 +79,25 @@ prepareBundleDefaults maybeModuleName maybeTargetPath = (moduleName, targetPath) moduleName = fromMaybe (Purs.ModuleName "Main") maybeModuleName targetPath = fromMaybe (Purs.TargetPath "index.js") maybeTargetPath - --- | Build the project with purs, passing through additional args and -- eventually running some other action after the build build :: Spago m => BuildOptions -> Maybe (m ()) -> m () build BuildOptions{..} maybePostBuild = do echoDebug "Running `spago build`" - config@Config.Config{ packageSet = PackageSet.PackageSet{..}, ..} <- Config.ensureConfig + config@Config.Config{ packageSet = Types.PackageSet{..}, ..} <- Config.ensureConfig deps <- Packages.getProjectDeps config case noInstall of DoInstall -> Fetch.fetchPackages cacheConfig deps packagesMinPursVersion NoInstall -> pure () - + sharedOutputArgs <- case sharedOutput of + UseSharedOutputFolder -> getBuildArgsForSharedFolder + NoSharedOutput -> pure [] let allPsGlobs = Packages.getGlobs deps depsOnly configSourcePaths <> sourcePaths allJsGlobs = Packages.getJsGlobs deps depsOnly configSourcePaths <> sourcePaths buildAction globs = do case alternateBackend of Nothing -> - Purs.compile globs pursArgs + Purs.compile globs (pursArgs <> sharedOutputArgs) Just backend -> do when (Purs.ExtraArg "--codegen" `List.elem` pursArgs) $ die "Can't pass `--codegen` option to build when using a backend. Hint: No need to pass `--codegen corefn` explicitly when using the `backend` option. Remove the argument to solve the error" @@ -133,12 +138,11 @@ build BuildOptions{..} maybePostBuild = do wrap = Purs.SourcePath . Text.pack unwrap = Text.unpack . Purs.unSourcePath - -- | Start a repl repl :: Spago m => Maybe GlobalCache.CacheFlag - -> [PackageSet.PackageName] + -> [Types.PackageName] -> [Purs.SourcePath] -> [Purs.ExtraArg] -> Packages.DepsOnly @@ -159,7 +163,7 @@ repl cacheFlag newPackages sourcePaths pursArgs depsOnly = do Packages.initProject False Dhall.WithComments - config@Config.Config{ packageSet = PackageSet.PackageSet{..}, ..} <- Config.ensureConfig + config@Config.Config{ packageSet = Types.PackageSet{..}, ..} <- Config.ensureConfig let updatedConfig = Config.Config name (dependencies <> newPackages) (Config.packageSet config) alternateBackend configSourcePaths publishConfig @@ -319,3 +323,19 @@ search = do let cmd = "node .spago/purescript-docs-search search" echoDebug $ "Running `" <> cmd <> "`" viewShell $ callCommand $ Text.unpack cmd + +-- | If we are using the --sharedOutput flag, calculate the extra args to +-- | send to Purs compile +getBuildArgsForSharedFolder + :: Spago m + => m [Purs.ExtraArg] +getBuildArgsForSharedFolder = do + configPath <- asks globalConfigPath + outputFolder <- PackageSet.findRootOutputPath (Text.unpack configPath) + case pathToOutputArg <$> outputFolder of + Just newArg -> pure [newArg] + _ -> pure [] + +-- | Take root output path and turn it into Purs argument +pathToOutputArg :: String -> Purs.ExtraArg +pathToOutputArg = Purs.ExtraArg . Text.pack . ((++) "-o ") diff --git a/src/Spago/PackageSet.hs b/src/Spago/PackageSet.hs index fb998ac29..03118fc04 100644 --- a/src/Spago/PackageSet.hs +++ b/src/Spago/PackageSet.hs @@ -5,6 +5,7 @@ module Spago.PackageSet , freeze , ensureFrozen , packagesPath + , findRootOutputPath ) where import Spago.Prelude @@ -20,7 +21,7 @@ import Spago.Messages as Messages import qualified Spago.Purs as Purs import qualified Spago.Templates as Templates import qualified System.IO - +import qualified System.FilePath packagesPath :: IsString t => t packagesPath = "packages.dhall" @@ -219,6 +220,32 @@ localImportPath (Dhall.Import }) = Just $ Text.unpack $ pretty localImport localImportPath _ = Nothing +-- | In a Monorepo we don't wish to rebuild our shared packages over and over, +-- | so we build into an output folder at the highest point +-- | (where, hopefully, packages.dhall lives) +findRootOutputPath :: Spago m => System.IO.FilePath -> m (Maybe System.IO.FilePath) +findRootOutputPath path = do + echoDebug "Locating root path of packages.dhall" + imports <- liftIO $ Dhall.readImports $ Text.pack path + let localImports = catMaybes (map localImportPath imports) + pure $ (flip System.FilePath.replaceFileName) "output" <$> (findRootPath localImports) + +-- | Given a list of filepaths, find the one with the least folders +findRootPath :: [System.IO.FilePath] -> Maybe System.IO.FilePath +findRootPath paths + = foldr comparePaths Nothing paths + where + isLessThan :: Ord a => a -> Maybe a -> Bool + isLessThan a maybeA + = isNothing maybeA + || fromMaybe False (fmap (\a' -> a < a') maybeA) + + comparePaths path current + = if isLessThan + (length (System.FilePath.splitSearchPath path)) + (length <$> current) + then Just path + else current -- | Freeze the package set remote imports so they will be cached freeze :: Spago m => System.IO.FilePath -> m () diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 91ad3e402..4f53a825f 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -271,6 +271,49 @@ spec = around_ setup $ do spago ["install"] >>= shouldBeSuccess mv "spago.dhall" "spago-configV2.dhall" checkFixture "spago-configV2.dhall" + + it "Spago should create a local output folder when we are not using --sharedOutput" $ do + + -- Create root-level packages.dhall + mkdir "monorepo" + cd "monorepo" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + + -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) + mkdir "lib-a" + cd "lib-a" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../packages.dhall" + spago ["build"] >>= shouldBeSuccess + testdir "output" >>= (`shouldBe` True) + + cd ".." + testdir "output" >>= (`shouldBe` False) + + it "Spago should create an output folder in the root when we are using --sharedOutput" $ do + + -- Create root-level packages.dhall + mkdir "monorepo2" + cd "monorepo2" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + + -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) + mkdir "lib-a" + cd "lib-a" + spago ["init"] >>= shouldBeSuccess + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../packages.dhall" + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + spago ["build", "--sharedOutput"] >>= shouldBeSuccess + + cd ".." + testdir "output" >>= (`shouldBe` True) describe "alternate backend" $ do From 2440600881b73f4165ce5c9958c5235e5d5fafa8 Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Sun, 22 Sep 2019 13:55:59 +0100 Subject: [PATCH 2/8] Update changelog and docs --- CHANGELOG.md | 1 + README.md | 2 +- test/SpagoSpec.hs | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4897daccf..85281487a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) +- Add shared output folder to reduce build duplication. Pass `--no-share-output` flag to `spago build` to disable (#377) Bugfixes: - Warn (but don't error) when trying to watch missing directories (#406) diff --git a/README.md b/README.md index af8ba707e..601d54538 100644 --- a/README.md +++ b/README.md @@ -637,7 +637,7 @@ in upstream // overrides } ``` -To avoid building the same packages over and over, use `--sharedOutput` in `spago build` to use one `output` folder in the location of your root `packages.dhall` to speed up builds. +To avoid building the same packages over and over, use `--sharedOutput` in `spago build` to use one `output` folder in the location of your root `packages.dhall` to speed up builds. In the example above, this would create an `output` folder in the root, instead of ending up with `lib1/output`, `lib2/output` etc. ### `devDependencies`, `testDependencies`, or in general a situation with many configurations diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 4f53a825f..2ae6409f6 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -311,6 +311,7 @@ spec = around_ setup $ do rm "spago.dhall" writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" spago ["build", "--sharedOutput"] >>= shouldBeSuccess + testdir "output" >>= (`shouldBe` False) cd ".." testdir "output" >>= (`shouldBe` True) From 2c377dc9be6b56b3f30f3c834a590848b468be07 Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Mon, 23 Sep 2019 19:56:29 +0100 Subject: [PATCH 3/8] Name changes and check for output args WIP Remove garbage Remove yarn.lock Remove package.json Fixed --- app/Spago.hs | 6 +- src/Spago/Build.hs | 59 +++++++++++-------- src/Spago/PackageSet.hs | 18 ++++-- test/SpagoSpec.hs | 50 ++++++++++++++-- test/fixtures/run-no-psa.txt | 3 +- .../fixtures/run-output-psa-not-installed.txt | 3 +- test/fixtures/run-output.txt | 3 +- 7 files changed, 102 insertions(+), 40 deletions(-) diff --git a/app/Spago.hs b/app/Spago.hs index 0d82e47dd..fdb5ab575 100644 --- a/app/Spago.hs +++ b/app/Spago.hs @@ -12,8 +12,8 @@ import qualified Turtle as CLI import Spago.Build (BuildOptions (..), DepsOnly (..), ExtraArg (..), ModuleName (..), NoBuild (..), NoInstall (..), NoSearch (..), - OpenDocs (..), SourcePath (..), TargetPath (..), - UseSharedOutputFolder (..), Watch (..), WithMain (..)) + OpenDocs (..), ShareOutput (..), SourcePath (..), + TargetPath (..), Watch (..), WithMain (..)) import qualified Spago.Build import qualified Spago.Config as Config import Spago.Dhall (TemplateComments (..)) @@ -155,7 +155,7 @@ parser = do packageName = CLI.arg (Just . PackageName) "package" "Specify a package name. You can list them with `list-packages`" packageNames = many $ CLI.arg (Just . PackageName) "package" "Package name to add as dependency" pursArgs = many $ CLI.opt (Just . ExtraArg) "purs-args" 'u' "Argument to pass to purs" - useSharedOutput = bool NoSharedOutput UseSharedOutputFolder <$> CLI.switch "sharedOutput" 'S' "Use shared output folder in location of packages.dhall" + useSharedOutput = bool ShareOutput NoShareOutput <$> CLI.switch "no-share-output" 'S' "Disabled using a shared output folder in location of root packages.dhall" buildOptions = BuildOptions <$> cacheFlag <*> watch <*> clearScreen <*> sourcePaths <*> noInstall <*> pursArgs <*> depsOnly <*> useSharedOutput -- Note: by default we limit concurrency to 20 diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index d738bdca8..ea42cdeaf 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -10,7 +10,7 @@ module Spago.Build , Watch (..) , NoBuild (..) , NoInstall (..) - , UseSharedOutputFolder (..) + , ShareOutput (..) , BuildOptions (..) , Packages.DepsOnly (..) , NoSearch (..) @@ -57,17 +57,17 @@ data NoBuild = NoBuild | DoBuild data NoInstall = NoInstall | DoInstall -- | Flag to use shared output folder if possible -data UseSharedOutputFolder = UseSharedOutputFolder | NoSharedOutput +data ShareOutput = ShareOutput | NoShareOutput data BuildOptions = BuildOptions - { cacheConfig :: Maybe GlobalCache.CacheFlag - , shouldWatch :: Watch - , shouldClear :: Watch.ClearScreen - , sourcePaths :: [Purs.SourcePath] - , noInstall :: NoInstall - , pursArgs :: [Purs.ExtraArg] - , depsOnly :: Packages.DepsOnly - , sharedOutput :: UseSharedOutputFolder + { cacheConfig :: Maybe GlobalCache.CacheFlag + , shouldWatch :: Watch + , shouldClear :: Watch.ClearScreen + , sourcePaths :: [Purs.SourcePath] + , noInstall :: NoInstall + , pursArgs :: [Purs.ExtraArg] + , depsOnly :: Packages.DepsOnly + , shareOutput :: ShareOutput } prepareBundleDefaults @@ -88,16 +88,16 @@ build BuildOptions{..} maybePostBuild = do case noInstall of DoInstall -> Fetch.fetchPackages cacheConfig deps packagesMinPursVersion NoInstall -> pure () - sharedOutputArgs <- case sharedOutput of - UseSharedOutputFolder -> getBuildArgsForSharedFolder - NoSharedOutput -> pure [] + sharedOutputArgs <- case shareOutput of + ShareOutput -> getBuildArgsForSharedFolder pursArgs + NoShareOutput -> pure [] let allPsGlobs = Packages.getGlobs deps depsOnly configSourcePaths <> sourcePaths allJsGlobs = Packages.getJsGlobs deps depsOnly configSourcePaths <> sourcePaths buildAction globs = do case alternateBackend of Nothing -> - Purs.compile globs (pursArgs <> sharedOutputArgs) + Purs.compile globs sharedOutputArgs Just backend -> do when (Purs.ExtraArg "--codegen" `List.elem` pursArgs) $ die "Can't pass `--codegen` option to build when using a backend. Hint: No need to pass `--codegen corefn` explicitly when using the `backend` option. Remove the argument to solve the error" @@ -324,18 +324,25 @@ search = do echoDebug $ "Running `" <> cmd <> "`" viewShell $ callCommand $ Text.unpack cmd --- | If we are using the --sharedOutput flag, calculate the extra args to +-- | If we aren't using the --no-share-output flag, calculate the extra args to -- | send to Purs compile getBuildArgsForSharedFolder :: Spago m - => m [Purs.ExtraArg] -getBuildArgsForSharedFolder = do - configPath <- asks globalConfigPath - outputFolder <- PackageSet.findRootOutputPath (Text.unpack configPath) - case pathToOutputArg <$> outputFolder of - Just newArg -> pure [newArg] - _ -> pure [] - --- | Take root output path and turn it into Purs argument -pathToOutputArg :: String -> Purs.ExtraArg -pathToOutputArg = Purs.ExtraArg . Text.pack . ((++) "-o ") + => [Purs.ExtraArg] + -> m [Purs.ExtraArg] +getBuildArgsForSharedFolder pursArgs = do + let pathToOutputArg + = Purs.ExtraArg . Text.pack . ((++) "--output ") + containsOutputRule (Purs.ExtraArg a) + = Text.isInfixOf "--output" a + || Text.isInfixOf "-o" a + if (or $ containsOutputRule <$> pursArgs) + then do + echo "Output path set explicitly - not using shared output path" + pure pursArgs + else do + configPath <- asks globalConfigPath + outputFolder <- PackageSet.findRootOutputPath (Text.unpack configPath) + case pathToOutputArg <$> outputFolder of + Just newArg -> pure (pursArgs <> [newArg]) + _ -> pure pursArgs diff --git a/src/Spago/PackageSet.hs b/src/Spago/PackageSet.hs index 03118fc04..c0fbd1493 100644 --- a/src/Spago/PackageSet.hs +++ b/src/Spago/PackageSet.hs @@ -220,14 +220,24 @@ localImportPath (Dhall.Import }) = Just $ Text.unpack $ pretty localImport localImportPath _ = Nothing + +rootPackagePath :: Dhall.Import -> Maybe System.IO.FilePath +rootPackagePath (Dhall.Import + { importHashed = Dhall.ImportHashed + { importType = localImport@(Dhall.Local _ Dhall.File { file = "packages.dhall" }) + } + , Dhall.importMode = Dhall.Code + }) = Just $ Text.unpack $ pretty localImport +rootPackagePath _ = Nothing + + -- | In a Monorepo we don't wish to rebuild our shared packages over and over, --- | so we build into an output folder at the highest point --- | (where, hopefully, packages.dhall lives) +-- | so we build into an output folder where our root packages.dhall lives findRootOutputPath :: Spago m => System.IO.FilePath -> m (Maybe System.IO.FilePath) findRootOutputPath path = do echoDebug "Locating root path of packages.dhall" imports <- liftIO $ Dhall.readImports $ Text.pack path - let localImports = catMaybes (map localImportPath imports) + let localImports = catMaybes (map rootPackagePath imports) pure $ (flip System.FilePath.replaceFileName) "output" <$> (findRootPath localImports) -- | Given a list of filepaths, find the one with the least folders @@ -239,7 +249,7 @@ findRootPath paths isLessThan a maybeA = isNothing maybeA || fromMaybe False (fmap (\a' -> a < a') maybeA) - + comparePaths path current = if isLessThan (length (System.FilePath.splitSearchPath path)) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 2ae6409f6..e61a4a044 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -271,8 +271,8 @@ spec = around_ setup $ do spago ["install"] >>= shouldBeSuccess mv "spago.dhall" "spago-configV2.dhall" checkFixture "spago-configV2.dhall" - - it "Spago should create a local output folder when we are not using --sharedOutput" $ do + + it "Spago should create a local output folder when we are using --no-share-output" $ do -- Create root-level packages.dhall mkdir "monorepo" @@ -288,13 +288,55 @@ spec = around_ setup $ do writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" rm "packages.dhall" writeTextFile "packages.dhall" $ "../packages.dhall" + spago ["build", "--no-share-output"] >>= shouldBeSuccess + testdir "output" >>= (`shouldBe` True) + + cd ".." + testdir "output" >>= (`shouldBe` False) + + it "Spago should find the middle packages.dhall even when another file is further up the tree" $ do + + -- Create root-level module to confuse things + mkdir "monorepo-root" + cd "monorepo-root" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-extra\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + + -- get rid of duplicate Main module + cd "src" + rm "Main.purs" + writeTextFile "Main.purs" $ "module OtherMain where \n import Prelude\n import Effect\n main :: Effect Unit\n main = pure unit" + cd ".." + + -- create real root + mkdir "subfolder" + cd "subfolder" + spago ["init"] >>= shouldBeSuccess + packageDhall <- readTextFile "packages.dhall" + writeTextFile "packages.dhall" $ packageDhall <> " // { lib-extra = ../spago.dhall as Location }" + + -- Create local 'lib-a' package that uses packages.dhall in middle folder + mkdir "lib-a" + cd "lib-a" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"lib-extra\",\"console\", \"effect\", \"prelude\"], packages = ../packages.dhall }" + rm "packages.dhall" spago ["build"] >>= shouldBeSuccess + + -- don't use nested folder + testdir "output" >>= (`shouldBe` False) + + -- use middle one + cd ".." testdir "output" >>= (`shouldBe` True) + -- not the trick root folder cd ".." testdir "output" >>= (`shouldBe` False) - it "Spago should create an output folder in the root when we are using --sharedOutput" $ do + it "Spago should create an output folder in the root when we are not passing --no-share-output" $ do -- Create root-level packages.dhall mkdir "monorepo2" @@ -310,7 +352,7 @@ spec = around_ setup $ do writeTextFile "packages.dhall" $ "../packages.dhall" rm "spago.dhall" writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" - spago ["build", "--sharedOutput"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess testdir "output" >>= (`shouldBe` False) cd ".." diff --git a/test/fixtures/run-no-psa.txt b/test/fixtures/run-no-psa.txt index 5bc6f3f1e..4fc58f6d4 100644 --- a/test/fixtures/run-no-psa.txt +++ b/test/fixtures/run-no-psa.txt @@ -8,7 +8,8 @@ Running `fetchPackages` Checking if `purs` is up to date Running `getGlobalCacheDir` Installation complete. +Locating root path of packages.dhall Compiling with "purs" -Running command: `purs compile ".spago/console/v4.2.0/src/**/*.purs" ".spago/effect/v2.0.1/src/**/*.purs" ".spago/prelude/v4.1.1/src/**/*.purs" ".spago/psci-support/v4.0.0/src/**/*.purs" "src/**/*.purs" "test/**/*.purs"` +Running command: `purs compile --output ./output ".spago/console/v4.2.0/src/**/*.purs" ".spago/effect/v2.0.1/src/**/*.purs" ".spago/prelude/v4.1.1/src/**/*.purs" ".spago/psci-support/v4.0.0/src/**/*.purs" "src/**/*.purs" "test/**/*.purs"` Build succeeded. Writing .spago/run.js diff --git a/test/fixtures/run-output-psa-not-installed.txt b/test/fixtures/run-output-psa-not-installed.txt index 5bc6f3f1e..4fc58f6d4 100644 --- a/test/fixtures/run-output-psa-not-installed.txt +++ b/test/fixtures/run-output-psa-not-installed.txt @@ -8,7 +8,8 @@ Running `fetchPackages` Checking if `purs` is up to date Running `getGlobalCacheDir` Installation complete. +Locating root path of packages.dhall Compiling with "purs" -Running command: `purs compile ".spago/console/v4.2.0/src/**/*.purs" ".spago/effect/v2.0.1/src/**/*.purs" ".spago/prelude/v4.1.1/src/**/*.purs" ".spago/psci-support/v4.0.0/src/**/*.purs" "src/**/*.purs" "test/**/*.purs"` +Running command: `purs compile --output ./output ".spago/console/v4.2.0/src/**/*.purs" ".spago/effect/v2.0.1/src/**/*.purs" ".spago/prelude/v4.1.1/src/**/*.purs" ".spago/psci-support/v4.0.0/src/**/*.purs" "src/**/*.purs" "test/**/*.purs"` Build succeeded. Writing .spago/run.js diff --git a/test/fixtures/run-output.txt b/test/fixtures/run-output.txt index 5b0f20585..da327c210 100644 --- a/test/fixtures/run-output.txt +++ b/test/fixtures/run-output.txt @@ -8,7 +8,8 @@ Running `fetchPackages` Checking if `purs` is up to date Running `getGlobalCacheDir` Installation complete. +Locating root path of packages.dhall Compiling with "psa" -Running command: `psa compile ".spago/console/v4.2.0/src/**/*.purs" ".spago/effect/v2.0.1/src/**/*.purs" ".spago/prelude/v4.1.1/src/**/*.purs" ".spago/psci-support/v4.0.0/src/**/*.purs" "src/**/*.purs" "test/**/*.purs"` +Running command: `psa compile --output ./output ".spago/console/v4.2.0/src/**/*.purs" ".spago/effect/v2.0.1/src/**/*.purs" ".spago/prelude/v4.1.1/src/**/*.purs" ".spago/psci-support/v4.0.0/src/**/*.purs" "src/**/*.purs" "test/**/*.purs"` Build succeeded. Writing .spago/run.js From a8065fa6da257a15c74e8dbbe5eb5db42b46d729 Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Thu, 26 Sep 2019 01:09:02 +0100 Subject: [PATCH 4/8] Update docs --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 601d54538..21a34f1ba 100644 --- a/README.md +++ b/README.md @@ -637,7 +637,9 @@ in upstream // overrides } ``` -To avoid building the same packages over and over, use `--sharedOutput` in `spago build` to use one `output` folder in the location of your root `packages.dhall` to speed up builds. In the example above, this would create an `output` folder in the root, instead of ending up with `lib1/output`, `lib2/output` etc. +To avoid building the same packages over, a shared `output` folder will be created next to your root `packages.dhall`. + +To disable this behaviour, pass `--no-share-output` to `spago build`. ### `devDependencies`, `testDependencies`, or in general a situation with many configurations From e9fe063225eb80875b95d6f2e9dfd54af1d22a32 Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Tue, 1 Oct 2019 08:19:07 +0100 Subject: [PATCH 5/8] Add additional test for peace of mind --- test/SpagoSpec.hs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index e61a4a044..97d0ecd1a 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -294,6 +294,42 @@ spec = around_ setup $ do cd ".." testdir "output" >>= (`shouldBe` False) + it "Spago should use the main packages.dhall even when another packages.dhall is further up the tree" $ do + + -- Create root-level packages.dhall that directs to middle one + mkdir "monorepo-1" + cd "monorepo-1" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "./monorepo-2/packages.dhall" + + -- Create local 'monorepo-2' package that is the real root + mkdir "monorepo-2" + cd "monorepo-2" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + spago ["build", "--no-share-output"] >>= shouldBeSuccess + testdir "output" >>= (`shouldBe` True) + + -- Create local 'monorepo-3' package that uses packages.dhall on top level + mkdir "monorepo-3" + cd "monorepo-3" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../../packages.dhall" + spago ["build"] >>= shouldBeSuccess + testdir "output" >>= (`shouldBe` False) + + cd ".." + testdir "output" >>= (`shouldBe` True) + + cd ".." + testdir "output" >>= (`shouldBe` False) + it "Spago should find the middle packages.dhall even when another file is further up the tree" $ do -- Create root-level module to confuse things From a96e1687f071b5f8deea7dfa3505012c8d382e9f Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Wed, 2 Oct 2019 23:03:19 +0100 Subject: [PATCH 6/8] Find output path for tests --- src/Spago/Build.hs | 44 ++++++++++++------- test/SpagoSpec.hs | 21 +++++++++ test/fixtures/run-no-psa.txt | 1 + .../fixtures/run-output-psa-not-installed.txt | 1 + test/fixtures/run-output.txt | 1 + 5 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index ea42cdeaf..dffa7b049 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -81,7 +81,7 @@ prepareBundleDefaults maybeModuleName maybeTargetPath = (moduleName, targetPath) -- eventually running some other action after the build build :: Spago m => BuildOptions -> Maybe (m ()) -> m () -build BuildOptions{..} maybePostBuild = do +build buildOpts@BuildOptions{..} maybePostBuild = do echoDebug "Running `spago build`" config@Config.Config{ packageSet = Types.PackageSet{..}, ..} <- Config.ensureConfig deps <- Packages.getProjectDeps config @@ -89,7 +89,7 @@ build BuildOptions{..} maybePostBuild = do DoInstall -> Fetch.fetchPackages cacheConfig deps packagesMinPursVersion NoInstall -> pure () sharedOutputArgs <- case shareOutput of - ShareOutput -> getBuildArgsForSharedFolder pursArgs + ShareOutput -> getBuildArgsForSharedFolder buildOpts NoShareOutput -> pure [] let allPsGlobs = Packages.getGlobs deps depsOnly configSourcePaths <> sourcePaths allJsGlobs = Packages.getJsGlobs deps depsOnly configSourcePaths <> sourcePaths @@ -197,15 +197,18 @@ runWithNode -> m () runWithNode defaultModuleName maybeSuccessMessage failureMessage maybeModuleName buildOpts nodeArgs = do echoDebug "Running NodeJS" - build buildOpts (Just nodeAction) + outputPath <- getOutputPath buildOpts + build buildOpts (Just (nodeAction outputPath)) where moduleName = fromMaybe defaultModuleName maybeModuleName args = Text.intercalate " " $ map Purs.unExtraArg nodeArgs - contents = "#!/usr/bin/env node\n\n" <> "require('../output/" <> Purs.unModuleName moduleName <> "').main()" + contents = \outputPath' + -> let path = fromMaybe "output" outputPath' + in "#!/usr/bin/env node\n\n" <> "require('../" <> Text.pack path <> "/" <> Purs.unModuleName moduleName <> "').main()" cmd = "node .spago/run.js " <> args - nodeAction = do + nodeAction outputPath' = do echoDebug $ "Writing .spago/run.js" - writeTextFile ".spago/run.js" contents + writeTextFile ".spago/run.js" (contents outputPath') chmod executable ".spago/run.js" shell cmd empty >>= \case ExitSuccess -> fromMaybe (pure ()) (echo <$> maybeSuccessMessage) @@ -324,25 +327,36 @@ search = do echoDebug $ "Running `" <> cmd <> "`" viewShell $ callCommand $ Text.unpack cmd + +getOutputPath + :: Spago m + => BuildOptions + -> m (Maybe Sys.FilePath) +getOutputPath _ = do + + configPath <- asks globalConfigPath + PackageSet.findRootOutputPath (Text.unpack configPath) + -- | If we aren't using the --no-share-output flag, calculate the extra args to -- | send to Purs compile getBuildArgsForSharedFolder :: Spago m - => [Purs.ExtraArg] + => BuildOptions -> m [Purs.ExtraArg] -getBuildArgsForSharedFolder pursArgs = do - let pathToOutputArg +getBuildArgsForSharedFolder buildOpts = do + let pursArgs' + = pursArgs buildOpts + pathToOutputArg = Purs.ExtraArg . Text.pack . ((++) "--output ") containsOutputRule (Purs.ExtraArg a) = Text.isInfixOf "--output" a || Text.isInfixOf "-o" a - if (or $ containsOutputRule <$> pursArgs) + if (or $ containsOutputRule <$> pursArgs') then do echo "Output path set explicitly - not using shared output path" - pure pursArgs + pure pursArgs' else do - configPath <- asks globalConfigPath - outputFolder <- PackageSet.findRootOutputPath (Text.unpack configPath) + outputFolder <- getOutputPath buildOpts case pathToOutputArg <$> outputFolder of - Just newArg -> pure (pursArgs <> [newArg]) - _ -> pure pursArgs + Just newArg -> pure (pursArgs' <> [newArg]) + _ -> pure pursArgs' diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 97d0ecd1a..e41aa2480 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -429,6 +429,27 @@ spec = around_ setup $ do spago ["build"] >>= shouldBeSuccess spago ["test"] >>= shouldBeSuccessOutput "test-output.txt" + it "Spago should test successfully with a different output folder" $ do + + -- Create root-level packages.dhall + mkdir "monorepo" + cd "monorepo" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + + -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) + mkdir "lib-a" + cd "lib-a" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../packages.dhall" + spago ["test"] >>= shouldBeSuccess + testdir "output" >>= (`shouldBe` False) + + cd ".." + testdir "output" >>= (`shouldBe` True) describe "spago upgrade-set" $ do diff --git a/test/fixtures/run-no-psa.txt b/test/fixtures/run-no-psa.txt index 4fc58f6d4..2d8eb827c 100644 --- a/test/fixtures/run-no-psa.txt +++ b/test/fixtures/run-no-psa.txt @@ -1,5 +1,6 @@ 🍝 Running NodeJS +Locating root path of packages.dhall Running `spago build` Transformed config is the same as the read one, not overwriting it Ensuring that the package set is frozen diff --git a/test/fixtures/run-output-psa-not-installed.txt b/test/fixtures/run-output-psa-not-installed.txt index 4fc58f6d4..2d8eb827c 100644 --- a/test/fixtures/run-output-psa-not-installed.txt +++ b/test/fixtures/run-output-psa-not-installed.txt @@ -1,5 +1,6 @@ 🍝 Running NodeJS +Locating root path of packages.dhall Running `spago build` Transformed config is the same as the read one, not overwriting it Ensuring that the package set is frozen diff --git a/test/fixtures/run-output.txt b/test/fixtures/run-output.txt index da327c210..ce7a4c6f2 100644 --- a/test/fixtures/run-output.txt +++ b/test/fixtures/run-output.txt @@ -1,5 +1,6 @@ 🍝 Running NodeJS +Locating root path of packages.dhall Running `spago build` Transformed config is the same as the read one, not overwriting it Ensuring that the package set is frozen From fa6700bde5a08f2474cadd8b84b6175af09d2574 Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Wed, 2 Oct 2019 23:34:58 +0100 Subject: [PATCH 7/8] Find output folder for tests --- src/Spago/Build.hs | 21 ++++++++++++++++++--- test/SpagoSpec.hs | 29 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index dffa7b049..54f7158e5 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -332,10 +332,25 @@ getOutputPath :: Spago m => BuildOptions -> m (Maybe Sys.FilePath) -getOutputPath _ = do - +getOutputPath buildOpts = do configPath <- asks globalConfigPath - PackageSet.findRootOutputPath (Text.unpack configPath) + outputPath <- PackageSet.findRootOutputPath (Text.unpack configPath) + case findOutputFlag (pursArgs buildOpts) of + Just path -> pure (Just path) + Nothing -> + case shareOutput buildOpts of + NoShareOutput -> pure Nothing + ShareOutput -> pure outputPath + +findOutputFlag :: [Purs.ExtraArg] -> Maybe Sys.FilePath +findOutputFlag [] = Nothing +findOutputFlag (_:[]) = Nothing +findOutputFlag (x:y:xs) + = if ( Text.isInfixOf "-o" (Purs.unExtraArg x) + || Text.isInfixOf "--output" (Purs.unExtraArg x) + ) + then Just $ Text.unpack (Purs.unExtraArg y) + else findOutputFlag (y : xs) -- | If we aren't using the --no-share-output flag, calculate the extra args to -- | send to Purs compile diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index e41aa2480..9d0fee1cf 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -429,6 +429,12 @@ spec = around_ setup $ do spago ["build"] >>= shouldBeSuccess spago ["test"] >>= shouldBeSuccessOutput "test-output.txt" + it "Spago should test in custom output folder" $ do + + spago ["init"] >>= shouldBeSuccess + spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess + testdir "myOutput" >>= (`shouldBe` True) + it "Spago should test successfully with a different output folder" $ do -- Create root-level packages.dhall @@ -451,6 +457,29 @@ spec = around_ setup $ do cd ".." testdir "output" >>= (`shouldBe` True) + it "Spago should test successfully with --no-share-output" $ do + + -- Create root-level packages.dhall + mkdir "monorepo" + cd "monorepo" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + + -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) + mkdir "lib-a" + cd "lib-a" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../packages.dhall" + spago ["test", "--no-share-output"] >>= shouldBeSuccess + testdir "output" >>= (`shouldBe` True) + + cd ".." + testdir "output" >>= (`shouldBe` False) + + describe "spago upgrade-set" $ do it "Spago should migrate package-sets from src/packages.dhall to the released one" $ do From 0850ec01688335b0a417eb4a61d8e4038caf7df8 Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Thu, 3 Oct 2019 09:50:53 +0100 Subject: [PATCH 8/8] Fix test path and tidying --- src/Spago/Build.hs | 25 ++++++++++++++++++------- src/Spago/PackageSet.hs | 2 +- test/SpagoSpec.hs | 37 ++++++++++++++++++------------------- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 54f7158e5..7ddeddd03 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -328,6 +328,9 @@ search = do viewShell $ callCommand $ Text.unpack cmd +-- | Find the output path for purs compiler +-- | This is based on the location of packages.dhall, the shareOutput flag +-- | and whether the user has manually specified a path in pursArgs getOutputPath :: Spago m => BuildOptions @@ -342,16 +345,27 @@ getOutputPath buildOpts = do NoShareOutput -> pure Nothing ShareOutput -> pure outputPath +-- | Find an output flag and then return the next item +-- | which should be the output folder findOutputFlag :: [Purs.ExtraArg] -> Maybe Sys.FilePath findOutputFlag [] = Nothing findOutputFlag (_:[]) = Nothing findOutputFlag (x:y:xs) - = if ( Text.isInfixOf "-o" (Purs.unExtraArg x) - || Text.isInfixOf "--output" (Purs.unExtraArg x) - ) + = if isOutputFlag x then Just $ Text.unpack (Purs.unExtraArg y) else findOutputFlag (y : xs) +-- | is this argument specifying an output folder? +isOutputFlag :: Purs.ExtraArg -> Bool +isOutputFlag (Purs.ExtraArg a) + = firstWord == "-o" + || firstWord == "--output" + where + firstWord + = fromMaybe "" $ case Text.words a of + [] -> Nothing + (word:_) -> Just word + -- | If we aren't using the --no-share-output flag, calculate the extra args to -- | send to Purs compile getBuildArgsForSharedFolder @@ -363,10 +377,7 @@ getBuildArgsForSharedFolder buildOpts = do = pursArgs buildOpts pathToOutputArg = Purs.ExtraArg . Text.pack . ((++) "--output ") - containsOutputRule (Purs.ExtraArg a) - = Text.isInfixOf "--output" a - || Text.isInfixOf "-o" a - if (or $ containsOutputRule <$> pursArgs') + if (or $ isOutputFlag <$> pursArgs') then do echo "Output path set explicitly - not using shared output path" pure pursArgs' diff --git a/src/Spago/PackageSet.hs b/src/Spago/PackageSet.hs index c0fbd1493..fa0c34111 100644 --- a/src/Spago/PackageSet.hs +++ b/src/Spago/PackageSet.hs @@ -237,7 +237,7 @@ findRootOutputPath :: Spago m => System.IO.FilePath -> m (Maybe System.IO.FilePa findRootOutputPath path = do echoDebug "Locating root path of packages.dhall" imports <- liftIO $ Dhall.readImports $ Text.pack path - let localImports = catMaybes (map rootPackagePath imports) + let localImports = mapMaybe rootPackagePath imports pure $ (flip System.FilePath.replaceFileName) "output" <$> (findRootPath localImports) -- | Given a list of filepaths, find the one with the least folders diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 9d0fee1cf..18c36ee33 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -5,7 +5,7 @@ import qualified Data.Text as Text import Prelude hiding (FilePath) import qualified System.IO.Temp as Temp import Test.Hspec (Spec, around_, describe, it, shouldBe, shouldNotSatisfy, - shouldSatisfy) + shouldReturn, shouldSatisfy) import Turtle (ExitCode (..), cd, cp, decodeString, empty, mkdir, mktree, mv, readTextFile, rm, shell, shellStrictWithErr, testdir, writeTextFile) @@ -238,13 +238,13 @@ spec = around_ setup $ do spago ["init"] >>= shouldBeSuccess spago ["build", "--purs-args", "-o myOutput"] >>= shouldBeSuccess - testdir "myOutput" >>= (`shouldBe` True) + testdir "myOutput" `shouldReturn` True it "Spago should pass multiple options to purs" $ do spago ["init"] >>= shouldBeSuccess spago ["build", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess - testdir "myOutput" >>= (`shouldBe` True) + testdir "myOutput" `shouldReturn` True it "Spago should build successfully with sources included from custom path" $ do @@ -289,7 +289,7 @@ spec = around_ setup $ do rm "packages.dhall" writeTextFile "packages.dhall" $ "../packages.dhall" spago ["build", "--no-share-output"] >>= shouldBeSuccess - testdir "output" >>= (`shouldBe` True) + testdir "output" `shouldReturn` True cd ".." testdir "output" >>= (`shouldBe` False) @@ -311,7 +311,7 @@ spec = around_ setup $ do rm "spago.dhall" writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" spago ["build", "--no-share-output"] >>= shouldBeSuccess - testdir "output" >>= (`shouldBe` True) + testdir "output" `shouldReturn` True -- Create local 'monorepo-3' package that uses packages.dhall on top level mkdir "monorepo-3" @@ -322,13 +322,13 @@ spec = around_ setup $ do rm "packages.dhall" writeTextFile "packages.dhall" $ "../../packages.dhall" spago ["build"] >>= shouldBeSuccess - testdir "output" >>= (`shouldBe` False) + testdir "output" `shouldReturn` False cd ".." - testdir "output" >>= (`shouldBe` True) + testdir "output" `shouldReturn` True cd ".." - testdir "output" >>= (`shouldBe` False) + testdir "output" `shouldReturn` False it "Spago should find the middle packages.dhall even when another file is further up the tree" $ do @@ -362,15 +362,15 @@ spec = around_ setup $ do spago ["build"] >>= shouldBeSuccess -- don't use nested folder - testdir "output" >>= (`shouldBe` False) + testdir "output" `shouldReturn` False -- use middle one cd ".." - testdir "output" >>= (`shouldBe` True) + testdir "output" `shouldReturn` True -- not the trick root folder cd ".." - testdir "output" >>= (`shouldBe` False) + testdir "output" `shouldReturn` False it "Spago should create an output folder in the root when we are not passing --no-share-output" $ do @@ -389,10 +389,10 @@ spec = around_ setup $ do rm "spago.dhall" writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" spago ["build"] >>= shouldBeSuccess - testdir "output" >>= (`shouldBe` False) + testdir "output" `shouldReturn` False cd ".." - testdir "output" >>= (`shouldBe` True) + testdir "output" `shouldReturn` True describe "alternate backend" $ do @@ -402,7 +402,6 @@ spec = around_ setup $ do mv "spago.dhall" "spago-old.dhall" writeTextFile "spago.dhall" configWithBackend - spago ["build"] >>= shouldBeSuccess checkFixture "alternate-backend-output.txt" @@ -433,7 +432,7 @@ spec = around_ setup $ do spago ["init"] >>= shouldBeSuccess spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess - testdir "myOutput" >>= (`shouldBe` True) + testdir "myOutput" `shouldReturn` True it "Spago should test successfully with a different output folder" $ do @@ -452,10 +451,10 @@ spec = around_ setup $ do rm "packages.dhall" writeTextFile "packages.dhall" $ "../packages.dhall" spago ["test"] >>= shouldBeSuccess - testdir "output" >>= (`shouldBe` False) + testdir "output" `shouldReturn` False cd ".." - testdir "output" >>= (`shouldBe` True) + testdir "output" `shouldReturn` True it "Spago should test successfully with --no-share-output" $ do @@ -474,10 +473,10 @@ spec = around_ setup $ do rm "packages.dhall" writeTextFile "packages.dhall" $ "../packages.dhall" spago ["test", "--no-share-output"] >>= shouldBeSuccess - testdir "output" >>= (`shouldBe` True) + testdir "output" `shouldReturn` True cd ".." - testdir "output" >>= (`shouldBe` False) + testdir "output" `shouldReturn` False describe "spago upgrade-set" $ do