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

Reserve a package namespace for sub-libraries in GHC 7.8 and prior #3017

Closed
ezyang opened this issue Jan 1, 2016 · 1 comment
Closed

Reserve a package namespace for sub-libraries in GHC 7.8 and prior #3017

ezyang opened this issue Jan 1, 2016 · 1 comment

Comments

@ezyang
Copy link
Contributor

ezyang commented Jan 1, 2016

In #269, and even the existing support for test suite libraries (detailed-0.9) (and related to #2716), there are situations when Cabal generates multiple libraries for a single package. At the moment, these libraries are only ever installed locally; however, they are installed to the inplace package database and are communicated to GHC.

Now, there is a very big wart in the current handling of detailed-0.9 test suite libraries: we give them a very fake, very not-globally-unique installed package ID for their registration in the database. This seems to work mostly OK, but actually the possibility for namespace collision is rife. For example, the test suite is not allowed to have the same name as the package (otherwise, they would collide: fortunately, there is an ad hoc test for this); if the test suite has the same name as a package which Cabal transitively depends on, and god forbid you also have same package, it will SHADOW that package and break the build:

ezyang@sabre:~/Dev/cabal-prof/Cabal/tests/PackageTests/TestNameCollision/child$ cabal configure --enable-tests
Resolving dependencies...
Configuring child-0.1...
Warning: Packages using 'cabal-version: >= 1.10' must specify the
'default-language' field for each component (e.g. Haskell98 or Haskell2010).
If a component uses different languages in different modules then list the
other ones in the 'other-languages' field.
ezyang@sabre:~/Dev/cabal-prof/Cabal/tests/PackageTests/TestNameCollision/child$ cabal build
Building child-0.1...
Preprocessing library child-0.1...
[1 of 1] Compiling Child            ( Child.hs, dist/build/Child.o )
Preprocessing test suite 'parent' for child-0.1...
[1 of 1] Compiling Test             ( tests/Test.hs, dist/build/Test.o )
<command line>: cannot satisfy -package-id parent-0.1: 
    parent-0.1 is shadowed by package parent-0.1-3gsxHRbNxfPaOGowp0Hdrk
    (use -v for more information)

The correct thing to do (and the thing that will also support us INSTALLING these sub-libraries to the database, as well), is to give PROPER, unique names to these sub-libraries, so that they won't shadow anything else.

That's all very fine and well... but GHC 7.8 (specifically, the shipped Cabal library shipped with ghc-pkg) doesn't support any -package-name which does not parse as a good old-fashioned package ID. So if we want to pick a unique name, we will have to come up with a new package name, which is guaranteed not to conflict with anything on Hackage.

The only way to do this is to reserve a namespace of package names, which we can then use for test names (and whatever private packages we might be interested in.)

I don't particularly care about what we name the prefix, but I propose z- for this purpose: it's short, is an oblique reference to GHC's z-encoding, and has no conflicts on public Hackage. My intention is to then encode "test suite foo in package mylibrary-0.2" as z-mylibrary-z-test-foo-0.2 (with a literal -z- component getting encoded with an extra z).

This hoohah is not necessary for GHC 7.10 or later.

ezyang added a commit to ezyang/cabal that referenced this issue Jan 2, 2016
When building a LibV09 test library, Cabal previously dumped
it into the same directory as the library proper.  This means
that if there are any module name conflicts, they'd override
each other. Bad!

The way to fix this is to build test libraries in different
directories.  We need to teach Cabal that not all libraries
are the main library.  This patch is a minimal patch to make
this work for GHC; doubtless refactoring can make this
generalize to all other backends (and make it hard to get
wrong.)

This follows the reserved namespace as per haskell#3017.

Signed-off-by: Edward Z. Yang <[email protected]>
ezyang added a commit to ezyang/cabal that referenced this issue Jan 2, 2016
When building a LibV09 test library, Cabal previously dumped
it into the same directory as the library proper.  This means
that if there are any module name conflicts, they'd override
each other. Bad!

The way to fix this is to build test libraries in different
directories.  We need to teach Cabal that not all libraries
are the main library.  This patch is a minimal patch to make
this work for GHC; doubtless refactoring can make this
generalize to all other backends (and make it hard to get
wrong.)

This follows the reserved namespace as per haskell#3017.

Signed-off-by: Edward Z. Yang <[email protected]>
ezyang added a commit to ezyang/cabal that referenced this issue Jan 2, 2016
Cabal's LibV09 support has always been a bit skeevy.  The general
idea was that a detailed-0.9 test-suite is built as a library
and an Cabal-provided stub executable.  In particular, the test suite
library must be installed to the installed package database so that the
executable can be compiled.

Old versions of Cabal did something very skeevy here:  they installed
the test library as a "package", with the same package name as
the "test-suite" stanza; furthermore, they built the products
into the same directory as the library proper.

Consequently, a lot of bad things could happen (both of which I've
added tests for):

    1. If the name of the test suite and the name of some other
    package coincide (and have the same version), they will clobber
    each other.  In GHC 7.8 and earlier, this just flat out
    kills the build, because it will shadow.  There's an explicit
    test to make sure test suites don't conflict with the package
    name, but you can get unlucky.

    2. The test suite library is built into the same directory
    as the main library, which means that if the test library
    implements the same module name as something in the main
    library it will clobber the interface file and badness
    will ensue.

This patchset fixes both of these issues, by (1) giving internal
test libraries proper names which are guaranteed to be unique
up to Cabal's dependency resolution, and (2) building the test
suite library into a separate directory.

In doing so, it also lays the groundwork for other types of
internal libraries, e.g. haskell#269, as well as extra (invisible)
libraries which we may install.

For GHC 7.8 and earlier, we follow the reserved namespace
convention as per haskell#3017.

Signed-off-by: Edward Z. Yang <[email protected]>
ezyang added a commit to ezyang/cabal that referenced this issue Jan 2, 2016
Cabal's LibV09 support has always been a bit skeevy.  The general
idea was that a detailed-0.9 test-suite is built as a library
and an Cabal-provided stub executable.  In particular, the test suite
library must be installed to the installed package database so that the
executable can be compiled.

Old versions of Cabal did something very skeevy here:  they installed
the test library as a "package", with the same package name as
the "test-suite" stanza; furthermore, they built the products
into the same directory as the library proper.

Consequently, a lot of bad things could happen (both of which I've
added tests for):

    1. If the name of the test suite and the name of some other
    package coincide (and have the same version), they will clobber
    each other.  In GHC 7.8 and earlier, this just flat out
    kills the build, because it will shadow.  There's an explicit
    test to make sure test suites don't conflict with the package
    name, but you can get unlucky.

    2. The test suite library is built into the same directory
    as the main library, which means that if the test library
    implements the same module name as something in the main
    library it will clobber the interface file and badness
    will ensue.

This patchset fixes both of these issues, by (1) giving internal
test libraries proper names which are guaranteed to be unique
up to Cabal's dependency resolution, and (2) building the test
suite library into a separate directory.

In doing so, it also lays the groundwork for other types of
internal libraries, e.g. haskell#269, as well as extra (invisible)
libraries which we may install.

For GHC 7.8 and earlier, we follow the reserved namespace
convention as per haskell#3017.

Signed-off-by: Edward Z. Yang <[email protected]>
ezyang added a commit to ezyang/cabal that referenced this issue Jan 3, 2016
Cabal's LibV09 support has always been a bit skeevy.  The general
idea was that a detailed-0.9 test-suite is built as a library
and an Cabal-provided stub executable.  In particular, the test suite
library must be installed to the installed package database so that the
executable can be compiled.

Old versions of Cabal did something very skeevy here:  they installed
the test library as a "package", with the same package name as
the "test-suite" stanza; furthermore, they built the products
into the same directory as the library proper.

Consequently, a lot of bad things could happen (both of which I've
added tests for):

    1. If the name of the test suite and the name of some other
    package coincide (and have the same version), they will clobber
    each other.  In GHC 7.8 and earlier, this just flat out
    kills the build, because it will shadow.  There's an explicit
    test to make sure test suites don't conflict with the package
    name, but you can get unlucky.

    2. The test suite library is built into the same directory
    as the main library, which means that if the test library
    implements the same module name as something in the main
    library it will clobber the interface file and badness
    will ensue.

This patchset fixes both of these issues, by (1) giving internal
test libraries proper names which are guaranteed to be unique
up to Cabal's dependency resolution, and (2) building the test
suite library into a separate directory.

In doing so, it also lays the groundwork for other types of
internal libraries, e.g. haskell#269, as well as extra (invisible)
libraries which we may install.

For GHC 7.8 and earlier, we follow the reserved namespace
convention as per haskell#3017.

Signed-off-by: Edward Z. Yang <[email protected]>
ezyang added a commit to ezyang/cabal that referenced this issue Jan 8, 2016
Cabal's LibV09 support has always been a bit skeevy.  The general
idea was that a detailed-0.9 test-suite is built as a library
and an Cabal-provided stub executable.  In particular, the test suite
library must be installed to the installed package database so that the
executable can be compiled.

Old versions of Cabal did something very skeevy here:  they installed
the test library as a "package", with the same package name as
the "test-suite" stanza; furthermore, they built the products
into the same directory as the library proper.

Consequently, a lot of bad things could happen (both of which I've
added tests for):

    1. If the name of the test suite and the name of some other
    package coincide (and have the same version), they will clobber
    each other.  In GHC 7.8 and earlier, this just flat out
    kills the build, because it will shadow.  There's an explicit
    test to make sure test suites don't conflict with the package
    name, but you can get unlucky.

    2. The test suite library is built into the same directory
    as the main library, which means that if the test library
    implements the same module name as something in the main
    library it will clobber the interface file and badness
    will ensue.

This patchset fixes both of these issues, by (1) giving internal
test libraries proper names which are guaranteed to be unique
up to Cabal's dependency resolution, and (2) building the test
suite library into a separate directory.

In doing so, it also lays the groundwork for other types of
internal libraries, e.g. haskell#269, as well as extra (invisible)
libraries which we may install.

For GHC 7.8 and earlier, we follow the reserved namespace
convention as per haskell#3017.

Signed-off-by: Edward Z. Yang <[email protected]>
ezyang added a commit that referenced this issue Jan 10, 2016
Cabal's LibV09 support has always been a bit skeevy.  The general
idea was that a detailed-0.9 test-suite is built as a library
and an Cabal-provided stub executable.  In particular, the test suite
library must be installed to the installed package database so that the
executable can be compiled.

Old versions of Cabal did something very skeevy here:  they installed
the test library as a "package", with the same package name as
the "test-suite" stanza; furthermore, they built the products
into the same directory as the library proper.

Consequently, a lot of bad things could happen (both of which I've
added tests for):

    1. If the name of the test suite and the name of some other
    package coincide (and have the same version), they will clobber
    each other.  In GHC 7.8 and earlier, this just flat out
    kills the build, because it will shadow.  There's an explicit
    test to make sure test suites don't conflict with the package
    name, but you can get unlucky.

    2. The test suite library is built into the same directory
    as the main library, which means that if the test library
    implements the same module name as something in the main
    library it will clobber the interface file and badness
    will ensue.

This patchset fixes both of these issues, by (1) giving internal
test libraries proper names which are guaranteed to be unique
up to Cabal's dependency resolution, and (2) building the test
suite library into a separate directory.

In doing so, it also lays the groundwork for other types of
internal libraries, e.g. #269, as well as extra (invisible)
libraries which we may install.

For GHC 7.8 and earlier, we follow the reserved namespace
convention as per #3017.

Signed-off-by: Edward Z. Yang <[email protected]>
@ezyang ezyang added the ezyang label Jan 13, 2016
garetxe pushed a commit to garetxe/cabal that referenced this issue Mar 5, 2016
Cabal's LibV09 support has always been a bit skeevy.  The general
idea was that a detailed-0.9 test-suite is built as a library
and an Cabal-provided stub executable.  In particular, the test suite
library must be installed to the installed package database so that the
executable can be compiled.

Old versions of Cabal did something very skeevy here:  they installed
the test library as a "package", with the same package name as
the "test-suite" stanza; furthermore, they built the products
into the same directory as the library proper.

Consequently, a lot of bad things could happen (both of which I've
added tests for):

    1. If the name of the test suite and the name of some other
    package coincide (and have the same version), they will clobber
    each other.  In GHC 7.8 and earlier, this just flat out
    kills the build, because it will shadow.  There's an explicit
    test to make sure test suites don't conflict with the package
    name, but you can get unlucky.

    2. The test suite library is built into the same directory
    as the main library, which means that if the test library
    implements the same module name as something in the main
    library it will clobber the interface file and badness
    will ensue.

This patchset fixes both of these issues, by (1) giving internal
test libraries proper names which are guaranteed to be unique
up to Cabal's dependency resolution, and (2) building the test
suite library into a separate directory.

In doing so, it also lays the groundwork for other types of
internal libraries, e.g. haskell#269, as well as extra (invisible)
libraries which we may install.

For GHC 7.8 and earlier, we follow the reserved namespace
convention as per haskell#3017.

Signed-off-by: Edward Z. Yang <[email protected]>
@ezyang
Copy link
Contributor Author

ezyang commented Aug 15, 2016

OK it's been reserved in HEAD.

@ezyang ezyang closed this as completed Aug 15, 2016
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