diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2021-08-12 10:46:33 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-08-13 21:48:03 -0400 |
commit | a975583c70e57434340d9a20c976c8f06fde9beb (patch) | |
tree | 69981dcd7fe395fd5dfd13d5a49002cbc626dfb6 /hadrian | |
parent | 9700b9a878640747f9460e2d681b6dd08cd7da54 (diff) | |
download | haskell-a975583c70e57434340d9a20c976c8f06fde9beb.tar.gz |
hadrian: Also produce versioned wrapper scripts
Since !6133 we are more consistent about producing versioned
executables but we still didn't produce versioned wrappers. This patch
adds the corresponding versioned wrappers to match the versioned
executables in the relocatable bindist.
I also fixed the ghci wrapper so that it wasn't overwritten during
installation.
The final bindir looks like:
```
lrwxrwxrwx 1 matt users 16 Aug 12 11:56 ghc -> ghc-9.3.20210809
-rwxr-xr-x 1 matt users 674 Aug 12 11:56 ghc-9.3.20210809
lrwxrwxrwx 1 matt users 17 Aug 12 11:56 ghci -> ghci-9.3.20210809
-rwxr-xr-x 1 matt users 708 Aug 12 11:56 ghci-9.3.20210809
lrwxrwxrwx 1 matt users 20 Aug 12 11:56 ghc-pkg -> ghc-pkg-9.3.20210809
-rwxr-xr-x 1 matt users 734 Aug 12 11:56 ghc-pkg-9.3.20210809
lrwxrwxrwx 1 matt users 14 Aug 12 11:56 haddock -> haddock-2.24.0
-rwxr-xr-x 1 matt users 682 Aug 12 11:56 haddock-2.24.0
lrwxrwxrwx 1 matt users 9 Aug 12 11:56 hp2ps -> hp2ps-0.1
-rwxr-xr-x 1 matt users 648 Aug 12 11:56 hp2ps-0.1
lrwxrwxrwx 1 matt users 8 Aug 12 11:56 hpc -> hpc-0.68
-rwxr-xr-x 1 matt users 646 Aug 12 11:56 hpc-0.68
lrwxrwxrwx 1 matt users 13 Aug 12 11:56 hsc2hs -> hsc2hs-0.68.8
-rwxr-xr-x 1 matt users 1.4K Aug 12 11:56 hsc2hs-0.68.8
lrwxrwxrwx 1 matt users 19 Aug 12 11:56 runghc -> runghc-9.3.20210809
-rwxr-xr-x 1 matt users 685 Aug 12 11:56 runghc-9.3.20210809
```
Fixes #20225
Diffstat (limited to 'hadrian')
-rw-r--r-- | hadrian/bindist/Makefile | 41 | ||||
-rw-r--r-- | hadrian/src/Rules/BinaryDist.hs | 34 |
2 files changed, 41 insertions, 34 deletions
diff --git a/hadrian/bindist/Makefile b/hadrian/bindist/Makefile index d043cf2425..892bbb4f64 100644 --- a/hadrian/bindist/Makefile +++ b/hadrian/bindist/Makefile @@ -30,19 +30,25 @@ define installscript # to it. This implementation is a bit hacky and depends on consistency # of program names. For hadrian build this will work as programs have a # consistent naming procedure. - rm -f '$2' - $(CREATE_SCRIPT) '$2' - @echo "#!$(SHELL)" >> '$2' - @echo "exedir=\"$4\"" >> '$2' - @echo "exeprog=\"$1\"" >> '$2' - @echo "executablename=\"$5\"" >> '$2' - @echo "bindir=\"$3\"" >> '$2' - @echo "libdir=\"$6\"" >> '$2' - @echo "docdir=\"$7\"" >> '$2' - @echo "includedir=\"$8\"" >> '$2' - @echo "" >> '$2' - cat wrappers/$1 >> '$2' - $(EXECUTABLE_FILE) '$2' ; + if [ -L wrappers/$1 ]; then echo "$1 is a symlink"; fi + @if [ -L wrappers/$1 ]; then \ + cp -P wrappers/$1 $2; \ + else \ + rm -f '$2' && \ + $(CREATE_SCRIPT) '$2' && \ + echo "#!$(SHELL)" >> '$2' && \ + echo "exedir=\"$4\"" >> '$2' && \ + echo "exeprog=\"$1\"" >> '$2' && \ + echo "executablename=\"$5\"" >> '$2' && \ + echo "bindir=\"$3\"" >> '$2' && \ + echo "libdir=\"$6\"" >> '$2' && \ + echo "docdir=\"$7\"" >> '$2' && \ + echo "includedir=\"$8\"" >> '$2' && \ + echo "" >> '$2' && \ + cat wrappers/$1 >> '$2' && \ + $(EXECUTABLE_FILE) '$2' ; \ + fi + @echo "$1 installed to $2" endef # Hacky function to patch up the 'haddock-interfaces' and 'haddock-html' @@ -79,7 +85,7 @@ install_bin: install_bin_libdir install_wrappers endif install: install_bin install_lib install_includes -install: install_docs install_ghci update_package_db +install: install_docs update_package_db ActualBinsDir=${ghclibdir}/bin ifeq "$(TargetOS_CPP)" "mingw32" @@ -103,13 +109,6 @@ install_bin_direct: $(INSTALL_DIR) "$(WrapperBinsDir)" cp ./bin/* "$(WrapperBinsDir)/" -install_ghci: - @echo "Copying and installing ghci" - $(CREATE_SCRIPT) '$(WrapperBinsDir)/ghci' - @echo "#!$(SHELL)" >> '$(WrapperBinsDir)/ghci' - cat wrappers/ghci-script >> '$(WrapperBinsDir)/ghci' - $(EXECUTABLE_FILE) '$(WrapperBinsDir)/ghci' - LIBRARIES = $(wildcard ./lib/*) install_lib: @echo "Copying libraries to $(ActualLibsDir)" diff --git a/hadrian/src/Rules/BinaryDist.hs b/hadrian/src/Rules/BinaryDist.hs index b8b980d245..6c6535fcc3 100644 --- a/hadrian/src/Rules/BinaryDist.hs +++ b/hadrian/src/Rules/BinaryDist.hs @@ -129,7 +129,7 @@ bindistRules = do (lib_targets, bin_targets) <- partitionEithers <$> mapM pkgTarget all_pkgs cross <- flag CrossCompiling iserv_targets <- if cross then pure [] else iservBins - need (lib_targets ++ (map fst (bin_targets ++ iserv_targets))) + need (lib_targets ++ (map (\(_, p, _) -> p) (bin_targets ++ iserv_targets))) version <- setting ProjectVersion targetPlatform <- setting TargetPlatformFull @@ -148,7 +148,7 @@ bindistRules = do createDirectory (bindistFilesDir -/- "bin") createDirectory (bindistFilesDir -/- "lib") -- Also create wrappers with version suffixes (#20074) - forM_ (bin_targets ++ iserv_targets) $ \(prog_path, ver) -> do + forM_ (bin_targets ++ iserv_targets) $ \(_pkg, prog_path, ver) -> do let orig_filename = takeFileName prog_path (name, ext) = splitExtensions orig_filename version_prog = name ++ "-" ++ ver ++ ext @@ -208,8 +208,19 @@ bindistRules = do -- other machine. need $ map (bindistFilesDir -/-) (["configure", "Makefile"] ++ bindistInstallFiles) - wrappers <- fmap concat (sequence [ pkgToWrappers p | p <- all_pkgs, isProgram p]) - need $ map ((bindistFilesDir -/- "wrappers") -/-) wrappers + forM_ bin_targets $ \(pkg, _, ver) -> do + needed_wrappers <- pkgToWrappers pkg + forM_ needed_wrappers $ \wrapper_name -> do + wrapper_content <- wrapper wrapper_name + let unversioned_wrapper_path = bindistFilesDir -/- "wrappers" -/- wrapper_name + versioned_wrapper = wrapper_name ++ "-" ++ ver + versioned_wrapper_path = bindistFilesDir -/- "wrappers" -/- versioned_wrapper + -- Write the wrapper to the versioned path + writeFile' versioned_wrapper_path wrapper_content + -- Create a symlink from the non-versioned to the versioned. + liftIO $ do + IO.removeFile unversioned_wrapper_path <|> return () + IO.createFileLink versioned_wrapper unversioned_wrapper_path let buildBinDist :: Compressor -> Action () @@ -253,9 +264,6 @@ bindistRules = do top <- topDirectory copyFile (top -/- "hadrian" -/- "bindist" -/- "Makefile") makefilePath - root -/- "bindist" -/- "ghc-*" -/- "wrappers/*" %> \wrapperPath -> do - content <- wrapper (takeFileName wrapperPath) - writeFile' wrapperPath content -- Copy various configure-related files needed for a working -- './configure [...] && make install' workflow @@ -297,20 +305,20 @@ bindistInstallFiles = -- for all libraries and programs that are needed for a complete build. -- For libraries, it returns the path to the @.conf@ file in the package -- database. For programs, it returns the path to the compiled executable. -pkgTarget :: Package -> Action (Either FilePath (FilePath, String)) +pkgTarget :: Package -> Action (Either FilePath (Package, FilePath, String)) pkgTarget pkg | isLibrary pkg = Left <$> pkgConfFile (vanillaContext Stage1 pkg) | otherwise = do path <- programPath =<< programContext Stage1 pkg version <- version <$> readPackageData pkg - return (Right (path, version)) + return (Right (pkg, path, version)) -- | Which wrappers point to a specific package pkgToWrappers :: Package -> Action [String] pkgToWrappers pkg -- ghc also has the ghci script wrapper - | pkg == ghc = pure ["ghc", "ghci-script"] + | pkg == ghc = pure ["ghc", "ghci"] -- These are the packages which we want to expose to the user and hence -- there are wrappers installed in the bindist. | pkg `elem` [hpcBin, haddock, hp2ps, hsc2hs, runGhc, ghc, ghcPkg] @@ -321,7 +329,7 @@ pkgToWrappers pkg wrapper :: FilePath -> Action String wrapper "ghc" = ghcWrapper wrapper "ghc-pkg" = ghcPkgWrapper -wrapper "ghci-script" = ghciScriptWrapper +wrapper "ghci" = ghciScriptWrapper wrapper "haddock" = haddockWrapper wrapper "hsc2hs" = hsc2hsWrapper wrapper "runghc" = runGhcWrapper @@ -372,11 +380,11 @@ ghciScriptWrapper = pure $ unlines -- the package to be built, since here we're generating 3 different -- executables out of just one package, so we need to specify all 3 contexts -- explicitly and 'need' the result of building them. -iservBins :: Action [(FilePath, String)] +iservBins :: Action [(Package, FilePath, String)] iservBins = do rtsways <- interpretInContext (vanillaContext Stage1 ghc) getRtsWays ver <- version <$> readPackageData iserv - traverse (fmap (,ver) . programPath) + traverse (fmap (\p -> (iserv, p, ver)) . programPath) [ Context Stage1 iserv w | w <- [vanilla, profiling, dynamic] , w `elem` rtsways |