From c03a5534eda1bf22a66fe7a806473248f6c9fcf5 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Wed, 6 Apr 2016 13:17:25 -0700 Subject: [PATCH] Add support for copy --one-shot. (#3287) Signed-off-by: Edward Z. Yang --- Cabal/Distribution/Simple/Install.hs | 31 ++++++++++++++----- Cabal/Distribution/Simple/Setup.hs | 7 +++++ .../Distribution/Client/ProjectPlanning.hs | 1 + 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Cabal/Distribution/Simple/Install.hs b/Cabal/Distribution/Simple/Install.hs index 3626f027c58..3290e597def 100644 --- a/Cabal/Distribution/Simple/Install.hs +++ b/Cabal/Distribution/Simple/Install.hs @@ -56,14 +56,21 @@ install :: PackageDescription -- ^information from the .cabal file -> LocalBuildInfo -- ^information from the configure step -> CopyFlags -- ^flags sent to copy or install -> IO () -install pkg_descr lbi flags = do - let distPref = fromFlag (copyDistPref flags) - verbosity = fromFlag (copyVerbosity flags) - copydest = fromFlag (copyDest flags) - - unless (hasLibs pkg_descr || hasExes pkg_descr) $ - die "No executables and no library found. Nothing to do." - +install pkg_descr lbi flags + | fromFlag (copyOneShot flags) = do + checkHasLibsOrExes + targets <- readBuildTargets pkg_descr (copyArgs flags) + targets' <- checkBuildTargets verbosity pkg_descr targets + case targets' of + [] -> copyPackage verbosity pkg_descr lbi distPref copydest + [(cname, _)] -> + let clbi = getComponentLocalBuildInfo lbi cname + comp = getComponent pkg_descr cname + in copyComponent verbosity pkg_descr lbi comp clbi copydest + _ -> die "In --one-shot mode you can only copy a single target" + + | otherwise = do + checkHasLibsOrExes targets <- readBuildTargets pkg_descr (copyArgs flags) targets' <- checkBuildTargets verbosity pkg_descr targets @@ -72,6 +79,14 @@ install pkg_descr lbi flags = do -- It's not necessary to do these in build-order, but it's harmless withComponentsInBuildOrder pkg_descr lbi (map fst targets') $ \comp clbi -> copyComponent verbosity pkg_descr lbi comp clbi copydest + where + distPref = fromFlag (copyDistPref flags) + verbosity = fromFlag (copyVerbosity flags) + copydest = fromFlag (copyDest flags) + + checkHasLibsOrExes = + unless (hasLibs pkg_descr || hasExes pkg_descr) $ + die "No executables and no library found. Nothing to do." -- | Copy package global files. copyPackage :: Verbosity -> PackageDescription diff --git a/Cabal/Distribution/Simple/Setup.hs b/Cabal/Distribution/Simple/Setup.hs index de84765eba9..54f13eff195 100644 --- a/Cabal/Distribution/Simple/Setup.hs +++ b/Cabal/Distribution/Simple/Setup.hs @@ -825,6 +825,7 @@ data CopyFlags = CopyFlags { copyDest :: Flag CopyDest, copyDistPref :: Flag FilePath, copyVerbosity :: Flag Verbosity, + copyOneShot :: Flag Bool, -- This is the same hack as in 'buildArgs'. But I (ezyang) don't -- think it's a hack, it's the right way to make hooks more robust copyArgs :: [String] @@ -836,6 +837,7 @@ defaultCopyFlags = CopyFlags { copyDest = Flag NoCopyDest, copyDistPref = NoFlag, copyVerbosity = Flag normal, + copyOneShot = Flag False, copyArgs = [] } @@ -865,6 +867,11 @@ copyCommand = CommandUI copyDistPref (\d flags -> flags { copyDistPref = d }) showOrParseArgs + , option "" ["one-shot"] + "One-shot copy" + copyOneShot (\c flags -> flags { copyOneShot = c }) + trueArg + ,option "" ["destdir"] "directory to copy files to, prepended to installation directories" copyDest (\v flags -> flags { copyDest = v }) diff --git a/cabal-install/Distribution/Client/ProjectPlanning.hs b/cabal-install/Distribution/Client/ProjectPlanning.hs index 52f02d9f262..dc8fdd95fa4 100644 --- a/cabal-install/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/Distribution/Client/ProjectPlanning.hs @@ -2134,6 +2134,7 @@ setupHsCopyFlags _ _ verbosity builddir = copyArgs = [], -- TODO: could use this to only copy what we enabled copyDest = toFlag InstallDirs.NoCopyDest, copyDistPref = toFlag builddir, + copyOneShot = toFlag False, copyVerbosity = toFlag verbosity }