@@ -2,15 +2,15 @@
2{-# LANGUAGE BangPatterns, GADTs, OverloadedStrings #-}
2{-# LANGUAGE BangPatterns, GADTs, OverloadedStrings #-}
3module Build
3module Build
4 ( fromExposed
4 ( fromExposed
5− , fromMains
5+ , fromPaths
7 , Artifacts(..)
7 , Artifacts(..)
8− , Main(..)
8+ , Root(..)
9 , Module(..)
9 , Module(..)
10 , CachedInterface(..)
10 , CachedInterface(..)
11 , ReplArtifacts(..)
11 , ReplArtifacts(..)
12 , DocsGoal(..)
12 , DocsGoal(..)
13− , getMainNames
13+ , getRootNames
@@ -164,14 +164,14 @@ fromExposed style root details docsGoal exposed@(NE.List e es) =
167−-- FROM MAINS
167+-- FROM PATHS
170data Artifacts =
170data Artifacts =
171 Artifacts
171 Artifacts
172 { _name :: Pkg.Name
172 { _name :: Pkg.Name
173 , _deps :: Dependencies
173 , _deps :: Dependencies
174− , _mains :: NE.List Main
174+ , _roots :: NE.List Root
175 , _modules :: [Module]
175 , _modules :: [Module]
@@ -185,25 +185,25 @@ type Dependencies =
185 Map.Map ModuleName.Canonical I.DependencyInterface
185 Map.Map ModuleName.Canonical I.DependencyInterface
188−fromMains :: Reporting.Style -> FilePath -> Details.Details -> NE.List FilePath -> IO (Either Exit.BuildProblem Artifacts)
188+fromPaths :: Reporting.Style -> FilePath -> Details.Details -> NE.List FilePath -> IO (Either Exit.BuildProblem Artifacts)
189−fromMains style root details paths =
189+fromPaths style root details paths =
190 Reporting.trackBuild style $ \key ->
190 Reporting.trackBuild style $ \key ->
191 do env <- makeEnv key root details
191 do env <- makeEnv key root details
193− elmains <- findMains env paths
193+ elroots <- findRoots env paths
194− case elmains of
194+ case elroots of
195 Left problem ->
195 Left problem ->
196 return (Left (Exit.BuildProjectProblem problem))
196 return (Left (Exit.BuildProjectProblem problem))
198− Right lmains ->
198+ Right lroots ->
199 do -- crawl
199 do -- crawl
200 dmvar <- Details.loadInterfaces root details
200 dmvar <- Details.loadInterfaces root details
201 smvar <- newMVar Map.empty
201 smvar <- newMVar Map.empty
202− smainMVars <- traverse (fork . crawlMain env smvar) lmains
202+ srootMVars <- traverse (fork . crawlRoot env smvar) lroots
203− smains <- traverse readMVar smainMVars
203+ sroots <- traverse readMVar srootMVars
204 statuses <- traverse readMVar =<< readMVar smvar
204 statuses <- traverse readMVar =<< readMVar smvar
206− midpoint <- checkMainsMidpoint dmvar statuses smains
206+ midpoint <- checkMidpointAndRoots dmvar statuses sroots
207 case midpoint of
207 case midpoint of
208 Left problem ->
208 Left problem ->
209 return (Left (Exit.BuildProjectProblem problem))
209 return (Left (Exit.BuildProjectProblem problem))
@@ -213,24 +213,24 @@ fromMains style root details paths =
213 rmvar <- newEmptyMVar
213 rmvar <- newEmptyMVar
214 resultsMVars <- forkWithKey (checkModule env foreigns rmvar) statuses
214 resultsMVars <- forkWithKey (checkModule env foreigns rmvar) statuses
215 putMVar rmvar resultsMVars
215 putMVar rmvar resultsMVars
216− rmainMVars <- traverse (fork . checkMain env resultsMVars) smains
216+ rrootMVars <- traverse (fork . checkRoot env resultsMVars) sroots
217 results <- traverse readMVar resultsMVars
217 results <- traverse readMVar resultsMVars
218 writeDetails root details results
218 writeDetails root details results
219− toArtifacts env foreigns results <$> traverse readMVar rmainMVars
219+ toArtifacts env foreigns results <$> traverse readMVar rrootMVars
223−-- GET MAIN NAMES
223+-- GET ROOT NAMES
226−getMainNames :: Artifacts -> NE.List ModuleName.Raw
226+getRootNames :: Artifacts -> NE.List ModuleName.Raw
227−getMainNames (Artifacts _ _ mains _) =
227+getRootNames (Artifacts _ _ roots _) =
228− fmap getMainName mains
228+ fmap getRootName roots
231−getMainName :: Main -> ModuleName.Raw
231+getRootName :: Root -> ModuleName.Raw
232−getMainName main =
232+getRootName root =
233− case main of
233+ case root of
234 Inside name -> name
234 Inside name -> name
235 Outside name _ _ -> name
235 Outside name _ _ -> name
@@ -585,11 +585,11 @@ checkMidpoint dmvar statuses =
585 return (Left (Exit.BP_Cycle name names))
585 return (Left (Exit.BP_Cycle name names))
588−checkMainsMidpoint :: MVar (Maybe Dependencies) -> Map.Map ModuleName.Raw Status -> NE.List MainStatus -> IO (Either Exit.BuildProjectProblem Dependencies)
588+checkMidpointAndRoots :: MVar (Maybe Dependencies) -> Map.Map ModuleName.Raw Status -> NE.List RootStatus -> IO (Either Exit.BuildProjectProblem Dependencies)
589−checkMainsMidpoint dmvar statuses smains =
589+checkMidpointAndRoots dmvar statuses sroots =
590 case checkForCycles statuses of
590 case checkForCycles statuses of
591 Nothing ->
591 Nothing ->
592− case checkUniqueMains statuses smains of
592+ case checkUniqueRoots statuses sroots of
593 Nothing ->
593 Nothing ->
594 do maybeForeigns <- readMVar dmvar
594 do maybeForeigns <- readMVar dmvar
595 case maybeForeigns of
595 case maybeForeigns of
@@ -651,14 +651,14 @@ addToGraph name status graph =
654−-- CHECK UNIQUE MAINS
654+-- CHECK UNIQUE ROOTS
657−checkUniqueMains :: Map.Map ModuleName.Raw Status -> NE.List MainStatus -> Maybe Exit.BuildProjectProblem
657+checkUniqueRoots :: Map.Map ModuleName.Raw Status -> NE.List RootStatus -> Maybe Exit.BuildProjectProblem
658−checkUniqueMains insides smains =
658+checkUniqueRoots insides sroots =
660 outsidesDict =
660 outsidesDict =
661− Map.fromListWith OneOrMore.more (Maybe.mapMaybe mainStatusToNamePathPair (NE.toList smains))
661+ Map.fromListWith OneOrMore.more (Maybe.mapMaybe rootStatusToNamePathPair (NE.toList sroots))
663 case Map.traverseWithKey checkOutside outsidesDict of
663 case Map.traverseWithKey checkOutside outsidesDict of
664 Left problem ->
664 Left problem ->
@@ -670,9 +670,9 @@ checkUniqueMains insides smains =
670 Left problem -> Just problem
670 Left problem -> Just problem
673−mainStatusToNamePathPair :: MainStatus -> Maybe (ModuleName.Raw, OneOrMore.OneOrMore FilePath)
673+rootStatusToNamePathPair :: RootStatus -> Maybe (ModuleName.Raw, OneOrMore.OneOrMore FilePath)
674−mainStatusToNamePathPair smain =
674+rootStatusToNamePathPair sroot =
675− case smain of
675+ case sroot of
676 SInside _ -> Nothing
676 SInside _ -> Nothing
677 SOutsideOk (Details.Local path _ _ _ _ _) _ modul -> Just (Src.getName modul, OneOrMore.one path)
677 SOutsideOk (Details.Local path _ _ _ _ _) _ modul -> Just (Src.getName modul, OneOrMore.one path)
678 SOutsideErr _ -> Nothing
678 SOutsideErr _ -> Nothing
@@ -682,14 +682,14 @@ checkOutside :: ModuleName.Raw -> OneOrMore.OneOrMore FilePath -> Either Exit.Bu
682checkOutside name paths =
682checkOutside name paths =
683 case OneOrMore.destruct NE.List paths of
683 case OneOrMore.destruct NE.List paths of
684 NE.List p [] -> Right p
684 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)
688checkInside :: ModuleName.Raw -> FilePath -> Status -> Either Exit.BuildProjectProblem ()
688checkInside :: ModuleName.Raw -> FilePath -> Status -> Either Exit.BuildProjectProblem ()
689checkInside name p1 status =
689checkInside name p1 status =
690 case status of
690 case status of
691− SCached (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_MainNameDuplicate name p1 p2)
692+ SChanged (Details.Local p2 _ _ _ _ _) _ _ _ -> Left (Exit.BP_RootNameDuplicate name p1 p2)
693 SBadImport _ -> Right ()
693 SBadImport _ -> Right ()
694 SBadSyntax _ _ _ _ -> Right ()
694 SBadSyntax _ _ _ _ -> Right ()
695 SForeign _ -> Right ()
695 SForeign _ -> Right ()
@@ -964,25 +964,25 @@ finalizeReplArtifacts env@(Env _ root projectType _ _ _ _) source modul@(Src.Mod
967−-- FIND MAIN
967+-- FIND ROOT
970−data MainLocation
970+data RootLocation
971 = LInside ModuleName.Raw
971 = LInside ModuleName.Raw
972 | LOutside FilePath
972 | LOutside FilePath
975−findMains :: Env -> NE.List FilePath -> IO (Either Exit.BuildProjectProblem (NE.List MainLocation))
975+findRoots :: Env -> NE.List FilePath -> IO (Either Exit.BuildProjectProblem (NE.List RootLocation))
976−findMains env paths =
976+findRoots env paths =
977− do mvars <- traverse (fork . findLocation env) paths
977+ do mvars <- traverse (fork . getRootInfo env) paths
978− elocs <- traverse readMVar mvars
978+ einfos <- traverse readMVar mvars
979− return $ checkLocations =<< sequence elocs
979+ return $ checkRoots =<< sequence einfos
982−checkLocations :: NE.List Location -> Either Exit.BuildProjectProblem (NE.List MainLocation)
982+checkRoots :: NE.List RootInfo -> Either Exit.BuildProjectProblem (NE.List RootLocation)
983−checkLocations locations =
983+checkRoots infos =
985− toOneOrMore loc@(Location absolute _ _) =
985+ toOneOrMore loc@(RootInfo absolute _ _) =
986 (absolute, OneOrMore.one loc)
986 (absolute, OneOrMore.one loc)
988 fromOneOrMore loc locs =
988 fromOneOrMore loc locs =
@@ -990,33 +990,33 @@ checkLocations locations =
990 [] -> Right ()
990 [] -> Right ()
991 loc2:_ -> Left (Exit.BP_MainPathDuplicate (_relative loc) (_relative loc2))
991 loc2:_ -> Left (Exit.BP_MainPathDuplicate (_relative loc) (_relative loc2))
993− fmap (\_ -> fmap _location locations) $
993+ fmap (\_ -> fmap _location infos) $
994 traverse (OneOrMore.destruct fromOneOrMore) $
994 traverse (OneOrMore.destruct fromOneOrMore) $
995− Map.fromListWith OneOrMore.more $ map toOneOrMore (NE.toList locations)
995+ Map.fromListWith OneOrMore.more $ map toOneOrMore (NE.toList infos)
999−-- LOCATIONS
999+-- ROOT INFO
1002−data Location =
1002+data RootInfo =
1003− Location
1003+ RootInfo
1004 { _absolute :: FilePath
1004 { _absolute :: FilePath
1005 , _relative :: FilePath
1005 , _relative :: FilePath
1006− , _location :: MainLocation
1006+ , _location :: RootLocation
1010−findLocation :: Env -> FilePath -> IO (Either Exit.BuildProjectProblem Location)
1010+getRootInfo :: Env -> FilePath -> IO (Either Exit.BuildProjectProblem RootInfo)
1011−findLocation env path =
1011+getRootInfo env path =
1012 do exists <- File.exists path
1012 do exists <- File.exists path
1013 if exists
1013 if exists
1014− then findLoc env path =<< Dir.canonicalizePath path
1014+ then getRootInfoHelp env path =<< Dir.canonicalizePath path
1015 else return (Left (Exit.BP_PathUnknown path))
1015 else return (Left (Exit.BP_PathUnknown path))
1018−findLoc :: Env -> FilePath -> FilePath -> IO (Either Exit.BuildProjectProblem Location)
1018+getRootInfoHelp :: Env -> FilePath -> FilePath -> IO (Either Exit.BuildProjectProblem RootInfo)
1019−findLoc (Env _ root _ srcDirs _ _ _) path absolutePath =
1019+getRootInfoHelp (Env _ _ _ srcDirs _ _ _) path absolutePath =
1021 (dirs, file) = FP.splitFileName absolutePath
1021 (dirs, file) = FP.splitFileName absolutePath
1022 (final, ext) = FP.splitExtension file
1022 (final, ext) = FP.splitExtension file
@@ -1030,7 +1030,7 @@ findLoc (Env _ root _ srcDirs _ _ _) path absolutePath =
1031 case Maybe.mapMaybe (isInsideSrcDirByPath absoluteSegments) srcDirs of
1031 case Maybe.mapMaybe (isInsideSrcDirByPath absoluteSegments) srcDirs of
1033− return $ Right $ Location absolutePath path (LOutside path)
1033+ return $ Right $ RootInfo absolutePath path (LOutside path)
1035 [(_, Right names)] ->
1035 [(_, Right names)] ->
1036 do let name = Name.fromChars (List.intercalate "." names)
1036 do let name = Name.fromChars (List.intercalate "." names)
@@ -1039,13 +1039,13 @@ findLoc (Env _ root _ srcDirs _ _ _) path absolutePath =
1039 d1:d2:_ ->
1039 d1:d2:_ ->
1040 do let p1 = addRelative d1 (FP.joinPath names <.> "elm")
1040 do let p1 = addRelative d1 (FP.joinPath names <.> "elm")
1041 let p2 = addRelative d2 (FP.joinPath names <.> "elm")
1041 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
1045− return $ Right $ Location absolutePath path (LInside name)
1045+ return $ Right $ RootInfo absolutePath path (LInside name)
1047 [(s, Left names)] ->
1047 [(s, Left names)] ->
1048− return $ Left $ Exit.BP_MainNameInvalid path s names
1048+ return $ Left $ Exit.BP_RootNameInvalid path s names
1050 (s1,_):(s2,_):_ ->
1050 (s1,_):(s2,_):_ ->
1051 return $ Left $ Exit.BP_WithAmbiguousSrcDir path s1 s2
1051 return $ Left $ Exit.BP_WithAmbiguousSrcDir path s1 s2
@@ -1094,18 +1094,18 @@ dropPrefix roots paths =
1097−-- CRAWL MAINS
1097+-- CRAWL ROOTS
1100−data MainStatus
1100+data RootStatus
1101 = SInside ModuleName.Raw
1101 = SInside ModuleName.Raw
1102 | SOutsideOk Details.Local B.ByteString Src.Module
1102 | SOutsideOk Details.Local B.ByteString Src.Module
1103 | SOutsideErr Error.Module
1103 | SOutsideErr Error.Module
1106−crawlMain :: Env -> MVar StatusDict -> MainLocation -> IO MainStatus
1106+crawlRoot :: Env -> MVar StatusDict -> RootLocation -> IO RootStatus
1107−crawlMain env@(Env _ _ projectType _ buildID _ _) mvar given =
1107+crawlRoot env@(Env _ _ projectType _ buildID _ _) mvar root =
1108− case given of
1108+ case root of
1109 LInside name ->
1109 LInside name ->
1110 do statusMVar <- newEmptyMVar
1110 do statusMVar <- newEmptyMVar
1111 statusDict <- takeMVar mvar
1111 statusDict <- takeMVar mvar
@@ -1128,19 +1128,19 @@ crawlMain env@(Env _ _ projectType _ buildID _ _) mvar given =
1131−-- CHECK MAINS
1131+-- CHECK ROOTS
1134−data MainResult
1134+data RootResult
1135 = RInside ModuleName.Raw
1135 = RInside ModuleName.Raw
1136 | ROutsideOk ModuleName.Raw I.Interface Opt.LocalGraph
1136 | ROutsideOk ModuleName.Raw I.Interface Opt.LocalGraph
1137 | ROutsideErr Error.Module
1137 | ROutsideErr Error.Module
1138 | ROutsideBlocked
1138 | ROutsideBlocked
1141−checkMain :: Env -> ResultDict -> MainStatus -> IO MainResult
1141+checkRoot :: Env -> ResultDict -> RootStatus -> IO RootResult
1142−checkMain env@(Env _ root _ _ _ _ _) results pendingMain =
1142+checkRoot env@(Env _ root _ _ _ _ _) results rootStatus =
1143− case pendingMain of
1143+ case rootStatus of
1144 SInside name ->
1144 SInside name ->
1145 return (RInside name)
1145 return (RInside name)
@@ -1167,7 +1167,7 @@ checkMain env@(Env _ root _ _ _ _ _) results pendingMain =
1167 Error.BadImports (toImportErrors env results imports problems)
1167 Error.BadImports (toImportErrors env results imports problems)
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
1171compileOutside (Env key _ projectType _ _ _ _) (Details.Local path time _ _ _ _) source ifaces modul =
1171compileOutside (Env key _ projectType _ _ _ _) (Details.Local path time _ _ _ _) source ifaces modul =
1173 pkg = projectTypeToPkg projectType
1173 pkg = projectTypeToPkg projectType
@@ -1186,35 +1186,35 @@ compileOutside (Env key _ projectType _ _ _ _) (Details.Local path time _ _ _ _)
1186-- TO ARTIFACTS
1186-- TO ARTIFACTS
1189−data Main
1189+data Root
1190 = Inside ModuleName.Raw
1190 = Inside ModuleName.Raw
1191 | Outside ModuleName.Raw I.Interface Opt.LocalGraph
1191 | Outside ModuleName.Raw I.Interface Opt.LocalGraph
1194−toArtifacts :: Env -> Dependencies -> Map.Map ModuleName.Raw Result -> NE.List MainResult -> Either Exit.BuildProblem Artifacts
1194+toArtifacts :: Env -> Dependencies -> Map.Map ModuleName.Raw Result -> NE.List RootResult -> Either Exit.BuildProblem Artifacts
1195−toArtifacts (Env _ root projectType _ _ _ _) foreigns results mainResults =
1195+toArtifacts (Env _ root projectType _ _ _ _) foreigns results rootResults =
1196− case gatherProblemsOrMains results mainResults of
1196+ case gatherProblemsOrMains results rootResults of
1197 Left (NE.List e es) ->
1197 Left (NE.List e es) ->
1198 Left (Exit.BuildBadModules root e es)
1198 Left (Exit.BuildBadModules root e es)
1200− Right mains ->
1200+ Right roots ->
1201− Right $ Artifacts (projectTypeToPkg projectType) foreigns mains $
1201+ Right $ Artifacts (projectTypeToPkg projectType) foreigns roots $
1202− Map.foldrWithKey addInside (foldr addOutside [] mainResults) results
1202+ Map.foldrWithKey addInside (foldr addOutside [] rootResults) results
1205−gatherProblemsOrMains :: Map.Map ModuleName.Raw Result -> NE.List MainResult -> Either (NE.List Error.Module) (NE.List Main)
1205+gatherProblemsOrMains :: Map.Map ModuleName.Raw Result -> NE.List RootResult -> Either (NE.List Error.Module) (NE.List Root)
1206−gatherProblemsOrMains results (NE.List mainResult mainResults) =
1206+gatherProblemsOrMains results (NE.List rootResult rootResults) =
1208− sortMain result (es, mains) =
1208+ addResult result (es, roots) =
1209 case result of
1209 case result of
1210− RInside n -> ( es, Inside n : mains)
1210+ RInside n -> ( es, Inside n : roots)
1211− ROutsideOk n i o -> ( es, Outside n i o : mains)
1211+ ROutsideOk n i o -> ( es, Outside n i o : roots)
1212− ROutsideErr e -> (e:es, mains)
1212+ ROutsideErr e -> (e:es, roots)
1213− ROutsideBlocked -> ( es, mains)
1213+ ROutsideBlocked -> ( es, roots)
1215 errors = Map.foldr addErrors [] results
1215 errors = Map.foldr addErrors [] results
1217− case (mainResult, foldr sortMain (errors, []) mainResults) of
1217+ case (rootResult, foldr addResult (errors, []) rootResults) of
1218 (RInside n , ( [], ms)) -> Right (NE.List (Inside n) ms)
1218 (RInside n , ( [], ms)) -> Right (NE.List (Inside n) ms)
1219 (RInside _ , (e:es, _ )) -> Left (NE.List e es)
1219 (RInside _ , (e:es, _ )) -> Left (NE.List e es)
1220 (ROutsideOk n i o, ( [], ms)) -> Right (NE.List (Outside n i o) ms)
1220 (ROutsideOk n i o, ( [], ms)) -> Right (NE.List (Outside n i o) ms)
@@ -1242,9 +1242,9 @@ badInside name =
1242 "Error from `" ++ Name.toChars name ++ "` should have been reported already."
1242 "Error from `" ++ Name.toChars name ++ "` should have been reported already."
1245−addOutside :: MainResult -> [Module] -> [Module]
1245+addOutside :: RootResult -> [Module] -> [Module]
1246−addOutside main modules =
1246+addOutside root modules =
1247− case main of
1247+ case root of
1248 RInside _ -> modules
1248 RInside _ -> modules
1249 ROutsideOk name iface objs -> Fresh name iface objs : modules
1249 ROutsideOk name iface objs -> Fresh name iface objs : modules
1250 ROutsideErr _ -> modules
1250 ROutsideErr _ -> modules