Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

Commit

Permalink
.bat file tidy up plus shake-0.16 compatibility (#392)
Browse files Browse the repository at this point in the history
* Switch from @ to @echo off in the batch files

* Make sure the .bat files do setlocal - ensures if it fails you don't keep the directory change

* Give RuleResult instances to all the oracles, as required by the forthcoming shake-0.16
  • Loading branch information
ndmitchell authored and snowleopard committed Aug 17, 2017
1 parent 67ae38d commit df4848c
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 32 deletions.
52 changes: 27 additions & 25 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
@cd %~dp0
@mkdir bin 2> nul
@echo off
setlocal
cd %~dp0
mkdir bin 2> nul

@set ghcArgs=--make ^
-Wall ^
-fno-warn-name-shadowing ^
-XRecordWildCards ^
src\Main.hs ^
-threaded ^
-isrc ^
-i..\libraries\Cabal\Cabal ^
-rtsopts ^
-with-rtsopts=-I0 ^
-outputdir=bin ^
-j ^
-O ^
-o bin\hadrian
set ghcArgs=--make ^
-Wall ^
-fno-warn-name-shadowing ^
-XRecordWildCards ^
src\Main.hs ^
-threaded ^
-isrc ^
-i..\libraries\Cabal\Cabal ^
-rtsopts ^
-with-rtsopts=-I0 ^
-outputdir=bin ^
-j ^
-O ^
-o bin\hadrian

@set hadrianArgs=--lint ^
--directory ^
".." ^
%*
set hadrianArgs=--lint ^
--directory ^
".." ^
%*


@ghc %ghcArgs%
ghc %ghcArgs%

@if %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
if %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%

@rem Unset GHC_PACKAGE_PATH variable, as otherwise ghc-cabal complains
@set GHC_PACKAGE_PATH=
@bin\hadrian %hadrianArgs%
rem Unset GHC_PACKAGE_PATH variable, as otherwise ghc-cabal complains
set GHC_PACKAGE_PATH=
bin\hadrian %hadrianArgs%
16 changes: 9 additions & 7 deletions build.stack.bat
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
@rem Change the current directory to the one containing this script
@cd %~dp0
@echo off
setlocal
rem Change the current directory to the one containing this script
cd %~dp0

@rem Build Hadrian and dependencies and exit the script if the build failed
@stack build
@if %errorlevel% neq 0 exit /B %errorlevel%
rem Build Hadrian and dependencies and exit the script if the build failed
stack build
if %errorlevel% neq 0 exit /B %errorlevel%

@rem Run Hadrian in GHC top directory forwarding additional user arguments
@stack exec hadrian -- --lint --directory ".." %*
rem Run Hadrian in GHC top directory forwarding additional user arguments
stack exec hadrian -- --lint --directory ".." %*
3 changes: 3 additions & 0 deletions src/Hadrian/Oracles/ArgsHash.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE TypeFamilies #-}
module Hadrian.Oracles.ArgsHash (
TrackArgument, trackAllArguments, trackArgsHash, argsHashOracle
) where
Expand All @@ -8,6 +9,7 @@ import Development.Shake.Classes

import Hadrian.Expression hiding (inputs, outputs)
import Hadrian.Target
import Hadrian.Utilities

-- | 'TrackArgument' is used to specify the arguments that should be tracked by
-- the @ArgsHash@ oracle. The safest option is to track all arguments, but some
Expand Down Expand Up @@ -38,6 +40,7 @@ trackArgsHash t = do

newtype ArgsHash c b = ArgsHash (Target c b)
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
type instance RuleResult (ArgsHash c b) = Int

-- | This oracle stores per-target argument list hashes in the Shake database,
-- allowing the user to track them between builds using 'trackArgsHash' queries.
Expand Down
2 changes: 2 additions & 0 deletions src/Hadrian/Oracles/DirectoryContents.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE TypeFamilies #-}
module Hadrian.Oracles.DirectoryContents (
directoryContents, copyDirectoryContents, directoryContentsOracle,
Match (..), matches, matchAll
Expand Down Expand Up @@ -46,6 +47,7 @@ copyDirectoryContents expr source target = do

newtype DirectoryContents = DirectoryContents (Match, FilePath)
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
type instance RuleResult DirectoryContents = [FilePath]

-- | This oracle answers 'directoryContents' queries and tracks the results.
directoryContentsOracle :: Rules ()
Expand Down
2 changes: 2 additions & 0 deletions src/Hadrian/Oracles/FileCache.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE TypeFamilies #-}
-----------------------------------------------------------------------------
-- |
-- Module : Hadrian.Oracles.FileCache
Expand All @@ -22,6 +23,7 @@ import Hadrian.Utilities

newtype FileCache = FileCache FilePath
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
type instance RuleResult FileCache = String

-- | Read a text file, caching and tracking the result. To read and track
-- individual lines of the file, see "Hadrian.Oracles.KeyValue".
Expand Down
3 changes: 3 additions & 0 deletions src/Hadrian/Oracles/KeyValue.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE TypeFamilies #-}
module Hadrian.Oracles.KeyValue (
lookupValue, lookupValueOrEmpty, lookupValueOrError, lookupValues,
lookupValuesOrEmpty, lookupValuesOrError, lookupDependencies, keyValueOracle
Expand All @@ -14,9 +15,11 @@ import Hadrian.Utilities

newtype KeyValue = KeyValue (FilePath, String)
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
type instance RuleResult KeyValue = Maybe String

newtype KeyValues = KeyValues (FilePath, String)
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
type instance RuleResult KeyValues = Maybe [String]

-- | Lookup a value in a text file, tracking the result. Each line of the file
-- is expected to have @key = value@ format.
Expand Down
3 changes: 3 additions & 0 deletions src/Hadrian/Oracles/Path.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE TypeFamilies #-}
module Hadrian.Oracles.Path (
lookupInPath, bashPath, fixAbsolutePathOnWindows, pathOracle
) where
Expand Down Expand Up @@ -39,9 +40,11 @@ fixAbsolutePathOnWindows path = do

newtype LookupInPath = LookupInPath String
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
type instance RuleResult LookupInPath = String

newtype WindowsPath = WindowsPath FilePath
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
type instance RuleResult WindowsPath = String

-- | Oracles for looking up paths. These are slow and require caching.
pathOracle :: Rules ()
Expand Down
7 changes: 7 additions & 0 deletions src/Hadrian/Utilities.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE TypeFamilies #-}
module Hadrian.Utilities (
-- * List manipulation
fromSingleton, replaceEq, minusOrd, intersectOrd, lookupAll,
Expand All @@ -24,6 +25,9 @@ module Hadrian.Utilities (
putProgressInfo, renderAction, renderProgram, renderLibrary, renderBox,
renderUnicorn,

-- * Shake compatibility
RuleResult,

-- * Miscellaneous
(<&>), (%%>),

Expand Down Expand Up @@ -156,6 +160,9 @@ buildRoot = do

infixl 1 <&>

-- | Introduced in shake-0.16, so use to make the rest of the code compatible
type family RuleResult a

-- | Given a 'FilePath' to a source file, return 'True' if it is generated.
-- The current implementation simply assumes that a file is generated if it
-- lives in the 'buildRoot' directory. Since most files are not generated the
Expand Down
3 changes: 3 additions & 0 deletions src/Oracles/ModuleFiles.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE TypeFamilies #-}
module Oracles.ModuleFiles (
decodeModule, encodeModule, findGenerator, hsSources, hsObjects, moduleFilesOracle
) where
Expand All @@ -11,9 +12,11 @@ import Oracles.PackageData

newtype ModuleFiles = ModuleFiles (Stage, Package)
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
type instance RuleResult ModuleFiles = [Maybe FilePath]

newtype Generator = Generator (Stage, Package, FilePath)
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
type instance RuleResult Generator = Maybe FilePath

-- | We scan for the following Haskell source extensions when looking for module
-- files. Note, we do not list "*.(l)hs-boot" files here, as they can never
Expand Down

0 comments on commit df4848c

Please sign in to comment.