on master help sign in
report error when the same module name is in multiple src-dirs
b8819c7Evan Czaplicki
builder/src/Build.hs+35−12
@@ -954,18 +954,19 @@ findLocation :: Env -> FilePath -> IO (Either Exit.BuildProjectProblem Location)
954findLocation env path =
954findLocation env path =
955 do exists <- File.exists path
955 do exists <- File.exists path
956 if exists
956 if exists
957− then findLoc env path <$> Dir.canonicalizePath path
957+ then findLoc env path =<< Dir.canonicalizePath path
958 else return (Left (Exit.BP_PathUnknown path))
958 else return (Left (Exit.BP_PathUnknown path))
959
959
960
960
961−findLoc :: Env -> FilePath -> FilePath -> Either Exit.BuildProjectProblem Location
961+findLoc :: Env -> FilePath -> FilePath -> IO (Either Exit.BuildProjectProblem Location)
962findLoc (Env _ root _ srcDirs _ _) path absolutePath =
962findLoc (Env _ root _ srcDirs _ _) path absolutePath =
963 let
963 let
964 (dirs, file) = FP.splitFileName absolutePath
964 (dirs, file) = FP.splitFileName absolutePath
965 (final, ext) = FP.splitExtension file
965 (final, ext) = FP.splitExtension file
966 in
966 in
967 if ext /= ".elm"
967 if ext /= ".elm"
968+ then
968− then Left (Exit.BP_WithBadExtension path)
969+ return $ Left $ Exit.BP_WithBadExtension path
969 else
970 else
970 let
971 let
971 roots = FP.splitDirectories root
972 roots = FP.splitDirectories root
@@ -973,25 +974,47 @@ findLoc (Env _ root _ srcDirs _ _) path absolutePath =
973 in
974 in
974 case dropPrefix roots segments of
975 case dropPrefix roots segments of
975 Nothing ->
976 Nothing ->
976− Right (Location absolutePath path (LOutside path))
977+ return $ Right $ Location absolutePath path (LOutside path)
977
978
978 Just relativeSegments ->
979 Just relativeSegments ->
979− case Maybe.mapMaybe (isInsideSrcDir relativeSegments) srcDirs of
980+ case Maybe.mapMaybe (isInsideSrcDirByPath relativeSegments) srcDirs of
981+ [] ->
980− [] -> Right $ Location absolutePath path (LOutside path)
982+ return $ Right $ Location absolutePath path (LOutside path)
981− [(_, Right name)] -> Right $ Location absolutePath path (LInside name)
982− [(s, Left names)] -> Left $ Exit.BP_MainNameInvalid path s names
983− (s1,_):(s2,_):_ -> Left $ Exit.BP_WithAmbiguousSrcDir path s1 s2
984
983
984+ [(_, Right names)] ->
985+ do let name = Name.fromChars (List.intercalate "." names)
986+ dirs <- filterM (isInsideSrcDirByName root names) srcDirs
987+ case dirs of
988+ d1:d2:_ ->
989+ do let p1 = d1 </> FP.joinPath names <.> "elm"
990+ let p2 = d2 </> FP.joinPath names <.> "elm"
991+ return $ Left $ Exit.BP_MainNameDuplicate name p1 p2
985
992
993+ _ ->
994+ return $ Right $ Location absolutePath path (LInside name)
995+
996+ [(s, Left names)] ->
997+ return $ Left $ Exit.BP_MainNameInvalid path s names
998+
999+ (s1,_):(s2,_):_ ->
1000+ return $ Left $ Exit.BP_WithAmbiguousSrcDir path s1 s2
1001+
1002+
1003+
1004+isInsideSrcDirByName :: FilePath -> [String] -> FilePath -> IO Bool
1005+isInsideSrcDirByName root names srcDir =
1006+ File.exists (root </> srcDir </> FP.joinPath names <.> "elm")
1007+
1008+
986−isInsideSrcDir :: [String] -> FilePath -> Maybe (FilePath, Either [String] ModuleName.Raw)
1009+isInsideSrcDirByPath :: [String] -> FilePath -> Maybe (FilePath, Either [String] [String])
987−isInsideSrcDir segments srcDir =
1010+isInsideSrcDirByPath segments srcDir =
988 case dropPrefix (FP.splitDirectories srcDir) segments of
1011 case dropPrefix (FP.splitDirectories srcDir) segments of
989 Nothing ->
1012 Nothing ->
990 Nothing
1013 Nothing
991
1014
992 Just names ->
1015 Just names ->
993 if all isGoodName names
1016 if all isGoodName names
994− then Just (srcDir, Right (Name.fromChars (List.intercalate "." names)))
1017+ then Just (srcDir, Right names)
995 else Just (srcDir, Left names)
1018 else Just (srcDir, Left names)
996
1019
997
1020