From f7e21fabffa1c61ce16687362fbb0b85921421a6 Mon Sep 17 00:00:00 2001 From: Matthew Pickering <matthewtpickering@gmail.com> Date: Thu, 5 Oct 2023 15:09:19 +0100 Subject: [PATCH] hadrian: Build all executables in bin/ folder In the end the bindist creation logic copies them all into the bin folder. There is no benefit to building a specific few binaries in the lib/bin folder anymore. This also removes the ad-hoc logic to copy the touchy and unlit executables from stage0 into stage1. It takes <1s to build so we might as well just build it. --- compiler/GHC/Settings/IO.hs | 2 +- hadrian/bindist/Makefile | 3 +-- hadrian/src/Packages.hs | 8 +------- hadrian/src/Rules/BinaryDist.hs | 7 ++++++- hadrian/src/Rules/Generate.hs | 2 +- hadrian/src/Rules/Program.hs | 5 +---- m4/fp_settings.m4 | 4 ++-- 7 files changed, 13 insertions(+), 18 deletions(-) diff --git a/compiler/GHC/Settings/IO.hs b/compiler/GHC/Settings/IO.hs index dedd6fb9af12..a26340090e1e 100644 --- a/compiler/GHC/Settings/IO.hs +++ b/compiler/GHC/Settings/IO.hs @@ -38,7 +38,7 @@ initSettings top_dir = do let installed :: FilePath -> FilePath installed file = top_dir </> file libexec :: FilePath -> FilePath - libexec file = top_dir </> "bin" </> file + libexec file = top_dir </> ".." </> "bin" </> file settingsFile = installed "settings" readFileSafe :: FilePath -> ExceptT SettingsError m String diff --git a/hadrian/bindist/Makefile b/hadrian/bindist/Makefile index 293a0bfdd380..e4ed0476d48d 100644 --- a/hadrian/bindist/Makefile +++ b/hadrian/bindist/Makefile @@ -118,7 +118,7 @@ lib/settings : config.mk @echo ',("install_name_tool command", "$(SettingsInstallNameToolCommand)")' >> $@ @echo ',("touch command", "$(SettingsTouchCommand)")' >> $@ @echo ',("windres command", "$(SettingsWindresCommand)")' >> $@ - @echo ',("unlit command", "$$topdir/bin/$(CrossCompilePrefix)unlit")' >> $@ + @echo ',("unlit command", "$$topdir/../bin/$(CrossCompilePrefix)unlit")' >> $@ @echo ',("cross compiling", "$(CrossCompiling)")' >> $@ @echo ',("target platform string", "$(TARGETPLATFORM)")' >> $@ @echo ',("target os", "$(HaskellTargetOs)")' >> $@ @@ -189,7 +189,6 @@ install_lib: lib/settings $(INSTALL_DATA) $$i "$$dest/`dirname $$i`" ;; \ esac; \ done; \ - chmod ugo+rx "$$dest"/bin/* # Work around #17418 on Darwin if [ -e "${XATTR}" ]; then \ "${XATTR}" -c -r "$(DESTDIR)$(ActualLibsDir)"; \ diff --git a/hadrian/src/Packages.hs b/hadrian/src/Packages.hs index 43a45f4770e7..37b793626c3c 100644 --- a/hadrian/src/Packages.hs +++ b/hadrian/src/Packages.hs @@ -202,14 +202,8 @@ programName Context {..} = do -- | The 'FilePath' to a program executable in a given 'Context'. programPath :: Context -> Action FilePath programPath context@Context {..} = do - -- TODO: The @touchy@ utility lives in the @lib/bin@ directory instead of - -- @bin@, which is likely just a historical accident that should be fixed. - -- See: https://github.com/snowleopard/hadrian/issues/570 - -- Likewise for @iserv@ and @unlit@. name <- programName context - path <- if package `elem` [iserv, touchy, unlit] - then stageLibPath stage <&> (-/- "bin") - else stageBinPath stage + path <- stageBinPath stage return $ path -/- name <.> exe -- TODO: Move @timeout@ to the @util@ directory and build in a more standard diff --git a/hadrian/src/Rules/BinaryDist.hs b/hadrian/src/Rules/BinaryDist.hs index 6d4df5f1fb58..4547cde65137 100644 --- a/hadrian/src/Rules/BinaryDist.hs +++ b/hadrian/src/Rules/BinaryDist.hs @@ -125,6 +125,7 @@ installTo relocatable prefix = do NotRelocatable -> [] runBuilderWithCmdOptions env (Make bindistFilesDir) ["install"] [] [] + bindistRules :: Rules () bindistRules = do root <- buildRootRules @@ -188,7 +189,11 @@ bindistRules = do -- 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 pkg version_prog unversioned_install_path + then if pkg == unlit + -- The unlit executable is a C executable already, wrapping it again causes + -- paths to be double escaped, so we just copy this one as it is already small. + then copyFile install_path unversioned_install_path + else createVersionWrapper pkg version_prog unversioned_install_path else liftIO $ do -- Use the IO versions rather than createFileLink because -- we need to create a relative symlink. diff --git a/hadrian/src/Rules/Generate.hs b/hadrian/src/Rules/Generate.hs index bf84da2f9de3..072cedd6b58d 100644 --- a/hadrian/src/Rules/Generate.hs +++ b/hadrian/src/Rules/Generate.hs @@ -387,7 +387,7 @@ generateSettings = do , ("install_name_tool command", expr $ settingsFileSetting ToolchainSetting_InstallNameToolCommand) , ("touch command", expr $ settingsFileSetting ToolchainSetting_TouchCommand) , ("windres command", queryTarget (maybe "/bin/false" prgPath . tgtWindres)) -- TODO: /bin/false is not available on many distributions by default, but we keep it as it were before the ghc-toolchain patch. Fix-me. - , ("unlit command", ("$topdir/bin/" <>) <$> expr (programName (ctx { Context.package = unlit }))) + , ("unlit command", ("$topdir/../bin/" <>) <$> expr (programName (ctx { Context.package = unlit }))) , ("cross compiling", expr $ yesNo <$> flag CrossCompiling) , ("target platform string", queryTarget targetPlatformTriple) , ("target os", queryTarget (show . archOS_OS . tgtArchOs)) diff --git a/hadrian/src/Rules/Program.hs b/hadrian/src/Rules/Program.hs index 3c5e9f00d461..2490bffbd2ad 100644 --- a/hadrian/src/Rules/Program.hs +++ b/hadrian/src/Rules/Program.hs @@ -38,7 +38,7 @@ buildProgramRules rs = do -- Rules for programs that are actually built by hadrian. forM_ allStages $ \stage -> [ root -/- stageString stage -/- "bin" -/- "*" - , root -/- stageString stage -/- "lib/bin" -/- "*" ] |%> \bin -> do + ] |%> \bin -> do programContexts <- getProgramContexts stage case lookupProgramContext bin programContexts of Nothing -> error $ "Unknown program " ++ show bin @@ -103,9 +103,6 @@ buildProgram bin ctx@(Context{..}) rs = do (True, s) | s > stage0InTree -> do srcDir <- buildRoot <&> (-/- (stageString stage0InTree -/- "bin")) copyFile (srcDir -/- takeFileName bin) bin - (False, s) | s > stage0InTree && (package `elem` [touchy, unlit]) -> do - srcDir <- stageLibPath stage0InTree <&> (-/- "bin") - copyFile (srcDir -/- takeFileName bin) bin _ -> buildBinary rs bin ctx buildBinary :: [(Resource, Int)] -> FilePath -> Context -> Action () diff --git a/m4/fp_settings.m4 b/m4/fp_settings.m4 index 26b42d6c6032..1061cec05df9 100644 --- a/m4/fp_settings.m4 +++ b/m4/fp_settings.m4 @@ -75,7 +75,7 @@ AC_DEFUN([FP_SETTINGS], fi if test "$HostOS" = "mingw32"; then - SettingsTouchCommand='$$topdir/bin/touchy.exe' + SettingsTouchCommand='$$topdir/../bin/touchy.exe' else SettingsTouchCommand='touch' fi @@ -109,7 +109,7 @@ AC_DEFUN([FP_SETTINGS], SUBST_TOOLDIR([SettingsArCommand]) SUBST_TOOLDIR([SettingsRanlibCommand]) SUBST_TOOLDIR([SettingsWindresCommand]) - SettingsTouchCommand='$$topdir/bin/touchy.exe' + SettingsTouchCommand='$$topdir/../bin/touchy.exe' fi # LLVM backend tools -- GitLab