Skip to content

Commit

Permalink
Try to fix CI by splitting package
Browse files Browse the repository at this point in the history
  • Loading branch information
sheaf committed Apr 4, 2024
1 parent 1c76258 commit 1c17566
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 111 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@ jobs:
rm -rf C:/ProgramData/Chocolatey/bin/ghc*
stack ${{ matrix.args }} exec pacman -- --sync --refresh --noconfirm autoconf
fi
stack test --bench --no-run-benchmarks --haddock --no-terminal ${{ matrix.args }}
stack build
stack sdist --test-tarball
cd test
stack test --bench --no-run-benchmarks --haddock --no-terminal ${{ matrix.args }}
72 changes: 1 addition & 71 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -1,82 +1,12 @@
{-# OPTIONS_GHC -Wall #-}

module Main (main) where

-- Cabal
import Distribution.Simple
( defaultMainWithHooks
, autoconfUserHooks
, UserHooks(buildHook)
)
import Distribution.Simple.BuildPaths
( autogenComponentModulesDir
, exeExtension
)
import Distribution.Simple.LocalBuildInfo
( hostPlatform
, buildDir
, withTestLBI
)
import Distribution.Types.LocalBuildInfo
( LocalBuildInfo
, allTargetsInBuildOrder'
)
import Distribution.Types.Component
( Component(CExe) )
import Distribution.Types.Executable
( Executable(exeName) )
import Distribution.Types.PackageDescription
( PackageDescription )
import Distribution.Types.TargetInfo
( targetComponent )
import Distribution.Types.UnqualComponentName
( unUnqualComponentName )

-- directory
import System.Directory
( createDirectoryIfMissing )

-- filepath
import System.FilePath
( (</>), (<.>), takeDirectory )

--------------------------------------------------------------------------------

main :: IO ()
main = defaultMainWithHooks processHooks

-- The following code works around Cabal bug #9854.
--
-- The process package has an executable component named "cli-child",
-- used for testing. We want to invoke this executable when running tests;
-- however, due to the Cabal bug this executable does not get added to PATH.
-- To fix this, we create a "Test.Paths" module in a Custom setup script,
-- which contains paths to executables used for testing.
processHooks :: UserHooks
processHooks =
defaultConfigureHooks
{ buildHook = \ pd lbi userHooks buildFlags ->
withTestLBI pd lbi $ \ _testSuite clbi -> do
let pathsFile = autogenComponentModulesDir lbi clbi </> "Test" </> "Paths" <.> "hs"
createDirectoryIfMissing True (takeDirectory pathsFile)
writeFile pathsFile $ unlines
[ "module Test.Paths where"
, "processInternalExes :: [(String, FilePath)]"
, "processInternalExes = " ++ show (processInternalExes pd lbi)
]
buildHook defaultConfigureHooks pd lbi userHooks buildFlags
}

defaultConfigureHooks :: UserHooks
defaultConfigureHooks = autoconfUserHooks

processInternalExes :: PackageDescription -> LocalBuildInfo -> [(String, FilePath)]
processInternalExes pd lbi =
[ (toolName, toolLocation)
| tgt <- allTargetsInBuildOrder' pd lbi
, CExe exe <- [targetComponent tgt]
, let toolName = unUnqualComponentName $ exeName exe
toolLocation =
buildDir lbi
</> (toolName </> toolName <.> exeExtension (hostPlatform lbi))
]
main = defaultMainWithHooks autoconfUserHooks
39 changes: 1 addition & 38 deletions process.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ maintainer: libraries@haskell.org
bug-reports: https://github.com/haskell/process/issues
synopsis: Process libraries
category: System
build-type: Custom
build-type: Configure
description:
This package contains libraries for dealing with system processes.
.
Expand Down Expand Up @@ -39,13 +39,6 @@ source-repository head
type: git
location: https://github.com/haskell/process.git

custom-setup
setup-depends:
base >= 4.10 && < 4.20,
directory >= 1.1 && < 1.4,
filepath >= 1.2 && < 1.6,
Cabal >= 2.4 && < 3.12,

library
default-language: Haskell2010
other-extensions:
Expand Down Expand Up @@ -98,33 +91,3 @@ library
directory >= 1.1 && < 1.4,
filepath >= 1.2 && < 1.6,
deepseq >= 1.1 && < 1.6

-- Test executable for the CommunicationHandle functionality
executable cli-child
default-language: Haskell2010
hs-source-dirs: test/cli-child
main-is: main.hs
build-depends: base >= 4 && < 5
, deepseq
, process
ghc-options: -threaded -rtsopts

test-suite test
default-language: Haskell2010
hs-source-dirs: test
main-is: main.hs
type: exitcode-stdio-1.0
-- Add otherwise redundant bounds on base since GHC's build system runs
-- `cabal check`, which mandates bounds on base.
build-depends: base >= 4 && < 5
, bytestring
, deepseq
, directory
, filepath
, process
-- The autogenerated Test.Paths module works around Cabal bug #9854.
-- See the custom Setup for details.
other-modules: Test.Paths
autogen-modules: Test.Paths
build-tool-depends: process:cli-child
ghc-options: -threaded -rtsopts -with-rtsopts "-N"
79 changes: 79 additions & 0 deletions test/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{-# OPTIONS_GHC -Wall #-}

module Main (main) where

-- Cabal
import Distribution.Simple
( defaultMainWithHooks
, simpleUserHooks
, UserHooks(buildHook)
)
import Distribution.Simple.BuildPaths
( autogenComponentModulesDir
, exeExtension
)
import Distribution.Simple.LocalBuildInfo
( hostPlatform
, buildDir
, withTestLBI
)
import Distribution.Types.LocalBuildInfo
( LocalBuildInfo
, allTargetsInBuildOrder'
)
import Distribution.Types.Component
( Component(CExe) )
import Distribution.Types.Executable
( Executable(exeName) )
import Distribution.Types.PackageDescription
( PackageDescription )
import Distribution.Types.TargetInfo
( targetComponent )
import Distribution.Types.UnqualComponentName
( unUnqualComponentName )

-- directory
import System.Directory
( createDirectoryIfMissing )

-- filepath
import System.FilePath
( (</>), (<.>), takeDirectory )

--------------------------------------------------------------------------------

main :: IO ()
main = defaultMainWithHooks testProcessHooks

-- The following code works around Cabal bug #9854.
--
-- The process-tests package has an executable component named "cli-child",
-- used for testing. We want to invoke this executable when running tests;
-- however, due to the Cabal bug this executable does not get added to PATH.
-- To fix this, we create a "Test.Paths" module in a Custom setup script,
-- which contains paths to executables used for testing.
testProcessHooks :: UserHooks
testProcessHooks =
simpleUserHooks
{ buildHook = \ pd lbi userHooks buildFlags ->
withTestLBI pd lbi $ \ _testSuite clbi -> do
let pathsFile = autogenComponentModulesDir lbi clbi </> "Test" </> "Paths" <.> "hs"
createDirectoryIfMissing True (takeDirectory pathsFile)
writeFile pathsFile $ unlines
[ "module Test.Paths where"
, "processInternalExes :: [(String, FilePath)]"
, "processInternalExes = " ++ show (processInternalExes pd lbi)
]
buildHook simpleUserHooks pd lbi userHooks buildFlags
}

processInternalExes :: PackageDescription -> LocalBuildInfo -> [(String, FilePath)]
processInternalExes pd lbi =
[ (toolName, toolLocation)
| tgt <- allTargetsInBuildOrder' pd lbi
, CExe exe <- [targetComponent tgt]
, let toolName = unUnqualComponentName $ exeName exe
toolLocation =
buildDir lbi
</> (toolName </> toolName <.> exeExtension (hostPlatform lbi))
]
4 changes: 3 additions & 1 deletion test/cli-child/main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ main = do
hPutStr hWrite output
putStrLn "cli-child }"
hClose hWrite
_ -> error "expected two CommunicationHandle arguments"
_ -> error $
unlines [ "expected two CommunicationHandle arguments, but got:"
, show args ]
53 changes: 53 additions & 0 deletions test/process-tests.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cabal-version: 2.4
name: process-tests
version: 1.6.19.0
license: BSD-3-Clause
license-file: ../LICENSE
maintainer: libraries@haskell.org
bug-reports: https://github.com/haskell/process/issues
synopsis: Testing package for the process library
category: System
build-type: Custom
description:
This package contains the testing infrastructure for the process library

source-repository head
type: git
location: https://github.com/haskell/process.git
subdir: tests

custom-setup
setup-depends:
base >= 4.10 && < 4.20,
directory >= 1.1 && < 1.4,
filepath >= 1.2 && < 1.6,
Cabal >= 2.4 && < 3.12,

-- Test executable for the CommunicationHandle functionality
executable cli-child
default-language: Haskell2010
hs-source-dirs: cli-child
main-is: main.hs
build-depends: base >= 4 && < 5
, deepseq
, process
ghc-options: -threaded -rtsopts

test-suite test
default-language: Haskell2010
hs-source-dirs: .
main-is: main.hs
type: exitcode-stdio-1.0
-- Add otherwise redundant bounds on base since GHC's build system runs
-- `cabal check`, which mandates bounds on base.
build-depends: base >= 4 && < 5
, bytestring
, deepseq
, directory
, filepath
, process == 1.6.19.0
build-tool-depends: process-tests:cli-child
ghc-options: -threaded -rtsopts -with-rtsopts "-N"
other-modules: Test.Paths
autogen-modules: Test.Paths

9 changes: 9 additions & 0 deletions test/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resolver: ghc-9.2.3

extra-deps:
- ..
- Cabal-3.10.2.0

allow-newer: True
allow-newer-deps:
- Cabal

0 comments on commit 1c17566

Please sign in to comment.