Skip to content

Commit

Permalink
Merge branch 'master' into m-renaud-docs-remove-v2-prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jneira authored Mar 4, 2022
2 parents 7cc6485 + c2eb7ba commit 67d26c6
Show file tree
Hide file tree
Showing 35 changed files with 351 additions and 167 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/users-guide.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ defaults:

jobs:
build:
if: |
!contains(github.event.head_commit.message, '[skip ci]')
&& !contains(github.event.head_commit.message, '[ci skip]')
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
41 changes: 35 additions & 6 deletions Cabal/src/Distribution/Simple/PackageDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ import Distribution.Compat.Prelude
import Distribution.Fields.ParseResult
import Distribution.PackageDescription
import Distribution.PackageDescription.Parsec
import Distribution.Parsec.Error (showPError)
import Distribution.Parsec.Warning (showPWarning)
import Distribution.Simple.Utils
import Distribution.Verbosity
( parseGenericPackageDescription, parseHookedBuildInfo )
import Distribution.Parsec.Error ( showPError )
import Distribution.Parsec.Warning
( PWarning(..), PWarnType(PWTExperimental), showPWarning )
import Distribution.Simple.Utils ( equating, die', warn )
import Distribution.Verbosity ( normal, Verbosity )

import qualified Data.ByteString as BS
import Data.List ( groupBy )
import Text.Printf ( printf )
import qualified Data.ByteString as BS
import System.Directory (doesFileExist)

readGenericPackageDescription :: Verbosity -> FilePath -> IO GenericPackageDescription
Expand Down Expand Up @@ -65,10 +69,35 @@ parseString
-> IO a
parseString parser verbosity name bs = do
let (warnings, result) = runParseResult (parser bs)
traverse_ (warn verbosity . showPWarning name) warnings
traverse_ (warn verbosity . showPWarning name) (flattenDups verbosity warnings)
case result of
Right x -> return x
Left (_, errors) -> do
traverse_ (warn verbosity . showPError name) errors
die' verbosity $ "Failed parsing \"" ++ name ++ "\"."

-- | Collapse duplicate experimental feature warnings into single warning, with
-- a count of further sites
flattenDups :: Verbosity -> [PWarning] -> [PWarning]
flattenDups verbosity ws
| verbosity <= normal = rest ++ experimentals
| otherwise = ws -- show all instances
where
(exps, rest) = partition (\(PWarning w _ _) -> w == PWTExperimental) ws
experimentals =
concatMap flatCount
. groupBy (equating warningStr)
. sortBy (comparing warningStr)
$ exps

warningStr (PWarning _ _ w) = w

-- flatten if we have 3 or more examples
flatCount :: [PWarning] -> [PWarning]
flatCount w@[] = w
flatCount w@[_] = w
flatCount w@[_,_] = w
flatCount (PWarning t pos w:xs) =
[PWarning t pos
(w <> printf " (and %d more occurrences)" (length xs))
]
2 changes: 1 addition & 1 deletion cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ Test-Suite memory-usage-tests
hs-source-dirs: tests
default-language: Haskell2010

ghc-options: -threaded -rtsopts "-with-rtsopts=-M8M -K1K"
ghc-options: -threaded -rtsopts "-with-rtsopts=-M16M -K1K"

other-modules:
UnitTests.Distribution.Solver.Modular.DSL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,11 @@ licensePrompt flags = getLicense flags $ do

case simpleParsec l of
Nothing -> do
putStrLn "The license must be a valid SPDX expression."
putStrLn ( "The license must be a valid SPDX expression:"
++ "\n - On the SPDX License List: https://spdx.org/licenses/"
++ "\n - NONE, if you do not want to grant any license"
++ "\n - LicenseRef-( alphanumeric | - | . )+"
)
licensePrompt flags
Just l' -> return l'
where
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/src/Distribution/Client/ProjectConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ module Distribution.Client.ProjectConfig (
readGlobalConfig,
readProjectLocalExtraConfig,
readProjectLocalFreezeConfig,
parseProjectConfig,
reportParseResult,
showProjectConfig,
withProjectOrGlobalConfig,
writeProjectLocalExtraConfig,
Expand Down
72 changes: 48 additions & 24 deletions cabal-install/src/Distribution/Client/ScriptUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import Distribution.Client.HashValue
import Distribution.Client.NixStyleOptions
( NixStyleFlags (..) )
import Distribution.Client.ProjectConfig
( ProjectConfig(..), ProjectConfigShared(..), withProjectOrGlobalConfig )
( ProjectConfig(..), ProjectConfigShared(..)
, parseProjectConfig, reportParseResult, withProjectOrGlobalConfig )
import Distribution.Client.ProjectFlags
( flagIgnoreProject )
import Distribution.Client.Setup
Expand All @@ -46,7 +47,7 @@ import Distribution.Fields
import Distribution.PackageDescription.FieldGrammar
( executableFieldGrammar )
import Distribution.PackageDescription.PrettyPrint
( showGenericPackageDescription, writeGenericPackageDescription )
( showGenericPackageDescription )
import Distribution.Parsec
( Position(..) )
import Distribution.Simple.Flag
Expand All @@ -56,7 +57,7 @@ import Distribution.Simple.PackageDescription
import Distribution.Simple.Setup
( Flag(..) )
import Distribution.Simple.Utils
( createDirectoryIfMissingVerbose, createTempDirectory, die', handleDoesNotExist, readUTF8File, warn )
( createDirectoryIfMissingVerbose, createTempDirectory, die', handleDoesNotExist, readUTF8File, warn, writeUTF8File )
import qualified Distribution.SPDX.License as SPDX
import Distribution.Solver.Types.SourcePackage as SP
( SourcePackage(..) )
Expand Down Expand Up @@ -214,10 +215,13 @@ withContextAndSelectors noTargets kind flags@NixStyleFlags {..} targetStrings gl
let projectRoot = distProjectRootDirectory $ distDirLayout ctx
writeFile (projectRoot </> "scriptlocation") =<< canonicalizePath script

executable <- readScriptBlockFromScript verbosity =<< BS.readFile script
scriptContents <- BS.readFile script
executable <- readExecutableBlockFromScript verbosity scriptContents
projectCfg <- readProjectBlockFromScript verbosity (takeFileName script) scriptContents

let executable' = executable & L.buildInfo . L.defaultLanguage %~ maybe (Just Haskell2010) Just
return (ScriptContext script executable', ctx, defaultTarget)
ctx' = ctx & lProjectConfig %~ (<> projectCfg)
return (ScriptContext script executable', ctx', defaultTarget)
else reportTargetSelectorProblems verbosity err

withTemporaryTempDirectory :: (IO FilePath -> IO a) -> IO a
Expand All @@ -236,17 +240,18 @@ withTemporaryTempDirectory act = newEmptyMVar >>= \m -> bracket (getMkTmp m) (rm
-- | Add the 'SourcePackage' to the context and use it to write a .cabal file.
updateContextAndWriteProjectFile' :: ProjectBaseContext -> SourcePackage (PackageLocation (Maybe FilePath)) -> IO ProjectBaseContext
updateContextAndWriteProjectFile' ctx srcPkg = do
let projectRoot = distProjectRootDirectory $ distDirLayout ctx
projectFile = projectRoot </> fakePackageCabalFileName
writeProjectFile = writeGenericPackageDescription (projectRoot </> fakePackageCabalFileName) (srcpkgDescription srcPkg)
projectFileExists <- doesFileExist projectFile
let projectRoot = distProjectRootDirectory $ distDirLayout ctx
packageFile = projectRoot </> fakePackageCabalFileName
contents = showGenericPackageDescription (srcpkgDescription srcPkg)
writePackageFile = writeUTF8File packageFile contents
-- TODO This is here to prevent reconfiguration of cached repl packages.
-- It's worth investigating why it's needed in the first place.
if projectFileExists then do
contents <- force <$> readUTF8File projectFile
when (contents /= showGenericPackageDescription (srcpkgDescription srcPkg))
writeProjectFile
else writeProjectFile
packageFileExists <- doesFileExist packageFile
if packageFileExists then do
cached <- force <$> readUTF8File packageFile
when (cached /= contents)
writePackageFile
else writePackageFile
return (ctx & lLocalPackages %~ (++ [SpecificSourcePackage srcPkg]))

-- | Add add the executable metadata to the context and write a .cabal file.
Expand Down Expand Up @@ -283,26 +288,41 @@ parseScriptBlock str =
readScriptBlock :: Verbosity -> BS.ByteString -> IO Executable
readScriptBlock verbosity = parseString parseScriptBlock verbosity "script block"

-- | Extract the first encountered script metadata block started end
-- terminated by the bellow tokens or die.
-- | Extract the first encountered executable metadata block started and
-- terminated by the below tokens or die.
--
-- * @{- cabal:@
--
-- * @-}@
--
-- Return the metadata.
readScriptBlockFromScript :: Verbosity -> BS.ByteString -> IO Executable
readScriptBlockFromScript verbosity str = do
str' <- case extractScriptBlock str of
readExecutableBlockFromScript :: Verbosity -> BS.ByteString -> IO Executable
readExecutableBlockFromScript verbosity str = do
str' <- case extractScriptBlock "cabal" str of
Left e -> die' verbosity $ "Failed extracting script block: " ++ e
Right x -> return x
when (BS.all isSpace str') $ warn verbosity "Empty script block"
readScriptBlock verbosity str'

-- | Extract the first encountered project metadata block started and
-- terminated by the below tokens.
--
-- * @{- project:@
--
-- * @-}@
--
-- Return the metadata.
readProjectBlockFromScript :: Verbosity -> String -> BS.ByteString -> IO ProjectConfig
readProjectBlockFromScript verbosity scriptName str = do
case extractScriptBlock "project" str of
Left _ -> return mempty
Right x -> reportParseResult verbosity "script" scriptName
$ parseProjectConfig scriptName x

-- | Extract the first encountered script metadata block started end
-- terminated by the tokens
--
-- * @{- cabal:@
-- * @{- <header>:@
--
-- * @-}@
--
Expand All @@ -311,8 +331,8 @@ readScriptBlockFromScript verbosity str = do
--
-- In case of missing or unterminated blocks a 'Left'-error is
-- returned.
extractScriptBlock :: BS.ByteString -> Either String BS.ByteString
extractScriptBlock str = goPre (BS.lines str)
extractScriptBlock :: BS.ByteString -> BS.ByteString -> Either String BS.ByteString
extractScriptBlock header str = goPre (BS.lines str)
where
isStartMarker = (== startMarker) . stripTrailSpace
isEndMarker = (== endMarker) . stripTrailSpace
Expand All @@ -330,8 +350,8 @@ extractScriptBlock str = goPre (BS.lines str)
| otherwise = goBody (l:acc) ls

startMarker, endMarker :: BS.ByteString
startMarker = fromString "{- cabal:"
endMarker = fromString "-}"
startMarker = "{- " <> header <> ":"
endMarker = "-}"

-- | The base for making a 'SourcePackage' for a fake project.
-- It needs a 'Distribution.Types.Library.Library' or 'Executable' depending on the command.
Expand Down Expand Up @@ -362,6 +382,10 @@ lLocalPackages :: Lens' ProjectBaseContext [PackageSpecifier UnresolvedSourcePac
lLocalPackages f s = fmap (\x -> s { localPackages = x }) (f (localPackages s))
{-# inline lLocalPackages #-}

lProjectConfig :: Lens' ProjectBaseContext ProjectConfig
lProjectConfig f s = fmap (\x -> s { projectConfig = x }) (f (projectConfig s))
{-# inline lProjectConfig #-}

-- Character classes
-- Transcribed from "templates/Lexer.x"
ccSpace, ccCtrlchar, ccPrintable, ccSymbol', ccParen, ccNamecore :: Set Char
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Test.Cabal.Prelude
main = setupAndCabalTest $ do
skipUnlessGhcVersion ">= 8.1"
skipUnlessGhcVersion ">= 8.1"
ghc <- isGhcVersion "== 9.0.2 || == 9.2.1"
expectBrokenIf ghc 7987 $ do
withPackageDb $ do
withDirectory "mylib" $ setup_install_with_docs ["--ipid", "mylib-0.1.0.0"]
withDirectory "mysql" $ setup_install_with_docs ["--ipid", "mysql-0.1.0.0"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Test.Cabal.Prelude
main = setupTest $ do
-- No cabal test because per-component is broken with it
skipUnlessGhcVersion ">= 8.1"
-- No cabal test because per-component is broken with it
skipUnlessGhcVersion ">= 8.1"
ghc <- isGhcVersion "== 9.0.2 || == 9.2.1"
expectBrokenIf ghc 7987 $
withPackageDb $ do
let setup_install' args = setup_install_with_docs (["--cabal-file", "Includes2.cabal"] ++ args)
setup_install' ["mylib", "--cid", "mylib-0.1.0.0"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import Test.Cabal.Prelude
import Data.List
import qualified Data.Char as Char
main = setupAndCabalTest $ do
skipUnlessGhcVersion ">= 8.1"
skipUnlessGhcVersion ">= 8.1"
ghc <- isGhcVersion "== 9.0.2 || == 9.2.1"
expectBrokenIf ghc 7987 $
withPackageDb $ do
containers_id <- getIPID "containers"
withDirectory "repo/sigs-0.1.0.0" $ setup_install_with_docs ["--ipid", "sigs-0.1.0.0"]
Expand Down
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/CmmSourcesDyn/setup.test.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Test.Cabal.Prelude

main = setupTest $ do
skipIf "ghc < 7.8" =<< ghcVersionIs (< mkVersion [7,8])
skipIf "ghc < 7.8" =<< isGhcVersion "< 7.8"
setup "configure" []
res <- setup' "build" []
assertOutputContains "= Post common block elimination =" res
5 changes: 0 additions & 5 deletions cabal-testsuite/PackageTests/CustomPlain/setup.test.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import Test.Cabal.Prelude
main = setupTest $ do
skipUnless "no Cabal for GHC" =<< hasCabalForGhc
-- On Travis OSX, Cabal shipped with GHC 7.8 does not work
-- with error "setup: /usr/bin/ar: permission denied"; see
-- also https://github.com/haskell/cabal/issues/3938
-- This is a hack to make the test not run in this case.
skipIf "osx and ghc < 7.10" =<< liftM2 (&&) isOSX (ghcVersionIs (< mkVersion [7,10]))
setup' "configure" [] >>= assertOutputContains "ThisIsCustomYeah"
setup' "build" [] >>= assertOutputContains "ThisIsCustomYeah"
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/DuplicateExperimental/Four.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Four where
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/DuplicateExperimental/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import One
import Two
import Three
import Four
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/DuplicateExperimental/One.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module One where
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Three where
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/DuplicateExperimental/Two.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Two where
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages:
./
35 changes: 35 additions & 0 deletions cabal-testsuite/PackageTests/DuplicateExperimental/duplicate.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cabal-version: 3.0
name: duplicate
version: 0
synopsis: Test of de-duping multiple warnings for experimental features
category: Tests
license: MIT

library
build-depends: base, one, two, three, four
exposed-modules: Main
default-language: Haskell2010

library one
visibility: public
exposed-modules: One
build-depends: base
default-language: Haskell2010

library two
visibility: public
exposed-modules: Two
build-depends: base
default-language: Haskell2010

library three
visibility: public
exposed-modules: Three
build-depends: base
default-language: Haskell2010

library four
visibility: public
exposed-modules: Four
build-depends: base
default-language: Haskell2010
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/DuplicateExperimental/setup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# cabal build
# cabal build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Test.Cabal.Prelude
main = cabalTest $ do
-- check output is summarized in -v1 (-v normal)
res <- cabal' "build" ["--only-configure","duplicate","-vnormal"]
assertOutputContains "(and 3 more occurrences)" res

-- check output is _not_ summarized in -v2 (verbose)
res <- cabal' "build" ["--only-configure","duplicate","-vverbose"]
assertOutputDoesNotContain "(and 3 more occurrences)" res
7 changes: 5 additions & 2 deletions cabal-testsuite/PackageTests/ForeignLibs/setup.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ import Test.Cabal.Prelude
-- Recording is turned off because versionedlib will or will not
-- be installed depending on if we're on Linux or not.
main = setupAndCabalTest . recordMode DoNotRecord $ do
-- Foreign libraries don't work with GHC 7.6 and earlier
skipUnlessGhcVersion ">= 7.8"
-- Foreign libraries don't work with GHC 7.6 and earlier
skipUnlessGhcVersion ">= 7.8"
osx <- isOSX
ghc <- isGhcVersion "== 8.0.2"
expectBrokenIf (osx && ghc) 7989 $
withPackageDb $ do
setup_install []
setup "copy" [] -- regression test #4156
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cabal v2-run
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O2
In order, the following will be built:
- fake-package-0 (exe:cabal-script-s.hs) (first run)
Configuring executable 'cabal-script-s.hs' for fake-package-0..
Building executable 'cabal-script-s.hs' for fake-package-0..
Loading

0 comments on commit 67d26c6

Please sign in to comment.