-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-add custom rule for GitClone and use git worktree to prepare source
This re-uses the git repository in the _cache/git/<user>/<repo> directory, but uses a temporary directory to get the worktree for a given rev to prepare the per-package directory in _cache/<package>.
- Loading branch information
Showing
4 changed files
with
72 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE DerivingVia #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
-- | Clone a github repository into a cache directory. | ||
module Foliage.GitClone ( | ||
gitClone, | ||
addGitCloneRule, | ||
) | ||
where | ||
|
||
import Development.Shake | ||
import Development.Shake.Classes | ||
import Development.Shake.FilePath | ||
import Development.Shake.Rule | ||
import Foliage.Meta (GitHubRepo) | ||
import GHC.Generics (Generic) | ||
|
||
newtype GitClone = GitClone {repo :: GitHubRepo} | ||
deriving (Eq, Generic) | ||
deriving newtype (NFData) | ||
|
||
instance Show GitClone where | ||
show GitClone{repo} = "gitClone " <> show repo | ||
|
||
instance Hashable GitClone | ||
|
||
instance Binary GitClone | ||
|
||
type instance RuleResult GitClone = FilePath | ||
|
||
-- | Clone given repo at given revision into the cache directory and return the working copy path. | ||
gitClone :: GitHubRepo -> Action FilePath | ||
gitClone repo = apply1 GitClone{repo} | ||
|
||
-- | Set up the 'GitClone' rule with a cache directory. | ||
addGitCloneRule | ||
:: FilePath | ||
-- ^ Cache directory | ||
-> Rules () | ||
addGitCloneRule cacheDir = addBuiltinRule noLint noIdentity run | ||
where | ||
run :: BuiltinRun GitClone FilePath | ||
run GitClone{repo} _old _mode = do | ||
let path = cacheDir </> "git" </> show repo | ||
|
||
alreadyCloned <- doesDirectoryExist path | ||
if alreadyCloned | ||
then command_ [Cwd path] "git" ["fetch"] | ||
else do | ||
let url = "https://github.com/" <> show repo <> ".git" | ||
command_ [] "git" ["clone", "--recursive", url, path] | ||
|
||
return $ RunResult{runChanged = ChangedRecomputeDiff, runStore = "", runValue = path} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters