[commit: ghc] wip/nfs-locking: Add DESTDIR to command line arguments (#397) (176bfd4)

git at git.haskell.org git at git.haskell.org
Fri Oct 27 00:40:17 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/nfs-locking
Link       : http://ghc.haskell.org/trac/ghc/changeset/176bfd4d524c59c64a182f8e04dd0084a9c5e482/ghc

>---------------------------------------------------------------

commit 176bfd4d524c59c64a182f8e04dd0084a9c5e482
Author: Zhen Zhang <izgzhen at gmail.com>
Date:   Sun Aug 20 19:29:36 2017 +0800

    Add DESTDIR to command line arguments (#397)


>---------------------------------------------------------------

176bfd4d524c59c64a182f8e04dd0084a9c5e482
 README.md                    |  2 +-
 src/CommandLine.hs           | 13 ++++++++++++-
 src/Rules/Install.hs         |  6 ++++++
 src/Settings.hs              |  7 +++----
 src/Settings/Packages/Rts.hs |  1 +
 5 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index 5e49393..ecf9728 100644
--- a/README.md
+++ b/README.md
@@ -111,7 +111,7 @@ To build a GHC source distribution tarball, run Hadrian with the `sdist-ghc` tar
 To build and install GHC artifacts, run the `install` target.
 
 By default, the artifacts will be installed to `<prefix>` on your system. For example,
-`ghc` will be installed to `/usr/local/bin`. By modifying `defaultDestDir` in `UserSettings.hs`,
+`ghc` will be installed to `/usr/local/bin`. By setting flag `--install-destdir=[DESTDIR]`,
 you can install things to non-system path `DESTDIR/<prefix>` instead.
 
 #### Testing
diff --git a/src/CommandLine.hs b/src/CommandLine.hs
index 5688d6f..fbf3e07 100644
--- a/src/CommandLine.hs
+++ b/src/CommandLine.hs
@@ -1,6 +1,7 @@
 module CommandLine (
     optDescrs, cmdLineArgsMap, cmdBuildHaddock, cmdFlavour, cmdIntegerSimple,
-    cmdProgressColour, cmdProgressInfo, cmdSkipConfigure, cmdSplitObjects
+    cmdProgressColour, cmdProgressInfo, cmdSkipConfigure, cmdSplitObjects,
+    cmdInstallDestDir
     ) where
 
 import Data.Either
@@ -14,6 +15,7 @@ import System.Environment
 -- | All arguments that can be passed to Hadrian via the command line.
 data CommandLineArgs = CommandLineArgs
     { buildHaddock   :: Bool
+    , installDestDir :: Maybe String
     , flavour        :: Maybe String
     , integerSimple  :: Bool
     , progressColour :: UseColour
@@ -27,6 +29,7 @@ defaultCommandLineArgs :: CommandLineArgs
 defaultCommandLineArgs = CommandLineArgs
     { buildHaddock   = False
     , flavour        = Nothing
+    , installDestDir = Nothing
     , integerSimple  = False
     , progressColour = Auto
     , progressInfo   = Normal
@@ -39,6 +42,9 @@ readBuildHaddock = Right $ \flags -> flags { buildHaddock = True }
 readFlavour :: Maybe String -> Either String (CommandLineArgs -> CommandLineArgs)
 readFlavour ms = Right $ \flags -> flags { flavour = lower <$> ms }
 
+readInstallDestDir :: Maybe String -> Either String (CommandLineArgs -> CommandLineArgs)
+readInstallDestDir ms = Right $ \flags -> flags { installDestDir = ms }
+
 readIntegerSimple :: Either String (CommandLineArgs -> CommandLineArgs)
 readIntegerSimple = Right $ \flags -> flags { integerSimple = True }
 
@@ -80,6 +86,8 @@ optDescrs =
       "Build flavour (Default, Devel1, Devel2, Perf, Prof, Quick or Quickest)."
     , Option [] ["haddock"] (NoArg readBuildHaddock)
       "Generate Haddock documentation."
+    , Option [] ["install-destdir"] (OptArg readInstallDestDir "DESTDIR")
+      "Installation destination directory."
     , Option [] ["integer-simple"] (NoArg readIntegerSimple)
       "Build GHC with integer-simple library."
     , Option [] ["progress-colour"] (OptArg readProgressColour "MODE")
@@ -107,6 +115,9 @@ cmdLineArgs = userSetting defaultCommandLineArgs
 cmdBuildHaddock :: Action Bool
 cmdBuildHaddock = buildHaddock <$> cmdLineArgs
 
+cmdInstallDestDir :: Action (Maybe String)
+cmdInstallDestDir = installDestDir <$> cmdLineArgs
+
 cmdFlavour :: Action (Maybe String)
 cmdFlavour = flavour <$> cmdLineArgs
 
diff --git a/src/Rules/Install.hs b/src/Rules/Install.hs
index 24d7703..0d7336b 100644
--- a/src/Rules/Install.hs
+++ b/src/Rules/Install.hs
@@ -60,6 +60,7 @@ getLibExecDir = (-/- "bin") <$> installGhcLibDir
 installLibExecScripts :: Action ()
 installLibExecScripts = do
     libExecDir <- getLibExecDir
+    destDir <- getDestDir
     installDirectory (destDir ++ libExecDir)
     forM_ libExecScripts $ \script -> do
         installScript script (destDir ++ libExecDir)
@@ -72,6 +73,7 @@ installLibExecScripts = do
 installLibExecs :: Action ()
 installLibExecs = do
     libExecDir <- getLibExecDir
+    destDir <- getDestDir
     installDirectory (destDir ++ libExecDir)
     forM_ installBinPkgs $ \pkg -> do
         withLatestBuildStage pkg $ \stage -> do
@@ -88,6 +90,7 @@ installBins :: Action ()
 installBins = do
     binDir <- setting InstallBinDir
     libDir <- installGhcLibDir
+    destDir <- getDestDir
     installDirectory (destDir ++ binDir)
     win <- windowsHost
     when win $
@@ -153,6 +156,7 @@ installPackages = do
 
     ghcLibDir <- installGhcLibDir
     binDir    <- setting InstallBinDir
+    destDir   <- getDestDir
 
     -- Install package.conf
     let installedPackageConf = destDir ++ ghcLibDir -/- "package.conf.d"
@@ -271,6 +275,7 @@ installPackages = do
 installCommonLibs :: Action ()
 installCommonLibs = do
     ghcLibDir <- installGhcLibDir
+    destDir   <- getDestDir
     installLibsTo inplaceLibCopyTargets (destDir ++ ghcLibDir)
 
 -- ref: ghc.mk
@@ -296,6 +301,7 @@ includeHSubdirs = [".", "rts", "rts/prof", "rts/storage", "stg"]
 installIncludes :: Action ()
 installIncludes = do
     ghclibDir <- installGhcLibDir
+    destDir   <- getDestDir
     let ghcheaderDir = ghclibDir -/- "include"
     installDirectory (destDir ++ ghcheaderDir)
     forM_ includeHSubdirs $ \dir -> do
diff --git a/src/Settings.hs b/src/Settings.hs
index 9fafd1e..52c36ad 100644
--- a/src/Settings.hs
+++ b/src/Settings.hs
@@ -2,7 +2,7 @@ module Settings (
     getArgs, getPackages, getLibraryWays, getRtsWays, flavour, knownPackages,
     findKnownPackage, getPkgData, getPkgDataList, isLibrary, stagePackages,
     builderPath, getBuilderPath, isSpecified, latestBuildStage, programPath,
-    programContext, integerLibraryName, destDir, stage1Only, buildDll0
+    programContext, integerLibraryName, getDestDir, stage1Only, buildDll0
     ) where
 
 import Context
@@ -103,7 +103,6 @@ programPath context at Context {..} = do
 stage1Only :: Bool
 stage1Only = defaultStage1Only
 
--- TODO: Set this from command line
 -- | Install's DESTDIR setting.
-destDir :: FilePath
-destDir = defaultDestDir
+getDestDir :: Action FilePath
+getDestDir = fromMaybe "" <$> cmdInstallDestDir
diff --git a/src/Settings/Packages/Rts.hs b/src/Settings/Packages/Rts.hs
index 0ae764f..a54e618 100644
--- a/src/Settings/Packages/Rts.hs
+++ b/src/Settings/Packages/Rts.hs
@@ -62,6 +62,7 @@ rtsPackageArgs = package rts ? do
     ffiIncludeDir  <- getSetting FfiIncludeDir
     ffiLibraryDir  <- getSetting FfiLibDir
     ghclibDir      <- expr installGhcLibDir
+    destDir        <- expr getDestDir
     let cArgs =
           [ arg "-Irts"
           , arg $ "-I" ++ path



More information about the ghc-commits mailing list