Skip to content

Commit 3a0e89b

Browse files
committed
[build] fix patches
I was applying patches only when making the source distribution but patches might modify the cabal file which goes into the index (yes one should use revisions for that). I am now applying patches right after I have the package source.
1 parent 9017837 commit 3a0e89b

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

Diff for: app/Foliage/CmdBuild.hs

+22-21
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,34 @@ cmdBuild
6969
getSourceMeta <- addOracle $ \(GetSourceMeta PackageId {pkgName, pkgVersion}) ->
7070
readSourceMeta' $ inputDir </> pkgName </> pkgVersion </> "meta.toml"
7171

72-
getSourceDir <- addOracle $ \(GetSourceDir pkgId) -> do
72+
getSourceDir <- addOracle $ \(GetSourceDir pkgId@PackageId {pkgName, pkgVersion}) -> do
7373
SourceMeta {sourceUrl, sourceSubdir} <- getSourceMeta (GetSourceMeta pkgId)
74-
let srcDir = "_cache" </> urlToFileName sourceUrl
74+
let urlDir = "_cache" </> urlToFileName sourceUrl
7575

76-
need [srcDir </> ".downloaded"]
76+
need [urlDir </> ".downloaded"]
7777
-- FIXME Without this, sometimes the download doesn't trigger
7878
putInfo $ "👀 " <> sourceUrl
7979

80-
projectFiles <- liftIO $ filter ("cabal.project" `isPrefixOf`) <$> IO.getDirectoryContents srcDir
80+
projectFiles <- liftIO $ filter ("cabal.project" `isPrefixOf`) <$> IO.getDirectoryContents urlDir
8181
unless (null projectFiles) $ do
82-
putWarn $ "⚠️ Deleting cabal project files from " ++ srcDir
83-
liftIO $ for_ projectFiles $ IO.removeFile . (srcDir </>)
82+
putWarn $ "⚠️ Deleting cabal project files from " ++ urlDir
83+
liftIO $ for_ projectFiles $ IO.removeFile . (urlDir </>)
8484

85-
return $ case sourceSubdir of
86-
Just s -> srcDir </> s
87-
Nothing -> srcDir
85+
let srcDir = case sourceSubdir of
86+
Just s -> urlDir </> s
87+
Nothing -> urlDir
88+
89+
let patchesDir = inputDir </> pkgName </> pkgVersion </> "patches"
90+
hasPatches <- doesDirectoryExist patchesDir
91+
92+
when hasPatches $ do
93+
patches <- getDirectoryFiles (inputDir </> pkgName </> pkgVersion </> "patches") ["*.patch"]
94+
for_ patches $ \patch -> do
95+
let patchfile = inputDir </> pkgName </> pkgVersion </> "patches" </> patch
96+
putInfo $ "Applying patch: " <> patch
97+
cmd_ Shell (Cwd srcDir) (FileStdin patchfile) "patch --backup -p1"
98+
99+
return srcDir
88100

89101
getPackages <- addOracle $ \GetPackages -> do
90102
metaFiles <- getDirectoryFiles inputDir ["*/*/meta.toml"]
@@ -341,23 +353,12 @@ cmdBuild
341353

342354
outputDir </> "package/*.tar.gz" %> \path -> do
343355
let [_, _, filename] = splitDirectories path
344-
let Just pkgId@PackageId {pkgName, pkgVersion} = parsePkgId <$> stripExtension "tar.gz" filename
356+
let Just pkgId = parsePkgId <$> stripExtension "tar.gz" filename
345357

346358
srcDir <- getSourceDir (GetSourceDir pkgId)
347359

348360
withTempDir $ \tmpDir -> do
349361
putInfo $ " Creating source distribution for " <> pkgIdToString pkgId
350-
351-
let patchesDir = inputDir </> pkgName </> pkgVersion </> "patches"
352-
hasPatches <- doesDirectoryExist patchesDir
353-
354-
when hasPatches $ do
355-
patches <- getDirectoryFiles (inputDir </> pkgName </> pkgVersion </> "patches") ["*.patch"]
356-
for_ patches $ \patch -> do
357-
let patchfile = inputDir </> pkgName </> pkgVersion </> "patches" </> patch
358-
putInfo $ "Applying patch: " <> patch
359-
cmd_ Shell (Cwd srcDir) (FileStdin patchfile) "patch --backup -p1"
360-
361362
cmd_ Shell (Cwd srcDir) (FileStdout path) ("cabal sdist --ignore-project --output-directory " <> tmpDir)
362363

363364
-- check cabal sdist has produced a single tarball with the

0 commit comments

Comments
 (0)