@@ -29,10 +29,7 @@ getSortedDependencies srcDirs builtIns root =
2929 result <- runErrorT $ readAllDeps allSrcDirs builtIns root
3030 case result of
3131 Right deps -> sortDeps deps
32− Left err -> failure $ err ++ if Maybe.isJust extras then "" else msg
33− where msg = "\nYou may need to create a " ++
34− Path.dependencyFile ++
35− " file if you\nare trying to use a 3rd party library."
32+ Left err -> failure err
3633
3734extraDependencies :: IO (Maybe [FilePath])
3835extraDependencies =
@@ -75,20 +72,22 @@ sortDeps depends =
7572 msg = "A cyclical module dependency or was detected in:\n"
7673
7774readAllDeps :: [FilePath] -> Module.Interfaces -> FilePath -> ErrorT String IO [Deps]
78−readAllDeps srcDirs builtIns root =
79− do let ifaces = (Set.fromList . Map.keys) builtIns
80− State.evalStateT (go ifaces root) Set.empty
75+readAllDeps srcDirs rawBuiltIns filePath =
76+ State.evalStateT (go Nothing filePath) Set.empty
8177 where
82− go :: Set.Set String -> FilePath -> State.StateT (Set.Set String) (ErrorT String IO) [Deps]
83− go builtIns root = do
84− root' <- lift $ findSrcFile srcDirs root
85− (name, deps) <- lift $ readDeps root'
78+ builtIns :: Set.Set String
79+ builtIns = Set.fromList $ Map.keys rawBuiltIns
80+
81+ go :: Maybe String -> FilePath -> State.StateT (Set.Set String) (ErrorT String IO) [Deps]
82+ go parentModuleName filePath = do
83+ filePath' <- lift $ findSrcFile parentModuleName srcDirs filePath
84+ (moduleName, deps) <- lift $ readDeps filePath'
8685 seen <- State.get
8786 let realDeps = Set.difference (Set.fromList deps) builtIns
8887 newDeps = Set.difference (Set.filter (not . isNative) realDeps) seen
89− State.put (Set.insert name (Set.union newDeps seen))
90− rest <- mapM (go builtIns . toFilePath) (Set.toList newDeps)
91− return ((makeRelative "." root', name, Set.toList realDeps) : concat rest)
88+ State.put (Set.insert moduleName (Set.union newDeps seen))
89+ rest <- mapM (go (Just moduleName) . toFilePath) (Set.toList newDeps)
90+ return ((makeRelative "." filePath', moduleName, Set.toList realDeps) : concat rest)
9291
9392readDeps :: FilePath -> ErrorT String IO (String, [String])
9493readDeps path = do
@@ -98,15 +97,10 @@ readDeps path = do
9897 where msg = "Error resolving dependencies in " ++ path ++ ":\n"
9998 Right o -> return o
10099
101−findSrcFile :: [FilePath] -> FilePath -> ErrorT String IO FilePath
102−findSrcFile dirs path = foldr tryDir notFound dirs
100+findSrcFile :: Maybe String -> [FilePath] -> FilePath -> ErrorT String IO FilePath
101+findSrcFile parentModuleName dirs path =
102+ foldr tryDir notFound dirs
103103 where
104− notFound = throwError $ unlines
105− [ "Could not find file: " ++ path
106− , " If it is not in the root directory of your project, use"
107− , " --src-dir to declare additional locations for source files."
108− , " If it is part of a 3rd party library, it needs to be declared"
109− , " as a dependency in the " ++ Path.dependencyFile ++ " file." ]
110104 tryDir dir next = do
111105 let path' = dir </> path
112106 exists <- liftIO $ doesFileExist path'
@@ -114,6 +108,20 @@ findSrcFile dirs path = foldr tryDir notFound dirs
114108 then return path'
115109 else next
116110
111+ parentModuleName' =
112+ case parentModuleName of
113+ Just name -> "module '" ++ name ++ "'"
114+ Nothing -> "the main module"
115+
116+ notFound = throwError $ unlines
117+ [ "When finding the imports declared in " ++ parentModuleName' ++ ", could not find file: " ++ path
118+ , " If you created this module, but it is in a subdirectory that does not"
119+ , " exactly match the module name, you may need to use the --src-dir flag."
120+ , ""
121+ , " If it is part of a 3rd party library, it needs to be declared"
122+ , " as a dependency in your project's " ++ Path.dependencyFile ++ " file."
123+ ]
124+
117125isNative :: String -> Bool
118126isNative name = List.isPrefixOf "Native." name
119127