You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cabal install; cabal test switches Cabal/GHC versions #1938
$ cabal test
cabal: You need to re-run the 'configure' command. The version of Cabal being
used has changed (was Cabal-1.16.0, now Cabal-1.18.1). Additionally the
compiler is different (was ghc-7.6, now ghc-7.4) which is probably the cause
of the problem.
This is the diff between this commit and one that builds correctly:
The cause of the version switch is that the commands "configure", "build", and "test" all attempt to use the version of Cabal with which cabal-install was built, whereas the "install" command tries to use the version of Cabal which is currently installed.
Sandboxes are still indirectly involved in the problem: whereas before, cabal-install was likely to be installed to ~/.cabal along with its copy of Cabal, it is now possible to take a version of cabal-install which has been built in one sandbox and to use that executable to build a project in another sandbox.
So why isn't cabal-install always using the version of Cabal with which it was built? The reason is explained in the documentation for determineSetupMethod:
-- Decide if we're going to be able to do a direct internal call to the
-- entry point in the Cabal library or if we're going to have to compile
-- and execute an external Setup.hs script.
While I'm not sure why only "install" would need to compile and execute the external Setup.hs script (the script should be used by all four commands), it does seem plausible that cabal-install would sometimes needs to compile something with the Cabal library. I guess one solution might be to always use the version of Cabal which is installed, but that would be unfortunate, because now that people tend to keep their ~/.cabal as empty as possible, that version is likely to be very old.
With the Simple build type, the installed Cabal is never used. With the Custom build type, the cabal-install executable still needs to determine if the package has been configured before attempting later phases, so it must try to read dist/setup-config. This will be fixed when as a side effect of fixing #2214.
When you say that "with the Simple build type, the installed Cabal is never used", do you mean that it should never be used? Because when I use cabal-install HEAD (1.23.0.0) to compile a hello-world project which uses the Simple build type, setup-config contains the number of the system version of Cabal, not the version with which cabal-install HEAD was built.
> cabal --version
cabal-install version 1.23.0.0
using version 1.23.0.0 of the Cabal library
> rm -rf dist/ .cabal-sandbox/ cabal.sandbox.config
> cabal sandbox init
> cabal install
...
> head -n1 dist/dist-sandbox-*/setup-config
Saved package config for hint-demo-0.1.0.0 written by Cabal-1.22.1.0 using ghc-7.10
Further exploration reveals that the "external build method", which uses the installed version of Cabal, is explicitly forced whenever cabal-install runs more than one job in parallel (-jN). Seems like running jobs in parallel is the default, too, because I haven't used -j in the above snippet and I can get the correct version to be written to setup-config by adding -j1:
> cabal --version
cabal-install version 1.23.0.0
using version 1.23.0.0 of the Cabal library
> rm -rf dist/ .cabal-sandbox/ cabal.sandbox.config
> cabal sandbox init
> cabal install -j1
...
> head -n1 dist/dist-sandbox-*/setup-config
Saved package config for hint-demo-0.1.0.0 written by Cabal-1.23.0.0 using ghc-7.8
Any idea why parallel builds force this external mode?
@gelisam Parallel builds happen in separate processes, not just separate threads, so I suspect that cabal-install is running the build through one of its cached Setup executables. I don't know why it is picking a different version. At least, we should be consistent with respect to in-tree builds about the version chosen.
Thanks Neil! I had skimmed that ticket, but its contents didn't make as much sense then as it does now.
@ttuegel Neither of them are "installed" in the sense in which I've been using the word above. I have installed cabal-install-1.23 and Cabal-1.23.0.0 in a separate sandbox, so when I run cabal-install on my hello world project, the only version of Cabal it sees installed is the one which comes with ghc 7.10.
Cabal uses cabal.exe (the installed cabal-install binary) when doing a test, or a configure. When doing a parallel install it builds a fresh binary using the installed Cabal library and uses that. I think that compiling against the Cabal library for a Simple build is a bug, and it should be reusing the installed cabal.exe, probably making use of a hidden extra entry point.
So, let's recap. The "install" command uses parallel builds, which in turn causes cabal-install to use the external setup method, which causes cabal-install to generate the source for a file called ./dist/setup/setup.hs, which must be linked against Cabal, which must be the installed somewhere, and that installed version might not be the same as the version with which cabal-install was linked.
Okay, so what is this generated setup.hs for? Must it be linked with other packages in the sandbox in which we are building, or could we somehow link it with the Cabal from the sandbox in which the current cabal-install was built?
Looking at the source of the generated setup.hs in a few sandboxes, it seems to be a copy of the user's Setup.hs, which was generated by cabal init and which few projects modify. If the user does modify this file, should all commands ("configure", "build", "install", "test") use the installed version of Cabal, or will some of them use the version with which cabal-install was linked?
We cannot link setup.hs against Cabal in the sandbox where cabal-install was built because cabal-install doesn't know about that sandbox and, in general, may not have been built in a sandbox at all! setup.hs is linked against whatever packages are in the current sandbox (or the user package database, if outside a sandbox) and the global package database.
The in-tree commands are run in the cabal-install process whenever possible, i.e. when build-type: Simple. That means these are performed using the Cabal version that cabal-install is linked against. Those commands are run in cabal-install because Cabal alone isn't smart enough to automatically re-/configure packages yet, and we consider that to be a critical feature of the user interface. That limitation will be lifted when #2214 is fixed, at which time we could consider running all commands through setup.hs. However, as Neil pointed out, there are reasons to prefer running all commands (at least for Simple packages) through cabal-install; primarily, transparency and efficiency.
The cause of the version switch is that the commands "configure", "build", and "test" all attempt to use the version of Cabal with which cabal-install was built, whereas the "install" command tries to use the version of Cabal which is currently installed.
Ok, so here's my analysis...
It's not that install "tries" to use a version of Cabal that's installed, but that when doing parallel builds we (currently) have to use multiple processes for the Setup.hs build parts, and currently that involves the "external setup method" of compiling a Setup.hs and using that for the install.
Now when it comes to build or test or whatever, we were then not in the situation where we had to force the use of the external setup method due to the multi-process issue, and so it was able to use the "internal setup method". The problem with this was twofold:
the external one could be a different version so you get behaviour differences,
and two it was that the selection of internal vs external was not stable. If having picked the external it stuck to always using it, things would be better.
However, now we have another fix (#2633) which allows us to use the cabal program itself as an external setup method for parallel builds. This and the new selection of setup method should fix both problems. The external and internal are now the same Cabal version. As for the stability of the choice, it's now:
Is this going to be stable? The build type and required cabal version are external info, coming from .cabal files and the command line. Those do switch between the external and self & internal methods, but that info itself can be considered stable. The logging and force-external conditions are internally generated choices but now these only switch between the self and internal setup methods, which are consistent with each other.
So I think I've convinced myself that this means it's stable overall. Which means I think this should be a full fix for the problem.
The other issue was about the test command not looking at the sandbox environment, which is fixed now right @ttuegel?
The other issue was about the test command not looking at the sandbox environment, which is fixed now right @ttuegel?
If you mean that cabal test builds the test suite with dependencies from the sandbox, then yes. #1953 is not fixed, but I don't think that affects this.
$ ~/src/cabal/cabal-install/dist/build/cabal/cabal --version
cabal-install version 1.23.0.0
using version 1.23.0.0 of the Cabal library
$ ghc-pkg list Cabal
/usr/local/lib/ghc-7.10.1/package.conf.d
Cabal-1.22.2.0
/Users/tibbe/.ghc/x86_64-darwin-7.10.1/package.conf.d
$ ~/src/cabal/cabal-install/dist/build/cabal/cabal install --enable-tests --dry-run -v3
...
$ ~/src/cabal/cabal-install/dist/build/cabal/cabal install --force-reinstalls --enable-tests
Resolving dependencies...
Warning: Note that reinstalls are always dangerous. Continuing anyway...
Configuring json-schema-0.7.3.6...
Building json-schema-0.7.3.6...
Installed json-schema-0.7.3.6
Updating documentation index /Users/tibbe/Library/Haskell/doc/index.html
$ ~/src/cabal/cabal-install/dist/build/cabal/cabal test --jobs=1
Preprocessing library json-schema-0.7.3.6...
...
In-place registering json-schema-0.7.3.6...
Preprocessing test suite 'json-schema-generic-aeson-tests' for
json-schema-0.7.3.6...
Running 1 test suites...
Test suite json-schema-generic-aeson-tests: RUNNING...
Test suite json-schema-generic-aeson-tests: PASS
Test suite logged to:
dist/test/json-schema-0.7.3.6-json-schema-generic-aeson-tests.log
1 of 1 test suites (1 of 1 test cases) passed.
Activity
[-]cabal install; cabal test switches GHC versions[/-][+]cabal install; cabal test switches Cabal/GHC versions[/+]MaxGabriel commentedon Jul 6, 2014
I had the same problem https://travis-ci.org/MaxGabriel/hackvote-yesod/builds/29276486
ttuegel commentedon Sep 13, 2014
I think this is related to #1953;
cabal testseems not to detect when it's run in a sandbox.gelisam commentedon Mar 24, 2015
The cause of the version switch is that the commands "configure", "build", and "test" all attempt to use the version of Cabal with which cabal-install was built, whereas the "install" command tries to use the version of Cabal which is currently installed.
Sandboxes are still indirectly involved in the problem: whereas before, cabal-install was likely to be installed to
~/.cabalalong with its copy of Cabal, it is now possible to take a version of cabal-install which has been built in one sandbox and to use that executable to build a project in another sandbox.So why isn't cabal-install always using the version of Cabal with which it was built? The reason is explained in the documentation for
determineSetupMethod:While I'm not sure why only "install" would need to compile and execute the external
Setup.hsscript (the script should be used by all four commands), it does seem plausible that cabal-install would sometimes needs to compile something with the Cabal library. I guess one solution might be to always use the version of Cabal which is installed, but that would be unfortunate, because now that people tend to keep their~/.cabalas empty as possible, that version is likely to be very old.ttuegel commentedon Mar 24, 2015
With the
Simplebuild type, the installed Cabal is never used. With theCustombuild type, the cabal-install executable still needs to determine if the package has been configured before attempting later phases, so it must try to readdist/setup-config. This will be fixed when as a side effect of fixing #2214.gelisam commentedon Mar 24, 2015
Thanks for the quick response!
When you say that "with the
Simplebuild type, the installed Cabal is never used", do you mean that it should never be used? Because when I use cabal-install HEAD (1.23.0.0) to compile a hello-world project which uses the Simple build type,setup-configcontains the number of the system version of Cabal, not the version with which cabal-install HEAD was built.gelisam commentedon Mar 24, 2015
Further exploration reveals that the "external build method", which uses the installed version of Cabal, is explicitly forced whenever cabal-install runs more than one job in parallel (
-jN). Seems like running jobs in parallel is the default, too, because I haven't used-jin the above snippet and I can get the correct version to be written tosetup-configby adding-j1:Any idea why parallel builds force this external mode?
ttuegel commentedon Mar 24, 2015
@gelisam Parallel builds happen in separate processes, not just separate threads, so I suspect that cabal-install is running the build through one of its cached Setup executables. I don't know why it is picking a different version. At least, we should be consistent with respect to in-tree builds about the version chosen.
ndmitchell commentedon Mar 24, 2015
The closed ticket #2438 details exactly why this happens.
ttuegel commentedon Mar 24, 2015
@gelisam Do you have
Cabal-1.23.0.0installed, or justcabal-install-1.23.0.0?gelisam commentedon Mar 24, 2015
Thanks Neil! I had skimmed that ticket, but its contents didn't make as much sense then as it does now.
@ttuegel Neither of them are "installed" in the sense in which I've been using the word above. I have installed cabal-install-1.23 and Cabal-1.23.0.0 in a separate sandbox, so when I run cabal-install on my hello world project, the only version of Cabal it sees installed is the one which comes with ghc 7.10.
ndmitchell commentedon Mar 24, 2015
Cabal uses
cabal.exe(the installed cabal-install binary) when doing a test, or a configure. When doing a parallel install it builds a fresh binary using the installedCaballibrary and uses that. I think that compiling against the Cabal library for a Simple build is a bug, and it should be reusing the installedcabal.exe, probably making use of a hidden extra entry point.gelisam commentedon Mar 24, 2015
So, let's recap. The "install" command uses parallel builds, which in turn causes cabal-install to use the external setup method, which causes cabal-install to generate the source for a file called
./dist/setup/setup.hs, which must be linked against Cabal, which must be the installed somewhere, and that installed version might not be the same as the version with which cabal-install was linked.Okay, so what is this generated
setup.hsfor? Must it be linked with other packages in the sandbox in which we are building, or could we somehow link it with the Cabal from the sandbox in which the current cabal-install was built?Looking at the source of the generated
setup.hsin a few sandboxes, it seems to be a copy of the user'sSetup.hs, which was generated bycabal initand which few projects modify. If the user does modify this file, should all commands ("configure", "build", "install", "test") use the installed version of Cabal, or will some of them use the version with which cabal-install was linked?ttuegel commentedon Mar 24, 2015
We cannot link
setup.hsagainst Cabal in the sandbox where cabal-install was built because cabal-install doesn't know about that sandbox and, in general, may not have been built in a sandbox at all!setup.hsis linked against whatever packages are in the current sandbox (or the user package database, if outside a sandbox) and the global package database.The in-tree commands are run in the cabal-install process whenever possible, i.e. when
build-type: Simple. That means these are performed using the Cabal version that cabal-install is linked against. Those commands are run in cabal-install because Cabal alone isn't smart enough to automatically re-/configure packages yet, and we consider that to be a critical feature of the user interface. That limitation will be lifted when #2214 is fixed, at which time we could consider running all commands throughsetup.hs. However, as Neil pointed out, there are reasons to prefer running all commands (at least forSimplepackages) through cabal-install; primarily, transparency and efficiency.7 remaining items
Work around Travis failures on HEAD due to Cabal bug
dcoutts commentedon Jun 1, 2015
Ok, so here's my analysis...
It's not that install "tries" to use a version of Cabal that's installed, but that when doing parallel builds we (currently) have to use multiple processes for the
Setup.hs buildparts, and currently that involves the "external setup method" of compiling a Setup.hs and using that for the install.Now when it comes to build or test or whatever, we were then not in the situation where we had to force the use of the external setup method due to the multi-process issue, and so it was able to use the "internal setup method". The problem with this was twofold:
However, now we have another fix (#2633) which allows us to use the
cabalprogram itself as an external setup method for parallel builds. This and the new selection of setup method should fix both problems. The external and internal are now the same Cabal version. As for the stability of the choice, it's now:Is this going to be stable? The build type and required cabal version are external info, coming from .cabal files and the command line. Those do switch between the external and self & internal methods, but that info itself can be considered stable. The logging and force-external conditions are internally generated choices but now these only switch between the self and internal setup methods, which are consistent with each other.
So I think I've convinced myself that this means it's stable overall. Which means I think this should be a full fix for the problem.
The other issue was about the test command not looking at the sandbox environment, which is fixed now right @ttuegel?
ttuegel commentedon Jun 2, 2015
If you mean that
cabal testbuilds the test suite with dependencies from the sandbox, then yes. #1953 is not fixed, but I don't think that affects this.tibbe commentedon Jun 2, 2015
This is fixed by #2633:
Allow using cabal program itself as the external setup method
Allow using cabal program itself as the external setup method
Allow using cabal program itself as the external setup method
bergmark commentedon Jun 2, 2015
Awesome, thanks!
Work around Travis failures on HEAD due to Cabal bug
Another attempt at fixing Cabal config issue
Remove workaround for haskell/cabal#1938, which has already been fixed
Remove workaround for haskell/cabal#1938, which has already been fixed
Remove workaround for haskell/cabal#1938, which has already been fixed