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

Commit

Permalink
Eliminate 'ghc.mk' from the 'sdist-ghc' rule
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiHa committed Jun 14, 2016
1 parent 7f167ab commit 9495da2
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 25 deletions.
4 changes: 3 additions & 1 deletion src/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import qualified Rules.Library
import qualified Rules.Perl
import qualified Rules.Program
import qualified Rules.Register
import qualified Rules.Sdist
import Settings

allStages :: [Stage]
Expand Down Expand Up @@ -76,7 +77,8 @@ packageRules = do
, Rules.Library.buildPackageGhciLibrary
, Rules.Generate.generatePackageCode
, Rules.Program.buildProgram readPackageDb
, Rules.Register.registerPackage writePackageDb ]
, Rules.Register.registerPackage writePackageDb
, Rules.Sdist.buildSourceDist ]

buildRules :: Rules ()
buildRules = do
Expand Down
17 changes: 15 additions & 2 deletions src/Rules/Actions.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module Rules.Actions (
build, buildWithCmdOptions, buildWithResources, copyFile, fixFile, moveFile,
removeFile, copyDirectory, createDirectory, moveDirectory, removeDirectory,
applyPatch, runBuilder, runBuilderWith, makeExecutable, renderProgram, renderLibrary
removeFile, copyDirectory, copyDirectory', createDirectory, moveDirectory,
removeDirectory, applyPatch, runBuilder, runBuilderWith, makeExecutable,
renderProgram, renderLibrary
) where

import qualified System.Directory as IO
import qualified System.IO as IO
import qualified Control.Exception.Base as IO
import qualified System.Directory.Extra as X

import Base
import CmdLineFlag
Expand Down Expand Up @@ -126,6 +128,17 @@ copyDirectory source target = do
putProgressInfo $ renderAction "Copy directory" source target
quietly $ cmd cmdEcho ["cp", "-r", source, target]

-- | Like copyDirectory, but with a predicate to decide which files/directories
-- to include.
copyDirectory' :: (FilePath -> IO Bool) -> FilePath -> FilePath -> Action ()
copyDirectory' test source target = do
putProgressInfo $ renderAction "Copy directory" source target
liftIO $ X.listFilesInside test' source >>= mapM_ cp
where
test' a = ifM (test a) (mkdir a >> return True) (return False)
mkdir a = IO.createDirectoryIfMissing True $ target -/- a
cp a = whenM (test a) (IO.copyFile a $ target -/- a)

-- | Move a directory. The contents of the source directory is untracked.
moveDirectory :: FilePath -> FilePath -> Action ()
moveDirectory source target = do
Expand Down
138 changes: 116 additions & 22 deletions src/Rules/Sdist.hs
Original file line number Diff line number Diff line change
@@ -1,35 +1,129 @@
module Rules.Sdist (sourceDistRules) where
module Rules.Sdist (buildSourceDist, sourceDistRules) where

import Base
import Builder
import Context
import GHC
import Oracles.Config.Setting
import Oracles.ModuleFiles
import Package
import Rules.Actions
import Settings
import Stage

sourceDistRules :: Rules ()
sourceDistRules = do
"sdist-ghc" ~> do
version <- setting ProjectVersion
let dest = "sdistprep/ghc/ghc-" ++ version
tarName = "../ghc-" ++ version ++ "-src.tar.xz"
cpFile a = copyFile ("hadrian" -/- a) (dest -/- "hadrian" -/- a)
cpDir a = copyDirectory ("hadrian" -/- a) (dest -/- "hadrian")
runBuilder (Make ".") [ "--no-print-directory", "-f", "ghc.mk"
, "sdist-ghc-prep", "NO_INCLUDE_DEPS=YES"
, "NO_INCLUDE_PKGDATA=YES"]
createDirectory $ dest -/- "hadrian"
cpDir "cfg"
cpDir "doc"
cpDir "src"
cpFile "LICENSE"
cpFile "Makefile"
cpFile "README.md"
cpFile "appveyor.yml"
cpFile "build.bat"
cpFile "build.cabal.sh"
cpFile "build.sh"
cpFile "build.stack.sh"
cpFile "hadrian.cabal"
cpFile "stack.yaml"
runBuilderWith [Cwd "sdistprep/ghc"] Tar ["cJf", tarName, "ghc-" ++ version]
tarName = "ghc-" ++ version ++ "-src.tar.xz"
removeDirectory dest
removeFile $ "sdistprep" -/- tarName
need ["sdist-ghc-" ++ pkgNameString x | x <- packages]
prepareTree dest
runBuilderWith [Cwd "sdistprep/ghc"] Tar ["cJf", ".." -/- tarName, "ghc-" ++ version]
putSuccess "| Done. "
"GIT_COMMIT_ID" %> \fname ->
setting ProjectGitCommitId >>= liftIO . writeFile fname
"VERSION" %> \fname ->
setting ProjectVersion >>= liftIO . writeFile fname
where
packages = [ compiler
, genprimopcode
, hpcBin ]


buildSourceDist :: Context -> Rules ()
buildSourceDist context@(Context Stage1 pkg _) = do
"sdist-ghc-" ++ pkgNameString pkg ~> do
version <- setting ProjectVersion
let dest = "sdistprep/ghc/ghc-" ++ version
cpFile a = copyFile a (dest -/- a)
srcs <- haskellSources context
forM_ srcs $ \src -> when ("_build/" `isPrefixOf` src) $ do
createDirectory $ dest <//> takeDirectory src
cpFile src
buildSourceDist (Context _ _ _) = return ()


prepareTree :: FilePath -> Action ()
prepareTree dest = do
createDirectory dest
mapM_ cpDir srcDirs
mapM_ cpFile srcFiles
where
cpFile a = copyFile a (dest -/- a)
cpDir a = copyDirectory' test a dest
test a = return $ not $ any (?== a) exclude
exclude =
[ "//.*"
, "//#*"
, "//*-SAVE"
, "//*.orig"
, "//*.rej"
, "//*~"
, "//autom4te*"
, "//log"
, "compiler/stage1"
, "compiler/stage2"
, "compiler/stage3"
, "hadrian/cabal.sandbox.config"
, "hadrian/cfg/system.config"
, "hadrian/dist"
, "hadrian/UserSettings.hs"
, "libraries//*.buildinfo"
, "libraries//GNUmakefile"
, "libraries//config.log"
, "libraries//config.status"
, "libraries//configure"
, "libraries//ghc.mk"
, "libraries//include/Hs*Config.h"
-- In the legacy system the following libraries are excluded.
-- But hadrian fails whithout them when compiling from the
-- source tar ball.
-- TDOD: Must we exclude these libraries?
-- , "libraries/dph"
-- , "libraries/parallel"
-- , "libraries/primitive"
-- , "libraries/random"
-- , "libraries/stm"
-- , "libraries/vector"
, "mk/build.mk" ]
srcDirs =
[ "bindisttest"
, "compiler"
, "distrib"
, "docs"
, "docs"
, "driver"
, "ghc"
, "hadrian"
, "includes"
, "iserv"
, "libffi"
, "libffi-tarballs"
, "libraries"
, "mk"
, "rts"
, "rules"
, "utils" ]
srcFiles =
[ "ANNOUNCE"
, "GIT_COMMIT_ID"
, "HACKING.md"
, "INSTALL.md"
, "LICENSE"
, "MAKEHELP.md"
, "Makefile"
, "README.md"
, "VERSION"
, "aclocal.m4"
, "boot"
, "config.guess"
, "config.sub"
, "configure"
, "configure.ac"
, "ghc.mk"
, "install-sh"
, "packages"
, "settings.in" ]

0 comments on commit 9495da2

Please sign in to comment.