@@ -46,6 +46,8 @@ import Stack.Types.BuildOptsCLI ( ApplyCLIFlag (..) )
4646import Stack.Types.Config ( Config (.. ), HasConfig (.. ), buildOptsL )
4747import Stack.Types.EnvConfig
4848 ( EnvConfig (.. ), HasEnvConfig (.. ), actualCompilerVersionL )
49+ import Stack.Types.Build.FileTargets
50+ ( FileTarget (.. ), unionFileTargets )
4951import Stack.Types.GhciPkg
5052 ( GhciPkgDesc (.. ), GhciPkgInfo (.. ), unionModuleMaps )
5153import Stack.Types.Installed ( InstallMap , InstalledMap )
@@ -75,20 +77,44 @@ findFileTargets ::
7577 -- ^ File targets to find
7678 -> RIO
7779 env
78- ( Map PackageName Target
79- , Maybe (Map PackageName [Path Abs File ], [Path Abs File ])
80+ ( Map PackageName FileTarget
81+ , Maybe
82+ ( Map PackageName [Path Abs File ]
83+ -- Dictionary of project package names and lists of file targets
84+ -- associated with the package.
85+ , [Path Abs File ]
86+ -- List of file targets not associated with any project package.
87+ )
8088 )
8189findFileTargets locals fileTargets = do
8290 filePackages <- forM locals $ \ lp -> do
8391 PackageComponentFile _ compFiles _ _ <- getPackageFile lp. package lp. cabalFP
8492 pure (lp, M. map (map dotCabalGetPath) compFiles)
85- let foundFileTargetComponents :: [(Path Abs File , [(PackageName , NamedComponent )])]
86- foundFileTargetComponents =
87- map (\ fp -> (fp, ) $ L. sort $
88- concatMap (\ (lp, files) -> map ((lp. package. name,) . fst )
89- (filter (elem fp . snd ) (M. toList files))
90- ) filePackages
91- ) fileTargets
93+ let foundFileTargetComponents ::
94+ [ ( Path Abs File
95+ -- The target file.
96+ , [ ( PackageName
97+ -- A relevant package.
98+ , NamedComponent
99+ -- A relevant component of the relevant package.
100+ , [Path Abs File ]
101+ -- The module source files of the relevant component.
102+ )
103+ ]
104+ )
105+ ]
106+ foundFileTargetComponents = map
107+ ( \ fp ->
108+ (fp,)
109+ $ L. sort
110+ $ concatMap
111+ ( \ (lp, files) -> map
112+ (\ (comp, compFiles) -> (lp. package. name, comp, compFiles))
113+ (filter (elem fp . snd ) (M. toList files))
114+ )
115+ filePackages
116+ )
117+ fileTargets
92118 results <- forM foundFileTargetComponents $ \ (fp, xs) ->
93119 case xs of
94120 [] -> do
@@ -99,36 +125,38 @@ findFileTargets locals fileTargets = do
99125 \Attempting to load the file anyway."
100126 ]
101127 pure $ Left fp
102- [x] -> do
128+ [x@ (name, comp, _) ] -> do
103129 prettyInfoL
104130 [ flow " Using configuration for"
105- , displayPkgComponent x
131+ , displayPkgComponent (name, comp)
106132 , flow " to load"
107133 , pretty fp
108134 ]
109135 pure $ Right (fp, x)
110- (x: _) -> do
136+ (x@ (name, comp, _) : _) -> do
111137 prettyWarn $
112138 fillSep
113139 [ flow " Multiple components contain file target"
114140 , pretty fp <> " :"
115- , fillSep $ punctuate " ," (map displayPkgComponent xs)
141+ , fillSep $ punctuate " ," (map ( \ (n, c, _) -> displayPkgComponent (n, c)) xs)
116142 ]
117143 <> line
118144 <> fillSep
119145 [ flow " Guessing the first one,"
120- , displayPkgComponent x <> " ."
146+ , displayPkgComponent (name, comp) <> " ."
121147 ]
122148 pure $ Right (fp, x)
123149 let (extraFiles, associatedFiles) = partitionEithers results
124150 targetMap =
125- foldl' unionTargets M. empty $
126- map (\ (_, (name, comp)) -> M. singleton name (TargetComps (S. singleton comp)))
127- associatedFiles
151+ foldl' unionFileTargets M. empty
152+ $ map
153+ (\ (_, (name, comp, compFiles)) -> M. singleton name (FileTarget (M. singleton comp compFiles)))
154+ associatedFiles
128155 infoMap =
129- foldl' (M. unionWith (<>) ) M. empty $
130- map (\ (fp, (name, _)) -> M. singleton name [fp])
131- associatedFiles
156+ foldl' (M. unionWith (<>) ) M. empty
157+ $ map
158+ (\ (fp, (name, _, _)) -> M. singleton name [fp])
159+ associatedFiles
132160 pure (targetMap, Just (infoMap, extraFiles))
133161
134162-- | Yields all of the targets that are local, those that are directly wanted
0 commit comments