Skip to content

Commit

Permalink
Add support for "--split-objs" #1284
Browse files Browse the repository at this point in the history
  • Loading branch information
mgsloan committed Mar 15, 2016
1 parent 64a69e0 commit 120d083
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Behavior changes:

Other enhancements:

* Experimental support for `--split-objs` added.
* `git` packages with submodules are supported by passing the `--recursive`
flag to `git clone`.
* When using [hpack](https://github.com/sol/hpack), only regenerate cabal files
Expand Down
19 changes: 17 additions & 2 deletions src/Stack/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module Stack.Build
(build
,withLoadPackage
,mkBaseConfigOpts
,queryBuildInfo)
,queryBuildInfo
,splitObjsWarning)
where

import Control.Monad
Expand Down Expand Up @@ -61,7 +62,7 @@ import Stack.Types.Internal
import System.FileLock (FileLock, unlockFile)

#ifdef WINDOWS
import System.Win32.Console (setConsoleCP, setConsoleOutputCP, getConsoleCP, getConsoleOutputCP)
import System.Win32.Console (setConsoleCP, setConsoleOutputCP, getConsoleCP, getConsoleOutputCP)
import qualified Control.Monad.Catch as Catch
#endif

Expand Down Expand Up @@ -112,6 +113,7 @@ build setLocalFiles mbuildLk boptsCli = fixCodePage $ do
liftIO $ unlockFile lk
_ -> return ()

warnAboutSplitObjs bopts
warnIfExecutablesWithSameNameCouldBeOverwritten locals plan

when (boptsPreFetch bopts) $
Expand Down Expand Up @@ -207,6 +209,19 @@ warnIfExecutablesWithSameNameCouldBeOverwritten locals plan =
collect :: Ord k => [(k,v)] -> Map k (NonEmpty v)
collect = Map.map NE.fromList . Map.fromDistinctAscList . groupSort

warnAboutSplitObjs :: MonadLogger m => BuildOpts -> m ()
warnAboutSplitObjs bopts | boptsSplitObjs bopts = do
$logWarn $ "Building with --split-objs is enabled. " <> T.pack splitObjsWarning
warnAboutSplitObjs _ = return ()

splitObjsWarning :: String
splitObjsWarning = unwords
[ "Note that this feature is EXPERIMENTAL, and its behavior may be changed and improved."
, "You will need to clean your workdirs before use. If you want to compile all dependencies"
, "with split-objs, you will need to delete the snapshot (and all snapshots that could"
, "reference that snapshot."
]

-- | Get the @BaseConfigOpts@ necessary for constructing configure options
mkBaseConfigOpts :: (MonadIO m, MonadReader env m, HasEnvConfig env, MonadThrow m)
=> BuildOptsCLI -> m BaseConfigOpts
Expand Down
6 changes: 4 additions & 2 deletions src/Stack/Config/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import Stack.Types

-- | Interprets BuildOptsMonoid options.
buildOptsFromMonoid :: BuildOptsMonoid -> BuildOpts
buildOptsFromMonoid BuildOptsMonoid{..} =
defaultBuildOpts
buildOptsFromMonoid BuildOptsMonoid{..} = BuildOpts
{ boptsLibProfile = fromMaybe
(boptsLibProfile defaultBuildOpts)
buildMonoidLibProfile
Expand Down Expand Up @@ -42,6 +41,9 @@ buildOptsFromMonoid BuildOptsMonoid{..} =
, boptsCabalVerbose = fromMaybe
(boptsCabalVerbose defaultBuildOpts)
buildMonoidCabalVerbose
, boptsSplitObjs = fromMaybe
(boptsSplitObjs defaultBuildOpts)
buildMonoidSplitObjs
}

testOptsFromMonoid :: TestOptsMonoid -> TestOpts
Expand Down
9 changes: 8 additions & 1 deletion src/Stack/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Stack.Options
,hpcReportOptsParser
,pvpBoundsOption
,globalOptsFromMonoid
,splitObjsWarning
) where

import Control.Monad.Logger (LogLevel (..))
Expand All @@ -44,6 +45,7 @@ import Options.Applicative
import Options.Applicative.Args
import Options.Applicative.Builder.Extra
import Options.Applicative.Types (fromM, oneM, readerAsk)
import Stack.Build (splitObjsWarning)
import Stack.Clean (CleanOpts (..))
import Stack.Config (packagesParser)
import Stack.ConfigCmd
Expand Down Expand Up @@ -355,7 +357,7 @@ buildOptsMonoidParser hide0 =
BuildOptsMonoid <$> libProfiling <*> exeProfiling <*> haddock <*>
haddockDeps <*> copyBins <*> preFetch <*> keepGoing <*> forceDirty <*>
tests <*> testOptsParser hide0 <*> benches <*> benchOptsParser hide0 <*> reconfigure <*>
cabalVerbose
cabalVerbose <*> splitObjs
libProfiling =
maybeBoolFlags
"library-profiling"
Expand Down Expand Up @@ -413,6 +415,11 @@ buildOptsMonoidParser hide0 =
"cabal-verbose"
"Ask Cabal to be verbose in its output"
hide
splitObjs =
maybeBoolFlags
"split-objs"
("Enable split-objs, to reduce output size (at the cost of build time). " ++ splitObjsWarning)
hide

nixOptsParser :: Bool -> Parser NixOptsMonoid
nixOptsParser hide0 = overrideActivation <$>
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Types/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ configureOptsNoDir econfig bco deps wanted isLocal package = concat
[ depOptions
, ["--enable-library-profiling" | boptsLibProfile bopts || boptsExeProfile bopts]
, ["--enable-executable-profiling" | boptsExeProfile bopts && isLocal]
, ["--enable-split-objs" | boptsSplitObjs bopts]
, map (\(name,enabled) ->
"-f" <>
(if enabled
Expand Down
10 changes: 10 additions & 0 deletions src/Stack/Types/Config/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ data BuildOpts =
-- ^ Perform the configure step even if already configured
,boptsCabalVerbose :: !Bool
-- ^ Ask Cabal to be verbose in its builds
,boptsSplitObjs :: !Bool
-- ^ Whether to enable split-objs.
}
deriving (Show)

Expand All @@ -83,6 +85,7 @@ defaultBuildOpts = BuildOpts
, boptsBenchmarkOpts = defaultBenchmarkOpts
, boptsReconfigure = False
, boptsCabalVerbose = False
, boptsSplitObjs = False
}

defaultBuildOptsCLI ::BuildOptsCLI
Expand Down Expand Up @@ -136,6 +139,7 @@ data BuildOptsMonoid = BuildOptsMonoid
, buildMonoidBenchmarkOpts :: !BenchmarkOptsMonoid
, buildMonoidReconfigure :: !(Maybe Bool)
, buildMonoidCabalVerbose :: !(Maybe Bool)
, buildMonoidSplitObjs :: !(Maybe Bool)
} deriving (Show)

instance FromJSON (BuildOptsMonoid, [JSONWarning]) where
Expand All @@ -154,6 +158,7 @@ instance FromJSON (BuildOptsMonoid, [JSONWarning]) where
buildMonoidBenchmarkOpts <- jsonSubWarnings (o ..:? buildMonoidBenchmarkOptsArgName ..!= mempty)
buildMonoidReconfigure <- o ..:? buildMonoidReconfigureArgName
buildMonoidCabalVerbose <- o ..:? buildMonoidCabalVerboseArgName
buildMonoidSplitObjs <- o ..:? buildMonoidSplitObjsName
return BuildOptsMonoid{..})

buildMonoidLibProfileArgName :: Text
Expand Down Expand Up @@ -198,6 +203,9 @@ buildMonoidReconfigureArgName = "reconfigure"
buildMonoidCabalVerboseArgName :: Text
buildMonoidCabalVerboseArgName = "cabal-verbose"

buildMonoidSplitObjsName :: Text
buildMonoidSplitObjsName = "split-objs"

instance Monoid BuildOptsMonoid where
mempty = BuildOptsMonoid
{buildMonoidLibProfile = Nothing
Expand All @@ -214,6 +222,7 @@ instance Monoid BuildOptsMonoid where
,buildMonoidBenchmarkOpts = mempty
,buildMonoidReconfigure = Nothing
,buildMonoidCabalVerbose = Nothing
,buildMonoidSplitObjs = Nothing
}

mappend l r = BuildOptsMonoid
Expand All @@ -231,6 +240,7 @@ instance Monoid BuildOptsMonoid where
,buildMonoidBenchmarkOpts = buildMonoidBenchmarkOpts l <> buildMonoidBenchmarkOpts r
,buildMonoidReconfigure = buildMonoidReconfigure l <|> buildMonoidReconfigure r
,buildMonoidCabalVerbose = buildMonoidCabalVerbose l <|> buildMonoidCabalVerbose r
,buildMonoidSplitObjs = buildMonoidSplitObjs l <|> buildMonoidSplitObjs r
}

-- | Which subset of packages to build
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ nix:
extra-deps:
- path-io-1.1.0
- hpack-0.10.0
- path-0.5.7
- path-0.5.7

0 comments on commit 120d083

Please sign in to comment.