Skip to content

Commit

Permalink
Make gitCheckout just an Action, no additional rule
Browse files Browse the repository at this point in the history
This avoids some boiler plate and works just the same.
  • Loading branch information
ch1bo committed Nov 13, 2023
1 parent 7cd94c9 commit cae3ce4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 63 deletions.
2 changes: 0 additions & 2 deletions app/Foliage/CmdBuild.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import Distribution.Package
import Distribution.Pretty (prettyShow)
import Distribution.Version
import Foliage.FetchURL (addFetchURLRule)
import Foliage.GitClone (addGitCloneRule)
import Foliage.HackageSecurity hiding (ToJSON, toJSON)
import Foliage.Meta
import Foliage.Meta.Aeson ()
Expand All @@ -43,7 +42,6 @@ cmdBuild buildOptions = do
shake opts $
do
addFetchURLRule cacheDir
addGitCloneRule cacheDir
addPrepareSourceRule (buildOptsInputDir buildOptions) cacheDir
addPrepareSdistRule outputDirRoot
phony "buildAction" (buildAction buildOptions)
Expand Down
57 changes: 0 additions & 57 deletions app/Foliage/GitClone.hs

This file was deleted.

19 changes: 16 additions & 3 deletions app/Foliage/PrepareSource.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import Distribution.Pretty (prettyShow)
import Distribution.Types.PackageId
import Distribution.Types.PackageName (unPackageName)
import Foliage.FetchURL (fetchURL)
import Foliage.GitClone (gitClone)
import Foliage.Meta
import Foliage.UpdateCabalFile (rewritePackageVersion)
import GHC.Generics
Expand Down Expand Up @@ -70,8 +69,8 @@ addPrepareSourceRule inputDir cacheDir = addBuiltinRule noLint noIdentity run
tarballPath <- fetchURL uri
extractFromTarball tarballPath mSubdir srcDir
GitHubSource repo rev mSubdir -> do
workDir <- gitClone repo rev
let packageDir = maybe workDir (workDir </>) mSubdir
workingCopy <- gitCheckout cacheDir repo rev
let packageDir = maybe workingCopy (workingCopy </>) mSubdir
copyDirectoryContents packageDir srcDir

let patchesDir = inputDir </> unPackageName pkgName </> prettyShow pkgVersion </> "patches"
Expand Down Expand Up @@ -120,6 +119,20 @@ addPrepareSourceRule inputDir cacheDir = addBuiltinRule noLint noIdentity run

copyDirectoryContents srcDir outDir

gitCheckout :: FilePath -> GitHubRepo -> GitHubRev -> Action FilePath
gitCheckout cacheDir repo rev = do
alreadyCloned <- doesDirectoryExist path
if alreadyCloned
then command_ [Cwd path] "git" ["fetch"]
else command_ [] "git" ["clone", "--recursive", url, path]
command_ [Cwd path] "git" ["checkout", show rev]
command_ [Cwd path] "git" ["submodule", "update"]
pure path
where
path = cacheDir </> "git" </> show repo

url = "https://github.com/" <> show repo <> ".git"

copyDirectoryContents :: FilePath -> FilePath -> Action ()
copyDirectoryContents source destination =
cmd_
Expand Down
1 change: 0 additions & 1 deletion foliage.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ executable foliage
Foliage.CmdCreateKeys
Foliage.CmdImportIndex
Foliage.FetchURL
Foliage.GitClone
Foliage.HackageSecurity
Foliage.Meta
Foliage.Meta.Aeson
Expand Down
4 changes: 4 additions & 0 deletions tests/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ main = do
inTemporaryDirectoryWithFixture "tests/fixtures/git-submodule" $ do
step "Building repository"
callCommand "foliage build"

doesFileExist "_cache/git/cardano-scaling/foliage-test-with-submodule/README.md" @? "Missing working copy"
doesFileExist "_cache/foliage-test-with-submodule/1.0.0/README.md" @? "Missing packaged version"
doesFileExist "_cache/foliage-test-with-submodule/1.1.0/README.md" @? "Missing packaged version"
, ---
testCaseSteps "accepts --no-signatures" $ \step ->
inTemporaryDirectoryWithFixture "tests/fixtures/simple" $ do
Expand Down

0 comments on commit cae3ce4

Please sign in to comment.