diff options
-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 |