Skip to content

Data files not working in new-build projects #4639

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

Closed
fgaz opened this issue Jul 28, 2017 · 1 comment
Closed

Data files not working in new-build projects #4639

fgaz opened this issue Jul 28, 2017 · 1 comment

Comments

@fgaz
Copy link
Member

fgaz commented Jul 28, 2017

Here's the problem: https://github.com/haskell/cabal/blob/484bb6c/cabal-install/Distribution/Client/CmdRun.hs#L211

We use the current directory as the base path for data files in new-run, but "current directory == package root" was true only before new-build.

Replacing curDir with the actual package root should fix this.

@fgaz fgaz self-assigned this Jul 28, 2017
fgaz added a commit to fgaz/cabal that referenced this issue Jul 28, 2017
Using the current directory worked with single packages, but cabal
projects can use packages in different places.

Fixes haskell#4639
fgaz added a commit to fgaz/cabal that referenced this issue Jul 29, 2017
Using the current directory worked with single packages, but cabal
projects can use packages in different places.

Fixes haskell#4639
@hvr
Copy link
Member

hvr commented Aug 5, 2017

I just ran into this problem, and didn't realise you were fully aware of this already :-)

As this made new-run unusable for some of my use-case, I had to yak-shave and fix this in my local cabal, and here's what I did including a few TODO-notes on what is missing:

diff --git a/cabal-install/Distribution/Client/CmdRun.hs b/cabal-install/Distribution/Client/CmdRun.hs
index 4d49167..807c5cb 100644
--- a/cabal-install/Distribution/Client/CmdRun.hs
+++ b/cabal-install/Distribution/Client/CmdRun.hs
@@ -19,6 +19,7 @@ import Distribution.Client.Compat.Prelude
 
 import Distribution.Client.ProjectOrchestration
 import Distribution.Client.CmdErrorMessages
+import Distribution.Client.Types (PackageLocation(..))
 
 import Distribution.Client.Setup
          ( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags
@@ -57,8 +58,6 @@ 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)
@@ -203,21 +202,29 @@ runAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, haddo
         ++ exeName
         ++ ":\n"
         ++ unlines (fmap (\p -> " - in package " ++ display (elabUnitId p)) elabPkgs)
+
     let exePath = binDirectoryFor (distDirLayout baseCtx)
                                   (elaboratedShared buildCtx)
                                   pkg
                                   exeName
                </> exeName
-    curDir <- getCurrentDirectory
-    let dataDirEnvVar = (pkgPathEnvVar (elabPkgDescription pkg) "datadir",
-                         Just $ curDir </> dataDir (elabPkgDescription pkg))
+
+    mexeDataDir <- case elabPkgSourceLocation pkg of
+                     LocalUnpackedPackage d -> pure $ Just (d </> dataDir (elabPkgDescription pkg))
+                     -- TODO/FIXME: figure out how to handle remaing constructors of PackageLocation
+
+    -- TODO/FIXME: dataDirEnvVars could be more than one variable, if local/inplace packages w/ package-data are involved!
+    let dataDirEnvVars = case mexeDataDir of
+                          Just _ -> [(pkgPathEnvVar (elabPkgDescription pkg) "datadir",
+                                      mexeDataDir)]
+                          Nothing -> []
         args = drop 1 targetStrings
     runProgramInvocation
       verbosity
       emptyProgramInvocation {
         progInvokePath  = exePath,
         progInvokeArgs  = args,
-        progInvokeEnv   = [dataDirEnvVar]
+        progInvokeEnv   = dataDirEnvVars
       }
   where
     verbosity = fromFlagOrDefault normal (configVerbosity configFlags)

fgaz added a commit to fgaz/cabal that referenced this issue Aug 6, 2017
Using the current directory worked with single packages, but cabal
projects can use packages in different places.

Fixes haskell#4639
@fgaz fgaz closed this as completed in #4641 Aug 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants