Skip to content

Commit 48dbe4e

Browse files
committed
tweak script used to build candidate ghcide in benchmarks
The goal is to convince Cabal to apply the ghc options only to the ghcide binary and not to all the dependencies, which causes massive rebuilds and leads to benchmarks timeouts
1 parent a6f5deb commit 48dbe4e

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

ghcide/bench/hist/Main.hs

+21-7
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ import System.Console.GetOpt
5656
import Data.Maybe
5757
import Control.Monad.Extra
5858
import System.FilePath
59+
import System.Directory as IO
60+
import System.IO.Extra
5961

6062

6163
configPath :: FilePath
@@ -138,20 +140,32 @@ type instance RuleResult GetSamples = Natural
138140

139141
--------------------------------------------------------------------------------
140142

141-
buildGhcide :: BuildSystem -> [CmdOption] -> FilePath -> Action ()
142-
buildGhcide Cabal args out = do
143-
command_ args "cabal"
143+
buildGhcide
144+
:: BuildSystem
145+
-> Maybe FilePath -- ^ working directory
146+
-> FilePath -- ^ output folder
147+
-> Action ()
148+
buildGhcide Cabal cwd out = do
149+
let cabalLocal = fromMaybe ".." cwd </> "cabal.project.local"
150+
previousValue <- liftIO $ do
151+
itExisted <- IO.doesFileExist cabalLocal
152+
whenMaybe itExisted $ System.IO.Extra.readFile' cabalLocal
153+
liftIO $ writeFile cabalLocal $ unlines
154+
[ "package ghcide"
155+
, " ghc-options: -eventlog -rtsopts"]
156+
command_ (maybe [] (pure . Cwd) cwd) "cabal"
144157
["install"
145158
,"exe:ghcide"
146159
,"--installdir=" ++ out
147160
,"--install-method=copy"
148161
,"--overwrite-policy=always"
149-
,"--ghc-options=-rtsopts"
150-
,"--ghc-options=-eventlog"
151162
]
163+
`actionFinally` do
164+
liftIO $ removeFile cabalLocal
165+
liftIO $ whenJust previousValue $ writeFile cabalLocal
152166

153-
buildGhcide Stack args out =
154-
command_ args "stack"
167+
buildGhcide Stack cwd out =
168+
command_ (maybe [] (pure . Cwd) cwd) "stack"
155169
["--local-bin-path=" <> out
156170
,"build"
157171
,"ghcide:ghcide"

shake-bench/src/Development/Benchmark/Rules.hs

+9-8
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,18 @@ phonyRules prefix executableName prof buildFolder examples = do
171171
phony (prefix <> "all-binaries") $ need =<< allBinaries buildFolder executableName
172172
--------------------------------------------------------------------------------
173173
type OutputFolder = FilePath
174+
type CWD = FilePath
174175

175176
data MkBuildRules buildSystem = MkBuildRules
176177
{ -- | Return the path to the GHC executable to use for the project found in the cwd
177-
findGhc :: buildSystem -> FilePath -> IO FilePath
178+
findGhc :: buildSystem -> Maybe CWD -> IO FilePath
178179
-- | Name of the binary produced by 'buildProject'
179180
, executableName :: String
180181
-- | An action that captures the source dependencies, used for the HEAD build
181182
, projectDepends :: Action ()
182183
-- | Build the project found in the cwd and save the build artifacts in the output folder
183184
, buildProject :: buildSystem
184-
-> [CmdOption]
185+
-> Maybe CWD
185186
-> OutputFolder
186187
-> Action ()
187188
}
@@ -209,8 +210,8 @@ buildRules build MkBuildRules{..} = do
209210
projectDepends
210211
liftIO $ createDirectoryIfMissing True $ dropFileName out
211212
buildSystem <- askOracle $ GetBuildSystem ()
212-
buildProject buildSystem [Cwd "."] (takeDirectory out)
213-
ghcLoc <- liftIO $ findGhc buildSystem "."
213+
buildProject buildSystem Nothing (takeDirectory out)
214+
ghcLoc <- liftIO $ findGhc buildSystem Nothing
214215
writeFile' ghcpath ghcLoc
215216

216217
-- build rules for non HEAD revisions
@@ -223,8 +224,8 @@ buildRules build MkBuildRules{..} = do
223224
cmd_ $ "git worktree add bench-temp-" ++ ver ++ " " ++ commitid
224225
buildSystem <- askOracle $ GetBuildSystem ()
225226
flip actionFinally (cmd_ ("git worktree remove bench-temp-" <> ver <> " --force" :: String)) $ do
226-
ghcLoc <- liftIO $ findGhc buildSystem ver
227-
buildProject buildSystem [Cwd $ "bench-temp-" <> ver] (".." </> takeDirectory out)
227+
ghcLoc <- liftIO $ findGhc buildSystem (Just ver)
228+
buildProject buildSystem (Just $ "bench-temp-" <> ver) (".." </> takeDirectory out)
228229
writeFile' ghcPath ghcLoc
229230

230231
--------------------------------------------------------------------------------
@@ -461,11 +462,11 @@ data BuildSystem = Cabal | Stack
461462
deriving (Eq, Read, Show, Generic)
462463
deriving (Binary, Hashable, NFData)
463464

464-
findGhcForBuildSystem :: BuildSystem -> FilePath -> IO FilePath
465+
findGhcForBuildSystem :: BuildSystem -> Maybe FilePath -> IO FilePath
465466
findGhcForBuildSystem Cabal _cwd =
466467
liftIO $ fromMaybe (error "ghc is not in the PATH") <$> findExecutable "ghc"
467468
findGhcForBuildSystem Stack cwd = do
468-
Stdout ghcLoc <- cmd [Cwd cwd] ("stack exec which ghc" :: String)
469+
Stdout ghcLoc <- cmd (maybe [] (pure . Cwd) cwd) ("stack exec which ghc" :: String)
469470
return ghcLoc
470471

471472
instance FromJSON BuildSystem where

0 commit comments

Comments
 (0)