Skip to content
This repository was archived by the owner on Nov 1, 2018. It is now read-only.

Commit 360d740

Browse files
committed
Squashed 'hadrian/' changes from fa3771f..4499b29
4499b29 Follow GHC changes 8fd6818 Add ways to build hadrian using nix e5c7a29 Do not depend on the in-tree filepath library 9dd7ad2 Fix dependencies 4971843 Bring mtl dependency back 6c5f5c9 Minor clean up of Hadrian dependencies 9aff81d Fix Windows build fa95caa Unbreak `cabal new-build` git-subtree-dir: hadrian git-subtree-split: 4499b29
1 parent c1fcd9b commit 360d740

File tree

12 files changed

+135
-37
lines changed

12 files changed

+135
-37
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ Notes:
4141
on Cabal sandboxes (`build.cabal.*`), Stack (`build.stack.*`) or the global package database
4242
(`build.global-db.*`). Also see [instructions for building GHC on Windows using Stack][windows-build].
4343

44-
* Hadrian is written in Haskell and depends on the following packages:
45-
`ansi-terminal extra mtl quickcheck shake`.
44+
* Hadrian is written in Haskell and depends on `shake` (plus a few packages that `shake` depends on),
45+
`ansi-terminal`, `mtl`, `quickcheck`, and GHC core libraries.
4646

4747
* If you have never built GHC before, start with the [preparation guide][ghc-preparation].
4848

build.nix.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env nix-shell
2+
#! nix-shell -i bash shell.nix
3+
4+
# This script sets up the build environment by invoking nix-shell shell.nix
5+
# and then runs the hadrian executable.
6+
7+
function rl {
8+
TARGET_FILE="$1"
9+
10+
cd "$(dirname "$TARGET_FILE")"
11+
TARGET_FILE="$(basename "$TARGET_FILE")"
12+
13+
# Iterate down a (possible) chain of symlinks
14+
while [ -L "$TARGET_FILE" ]
15+
do
16+
TARGET_FILE="$(readlink "$TARGET_FILE")"
17+
cd "$(dirname "$TARGET_FILE")"
18+
TARGET_FILE="$(basename "$TARGET_FILE")"
19+
done
20+
21+
# Compute the canonicalized name by finding the physical path
22+
# for the directory we're in and appending the target file.
23+
PHYS_DIR="$(pwd -P)"
24+
RESULT="$PHYS_DIR/$TARGET_FILE"
25+
echo "$RESULT"
26+
}
27+
28+
absoluteRoot="$(dirname "$(rl "$0")")"
29+
echo $absoluteRoot
30+
cd "$absoluteRoot"
31+
32+
hadrian \
33+
--lint \
34+
--directory="$absoluteRoot/.." \
35+
"$@"

cabal.project

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
packages: ./
22
../libraries/Cabal/Cabal/
3-
../libraries/filepath/
4-
../libraries/text/
53
../libraries/hpc/
64
../libraries/parsec/
5+
../libraries/text/

hadrian.cabal

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,17 @@ executable hadrian
116116
, TupleSections
117117
other-extensions: MultiParamTypeClasses
118118
, TypeFamilies
119-
build-depends: base >= 4.8 && < 5
119+
build-depends: base >= 4.8 && < 5
120120
, ansi-terminal == 0.6.*
121121
, Cabal >= 2.0.0.2 && < 2.2
122122
, containers == 0.5.*
123-
, directory >= 1.2 && < 1.4
123+
, directory >= 1.2 && < 1.4
124124
, extra >= 1.4.7
125125
, mtl == 2.2.*
126-
, QuickCheck >= 2.6 && < 2.10
126+
, QuickCheck >= 2.6 && < 2.10
127127
, shake == 0.16.*
128-
, transformers >= 0.4 && < 0.6
129-
, unordered-containers == 0.2.*
128+
, transformers >= 0.4 && < 0.6
129+
, unordered-containers >= 0.2.1 && < 0.3
130130
build-tools: alex >= 3.1
131131
, happy >= 1.19.4
132132
ghc-options: -Wall

shell.nix

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Invoking nix-shell sets up an environment where we can build ghc
2+
# by only invoking hadrian.
3+
4+
5+
{ nixpkgs ? import <nixpkgs> {} }:
6+
7+
let
8+
haskellPackages = nixpkgs.haskell.packages.ghc821;
9+
10+
removeBuild = path: type:
11+
let baseName = baseNameOf (toString path);
12+
in
13+
! (baseName == "_build"
14+
|| baseName == "dist"
15+
|| baseName == "dist-newstyle"
16+
|| baseName == ".stack-work"
17+
|| baseName == "config.log"
18+
|| baseName == "config.status"
19+
|| nixpkgs.lib.hasSuffix ".sh" baseName
20+
|| !(nixpkgs.lib.cleanSourceFilter path type)) ;
21+
22+
filterSrc = path: builtins.filterSource removeBuild path;
23+
24+
25+
hadrianPackages = nixpkgs.haskell.packages.ghc821.override {
26+
overrides = self: super: let
27+
localPackage = name: path: self.callCabal2nix name (filterSrc path) {};
28+
in {
29+
hadrian = localPackage "hadrian" ./. ;
30+
shake = self.callHackage "shake" "0.16" {};
31+
Cabal = localPackage "Cabal" ./../libraries/Cabal/Cabal ;
32+
filepath = localPackage "filepath" ./../libraries/filepath ;
33+
text = localPackage "text" ./../libraries/text ;
34+
hpc = localPackage"hpc" ./../libraries/hpc ;
35+
parsec = localPackage "parsec" ./../libraries/parsec ;
36+
HUnit = nixpkgs.haskell.lib.dontCheck (self.callHackage "HUnit" "1.3.1.2" {});
37+
process = localPackage "process" ./../libraries/process ;
38+
directory = localPackage "directory" ./../libraries/directory ;
39+
}; };
40+
41+
in
42+
43+
nixpkgs.stdenv.mkDerivation {
44+
name = "ghc-dev";
45+
buildInputs = [
46+
hadrianPackages.hadrian
47+
nixpkgs.haskell.compiler.ghc821
48+
haskellPackages.alex
49+
haskellPackages.happy
50+
nixpkgs.python3
51+
nixpkgs.git
52+
nixpkgs.autoconf
53+
nixpkgs.automake
54+
nixpkgs.perl
55+
nixpkgs.gcc
56+
nixpkgs.python3Packages.sphinx
57+
nixpkgs.ncurses
58+
nixpkgs.m4
59+
nixpkgs.gmp
60+
nixpkgs.file ];
61+
}

src/Rules/Compile.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ compilePackage rs context@Context {..} = do
2222
path <- buildPath context
2323
(src, deps) <- lookupDependencies (path -/- ".dependencies") obj
2424
need $ src : deps
25-
when (isLibrary package) $ need =<< return <$> pkgConfFile context
26-
needLibrary =<< contextDependencies context
2725
buildWithResources rs $ target context (Ghc CompileHs stage) [src] [obj]
2826

2927
priority 2.0 $ do

src/Rules/Dependencies.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ buildPackageDependencies rs context@Context {..} =
1919
orderOnly =<< interpretInContext context generatedDependencies
2020
let mk = deps <.> "mk"
2121
if null srcs
22-
then writeFileChanged mk ""
22+
then writeFile' mk ""
2323
else buildWithResources rs $
2424
target context (Ghc FindHsDependencies stage) srcs [mk]
2525
removeFile $ mk <.> "bak"
26-
mkDeps <- readFile' mk
26+
mkDeps <- liftIO $ readFile mk
2727
writeFileChanged deps . unlines
2828
. map (\(src, deps) -> unwords $ src : deps)
2929
. map (bimap unifyPath (map unifyPath))

src/Rules/Program.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ buildWrapper context@Context {..} wrapper wrapperPath wrapped = do
9292
putSuccess $ "| Successfully created wrapper for " ++
9393
quote (pkgName package) ++ " (" ++ show stage ++ ")."
9494

95-
-- TODO: Get rid of the Paths_hsc2hs.o hack.
9695
buildBinary :: [(Resource, Int)] -> FilePath -> Context -> Action ()
9796
buildBinary rs bin context@Context {..} = do
9897
binDeps <- if stage == Stage0 && package == ghcCabal
@@ -107,8 +106,6 @@ buildBinary rs bin context@Context {..} = do
107106
cObjs <- mapM (objectPath context) cSrcs
108107
hsObjs <- hsObjects context
109108
return $ cObjs ++ hsObjs
110-
++ [ path -/- "Paths_hsc2hs.o" | package == hsc2hs ]
111-
++ [ path -/- "Paths_haddock.o" | package == haddock ]
112109
need binDeps
113110
buildWithResources rs $ target context (Ghc LinkHs stage) binDeps [bin]
114111
synopsis <- traverse pkgSynopsis (pkgCabalFile package)

src/Settings/Builders/Ghc.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ haddockGhcArgs = mconcat [ commonGhcArgs, getPkgDataList HsArgs ]
8787
-- Used in ghcBuilderArgs, ghcCBuilderArgs, ghcMBuilderArgs and haddockGhcArgs.
8888
commonGhcArgs :: Args
8989
commonGhcArgs = do
90-
way <- getWay
91-
path <- getBuildPath
92-
pkg <- getPackage
93-
when (isLibrary pkg) $ do
90+
way <- getWay
91+
path <- getBuildPath
92+
pkg <- getPackage
93+
when (pkg == rts) $ do
9494
context <- getContext
9595
conf <- expr $ pkgConfFile context
9696
expr $ need [conf]

src/Settings/Packages/GhcCabal.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import Utilities
88

99
ghcCabalPackageArgs :: Args
1010
ghcCabalPackageArgs = stage0 ? package ghcCabal ? builder Ghc ? do
11-
cabalDeps <- expr $ stage1Dependencies cabal
11+
cabalDeps <- expr $ stage1Dependencies cabal
12+
let bootDeps = cabalDeps \\ [integerGmp, integerSimple, mtl, parsec, text]
1213
cabalVersion <- expr $ pkgVersion (unsafePkgCabalFile cabal) -- TODO: improve
1314
mconcat
14-
[ pure [ "-package " ++ pkgName pkg | pkg <- cabalDeps \\ [parsec, mtl] ]
15+
[ pure [ "-package " ++ pkgName pkg | pkg <- bootDeps ]
1516
, arg "--make"
1617
, arg "-j"
1718
, pure ["-Wall", "-fno-warn-unused-imports", "-fno-warn-warnings-deprecations"]

src/Utilities.hs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,29 @@ buildWithResources rs target = H.buildWithResources rs target getArgs
2424
buildWithCmdOptions :: [CmdOption] -> Target -> Action ()
2525
buildWithCmdOptions opts target = H.buildWithCmdOptions opts target getArgs
2626

27-
-- | Given a 'Context' this 'Action' look up the package dependencies and wrap
27+
-- TODO: Cache the computation.
28+
-- | Given a 'Context' this 'Action' looks up the package dependencies and wraps
2829
-- the results in appropriate contexts. The only subtlety here is that we never
2930
-- depend on packages built in 'Stage2' or later, therefore the stage of the
3031
-- resulting dependencies is bounded from above at 'Stage1'. To compute package
31-
-- dependencies we scan package @.cabal@ files, see 'pkgDependencies' defined
32-
-- in "Hadrian.Haskell.Cabal".
32+
-- dependencies we transitively scan @.cabal@ files using 'pkgDependencies'
33+
-- defined in "Hadrian.Haskell.Cabal".
3334
contextDependencies :: Context -> Action [Context]
34-
contextDependencies Context {..} = case pkgCabalFile package of
35-
Nothing -> return [] -- Non-Cabal packages have no dependencies.
36-
Just cabalFile -> do
37-
let depStage = min stage Stage1
38-
depContext = \pkg -> Context depStage pkg way
39-
deps <- pkgDependencies cabalFile
40-
pkgs <- sort <$> stagePackages depStage
41-
return . map depContext $ intersectOrd (compare . pkgName) pkgs deps
35+
contextDependencies Context {..} = do
36+
depPkgs <- go [package]
37+
return [ Context depStage pkg way | pkg <- depPkgs, pkg /= package ]
38+
where
39+
depStage = min stage Stage1
40+
go pkgs = do
41+
deps <- concatMapM step pkgs
42+
let newPkgs = nubOrd $ sort (deps ++ pkgs)
43+
if pkgs == newPkgs then return pkgs else go newPkgs
44+
step pkg = case pkgCabalFile pkg of
45+
Nothing -> return [] -- Non-Cabal packages have no dependencies.
46+
Just cabalFile -> do
47+
deps <- pkgDependencies cabalFile
48+
active <- sort <$> stagePackages depStage
49+
return $ intersectOrd (compare . pkgName) active deps
4250

4351
-- | Lookup dependencies of a 'Package' in the vanilla Stage1 context.
4452
stage1Dependencies :: Package -> Action [Package]

stack.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ resolver: lts-9.0
77
packages:
88
- '.'
99
- '../libraries/Cabal/Cabal'
10-
- '../libraries/filepath/'
11-
- '../libraries/text/'
12-
- '../libraries/hpc/'
13-
- '../libraries/parsec/'
10+
- '../libraries/hpc'
11+
- '../libraries/parsec'
12+
- '../libraries/text'
1413

1514
extra-deps:
1615
- shake-0.16

0 commit comments

Comments
 (0)