From f481c1890066b4dac78d981ca680fb01cfff9a11 Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Wed, 7 Jul 2021 10:46:29 +0100 Subject: packaging: Create both versioned and unversioned executables Before we would just copy the unversioned executable into the bindist. Now the actual executable is copied into the bindist and a version suffix is added. Then a wrapper or symlink is added which points to the versioned executable. Fixes #20074 --- hadrian/bindist/version-wrapper.hs | 17 +++++++++++++ hadrian/src/Rules/BinaryDist.hs | 50 +++++++++++++++++++++++++++++++++----- testsuite/driver/testlib.py | 6 +++++ 3 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 hadrian/bindist/version-wrapper.hs diff --git a/hadrian/bindist/version-wrapper.hs b/hadrian/bindist/version-wrapper.hs new file mode 100644 index 0000000000..dc7c344c5c --- /dev/null +++ b/hadrian/bindist/version-wrapper.hs @@ -0,0 +1,17 @@ +{-# LANGUAGE CPP #-} +module Main (main) where + +import System.Environment (getArgs, getExecutablePath) +import System.Exit (exitWith) +import System.Process (spawnProcess, waitForProcess) +import System.FilePath (replaceFileName) + +exe = EXE_PATH + +main :: IO () +main = do + args <- getArgs + exe_name <- getExecutablePath + ph <- spawnProcess (replaceFileName exe_name exe) args + code <- waitForProcess ph + exitWith code diff --git a/hadrian/src/Rules/BinaryDist.hs b/hadrian/src/Rules/BinaryDist.hs index 8a09389a2a..594bc55a17 100644 --- a/hadrian/src/Rules/BinaryDist.hs +++ b/hadrian/src/Rules/BinaryDist.hs @@ -32,10 +32,21 @@ It does so by following the steps below. - make sure we have a complete stage 2 compiler + haddock -- copy the bin and lib directories of the compiler we built: - /stage1/{bin, lib} +- copy the specific binaries which should be in the bindist to the + bin folder and add the version suffix: + /stage1/bin/xxxx to - /bindist/ghc-..--/{bin, lib} + ..--/bin/xxxx- + +- create symlink (or bash) wrapper to from unversioned to versioned executable: + ..--/bin/xxxx- + points to: + ..--/bin/xxxx + +- copy the lib directories of the compiler we built: + /stage1/lib + to + /bindist/ghc-..--/lib - copy the generated docs (user guide, haddocks, etc): /docs/ @@ -136,10 +147,23 @@ bindistRules = do createDirectory bindistFilesDir createDirectory (bindistFilesDir -/- "bin") createDirectory (bindistFilesDir -/- "lib") - -- Also create symlinks with version suffixes (#20074) - forM_ (bin_targets ++ iserv_targets) $ \(prog_path, _ver) -> do - let install_path = bindistFilesDir -/- "bin" -/- takeFileName prog_path + -- Also create wrappers with version suffixes (#20074) + forM_ (bin_targets ++ iserv_targets) $ \(prog_path, ver) -> do + let orig_filename = takeFileName prog_path + (name, ext) = splitExtensions orig_filename + version_prog = name ++ "-" ++ ver ++ ext + -- Install the actual executable with a version suffix + install_path = bindistFilesDir -/- "bin" -/- version_prog + -- The wrapper doesn't have a version + unversioned_install_path = (bindistFilesDir -/- "bin" -/- orig_filename) + -- 1. Copy the executable to the versioned executable name in + -- the directory copyFile prog_path install_path + -- 2. Either make a symlink for the unversioned version or + -- a wrapper script on platforms (windows) which don't support symlinks. + if windowsHost + then createVersionWrapper version_prog unversioned_install_path + else createFileLink install_path unversioned_install_path copyDirectory (ghcBuildDir -/- "lib") bindistFilesDir copyDirectory (rtsIncludeDir) bindistFilesDir @@ -345,3 +369,17 @@ iservBins = do | w <- [vanilla, profiling, dynamic] , w `elem` rtsways ] + +-- Version wrapper scripts + +-- | Create a wrapper script calls the executable given as first argument +createVersionWrapper :: String -> FilePath -> Action () +createVersionWrapper versioned_exe install_path = do + ghcPath <- builderPath (Ghc CompileHs Stage2) + top <- topDirectory + let version_wrapper = top -/- "hadrian" -/- "bindist" -/- "version-wrapper.hs" + cmd ghcPath ["-o", install_path, "-no-keep-hi-files" + , "-no-keep-o-files", "-rtsopts=ignore" + , "-DEXE_PATH=\"" ++ versioned_exe ++ "\"" + , version_wrapper] + diff --git a/testsuite/driver/testlib.py b/testsuite/driver/testlib.py index 8d71d1de46..d776c12bb3 100644 --- a/testsuite/driver/testlib.py +++ b/testsuite/driver/testlib.py @@ -2221,6 +2221,12 @@ def normalise_errmsg(s: str) -> str: # collisions, so we need to normalise that to just "ghc" s = re.sub('ghc-stage[123]', 'ghc', s) + # On windows error messages can mention versioned executables + s = re.sub('ghc-[0-9.]+', 'ghc', s) + s = re.sub('runghc-[0-9.]+', 'runghc', s) + s = re.sub('hpc-[0-9.]+', 'hpc', s) + s = re.sub('ghc-pkg-[0-9.]+', 'ghc-pkg', s) + # Error messages sometimes contain ghc-bignum implementation package s = re.sub('ghc-bignum-[0-9.]+', 'ghc-bignum-', s) -- cgit v1.2.1