Skip to content

Commit a54c549

Browse files
committed
Add the --only-locals flag (closes #5272)
1 parent 2de25b0 commit a54c549

File tree

9 files changed

+72
-4
lines changed

9 files changed

+72
-4
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Other enhancements:
6464
* Allow relative paths in `--setup-info-yaml` and tool paths
6565
[#3394](https://github.com/commercialhaskell/stack/issues/3394)
6666

67+
* Added the `--only-locals` flag. See
68+
[#5272](https://github.com/commercialhaskell/stack/issues/5272)
69+
6770
Bug fixes:
6871

6972
* Upgrade `pantry`: module mapping insertions into the database are now atomic.

src/Stack/Build/ConstructPlan.hs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,11 @@ constructPlan baseConfigOpts0 localDumpPkgs loadPackage0 sourceMap installedMap
203203
tasks = M.fromList $ mapMaybe toTask adrs
204204
takeSubset =
205205
case boptsCLIBuildSubset $ bcoBuildOptsCLI baseConfigOpts0 of
206-
BSAll -> id
207-
BSOnlySnapshot -> stripLocals
208-
BSOnlyDependencies -> stripNonDeps (M.keysSet $ smDeps sourceMap)
209-
return $ takeSubset Plan
206+
BSAll -> pure
207+
BSOnlySnapshot -> pure . stripLocals
208+
BSOnlyDependencies -> pure . stripNonDeps (M.keysSet $ smDeps sourceMap)
209+
BSOnlyLocals -> errorOnSnapshot
210+
takeSubset Plan
210211
{ planTasks = tasks
211212
, planFinals = M.fromList finals
212213
, planUnregisterLocal = mkUnregisterLocal tasks dirtyReason localDumpPkgs initialBuildSteps
@@ -267,6 +268,33 @@ constructPlan baseConfigOpts0 localDumpPkgs loadPackage0 sourceMap installedMap
267268
return $ PSFilePath lp
268269
return $ pPackages <> deps
269270

271+
-- | Throw an exception if there are any snapshot packages in the plan.
272+
errorOnSnapshot :: Plan -> RIO env Plan
273+
errorOnSnapshot plan@(Plan tasks _finals _unregister installExes) = do
274+
let snapTasks = Map.keys $ Map.filter (\t -> taskLocation t == Snap) tasks
275+
let snapExes = Map.keys $ Map.filter (== Snap) installExes
276+
unless (null snapTasks && null snapExes) $ throwIO $
277+
NotOnlyLocal snapTasks snapExes
278+
pure plan
279+
280+
data NotOnlyLocal = NotOnlyLocal [PackageName] [Text]
281+
282+
instance Show NotOnlyLocal where
283+
show (NotOnlyLocal packages exes) = concat
284+
[ "Specified only-locals, but I need to build snapshot contents:\n"
285+
, if null packages then "" else concat
286+
[ "Packages: "
287+
, intercalate ", " (map packageNameString packages)
288+
, "\n"
289+
]
290+
, if null exes then "" else concat
291+
[ "Executables: "
292+
, intercalate ", " (map T.unpack exes)
293+
, "\n"
294+
]
295+
]
296+
instance Exception NotOnlyLocal
297+
270298
-- | State to be maintained during the calculation of local packages
271299
-- to unregister.
272300
data UnregisterState = UnregisterState

src/Stack/Options/BuildParser.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ buildOptsParser cmd =
5454
(long "only-dependencies" <>
5555
help
5656
"Only build packages that are dependencies of targets on the command line") <|>
57+
flag'
58+
BSOnlyLocals
59+
(long "only-locals" <>
60+
help
61+
"Only build packages in the local database, fail if the build plan includes the snapshot database") <|>
5762
pure BSAll) <*>
5863
(flag'
5964
FileWatch

src/Stack/Types/Config/Build.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ data BuildSubset
339339
-- ^ Only install packages in the snapshot database, skipping
340340
-- packages intended for the local database.
341341
| BSOnlyDependencies
342+
| BSOnlyLocals
343+
-- ^ Refuse to build anything in the snapshot database, see
344+
-- https://github.com/commercialhaskell/stack/issues/5272
342345
deriving (Show, Eq)
343346

344347
-- | Options for the 'FinalAction' 'DoTests'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import StackTest
2+
import Control.Monad (void)
3+
4+
main :: IO ()
5+
main = do
6+
void $ stack' ["exec", "ghc-pkg", "unregister", "unliftio-core"]
7+
stack ["clean"]
8+
9+
stackErr ["build", "--only-locals"]
10+
stack ["build", "--only-snapshot"]
11+
stack ["build", "--only-locals"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo.cabal
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: foo
2+
version: 0.0.0
3+
4+
dependencies:
5+
- base
6+
- unliftio-core
7+
8+
library:
9+
source-dirs: src/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Foo () where
2+
3+
import Control.Monad.IO.Unlift ()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resolver: ghc-8.6.5
2+
extra-deps:
3+
- unliftio-core-0.1.2.0@rev:2
4+
# Force a unique snapshot
5+
- acme-missiles-0.3@rev:0

0 commit comments

Comments
 (0)