From 03e02403c8dbb8e2a717034b26b960ab70df4be7 Mon Sep 17 00:00:00 2001 From: justinwoo Date: Sun, 16 Jun 2019 14:46:52 +0200 Subject: [PATCH 1/5] add no-install flag for build to prevent automatic installation --- app/Spago.hs | 10 ++++++++-- src/Spago/Build.hs | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/Spago.hs b/app/Spago.hs index 8099e3e89..68f103171 100644 --- a/app/Spago.hs +++ b/app/Spago.hs @@ -12,7 +12,7 @@ import qualified Turtle as CLI import Spago.Build (BuildOptions (..), ExtraArg (..), ModuleName (..), NoBuild (..), SourcePath (..), TargetPath (..), Watch (..), - WithMain (..)) + WithMain (..), NoInstall (..)) import qualified Spago.Build import Spago.GlobalCache (CacheFlag (..)) import Spago.Messages as Messages @@ -114,6 +114,7 @@ parser = do force = CLI.switch "force" 'f' "Overwrite any project found in the current directory" verbose = CLI.switch "verbose" 'v' "Enable additional debug logging, e.g. printing `purs` commands" watchBool = CLI.switch "watch" 'w' "Watch for changes in local files and automatically rebuild" + noInstallBool = CLI.switch "no-install" 'n' "Don't run the automatic installation of packages" clearScreenBool = CLI.switch "clear-screen" 'l' "Clear the screen on rebuild (watch mode only)" noBuildBool = CLI.switch "no-build" 's' "Skip build step" watch = do @@ -121,6 +122,11 @@ parser = do pure $ case res of True -> Watch False -> BuildOnce + noInstall = do + res <- noInstallBool + pure $ case res of + True -> NoInstall + False -> DoInstall clearScreen = do res <- clearScreenBool pure $ case res of @@ -150,7 +156,7 @@ parser = do packageName = CLI.arg (Just . PackageName) "package" "Specify a package name. You can list them with `list-packages`" packageNames = CLI.many $ CLI.arg (Just . PackageName) "package" "Package name to add as dependency" passthroughArgs = many $ CLI.arg (Just . ExtraArg) " ..any `purs compile` option" "Options passed through to `purs compile`; use -- to separate" - buildOptions = BuildOptions <$> limitJobs <*> cacheFlag <*> watch <*> clearScreen <*> sourcePaths <*> passthroughArgs + buildOptions = BuildOptions <$> limitJobs <*> cacheFlag <*> watch <*> clearScreen <*> sourcePaths <*> noInstall <*> passthroughArgs globalOptions = GlobalOptions <$> verbose packagesFilter = let wrap = \case diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 14fa3fdbf..303faab68 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -8,6 +8,7 @@ module Spago.Build , docs , Watch (..) , NoBuild (..) + , NoInstall (..) , BuildOptions (..) , Purs.ExtraArg (..) , Purs.ModuleName (..) @@ -37,12 +38,16 @@ data Watch = Watch | BuildOnce -- or skip it, in the case of 'bundleApp' and 'bundleModule'. data NoBuild = NoBuild | DoBuild +-- | Flag to skip the automatic installation of libraries on build +data NoInstall = NoInstall | DoInstall + data BuildOptions = BuildOptions { maybeLimit :: Maybe Int , cacheConfig :: Maybe GlobalCache.CacheFlag , shouldWatch :: Watch , shouldClear :: Watch.ClearScreen , sourcePaths :: [Purs.SourcePath] + , noInstall :: NoInstall , passthroughArgs :: [Purs.ExtraArg] } @@ -63,7 +68,9 @@ build BuildOptions{..} maybePostBuild = do echoDebug "Running `spago build`" config@Config.Config{ packageSet = PackageSet.PackageSet{..}, ..} <- Config.ensureConfig deps <- Packages.getProjectDeps config - Fetch.fetchPackages maybeLimit cacheConfig deps packagesMinPursVersion + case noInstall of + DoInstall -> Fetch.fetchPackages maybeLimit cacheConfig deps packagesMinPursVersion + NoInstall -> pure () let projectGlobs = configSourcePaths <> sourcePaths allGlobs = Packages.getGlobs deps <> projectGlobs buildAction = do From 5ce8183ff096961a8e4f61cbbcdfd6ec6d1565cb Mon Sep 17 00:00:00 2001 From: Fabrizio Ferrai Date: Mon, 17 Jun 2019 10:45:44 +0200 Subject: [PATCH 2/5] Try to comment the test --- test/SpagoSpec.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index f4bb16ae9..fd011fa59 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -133,16 +133,16 @@ spec = around_ setup $ do mv "src/Main.purs" "another_source_path/Main.purs" spago ["build", "--path", "another_source_path/*.purs"] >>= shouldBeSuccess - it "Spago should add sources to config when key is missing" $ do + -- it "Spago should add sources to config when key is missing" $ do - configV1 <- readFixture "spago-configV1.dhall" - spago ["init"] >>= shouldBeSuccess - -- Replace initial config with the old config format (without 'sources') - writeTextFile "spago.dhall" configV1 + -- configV1 <- readFixture "spago-configV1.dhall" + -- spago ["init"] >>= shouldBeSuccess + -- -- Replace initial config with the old config format (without 'sources') + -- writeTextFile "spago.dhall" configV1 - spago ["build"] >>= shouldBeSuccess - mv "spago.dhall" "spago-configV2.dhall" - checkFixture "spago-configV2.dhall" + -- spago ["build"] >>= shouldBeSuccess + -- mv "spago.dhall" "spago-configV2.dhall" + -- checkFixture "spago-configV2.dhall" describe "spago test" $ do From 1a06005393c140280012a8097ef1076b05af060a Mon Sep 17 00:00:00 2001 From: Fabrizio Ferrai Date: Mon, 17 Jun 2019 11:00:47 +0200 Subject: [PATCH 3/5] Add test for the feature --- test/SpagoSpec.hs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index fd011fa59..2dc93925b 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -133,16 +133,23 @@ spec = around_ setup $ do mv "src/Main.purs" "another_source_path/Main.purs" spago ["build", "--path", "another_source_path/*.purs"] >>= shouldBeSuccess - -- it "Spago should add sources to config when key is missing" $ do + it "Spago should not install packages when passing the --no-install flag" - -- configV1 <- readFixture "spago-configV1.dhall" - -- spago ["init"] >>= shouldBeSuccess - -- -- Replace initial config with the old config format (without 'sources') - -- writeTextFile "spago.dhall" configV1 + spago ["init"] >>= shouldBeSuccess + spago ["build", "--no-install"] >>= shouldBeFailure + spago ["install"] >>= shouldBeSuccess + spago ["build", "--no-install"] >>= shouldBeSuccess + + it "Spago should add sources to config when key is missing" $ do - -- spago ["build"] >>= shouldBeSuccess - -- mv "spago.dhall" "spago-configV2.dhall" - -- checkFixture "spago-configV2.dhall" + configV1 <- readFixture "spago-configV1.dhall" + spago ["init"] >>= shouldBeSuccess + -- Replace initial config with the old config format (without 'sources') + writeTextFile "spago.dhall" configV1 + + spago ["build"] >>= shouldBeSuccess + mv "spago.dhall" "spago-configV2.dhall" + checkFixture "spago-configV2.dhall" describe "spago test" $ do From 5d992b10a263edf9eab9e0703031cabe0f486170 Mon Sep 17 00:00:00 2001 From: Fabrizio Ferrai Date: Mon, 17 Jun 2019 11:09:55 +0200 Subject: [PATCH 4/5] Fix typo --- test/SpagoSpec.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 2dc93925b..c9b61f917 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -133,7 +133,7 @@ spec = around_ setup $ do mv "src/Main.purs" "another_source_path/Main.purs" spago ["build", "--path", "another_source_path/*.purs"] >>= shouldBeSuccess - it "Spago should not install packages when passing the --no-install flag" + it "Spago should not install packages when passing the --no-install flag" $ do spago ["init"] >>= shouldBeSuccess spago ["build", "--no-install"] >>= shouldBeFailure From 5a3d68eb26c198b102ca322af9652cdcc9bb648d Mon Sep 17 00:00:00 2001 From: Fabrizio Ferrai Date: Mon, 17 Jun 2019 14:50:07 +0200 Subject: [PATCH 5/5] Maybe? --- test/SpagoSpec.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index c9b61f917..66ca6b629 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -145,9 +145,10 @@ spec = around_ setup $ do configV1 <- readFixture "spago-configV1.dhall" spago ["init"] >>= shouldBeSuccess -- Replace initial config with the old config format (without 'sources') + mv "spago.dhall" "spago-old.dhall" writeTextFile "spago.dhall" configV1 - spago ["build"] >>= shouldBeSuccess + spago ["install"] >>= shouldBeSuccess mv "spago.dhall" "spago-configV2.dhall" checkFixture "spago-configV2.dhall"