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
83
|
module CPM.Diff.Rename (prefixPackageAndDeps) where
import System.Directory (doesDirectoryExist, getDirectoryContents, createDirectory)
import System.FilePath ((</>), joinPath, takeDirectory, takeBaseName, takeExtension)
import Data.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 -> ErrorLogger [(String, String)]
prefixPackageAndDeps cfg repo gc dir prefix destDir = do
deps <- resolveAndCopyDependencies cfg repo gc dir
depMods <- liftIOEL $ (mapM
(findAllModulesInPackage . RuntimeCache.cacheDirectory dir) deps)
ownMods <- liftIOEL $ findAllModulesInPackage dir
let allMods = ownMods ++ concat depMods
let modMap = zip (map fst allMods) (map ((prefix ++) . fst) allMods)
mapM (copyMod dir deps destDir modMap) allMods
return 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 <- mapM doesDirectoryExist (map (d </>) filteredEntries)
directories <- return $ map fst $ filter snd $ zip filteredEntries directoryFlags
depMods <- mapM (\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) -> ErrorLogger ()
copyMod origDir deps dest nameMap (name, _) = do
liftIOEL $ 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"
|