Skip to content

Commit cf78a94

Browse files
committed
Minor fixes.
1 parent 3839162 commit cf78a94

File tree

5 files changed

+32
-30
lines changed

5 files changed

+32
-30
lines changed

MicroCabal.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.0
22
name: MicroCabal
3-
version: 0.5.7.0
3+
version: 0.5.8.0
44
-- Update src/MicroCabal/Main.hs with version
55
synopsis: A partial Cabal replacement
66
license: Apache-2.0

src/MicroCabal/Backend/GHC.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ ghcBackend env = do
3131
compiler = ghcVersion,
3232
compilerExe = exe,
3333
doesPkgExist = ghcExists,
34-
patchDepends = id,
35-
patchName = id,
34+
patchDepends = \ _ x -> x,
35+
patchName = \ _ x -> x,
3636
buildPkgExe = ghcBuildExe,
3737
buildPkgLib = ghcBuildLib,
3838
buildPkgForLib = ghcBuildForeignLib,

src/MicroCabal/Backend/MHS.hs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,27 +215,26 @@ stripSuffix :: String -> String -> Maybe String
215215
stripSuffix suf str = reverse <$> stripPrefix (reverse suf) (reverse str)
216216

217217
-- Update build-depends for packages that have a special mhs version, also add ghc-compat.
218-
mhsPatchDepends :: Cabal -> Cabal
219-
mhsPatchDepends cbl@(Cabal sects) = Cabal (map patchSect sects)
218+
mhsPatchDepends :: Env -> Cabal -> Cabal
219+
mhsPatchDepends env cbl@(Cabal sects) = Cabal (map patchSect sects)
220220
where
221221
patchSect (Section styp sname flds) = Section styp sname (map patchField flds)
222222
patchField (Field "build-depends" (VPkgs ds)) = Field "build-depends" (VPkgs (mhsExtraPkgs cbl ++ map patchDep ds))
223223
patchField fld = fld
224224
patchDep d@(pkg, xs, _mv) | n /= pkg = (n, xs, Just (VEQ v))
225225
| otherwise = d
226-
where (n, v) = mhsPatchName (pkg, undefined)
226+
where (n, v) = mhsPatchName env (pkg, undefined)
227227

228228
-- Add a dependency on ghc-compat
229229
mhsExtraPkgs :: Cabal -> [(Item, [Item], Maybe VersionRange)]
230230
mhsExtraPkgs cbl | forMhs (getCabalName cbl) = []
231231
| otherwise = [ ("ghc-compat", [], Nothing) ]
232232
where forMhs n = n `elem` ["base", "ghc-compat", "MicroHs", "MicroCabal"]
233233

234-
mhsPatchName :: (Name, Version) -> (Name, Version)
235-
mhsPatchName (n, _) | Just nv <- lookup n mhsPackages =
236-
trace ("Changing package " ++ n ++ " to " ++ n ++ "-mhs") $
237-
nv
238-
mhsPatchName nv = nv
234+
mhsPatchName :: Env -> (Name, Version) -> (Name, Version)
235+
mhsPatchName env (n, _) | Just nv <- lookup n mhsPackages =
236+
if verbose env >= 0 then trace ("Changing package " ++ n ++ " to " ++ n ++ "-mhs") nv else nv
237+
mhsPatchName _ nv = nv
239238

240239
mhsPackages :: [(Name, (Name, Version))]
241240
mhsPackages =

src/MicroCabal/Env.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ data Backend = Backend {
3434
compiler :: String, -- name&version, e.g., "ghc-9.8.2"
3535
compilerExe :: String, -- name of binary
3636
doesPkgExist :: Env -> PackageName -> IO Bool, -- is the package available in the database?
37-
patchDepends :: Cabal -> Cabal, -- patch dependencies
38-
patchName :: (Name, Version) -> (Name, Version), -- patch package name
37+
patchDepends :: Env -> Cabal -> Cabal, -- patch dependencies
38+
patchName :: Env -> (Name, Version) -> (Name, Version), -- patch package name
3939
buildPkgExe :: Env -> Section -> Section -> IO (), -- build executable the current directory
4040
buildPkgLib :: Env -> Section -> Section -> IO (), -- build the package in the current directory
4141
buildPkgForLib :: Env -> Section -> Section -> IO (), -- build the foreign-library in the current directory

src/MicroCabal/Main.hs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import MicroCabal.Unix
2121

2222
-- Update cabal file when this changes
2323
version :: String
24-
version = "MicroCabal 0.5.7.0"
24+
version = "MicroCabal 0.5.8.0"
2525

2626
main :: IO ()
2727
main = do
@@ -142,7 +142,7 @@ cmdUpdate env [] = do
142142
let yml = parseYAML stk file
143143
pkgs = map hackName $ yamlToStackageList yml ++ dist
144144
ghcVersion = yamlToGHCVersion yml
145-
hackName s = s{ stName = n, stVersion = v } where (n, v) = patchName (backend env) (stName s, stVersion s)
145+
hackName s = s{ stName = n, stVersion = v } where (n, v) = patchName (backend env) env (stName s, stVersion s)
146146
-- putStrLn $ "==== " ++ ghcVersion
147147
-- putStrLn $ showYAML yml
148148
-- putStrLn $ show pkgs
@@ -210,21 +210,24 @@ cmdFetch env [pkg] = do
210210
pkgz = pkgs ++ ".tar.gz"
211211
pdir = dirForPackage env st
212212
file = pdir ++ ".tar.gz"
213-
b <- doesDirectoryExist pdir
214-
if b then
215-
message env 1 $ "Already in " ++ pdir
216-
else do
217-
mkdir env pdir
218-
message env 1 $ "Fetching package " ++ pkgs
219-
case gitRepo env of
220-
Nothing -> do
213+
case gitRepo env of
214+
Nothing -> do
215+
-- Doing a regular hackage fetch.
216+
b <- doesDirectoryExist pdir
217+
if b then
218+
message env 1 $ "No fetch, directory already exists " ++ pdir
219+
else do
221220
message env 1 $ "Fetching from Hackage " ++ pkgz
221+
mkdir env pdir
222222
wget env url file
223223
message env 1 $ "Unpacking " ++ pkgz ++ " in " ++ pdir
224224
tarx env (dirPackage env) file
225-
Just repo -> do
226-
message env 1 $ "Fetching from git repo " ++ pkg
227-
gitClone env pdir (URL repo)
225+
Just repo -> do
226+
-- Doing a git fetch.
227+
-- With --git we will always fetch, blowing away the old repo.
228+
rmrf env pdir
229+
message env 1 $ "Fetching from git repo " ++ pkg
230+
gitClone env pdir (URL repo)
228231
cmdFetch _ _ = usage
229232

230233
-----------------------------------------
@@ -240,13 +243,13 @@ findCabalFile _env = do
240243
cmdBuild :: Env -> [String] -> IO ()
241244
cmdBuild env [] = build env
242245
cmdBuild env [apkg] = do
243-
let pkg = fst $ patchName (backend env) (apkg, undefined)
246+
let pkg = fst $ patchName (backend env) env (apkg, undefined)
244247
message env 0 $ "Build package " ++ pkg
245248
st <- getPackageInfo env pkg
246249
let dir = dirForPackage env st
247250
b <- doesDirectoryExist dir
248-
when (not b) $ do
249-
message env 0 $ "Package not found, running 'fetch " ++ pkg ++ "'"
251+
when (not b || isJust (gitRepo env)) $ do
252+
message env 0 $ "Running 'fetch " ++ pkg ++ "'"
250253
cmdFetch env [pkg]
251254
message env 0 $ "Building in " ++ dir
252255
let dir' = maybe dir (dir </>) (subDir env)
@@ -508,4 +511,4 @@ cmdParse env [fn] = do
508511
cmdParse _ _ = error "cmdParse"
509512

510513
normalizeAndPatch :: Env -> FlagInfo -> Cabal -> Cabal
511-
normalizeAndPatch env flags = patchDepends (backend env) . normalize flags
514+
normalizeAndPatch env flags = patchDepends (backend env) env . normalize flags

0 commit comments

Comments
 (0)