Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
Packages
Cabal
Commits
93d8ddb2
Commit
93d8ddb2
authored
Aug 07, 2017
by
Francesco Gazzetta
Committed by
GitHub
Aug 07, 2017
Browse files
Merge pull request #4641 from fgaz/new-run/datafiles-2
Use package root as data-file base path, not cwd
parents
8356832e
3d0f9be3
Changes
10
Hide whitespace changes
Inline
Side-by-side
cabal-install/Distribution/Client/CmdRun.hs
View file @
93d8ddb2
...
...
@@ -37,7 +37,7 @@ import Distribution.Verbosity
import
Distribution.Simple.Utils
(
wrapText
,
die'
,
ordNub
,
info
)
import
Distribution.Client.ProjectPlanning
(
ElaboratedConfiguredPackage
(
..
)
(
ElaboratedConfiguredPackage
(
..
)
,
BuildStyle
(
..
)
,
ElaboratedInstallPlan
,
binDirectoryFor
)
import
Distribution.Client.InstallPlan
(
toList
,
foldPlanPackage
)
...
...
@@ -52,13 +52,13 @@ import Distribution.Simple.Build.PathsModule
(
pkgPathEnvVar
)
import
Distribution.Types.UnitId
(
UnitId
)
import
Distribution.Client.Types
(
PackageLocation
(
..
)
)
import
qualified
Data.Map
as
Map
import
qualified
Data.Set
as
Set
import
System.FilePath
(
(
</>
)
)
import
System.Directory
(
getCurrentDirectory
)
runCommand
::
CommandUI
(
ConfigFlags
,
ConfigExFlags
,
InstallFlags
,
HaddockFlags
)
...
...
@@ -208,16 +208,13 @@ runAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, haddo
pkg
exeName
</>
exeName
curDir
<-
getCurrentDirectory
let
dataDirEnvVar
=
(
pkgPathEnvVar
(
elabPkgDescription
pkg
)
"datadir"
,
Just
$
curDir
</>
dataDir
(
elabPkgDescription
pkg
))
args
=
drop
1
targetStrings
let
args
=
drop
1
targetStrings
runProgramInvocation
verbosity
emptyProgramInvocation
{
progInvokePath
=
exePath
,
progInvokeArgs
=
args
,
progInvokeEnv
=
[
dataDirEnv
Var
]
progInvokeEnv
=
dataDir
s
Env
ironmentForPlan
elaboratedPlan
}
where
verbosity
=
fromFlagOrDefault
normal
(
configVerbosity
configFlags
)
...
...
@@ -225,6 +222,39 @@ runAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, haddo
globalFlags
configFlags
configExFlags
installFlags
haddockFlags
-- | Construct the environment needed for the data files to work.
-- This consists of a separate @*_datadir@ variable for each
-- inplace package in the plan.
dataDirsEnvironmentForPlan
::
ElaboratedInstallPlan
->
[(
String
,
Maybe
FilePath
)]
dataDirsEnvironmentForPlan
=
catMaybes
.
fmap
(
foldPlanPackage
(
const
Nothing
)
dataDirEnvVarForPackage
)
.
toList
-- | Construct an environment variable that points
-- the package's datadir to its correct location.
-- This might be:
-- * 'Just' the package's source directory plus the data subdirectory
-- for inplace packages.
-- * 'Nothing' for packages installed in the store (the path was
-- already included in the package at install/build time).
-- * The other cases are not handled yet. See below.
dataDirEnvVarForPackage
::
ElaboratedConfiguredPackage
->
Maybe
(
String
,
Maybe
FilePath
)
dataDirEnvVarForPackage
pkg
=
case
(
elabBuildStyle
pkg
,
elabPkgSourceLocation
pkg
)
of
(
BuildAndInstall
,
_
)
->
Nothing
(
BuildInplaceOnly
,
LocalUnpackedPackage
path
)
->
Just
(
pkgPathEnvVar
(
elabPkgDescription
pkg
)
"datadir"
,
Just
$
path
</>
dataDir
(
elabPkgDescription
pkg
))
-- TODO: handle the other cases for PackageLocation.
-- We will only need this when we add support for
-- remote/local tarballs.
(
BuildInplaceOnly
,
_
)
->
Nothing
singleExeOrElse
::
IO
(
UnitId
,
UnqualComponentName
)
->
TargetsMap
->
IO
(
UnitId
,
UnqualComponentName
)
singleExeOrElse
action
targetsMap
=
case
Set
.
toList
.
distinctTargetComponents
$
targetsMap
...
...
cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/bar/Main.hs
0 → 100644
View file @
93d8ddb2
import
LibFoo
main
=
putStrLn
=<<
LibFoo
.
getData
cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/bar/bar.cabal
0 → 100644
View file @
93d8ddb2
name: bar
version: 1.0
build-type: Simple
cabal-version: >= 1.10
executable bar
main-is: Main.hs
build-depends: base, foo
default-language: Haskell2010
cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/cabal.out
View file @
93d8ddb2
...
...
@@ -2,7 +2,18 @@
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- Datafiles-1.0 (exe:foo) (first run)
Configuring executable 'foo' for Datafiles-1.0..
Preprocessing executable 'foo' for Datafiles-1.0..
Building executable 'foo' for Datafiles-1.0..
- foo-1.0 (exe:foo) (first run)
Configuring executable 'foo' for foo-1.0..
Preprocessing executable 'foo' for foo-1.0..
Building executable 'foo' for foo-1.0..
# cabal new-run
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- foo-1.0 (lib) (first run)
- bar-1.0 (exe:bar) (first run)
Configuring library for foo-1.0..
Preprocessing library for foo-1.0..
Building library for foo-1.0..
Configuring executable 'bar' for bar-1.0..
Preprocessing executable 'bar' for bar-1.0..
Building executable 'bar' for bar-1.0..
cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/cabal.project
View file @
93d8ddb2
packages: .
packages:
foo
bar
cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/cabal.test.hs
View file @
93d8ddb2
import
Test.Cabal.Prelude
main
=
cabalTest
$
main
=
cabalTest
$
do
cabal'
"new-run"
[
"foo"
]
>>=
assertOutputContains
"Hello World"
cabal'
"new-run"
[
"bar"
]
>>=
assertOutputContains
"Hello World"
cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/foo/LibFoo.hs
0 → 100644
View file @
93d8ddb2
module
LibFoo
where
import
Paths_foo
getData
=
readFile
=<<
getDataFileName
"hello.txt"
cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/Main.hs
→
cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/
foo/
Main.hs
View file @
93d8ddb2
import
Paths_
Datafiles
import
Paths_
foo
main
=
putStrLn
=<<
readFile
=<<
getDataFileName
"hello.txt"
cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/data/hello.txt
→
cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/
foo/
data/hello.txt
View file @
93d8ddb2
File moved
cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/
Datafiles
.cabal
→
cabal-testsuite/PackageTests/NewBuild/CmdRun/Datafiles/
foo/foo
.cabal
View file @
93d8ddb2
name:
Datafiles
name:
foo
version: 1.0
build-type: Simple
cabal-version: >= 1.10
...
...
@@ -9,3 +9,11 @@ executable foo
main-is: Main.hs
build-depends: base
default-language: Haskell2010
library
exposed-modules: LibFoo
other-modules: Paths_foo
build-depends: base
default-language: Haskell2010
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment