[Git][ghc/ghc][wip/ghc-toolchain-fixes] 2 commits: ghc-toolchain: Add format mode to normalise differences before diffing.
Matthew Pickering (@mpickering)
gitlab at gitlab.haskell.org
Mon Aug 7 13:44:58 UTC 2023
Matthew Pickering pushed to branch wip/ghc-toolchain-fixes at Glasgow Haskell Compiler / GHC
Commits:
06f9a336 by Matthew Pickering at 2023-08-07T14:44:50+01:00
ghc-toolchain: Add format mode to normalise differences before diffing.
The "format" mode takes an "--input" and "--ouput" target file and
formats it.
This is intended to be useful on windows where the
configure/ghc-toolchain target files can't be diffed very easily because
the path separators are different.
- - - - -
9885b829 by Matthew Pickering at 2023-08-07T14:44:50+01:00
ghc-toolchain: Bump ci-images commit to get new ghc-wasm-meta
We needed to remove -Wno-unused-command-line-argument from the arguments
passed in order for the configure check to report correctly.
See https://gitlab.haskell.org/ghc/ghc/-/merge_requests/10976#note_516335
- - - - -
6 changed files:
- .gitlab-ci.yml
- configure.ac
- distrib/configure.ac.in
- m4/ghc_toolchain.m4
- utils/ghc-toolchain/exe/Main.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Program.hs
Changes:
=====================================
.gitlab-ci.yml
=====================================
@@ -2,7 +2,7 @@ variables:
GIT_SSL_NO_VERIFY: "1"
# Commit of ghc/ci-images repository from which to pull Docker images
- DOCKER_REV: a9c0f5efbe503c17f63070583b2d815e498acc68
+ DOCKER_REV: 17f816b010d4e585d3a935530ea3d1fc743eac0d
# Sequential version number of all cached things.
# Bump to invalidate GitLab CI cache.
=====================================
configure.ac
=====================================
@@ -1197,8 +1197,9 @@ checkMake380 make
checkMake380 gmake
# Toolchain target files
+FIND_GHC_TOOLCHAIN_BIN([NO])
PREP_TARGET_FILE
-FIND_GHC_TOOLCHAIN([hadrian/cfg],[NO])
+FIND_GHC_TOOLCHAIN([hadrian/cfg])
AC_CONFIG_FILES(
[ mk/project.mk
@@ -1336,3 +1337,5 @@ For more information on how to configure your GHC build, see
VALIDATE_GHC_TOOLCHAIN([hadrian/cfg/default.target],[hadrian/cfg/default.target.ghc-toolchain])
+rm -Rf acargs acghc-toolchain actmp-ghc-toolchain
+
=====================================
distrib/configure.ac.in
=====================================
@@ -311,11 +311,14 @@ checkMake380 make
checkMake380 gmake
# Toolchain target files
+FIND_GHC_TOOLCHAIN_BIN([YES])
PREP_TARGET_FILE
-FIND_GHC_TOOLCHAIN([.],[YES])
+FIND_GHC_TOOLCHAIN([.])
VALIDATE_GHC_TOOLCHAIN([default.target],[default.target.ghc-toolchain])
+rm -Rf acargs acghc-toolchain actmp-ghc-toolchain
+
echo "****************************************************"
echo "Configuration done, ready to 'make install'"
echo "(see README and INSTALL files for more info.)"
=====================================
m4/ghc_toolchain.m4
=====================================
@@ -60,31 +60,8 @@ AC_DEFUN([INVOKE_GHC_TOOLCHAIN],
])
dnl $1 is the path to the directory where to put the configured default.host.target.ghc-toolchain and default.target.ghc-toolchain
-dnl $2 is YES or NO,
-dnl * YES means we're calling GHC_TOOLCHAIN from the bindist configure script,
-dnl and that ghc-toolchain is already an available binary
-dnl * NO means we're calling GHC_TOOLCHAIN from the source tree configure script,
-dnl and that we must compile ghc-toolchain before invoking it
AC_DEFUN([FIND_GHC_TOOLCHAIN],
[
- case "$2" in
- YES)
- # We're configuring the bindist, and the binary is already available
- GHC_TOOLCHAIN_BIN="bin/ghc-toolchain-bin"
- ;;
- NO)
- # We're in the source tree, so compile ghc-toolchain
- "$GHC" -v0 \
- -ilibraries/ghc-platform/src -iutils/ghc-toolchain/src \
- -XNoImplicitPrelude \
- -odir actmp-ghc-toolchain -hidir actmp-ghc-toolchain \
- utils/ghc-toolchain/exe/Main.hs -o acghc-toolchain
- GHC_TOOLCHAIN_BIN="./acghc-toolchain"
- ;;
- *)
- AC_MSG_ERROR([In m4/ghc_toolchain.m4, expecting $2 to be either YES or NO.])
- ;;
- esac
# (1) Configure a toolchain for the build and host platform (we require that BUILD=HOST, so one toolchain suffices)
rm -f acargs
@@ -145,18 +122,43 @@ AC_DEFUN([FIND_GHC_TOOLCHAIN],
INVOKE_GHC_TOOLCHAIN()
- rm -Rf acargs acghc-toolchain actmp-ghc-toolchain
-
dnl Note: if we weren't passing the paths to the programs explicitly, to make
dnl ghc-toolchain use the bundled windows toolchain, simply add it to the search PATH
])
+dnl $1 is YES or NO,
+dnl * YES means we're calling GHC_TOOLCHAIN from the bindist configure script,
+dnl and that ghc-toolchain is already an available binary
+dnl * NO means we're calling GHC_TOOLCHAIN from the source tree configure script,
+dnl and that we must compile ghc-toolchain before invoking it
+AC_DEFUN([FIND_GHC_TOOLCHAIN_BIN],[
+ case "$1" in
+ YES)
+ # We're configuring the bindist, and the binary is already available
+ GHC_TOOLCHAIN_BIN="bin/ghc-toolchain-bin"
+ ;;
+ NO)
+ # We're in the source tree, so compile ghc-toolchain
+ "$GHC" -v0 \
+ -ilibraries/ghc-platform/src -iutils/ghc-toolchain/src \
+ -XNoImplicitPrelude \
+ -odir actmp-ghc-toolchain -hidir actmp-ghc-toolchain \
+ utils/ghc-toolchain/exe/Main.hs -o acghc-toolchain
+ GHC_TOOLCHAIN_BIN="./acghc-toolchain"
+ ;;
+ *)
+ AC_MSG_ERROR([In m4/ghc_toolchain.m4, expecting $2 to be either YES or NO.])
+ ;;
+ esac
+])
+
+
dnl Note [ghc-toolchain consistency checking]
dnl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dnl ghc-toolchain is the brand new way (2023) to configure toolchains for GHC,
dnl but this novelty musn't break user's installations, so we still
-dnl conservatively use the toolchains configured by configure (see also m4/prep_target_file.m4).
+dnl conservatively use the toolchains configured by configure (see also m4/tprep_target_file.m4).
dnl
dnl However, we already ship and run ghc-toolchain at configure time to /validate/ ghc-toolchain:
dnl * PREP_TARGET_FILE substitutes the toolchain into default.target.in and default.host.target.in
@@ -171,7 +173,11 @@ dnl files generated by ghc-toolchain instead).
dnl $1 like "default.target"
dnl $2 like "default.target.ghc-toolchain"
AC_DEFUN([VALIDATE_GHC_TOOLCHAIN],[
- diff_output=`diff "$1" "$2" 2>&1`
+ o1=$(mktemp)
+ o2=$(mktemp)
+ "$GHC_TOOLCHAIN_BIN" format --input="$1" --output="$o1"
+ "$GHC_TOOLCHAIN_BIN" format --input="$2" --output="$o2"
+ diff_output=`diff "$o1" "$o2" 2>&1`
if test -z "$diff_output"; then
true
else
=====================================
utils/ghc-toolchain/exe/Main.hs
=====================================
@@ -1,5 +1,6 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE TypeApplications #-}
module Main where
@@ -10,6 +11,7 @@ import System.Exit
import System.Console.GetOpt
import System.Environment
import System.FilePath ((</>))
+import qualified System.IO (readFile, writeFile)
import GHC.Platform.ArchOS
@@ -55,6 +57,22 @@ data Opts = Opts
, optKeepTemp :: Bool
}
+data FormatOpts = FormatOpts
+ { formatOptInput :: FilePath
+ , formatOptOutput :: FilePath
+ }
+
+_formatOptOutput :: Lens FormatOpts String
+_formatOptOutput = Lens formatOptOutput (\x o -> o {formatOptOutput=x})
+
+_formatOptInput :: Lens FormatOpts String
+_formatOptInput = Lens formatOptInput (\x o -> o {formatOptInput=x})
+
+emptyFormatOpts :: FormatOpts
+emptyFormatOpts = FormatOpts { formatOptInput = error "formatOpts: input"
+ , formatOptOutput = error "formatOpts: output"
+ }
+
emptyOpts :: Opts
emptyOpts = Opts
{ optTriple = ""
@@ -202,10 +220,41 @@ options =
outputOpt = Option ['o'] ["output"] (ReqArg (set _optOutput) "OUTPUT")
"The output path for the generated target toolchain configuration"
+formatOpts :: [OptDescr (FormatOpts -> FormatOpts)]
+formatOpts = [
+ (Option ['o'] ["output"] (ReqArg (set _formatOptOutput) "OUTPUT")
+ "The output path for the formatted target toolchain configuration")
+ , (Option ['i'] ["input"] (ReqArg (set _formatOptInput) "INPUT")
+ "The target file to format")
+ ]
+
main :: IO ()
main = do
argv <- getArgs
- let (opts0, _nonopts, errs) = getOpt RequireOrder options argv
+ case argv of
+ ("format": args) -> doFormat args
+ _ -> doConfigure argv
+
+-- The format mode is very useful for normalising paths and newlines on windows.
+doFormat :: [String] -> IO ()
+doFormat args = do
+ let (opts0, _nonopts, errs) = getOpt RequireOrder formatOpts args
+ case errs of
+ [] -> do
+ let opts = foldr (.) id opts0 emptyFormatOpts
+ tgt <- read @Target <$> System.IO.readFile (view _formatOptInput opts)
+ let file = formatOptOutput opts
+ System.IO.writeFile file (show tgt)
+ _ -> do
+ mapM_ putStrLn errs
+ putStrLn $ usageInfo "ghc-toolchain" formatOpts
+ exitWith (ExitFailure 1)
+
+
+
+doConfigure :: [String] -> IO ()
+doConfigure args = do
+ let (opts0, _nonopts, errs) = getOpt RequireOrder options args
let opts = foldr (.) id opts0 emptyOpts
case errs of
[] -> do
=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Program.hs
=====================================
@@ -33,7 +33,15 @@ import GHC.Toolchain.Utils
data Program = Program { prgPath :: FilePath
, prgFlags :: [String]
}
- deriving (Show, Read, Eq, Ord)
+ deriving (Read, Eq, Ord)
+
+instance Show Program where
+ -- Normalise filepaths before showing to aid with diffing the target files.
+ show (Program p f) = unlines
+ [ "Program {"
+ , " prgPath = " ++ normalise p
+ , " , prgFlags = " ++ show f
+ , "}" ]
_prgPath :: Lens Program FilePath
_prgPath = Lens prgPath (\x o -> o {prgPath = x})
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/334ba3b9571b9ae8a0f610ebd0f85f030c20e331...9885b829c10ced9328fe046f8dabd1284be0d93c
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/334ba3b9571b9ae8a0f610ebd0f85f030c20e331...9885b829c10ced9328fe046f8dabd1284be0d93c
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230807/23ed8616/attachment-0001.html>
More information about the ghc-commits
mailing list