From 48153639a92441991eda45b732b118cf376d4032 Mon Sep 17 00:00:00 2001 From: Jens Petersen Date: Tue, 17 Dec 2024 18:03:35 +0800 Subject: [PATCH] local,install: new --jobs option for rpmbuilds --- CHANGELOG.md | 1 + src/Cmd/Install.hs | 14 +++++++------- src/Cmd/Local.hs | 6 +++--- src/Cmd/Merge.hs | 1 - src/Cmd/ReviewPackage.hs | 4 ++-- src/Common.hs | 2 ++ src/Main.hs | 4 ++++ src/RpmBuild.hs | 12 ++++++++---- 8 files changed, 27 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38375ea1..aa7611ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 1.6.1 (2024-12-17) - 'build','parallel': waitrepo now just uses "koji wait-repo --request" - 'build': now respects --waitrepo +- 'local','install': new --jobs option for _smp_ncpus_max - waitrepo is timed - Koji targetMaybeSidetag: print sidetags if more than one diff --git a/src/Cmd/Install.hs b/src/Cmd/Install.hs index 9f1d2a9b..91f3e86f 100644 --- a/src/Cmd/Install.hs +++ b/src/Cmd/Install.hs @@ -29,11 +29,11 @@ import RpmBuild -- FIXME add --debug or respect --verbose for dnf commands -- FIXME handle subpackage renames (eg ghc-rpm-macros-no-prof to ghc-rpm-macros-quick) -- FIXME allow building an srpm --- FIXME ExistingStrategy option -installCmd :: Bool -> Bool -> Maybe Branch -> Maybe ForceShort -> [BCond] - -> Bool -> Bool -> Bool -> Select -> Maybe ExistingStrategy - -> (Maybe Branch,[String]) -> IO () -installCmd quiet recurse mfrom mforceshort bconds reinstall nobuild nobuilddeps select mexisting (mbr, pkgs) = do +installCmd :: Bool -> Bool -> Maybe Branch -> Maybe Natural + -> Maybe ForceShort -> [BCond] -> Bool -> Bool -> Bool -> Select + -> Maybe ExistingStrategy -> (Maybe Branch,[String]) + -> IO () +installCmd quiet recurse mfrom mjobs mforceshort bconds reinstall nobuild nobuilddeps select mexisting (mbr, pkgs) = do when (recurse && isShortCircuit mforceshort) $ error' "cannot use --recurse and --shortcircuit" withPackagesMaybeBranch (boolHeader (recurse || length pkgs > 1)) True Nothing installPkg (mbr, pkgs) @@ -76,7 +76,7 @@ installCmd quiet recurse mfrom mforceshort bconds reinstall nobuild nobuilddeps mpkgdir <- lookForPkgDir rbr ".." dep case mpkgdir of Nothing -> putStrLn $ dep +-+ "not known" - Just pkgdir -> installCmd quiet recurse mfrom mforceshort bconds reinstall nobuild nobuilddeps select mexisting (mbr, [pkgdir]) >> putNewLn + Just pkgdir -> installCmd quiet recurse mfrom mjobs mforceshort bconds reinstall nobuild nobuilddeps select mexisting (mbr, [pkgdir]) >> putNewLn -- FIXME option to enable/disable installing missing deps -- FIXME --skip-missing-deps or prompt else installDeps True spec @@ -84,7 +84,7 @@ installCmd quiet recurse mfrom mforceshort bconds reinstall nobuild nobuilddeps _wasbuilt <- if nobuild then return True - else buildRPMs quiet False False mforceshort' bconds rpms br spec + else buildRPMs quiet False False mjobs mforceshort' bconds rpms br spec unless (isShortCircuit mforceshort') $ do let nvras = rpmsToNVRAs rpms -- FIXME: prefix = fromMaybe (nvrName nvr) mprefix diff --git a/src/Cmd/Local.hs b/src/Cmd/Local.hs index b9fdeb3a..e57d829b 100644 --- a/src/Cmd/Local.hs +++ b/src/Cmd/Local.hs @@ -26,9 +26,9 @@ import Git import Package import RpmBuild -localCmd :: Bool -> Bool -> Maybe ForceShort -> [BCond] +localCmd :: Bool -> Bool -> Maybe Natural -> Maybe ForceShort -> [BCond] -> (BranchesReq, [String]) -> IO () -localCmd quiet debug mforceshort bconds = +localCmd quiet debug mjobs mforceshort bconds = withPackagesByBranches HeaderNone False Nothing ZeroOrOne localBuildPkg where localBuildPkg :: Package -> AnyBranch -> IO () @@ -38,7 +38,7 @@ localCmd quiet debug mforceshort bconds = then return [] else builtRpms br spec -- FIXME backup BUILD tree to .prev - void $ buildRPMs quiet debug True mforceshort bconds rpms br spec + void $ buildRPMs quiet debug True mjobs mforceshort bconds rpms br spec -- FIXME mark BUILD dir complete installDepsCmd :: (Maybe Branch,[String]) -> IO () diff --git a/src/Cmd/Merge.hs b/src/Cmd/Merge.hs index e1875332..438f2659 100644 --- a/src/Cmd/Merge.hs +++ b/src/Cmd/Merge.hs @@ -4,7 +4,6 @@ module Cmd.Merge ( getNewerBranch) where -import Numeric.Natural (Natural) import Safe (tailSafe) import Common diff --git a/src/Cmd/ReviewPackage.hs b/src/Cmd/ReviewPackage.hs index ec349441..2a90962a 100644 --- a/src/Cmd/ReviewPackage.hs +++ b/src/Cmd/ReviewPackage.hs @@ -113,13 +113,13 @@ doInteractiveReview importsrpm mspec srpm = do -- FIXME or download rpms build <- yesNoDefault importsrpm "Build package locally" when build $ - localCmd False False Nothing [] (Branches [],[]) + localCmd False False Nothing Nothing [] (Branches [],[]) putNewLn putStrLn "# RpmLint" void $ cmdBool "rpmlint" ["."] -- FIXME $ spec:srpm:rpms spec <- maybe findSpecfile return mspec whenM (yesNoDefault importsrpm "Install packages locally") $ do - installCmd False False Nothing Nothing [] False True True selectDefault Nothing (Nothing,[]) + installCmd False False Nothing Nothing Nothing [] False True True selectDefault Nothing (Nothing,[]) rpms <- cmdLines "rpmspec" ["-q", "--rpms", "--qf", "%{name}\n", spec] whenM (yesNoDefault importsrpm "Rpmlint installed packages") $ do (_ok, out, err) <- cmdFull "rpmlint" ("-i" : rpms) "" diff --git a/src/Common.hs b/src/Common.hs index 94ff6b8f..325f779d 100644 --- a/src/Common.hs +++ b/src/Common.hs @@ -4,6 +4,7 @@ module Common ( module Control.Monad.Extra, module Data.List.Extra, module Data.Maybe, + Natural, #if !MIN_VERSION_base(4,11,0) (<>), #endif @@ -34,6 +35,7 @@ import Data.Semigroup ((<>)) #endif import Network.HTTP.Query ((+/+)) +import Numeric.Natural (Natural) import SimpleCmd ((+-+)) pluralOnly :: [a] -> String -> String diff --git a/src/Main.hs b/src/Main.hs index 644ef022..59fd93dd 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -208,6 +208,7 @@ main = do localCmd <$> quietOpt "Hide the build.log until it errors" <*> debugOpt "show the rpmbuild command" + <*> jobsOpt <*> optional forceshortOpt <*> many bcondOpt <*> branchesPackages @@ -261,6 +262,7 @@ main = do <$> quietOpt "Quiet rpmbuild output" <*> switchWith 'R' "recurse" "build and install missing deps packages" <*> optional (optionLongWith branchM "from" "BRANCH" "Merge branch first") + <*> jobsOpt <*> optional forceshortOpt <*> many bcondOpt <*> switchWith 'r' "reinstall" "reinstall rpms" @@ -707,3 +709,5 @@ main = do allowHeadOpt = switchLongWith "allow-head" "allow detached HEAD" forceOpt = switchWith 'f' "force" + + jobsOpt = optional (optionWith auto 'j' "jobs" "NUM" "Max processes in rpmbuild") diff --git a/src/RpmBuild.hs b/src/RpmBuild.hs index 86cbd671..82777092 100644 --- a/src/RpmBuild.hs +++ b/src/RpmBuild.hs @@ -277,9 +277,9 @@ isShortCircuit ms = -- Note does not check if bcond changed -- FIXME check tarball timestamp -- FIXME handle prep (-bp) too? -buildRPMs :: Bool -> Bool -> Bool -> Maybe ForceShort -> [BCond] -> [FilePath] - -> AnyBranch -> FilePath -> IO Bool -buildRPMs quiet debug noclean mforceshort bconds rpms br spec = do +buildRPMs :: Bool -> Bool -> Bool -> Maybe Natural -> Maybe ForceShort + -> [BCond] -> [FilePath] -> AnyBranch -> FilePath -> IO Bool +buildRPMs quiet debug noclean mjobs mforceshort bconds rpms br spec = do needBuild <- if isJust mforceshort then return True @@ -306,8 +306,12 @@ buildRPMs quiet debug noclean mforceshort bconds rpms br spec = do Just ShortCompile -> ["-bc", "--short-circuit"] Just ShortInstall -> ["-bi", "--short-circuit"] _ -> "-bb" : ["--noclean" | noclean] + jobs = + case mjobs of + Nothing -> [] + Just n -> ["--define", "_smp_ncpus_max" +-+ show n] args = sourcediropt ++ distopt ++ - buildopt ++ map show bconds ++ autoreleaseOpt ++ [spec] + buildopt ++ jobs ++ map show bconds ++ autoreleaseOpt ++ [spec] date <- cmd "date" ["+%T"] rbr <- anyBranchToRelease br nvr <- do