Skip to content

Commit

Permalink
[build] fix patches
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andreabedini committed Mar 30, 2022
1 parent 9017837 commit 3a0e89b
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions app/Foliage/CmdBuild.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,34 @@ cmdBuild
getSourceMeta <- addOracle $ \(GetSourceMeta PackageId {pkgName, pkgVersion}) ->
readSourceMeta' $ inputDir </> pkgName </> pkgVersion </> "meta.toml"

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

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

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

return $ case sourceSubdir of
Just s -> srcDir </> s
Nothing -> srcDir
let srcDir = case sourceSubdir of
Just s -> urlDir </> s
Nothing -> urlDir

let patchesDir = inputDir </> pkgName </> pkgVersion </> "patches"
hasPatches <- doesDirectoryExist patchesDir

when hasPatches $ do
patches <- getDirectoryFiles (inputDir </> pkgName </> pkgVersion </> "patches") ["*.patch"]
for_ patches $ \patch -> do
let patchfile = inputDir </> pkgName </> pkgVersion </> "patches" </> patch
putInfo $ "Applying patch: " <> patch
cmd_ Shell (Cwd srcDir) (FileStdin patchfile) "patch --backup -p1"

return srcDir

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

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

srcDir <- getSourceDir (GetSourceDir pkgId)

withTempDir $ \tmpDir -> do
putInfo $ " Creating source distribution for " <> pkgIdToString pkgId

let patchesDir = inputDir </> pkgName </> pkgVersion </> "patches"
hasPatches <- doesDirectoryExist patchesDir

when hasPatches $ do
patches <- getDirectoryFiles (inputDir </> pkgName </> pkgVersion </> "patches") ["*.patch"]
for_ patches $ \patch -> do
let patchfile = inputDir </> pkgName </> pkgVersion </> "patches" </> patch
putInfo $ "Applying patch: " <> patch
cmd_ Shell (Cwd srcDir) (FileStdin patchfile) "patch --backup -p1"

cmd_ Shell (Cwd srcDir) (FileStdout path) ("cabal sdist --ignore-project --output-directory " <> tmpDir)

-- check cabal sdist has produced a single tarball with the
Expand Down

0 comments on commit 3a0e89b

Please sign in to comment.