Skip to content

Commit

Permalink
chore: only build files tracked by git
Browse files Browse the repository at this point in the history
  • Loading branch information
ncfavier committed Dec 14, 2023
1 parent 782088c commit b501a23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 15 additions & 1 deletion support/shake/app/Shake/Git.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{-# LANGUAGE BlockArguments, GeneralizedNewtypeDeriving, TypeFamilies #-}

module Shake.Git
( gitCommit
( gitFiles
, gitCommit
, gitAuthors
, gitRules
) where
Expand All @@ -22,6 +23,15 @@ import Development.Shake
gitCommand :: CmdResult r => [String] -> Action r
gitCommand args = command [] "git" (["--git-dir", ".git"] ++ args)

newtype GitFiles = GitFiles ()
deriving (Show, Typeable, Eq, Hashable, Binary, NFData)

type instance RuleResult GitFiles = [FilePath]

-- | Get the list of files tracked by git.
gitFiles :: Action [FilePath]
gitFiles = askOracle (GitFiles ())

newtype GitCommit = GitCommit ()
deriving (Show, Typeable, Eq, Hashable, Binary, NFData)

Expand Down Expand Up @@ -62,6 +72,10 @@ doGitAuthors (GitAuthors path) = do
-- | Shake rules required for reading Git information.
gitRules :: Rules()
gitRules = versioned 1 do
_ <- addOracle \(GitFiles ()) -> do
Stdout t <- gitCommand ["ls-files", "--full-name"]
pure (lines t)

_ <- addOracle \(GitCommit ()) -> do
Stdout t <- gitCommand ["rev-parse", "--verify", "HEAD"]
pure (head (lines t))
Expand Down
6 changes: 5 additions & 1 deletion support/shake/app/Shake/Modules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import GHC.Generics (Generic)

import HTML.Backend (moduleName)

import Shake.Git

type ModName = String

data ModulesQ = ModulesQ
Expand Down Expand Up @@ -55,11 +57,13 @@ moduleRules :: Rules ()
moduleRules = do
_ <- addOracle \ModulesQ -> do
let
isAgda x = any (?== x) ["src//*.agda", "src//*.lagda.md"]

toOut x | takeExtensions x == ".lagda.md"
= (moduleName (dropExtensions x), WithText)
toOut x = (moduleName (dropExtensions x), CodeOnly)

ModulesA . Map.fromList . map toOut <$> getDirectoryFiles "src" ["**/*.agda", "**/*.lagda.md"]
ModulesA . Map.fromList . map (toOut . dropDirectory1) . filter isAgda <$> gitFiles
pure ()

-- | Get all 1Lab modules.
Expand Down

0 comments on commit b501a23

Please sign in to comment.