Skip to content

Commit

Permalink
Add support for copy --one-shot. (haskell#3287)
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Z. Yang <[email protected]>
  • Loading branch information
ezyang committed Apr 8, 2016
1 parent d469e0f commit c03a553
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
31 changes: 23 additions & 8 deletions Cabal/Distribution/Simple/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Cabal/Distribution/Simple/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -836,6 +837,7 @@ defaultCopyFlags = CopyFlags {
copyDest = Flag NoCopyDest,
copyDistPref = NoFlag,
copyVerbosity = Flag normal,
copyOneShot = Flag False,
copyArgs = []
}

Expand Down Expand Up @@ -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 })
Expand Down
1 change: 1 addition & 0 deletions cabal-install/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit c03a553

Please sign in to comment.