Skip to content
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

restore support for -package-db #147

Merged
merged 11 commits into from
Mar 30, 2022
Merged

restore support for -package-db #147

merged 11 commits into from
Mar 30, 2022

Conversation

gelisam
Copy link
Contributor

@gelisam gelisam commented Mar 6, 2022

Fixes #142

gelisam added 7 commits March 6, 2022 07:42
such as @unsafeRunInterpreterWithArgs [...]@
'unsafeRunInterpreterWithArgs' is often used to specify the path to a
non-default package database, using the @-package-db@ flag.
Unfortunately, a previous refactoring accidentally broke this workflow.

The refactoring seems innocent on the surface, so it's worth explaining
how that refactoring managed to break anything.

The refactoring defined a 'modifyLogger' shim corresponding to the
ghc-9.2 function of the same name. In older versions of ghc,
'modifyLogger' is implemented using 'setSessionDynFlags'. As a result,
it now matters whether the logger is configured before other calls to
'setSessionDynFlags'.

In particular, the logger was configured too early, before the
@-package-db@ flags were given to ghc using a second call to
'setSessionDynFlags'. As a result, the first call to
'setSessionDynFlags', the one hidden inside 'modifyLogger', was reading
the default package databases and setting internal flag indicating that
the package databases have been read. Then, the second call to
'setSessionDynFlags' which specifies non-default package databases with
@-package-db@ flags, saw this internal flag and decided not to read the
package databases a second time.

fixes #142
An IOTestCase is allowed to run IO before calling 'runInterpreter', and
to instead call a variant of 'runInterpreter' such as
'runInterpreterWithArgs', as long as it threads it through the
IOTestCase constructor. Unfortunately, this threading API was limiting:
only a single variant per test could be used, and IO could not be used
to construct the variant. This new API fixes both issues.
@gelisam
Copy link
Contributor Author

gelisam commented Mar 6, 2022

The tests pass with cabal, but not with stack. Both use ghc-pkg under the hood though, so I don't understand why a stack-run test would not be able to load a package database created by cabal.

it is set by stack and cabal complains about it in the tests
@gelisam
Copy link
Contributor Author

gelisam commented Mar 7, 2022

Oh no! In the process of figuring out the difference between cabal and stack, I switched to ghc-8.10.7, and with that version the test is failing with cabal as well!

@gelisam
Copy link
Contributor Author

gelisam commented Mar 7, 2022

The test passes with:

  • cabal, ghc-9.2.1
  • cabal, ghc-8.8.4

But fails with:

  • cabal, ghc-8.10.7
  • stack, ghc-9.2.1
  • stack, ghc-8.10.7

The combination "stack, ghc-8.8.4" does not appear in either list because I can't even get to stack test, as stack build already fails with Prelude.chr: bad argument: 2600468483.

So I think there are two separate problems:

  1. the test fails with stack
  2. the test fails with ghc-8.10.7

@gelisam
Copy link
Contributor Author

gelisam commented Mar 8, 2022

In both cabal repl and stack repl, I can successfully load a cabal-built package database:

λ> unsafeRunInterpreterWithArgs ["-package-db=/home/gelisam/working/haskell/hint/my-package/dist-newstyle/packagedb/ghc-9.2.1"] (setImports ["MyModule"])
Right ()

So what's different between the running the test suite and running the repl?

@gelisam
Copy link
Contributor Author

gelisam commented Mar 30, 2022

Aha! stack test sets GHC_ENVIRONMENT to some file, while stack repl sets it to "-". That turned out to be the key difference, as setting it to "-" allows stack test to load the package-db. Unsetting it works too.

@gelisam
Copy link
Contributor Author

gelisam commented Mar 30, 2022

More precisely, that file contains:

clear-package-db
global-package-db
package-db /home/gelisam/.stack/snapshots/x86_64-linux/aa6a7b0bd3b2a5e23297306cc07c915ab5a27aaabfa2af46eda508fef75733ab/9.2.1/pkgdb
package-db /home/gelisam/working/haskell/hint/.stack-work/install/x86_64-linux/aa6a7b0bd3b2a5e23297306cc07c915ab5a27aaabfa2af46eda508fef75733ab/9.2.1/pkgdb
package-id hint-0.9.0.5-6W0hq4jSyuP2V4U8FIOqob
package-id template-haskell-2.18.0.0
package-id HUnit-1.6.2.0-6u2bDpVgA3a6qfMIwFsdBJ
package-id base-4.16.0.0
package-id bytestring-0.11.1.0
package-id containers-0.6.5.1
package-id directory-1.3.6.2
package-id exceptions-0.10.4
package-id filepath-1.4.2.1
package-id ghc-9.2.1
package-id ghc-boot-9.2.1
package-id ghc-paths-0.1.0.12-FlEU4hxbdpqIe5aj4NDoD0
package-id random-1.2.1-18ubVgOsD0ELHvvhJVTjcY
package-id stm-2.5.0.0
package-id temporary-1.3-7JBHaoFPoLg44nCSFR89ij
package-id text-1.2.5.0
package-id transformers-0.5.6.2
package-id typed-process-0.2.7.0-KFeUVnIhBQ45qsp5kIfkdT
package-id unix-2.7.2.2

There are two reasons why this file is causing problems. First, it clears the list of package databases, so if this file happens to be interpreted after the command-line -package-db argument, then that argument has no effect. Second, it limits the list of packages which can be loaded to a list which does not include the my-package package which we're tying to load.

gelisam added 3 commits March 29, 2022 22:59
it is set by stack to pin down the list of package databases and the
list of packages, which is problematic for a test which tries to
configure a package database which is not in that list in order to load
a package which is not on that list either.
@gelisam gelisam merged commit 0ed9c4c into main Mar 30, 2022
@gelisam gelisam deleted the issue-142/package-db branch March 30, 2022 03:17
@gelisam
Copy link
Contributor Author

gelisam commented Mar 30, 2022

Finally!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

can't find modules after switch from v0.9.0.4 to v0.9.0.5
1 participant