1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
module CPM.Diff.Rename (prefixPackageAndDeps) where
import Directory (doesDirectoryExist, getDirectoryContents, createDirectory)
import FilePath ((</>), joinPath, takeDirectory, takeBaseName, takeExtension)
import List (splitOn)
import CPM.AbstractCurry (transformAbstractCurryInDeps, applyModuleRenames)
import CPM.Config (Config)
import CPM.ErrorLogger
import CPM.Package (Package, loadPackageSpec)
import CPM.PackageCache.Runtime as RuntimeCache
import CPM.PackageCache.Global as GC
import CPM.PackageCopy (resolveAndCopyDependencies)
import CPM.Repository (Repository)
prefixPackageAndDeps :: Config -> Repository -> GC.GlobalCache -> String
-> String -> String -> IO (ErrorLogger [(String, String)])
prefixPackageAndDeps cfg repo gc dir prefix destDir =
fromELM (resolveAndCopyDependencies cfg repo gc dir) |>=
\deps -> (mapIO (findAllModulesInPackage . RuntimeCache.cacheDirectory dir) deps >>= succeedIO) |>=
\depMods -> (findAllModulesInPackage dir >>= succeedIO) |>=
\ownMods -> succeedIO (ownMods ++ concat depMods) |>=
\allMods -> succeedIO (zip (map fst allMods) (map ((prefix ++) . fst) allMods)) |>=
\modMap -> mapIO (copyMod dir deps destDir modMap) allMods >>
succeedIO modMap
findAllModulesInPackage :: String -> IO [(String, String)]
findAllModulesInPackage dir = findMods "" (dir </> "src")
where
findMods p d = do
entries <- getDirectoryContents d
filteredEntries <- return $ filter (\r -> length r >= 1 && head r /= '.') entries
curryFiles <- return $ filter ((== ".curry") . takeExtension) filteredEntries
directoryFlags <- mapIO doesDirectoryExist (map (d </>) filteredEntries)
directories <- return $ map fst $ filter snd $ zip filteredEntries directoryFlags
depMods <- mapIO (\d' -> findMods d' (d </> d')) directories
return $ (map (modWithPath p d) curryFiles) ++ concat depMods
modWithPath p d m = if p == "" then (takeBaseName m, d </> m)
else (p ++ "." ++ takeBaseName m, d </> m)
copyMod :: String -> [Package] -> String -> [(String, String)]
-> (String, String) -> IO ()
copyMod origDir deps dest nameMap (name, _) = do
dirExists <- doesDirectoryExist (takeDirectory destPath)
if dirExists
then return ()
else createDirectory (takeDirectory destPath)
transformAbstractCurryInDeps origDir deps (applyModuleRenames nameMap)
name destPath
where
newName = case lookup name nameMap of
Nothing -> name
Just n' -> n'
pathParts = splitOn "." newName
destPath = (joinPath (dest:pathParts)) ++ ".curry"
|