Skip to content

"Build profile" now reflects optimization level set in global config #8488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cabal-install/src/Distribution/Client/ProjectOrchestration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,10 @@ printPlan verbosity
ProjectBaseContext {
buildSettings = BuildTimeSettings{buildSettingDryRun},
projectConfig = ProjectConfig {
projectConfigAllPackages =
PackageConfig {packageConfigOptimization = globalOptimization},
projectConfigLocalPackages =
PackageConfig {packageConfigOptimization}
PackageConfig {packageConfigOptimization = localOptimization}
}
}
ProjectBuildContext {
Expand Down Expand Up @@ -994,7 +996,7 @@ printPlan verbosity
showBuildProfile :: String
showBuildProfile = "Build profile: " ++ unwords [
"-w " ++ (showCompilerId . pkgConfigCompiler) elaboratedShared,
"-O" ++ (case packageConfigOptimization of
"-O" ++ (case globalOptimization <> localOptimization of -- if local is not set, read global
Setup.Flag NoOptimisation -> "0"
Setup.Flag NormalOptimisation -> "1"
Setup.Flag MaximumOptimisation -> "2"
Expand Down
8 changes: 8 additions & 0 deletions cabal-testsuite/PackageTests/ConfigFile/T8487/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# cabal build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O2
In order, the following will be built:
- test-0.1.0.0 (lib) (first run)
Configuring library for test-0.1.0.0..
Preprocessing library for test-0.1.0.0..
Building library for test-0.1.0.0..
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/ConfigFile/T8487/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- 2022-09-20, issue #8487
--

import Test.Cabal.Prelude

main = cabalTest $ do
cabalG [ "--config-file", "config.file" ] "build" [ "test" ]
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/ConfigFile/T8487/config.file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
optimization: 2
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/ConfigFile/T8487/src/MyLib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module MyLib (someFunc) where

someFunc :: IO ()
someFunc = putStrLn "someFunc"
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/ConfigFile/T8487/test.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cabal-version: 3.0
name: test
version: 0.1.0.0
license: NONE
author: [email protected]
maintainer: Artem Pelenitsyn
build-type: Simple

library
exposed-modules: MyLib
build-depends: base
hs-source-dirs: src
default-language: Haskell2010
12 changes: 12 additions & 0 deletions changelog.d/issue-8487
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
synopsis: "Build profile" message now reflects optimization level set in global config
packages: cabal-install
prs: #8488
issues: #8487

description: {

Imagine you have `optimization: 2` in your `~/.cabal/config`, and you call `cabal build`
in a project that doesn't have optimization level explicitly set in its project file.
You will still see 'Build profile: -w ghc-<VER> -O1'. This is incorrect and was fixed
in this patch: now you'll see '-O2'.
}