@@ -2,15 +2,15 @@
22{-# LANGUAGE BangPatterns, GADTs, OverloadedStrings #-}
33module Build
44 ( fromExposed
5− , fromMains
5+ , fromPaths
66 , fromRepl
77 , Artifacts(..)
8− , Main(..)
8+ , Root(..)
99 , Module(..)
1010 , CachedInterface(..)
1111 , ReplArtifacts(..)
1212 , DocsGoal(..)
13− , getMainNames
13+ , getRootNames
1414 )
1515 where
1616
@@ -164,14 +164,14 @@ fromExposed style root details docsGoal exposed@(NE.List e es) =
164164
165165
166166
167−-- FROM MAINS
167+-- FROM PATHS
168168
169169
170170data Artifacts =
171171 Artifacts
172172 { _name :: Pkg.Name
173173 , _deps :: Dependencies
174− , _mains :: NE.List Main
174+ , _roots :: NE.List Root
175175 , _modules :: [Module]
176176 }
177177
@@ -185,25 +185,25 @@ type Dependencies =
185185 Map.Map ModuleName.Canonical I.DependencyInterface
186186
187187
188−fromMains :: Reporting.Style -> FilePath -> Details.Details -> NE.List FilePath -> IO (Either Exit.BuildProblem Artifacts)
189−fromMains style root details paths =
188+fromPaths :: Reporting.Style -> FilePath -> Details.Details -> NE.List FilePath -> IO (Either Exit.BuildProblem Artifacts)
189+fromPaths style root details paths =
190190 Reporting.trackBuild style $ \key ->
191191 do env <- makeEnv key root details
192192
193− elmains <- findMains env paths
194− case elmains of
193+ elroots <- findRoots env paths
194+ case elroots of
195195 Left problem ->
196196 return (Left (Exit.BuildProjectProblem problem))
197197
198− Right lmains ->
198+ Right lroots ->
199199 do -- crawl
200200 dmvar <- Details.loadInterfaces root details
201201 smvar <- newMVar Map.empty
202− smainMVars <- traverse (fork . crawlMain env smvar) lmains
203− smains <- traverse readMVar smainMVars
202+ srootMVars <- traverse (fork . crawlRoot env smvar) lroots
203+ sroots <- traverse readMVar srootMVars
204204 statuses <- traverse readMVar =<< readMVar smvar
205205
206− midpoint <- checkMainsMidpoint dmvar statuses smains
206+ midpoint <- checkMidpointAndRoots dmvar statuses sroots
207207 case midpoint of
208208 Left problem ->
209209 return (Left (Exit.BuildProjectProblem problem))
@@ -213,24 +213,24 @@ fromMains style root details paths =
213213 rmvar <- newEmptyMVar
214214 resultsMVars <- forkWithKey (checkModule env foreigns rmvar) statuses
215215 putMVar rmvar resultsMVars
216− rmainMVars <- traverse (fork . checkMain env resultsMVars) smains
216+ rrootMVars <- traverse (fork . checkRoot env resultsMVars) sroots
217217 results <- traverse readMVar resultsMVars
218218 writeDetails root details results
219− toArtifacts env foreigns results <$> traverse readMVar rmainMVars
219+ toArtifacts env foreigns results <$> traverse readMVar rrootMVars
220220
221221
222222
223−-- GET MAIN NAMES
223+-- GET ROOT NAMES
224224
225225
226−getMainNames :: Artifacts -> NE.List ModuleName.Raw
227−getMainNames (Artifacts _ _ mains _) =
228− fmap getMainName mains
226+getRootNames :: Artifacts -> NE.List ModuleName.Raw
227+getRootNames (Artifacts _ _ roots _) =
228+ fmap getRootName roots
229229
230230
231−getMainName :: Main -> ModuleName.Raw
232−getMainName main =
233− case main of
231+getRootName :: Root -> ModuleName.Raw
232+getRootName root =
233+ case root of
234234 Inside name -> name
235235 Outside name _ _ -> name
236236
@@ -585,11 +585,11 @@ checkMidpoint dmvar statuses =
585585 return (Left (Exit.BP_Cycle name names))
586586
587587
588−checkMainsMidpoint :: MVar (Maybe Dependencies) -> Map.Map ModuleName.Raw Status -> NE.List MainStatus -> IO (Either Exit.BuildProjectProblem Dependencies)
589−checkMainsMidpoint dmvar statuses smains =
588+checkMidpointAndRoots :: MVar (Maybe Dependencies) -> Map.Map ModuleName.Raw Status -> NE.List RootStatus -> IO (Either Exit.BuildProjectProblem Dependencies)
589+checkMidpointAndRoots dmvar statuses sroots =
590590 case checkForCycles statuses of
591591 Nothing ->
592− case checkUniqueMains statuses smains of
592+ case checkUniqueRoots statuses sroots of
593593 Nothing ->
594594 do maybeForeigns <- readMVar dmvar
595595 case maybeForeigns of
@@ -651,14 +651,14 @@ addToGraph name status graph =
651651
652652
653653
654−-- CHECK UNIQUE MAINS
654+-- CHECK UNIQUE ROOTS
655655
656656
657−checkUniqueMains :: Map.Map ModuleName.Raw Status -> NE.List MainStatus -> Maybe Exit.BuildProjectProblem
658−checkUniqueMains insides smains =
657+checkUniqueRoots :: Map.Map ModuleName.Raw Status -> NE.List RootStatus -> Maybe Exit.BuildProjectProblem
658+checkUniqueRoots insides sroots =
659659 let
660660 outsidesDict =
661− Map.fromListWith OneOrMore.more (Maybe.mapMaybe mainStatusToNamePathPair (NE.toList smains))
661+ Map.fromListWith OneOrMore.more (Maybe.mapMaybe rootStatusToNamePathPair (NE.toList sroots))
662662 in
663663 case Map.traverseWithKey checkOutside outsidesDict of
664664 Left problem ->
@@ -670,9 +670,9 @@ checkUniqueMains insides smains =
670670 Left problem -> Just problem
671671
672672
673−mainStatusToNamePathPair :: MainStatus -> Maybe (ModuleName.Raw, OneOrMore.OneOrMore FilePath)
674−mainStatusToNamePathPair smain =
675− case smain of
673+rootStatusToNamePathPair :: RootStatus -> Maybe (ModuleName.Raw, OneOrMore.OneOrMore FilePath)
674+rootStatusToNamePathPair sroot =
675+ case sroot of
676676 SInside _ -> Nothing
677677 SOutsideOk (Details.Local path _ _ _ _ _) _ modul -> Just (Src.getName modul, OneOrMore.one path)
678678 SOutsideErr _ -> Nothing
@@ -682,14 +682,14 @@ checkOutside :: ModuleName.Raw -> OneOrMore.OneOrMore FilePath -> Either Exit.Bu
682682checkOutside name paths =
683683 case OneOrMore.destruct NE.List paths of
684684 NE.List p [] -> Right p
685− NE.List p1 (p2:_) -> Left (Exit.BP_MainNameDuplicate name p1 p2)
685+ NE.List p1 (p2:_) -> Left (Exit.BP_RootNameDuplicate name p1 p2)
686686
687687
688688checkInside :: ModuleName.Raw -> FilePath -> Status -> Either Exit.BuildProjectProblem ()
689689checkInside name p1 status =
690690 case status of
691− SCached (Details.Local p2 _ _ _ _ _) -> Left (Exit.BP_MainNameDuplicate name p1 p2)
692− SChanged (Details.Local p2 _ _ _ _ _) _ _ _ -> Left (Exit.BP_MainNameDuplicate name p1 p2)
691+ SCached (Details.Local p2 _ _ _ _ _) -> Left (Exit.BP_RootNameDuplicate name p1 p2)
692+ SChanged (Details.Local p2 _ _ _ _ _) _ _ _ -> Left (Exit.BP_RootNameDuplicate name p1 p2)
693693 SBadImport _ -> Right ()
694694 SBadSyntax _ _ _ _ -> Right ()
695695 SForeign _ -> Right ()
@@ -964,25 +964,25 @@ finalizeReplArtifacts env@(Env _ root projectType _ _ _ _) source modul@(Src.Mod
964964
965965
966966
967−-- FIND MAIN
967+-- FIND ROOT
968968
969969
970−data MainLocation
970+data RootLocation
971971 = LInside ModuleName.Raw
972972 | LOutside FilePath
973973
974974
975−findMains :: Env -> NE.List FilePath -> IO (Either Exit.BuildProjectProblem (NE.List MainLocation))
976−findMains env paths =
977− do mvars <- traverse (fork . findLocation env) paths
978− elocs <- traverse readMVar mvars
979− return $ checkLocations =<< sequence elocs
975+findRoots :: Env -> NE.List FilePath -> IO (Either Exit.BuildProjectProblem (NE.List RootLocation))
976+findRoots env paths =
977+ do mvars <- traverse (fork . getRootInfo env) paths
978+ einfos <- traverse readMVar mvars
979+ return $ checkRoots =<< sequence einfos
980980
981981
982−checkLocations :: NE.List Location -> Either Exit.BuildProjectProblem (NE.List MainLocation)
983−checkLocations locations =
982+checkRoots :: NE.List RootInfo -> Either Exit.BuildProjectProblem (NE.List RootLocation)
983+checkRoots infos =
984984 let
985− toOneOrMore loc@(Location absolute _ _) =
985+ toOneOrMore loc@(RootInfo absolute _ _) =
986986 (absolute, OneOrMore.one loc)
987987
988988 fromOneOrMore loc locs =
@@ -990,33 +990,33 @@ checkLocations locations =
990990 [] -> Right ()
991991 loc2:_ -> Left (Exit.BP_MainPathDuplicate (_relative loc) (_relative loc2))
992992 in
993− fmap (\_ -> fmap _location locations) $
993+ fmap (\_ -> fmap _location infos) $
994994 traverse (OneOrMore.destruct fromOneOrMore) $
995− Map.fromListWith OneOrMore.more $ map toOneOrMore (NE.toList locations)
995+ Map.fromListWith OneOrMore.more $ map toOneOrMore (NE.toList infos)
996996
997997
998998
999−-- LOCATIONS
999+-- ROOT INFO
10001000
10011001
1002−data Location =
1003− Location
1002+data RootInfo =
1003+ RootInfo
10041004 { _absolute :: FilePath
10051005 , _relative :: FilePath
1006− , _location :: MainLocation
1006+ , _location :: RootLocation
10071007 }
10081008
10091009
1010−findLocation :: Env -> FilePath -> IO (Either Exit.BuildProjectProblem Location)
1011−findLocation env path =
1010+getRootInfo :: Env -> FilePath -> IO (Either Exit.BuildProjectProblem RootInfo)
1011+getRootInfo env path =
10121012 do exists <- File.exists path
10131013 if exists
1014− then findLoc env path =<< Dir.canonicalizePath path
1014+ then getRootInfoHelp env path =<< Dir.canonicalizePath path
10151015 else return (Left (Exit.BP_PathUnknown path))
10161016
10171017
1018−findLoc :: Env -> FilePath -> FilePath -> IO (Either Exit.BuildProjectProblem Location)
1019−findLoc (Env _ root _ srcDirs _ _ _) path absolutePath =
1018+getRootInfoHelp :: Env -> FilePath -> FilePath -> IO (Either Exit.BuildProjectProblem RootInfo)
1019+getRootInfoHelp (Env _ _ _ srcDirs _ _ _) path absolutePath =
10201020 let
10211021 (dirs, file) = FP.splitFileName absolutePath
10221022 (final, ext) = FP.splitExtension file
@@ -1030,7 +1030,7 @@ findLoc (Env _ root _ srcDirs _ _ _) path absolutePath =
10301030 in
10311031 case Maybe.mapMaybe (isInsideSrcDirByPath absoluteSegments) srcDirs of
10321032 [] ->
1033− return $ Right $ Location absolutePath path (LOutside path)
1033+ return $ Right $ RootInfo absolutePath path (LOutside path)
10341034
10351035 [(_, Right names)] ->
10361036 do let name = Name.fromChars (List.intercalate "." names)
@@ -1039,13 +1039,13 @@ findLoc (Env _ root _ srcDirs _ _ _) path absolutePath =
10391039 d1:d2:_ ->
10401040 do let p1 = addRelative d1 (FP.joinPath names <.> "elm")
10411041 let p2 = addRelative d2 (FP.joinPath names <.> "elm")
1042− return $ Left $ Exit.BP_MainNameDuplicate name p1 p2
1042+ return $ Left $ Exit.BP_RootNameDuplicate name p1 p2
10431043
10441044 _ ->
1045− return $ Right $ Location absolutePath path (LInside name)
1045+ return $ Right $ RootInfo absolutePath path (LInside name)
10461046
10471047 [(s, Left names)] ->
1048− return $ Left $ Exit.BP_MainNameInvalid path s names
1048+ return $ Left $ Exit.BP_RootNameInvalid path s names
10491049
10501050 (s1,_):(s2,_):_ ->
10511051 return $ Left $ Exit.BP_WithAmbiguousSrcDir path s1 s2
@@ -1094,18 +1094,18 @@ dropPrefix roots paths =
10941094
10951095
10961096
1097−-- CRAWL MAINS
1097+-- CRAWL ROOTS
10981098
10991099
1100−data MainStatus
1100+data RootStatus
11011101 = SInside ModuleName.Raw
11021102 | SOutsideOk Details.Local B.ByteString Src.Module
11031103 | SOutsideErr Error.Module
11041104
11051105
1106−crawlMain :: Env -> MVar StatusDict -> MainLocation -> IO MainStatus
1107−crawlMain env@(Env _ _ projectType _ buildID _ _) mvar given =
1108− case given of
1106+crawlRoot :: Env -> MVar StatusDict -> RootLocation -> IO RootStatus
1107+crawlRoot env@(Env _ _ projectType _ buildID _ _) mvar root =
1108+ case root of
11091109 LInside name ->
11101110 do statusMVar <- newEmptyMVar
11111111 statusDict <- takeMVar mvar
@@ -1128,19 +1128,19 @@ crawlMain env@(Env _ _ projectType _ buildID _ _) mvar given =
11281128
11291129
11301130
1131−-- CHECK MAINS
1131+-- CHECK ROOTS
11321132
11331133
1134−data MainResult
1134+data RootResult
11351135 = RInside ModuleName.Raw
11361136 | ROutsideOk ModuleName.Raw I.Interface Opt.LocalGraph
11371137 | ROutsideErr Error.Module
11381138 | ROutsideBlocked
11391139
11401140
1141−checkMain :: Env -> ResultDict -> MainStatus -> IO MainResult
1142−checkMain env@(Env _ root _ _ _ _ _) results pendingMain =
1143− case pendingMain of
1141+checkRoot :: Env -> ResultDict -> RootStatus -> IO RootResult
1142+checkRoot env@(Env _ root _ _ _ _ _) results rootStatus =
1143+ case rootStatus of
11441144 SInside name ->
11451145 return (RInside name)
11461146
@@ -1167,7 +1167,7 @@ checkMain env@(Env _ root _ _ _ _ _) results pendingMain =
11671167 Error.BadImports (toImportErrors env results imports problems)
11681168
11691169
1170−compileOutside :: Env -> Details.Local -> B.ByteString -> Map.Map ModuleName.Raw I.Interface -> Src.Module -> IO MainResult
1170+compileOutside :: Env -> Details.Local -> B.ByteString -> Map.Map ModuleName.Raw I.Interface -> Src.Module -> IO RootResult
11711171compileOutside (Env key _ projectType _ _ _ _) (Details.Local path time _ _ _ _) source ifaces modul =
11721172 let
11731173 pkg = projectTypeToPkg projectType
@@ -1186,35 +1186,35 @@ compileOutside (Env key _ projectType _ _ _ _) (Details.Local path time _ _ _ _)
11861186-- TO ARTIFACTS
11871187
11881188
1189−data Main
1189+data Root
11901190 = Inside ModuleName.Raw
11911191 | Outside ModuleName.Raw I.Interface Opt.LocalGraph
11921192
11931193
1194−toArtifacts :: Env -> Dependencies -> Map.Map ModuleName.Raw Result -> NE.List MainResult -> Either Exit.BuildProblem Artifacts
1195−toArtifacts (Env _ root projectType _ _ _ _) foreigns results mainResults =
1196− case gatherProblemsOrMains results mainResults of
1194+toArtifacts :: Env -> Dependencies -> Map.Map ModuleName.Raw Result -> NE.List RootResult -> Either Exit.BuildProblem Artifacts
1195+toArtifacts (Env _ root projectType _ _ _ _) foreigns results rootResults =
1196+ case gatherProblemsOrMains results rootResults of
11971197 Left (NE.List e es) ->
11981198 Left (Exit.BuildBadModules root e es)
11991199
1200− Right mains ->
1201− Right $ Artifacts (projectTypeToPkg projectType) foreigns mains $
1202− Map.foldrWithKey addInside (foldr addOutside [] mainResults) results
1200+ Right roots ->
1201+ Right $ Artifacts (projectTypeToPkg projectType) foreigns roots $
1202+ Map.foldrWithKey addInside (foldr addOutside [] rootResults) results
12031203
12041204
1205−gatherProblemsOrMains :: Map.Map ModuleName.Raw Result -> NE.List MainResult -> Either (NE.List Error.Module) (NE.List Main)
1206−gatherProblemsOrMains results (NE.List mainResult mainResults) =
1205+gatherProblemsOrMains :: Map.Map ModuleName.Raw Result -> NE.List RootResult -> Either (NE.List Error.Module) (NE.List Root)
1206+gatherProblemsOrMains results (NE.List rootResult rootResults) =
12071207 let
1208− sortMain result (es, mains) =
1208+ addResult result (es, roots) =
12091209 case result of
1210− RInside n -> ( es, Inside n : mains)
1211− ROutsideOk n i o -> ( es, Outside n i o : mains)
1212− ROutsideErr e -> (e:es, mains)
1213− ROutsideBlocked -> ( es, mains)
1210+ RInside n -> ( es, Inside n : roots)
1211+ ROutsideOk n i o -> ( es, Outside n i o : roots)
1212+ ROutsideErr e -> (e:es, roots)
1213+ ROutsideBlocked -> ( es, roots)
12141214
12151215 errors = Map.foldr addErrors [] results
12161216 in
1217− case (mainResult, foldr sortMain (errors, []) mainResults) of
1217+ case (rootResult, foldr addResult (errors, []) rootResults) of
12181218 (RInside n , ( [], ms)) -> Right (NE.List (Inside n) ms)
12191219 (RInside _ , (e:es, _ )) -> Left (NE.List e es)
12201220 (ROutsideOk n i o, ( [], ms)) -> Right (NE.List (Outside n i o) ms)
@@ -1242,9 +1242,9 @@ badInside name =
12421242 "Error from `" ++ Name.toChars name ++ "` should have been reported already."
12431243
12441244
1245−addOutside :: MainResult -> [Module] -> [Module]
1246−addOutside main modules =
1247− case main of
1245+addOutside :: RootResult -> [Module] -> [Module]
1246+addOutside root modules =
1247+ case root of
12481248 RInside _ -> modules
12491249 ROutsideOk name iface objs -> Fresh name iface objs : modules
12501250 ROutsideErr _ -> modules