Commit 1b000168 authored by Edward Z. Yang's avatar Edward Z. Yang Committed by Ben Gamari
Browse files

The -package flag should select match from right-most package db.



The shadowing and default behavior (in the absence of
-hide-all-packages) prefers packages that come from "later" package
databases.  So for example if tmp1.d and tmp2.d both expose p-1.0, then

    ghc -package-db tmp1.d -package-db tmp2.d

brings the p-1.0 from tmp2.d into scope (and if they have the same IPID,
tmp2.d shadows tmp1.d).  HOWEVER, -package flags do NOT respect this
behavior.

    ghc -package-db tmp1.d -package-db tmp2.d -package p-1.0

this will force the p-1.0 from tmp1.d to be exposed!  This is
confusing, so this patch makes the behavior of -package flags
consistent.
Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>

Test Plan: validate

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1709
parent c8d0af31
......@@ -593,7 +593,9 @@ selectPackages matches pkgs unusable
= let (ps,rest) = partition matches pkgs
in if null ps
then Left (filter (matches.fst) (Map.elems unusable))
else Right (sortByVersion ps, rest)
-- NB: packages from later package databases are LATER
-- in the list. We want to prefer the latest package.
else Right (sortByVersion (reverse ps), rest)
-- A package named on the command line can either include the
-- version, or just the name if it is unambiguous.
......
......@@ -121,6 +121,9 @@ mk/ghcconfig*_test___spaces_ghc*.exe.mk
/tests/cabal/cabal05/r-0.1.0.0/
/tests/cabal/cabal06/inst-*/
/tests/cabal/cabal06/tmp*
/tests/cabal/cabal08/Main
/tests/cabal/cabal08/inst-*
/tests/cabal/cabal08/tmp*
/tests/cabal/local01.package.conf/
/tests/cabal/local03.package.conf/
/tests/cabal/local04.package.conf/
......
import P
main = putStrLn p
TOP=../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
SETUP=../Setup -v0
# in both cases, p2 should be preferred
cabal08: clean
$(MAKE) clean
'$(GHC_PKG)' init tmp1.d
'$(GHC_PKG)' init tmp2.d
'$(TEST_HC)' -v0 --make Setup
cd p1 && $(SETUP) clean
cd p1 && $(SETUP) configure $(CABAL_MINIMAL_BUILD) --with-ghc='$(TEST_HC)' --ghc-options='$(TEST_HC_OPTS)' --package-db=../tmp1.d --prefix='$(PWD)/inst-p1'
cd p1 && $(SETUP) build
cd p1 && $(SETUP) copy
cd p1 && $(SETUP) register
cd p2 && $(SETUP) clean
cd p2 && $(SETUP) configure $(CABAL_MINIMAL_BUILD) --with-ghc='$(TEST_HC)' --ghc-options='$(TEST_HC_OPTS)' --package-db=../tmp2.d --prefix='$(PWD)/inst-p2'
cd p2 && $(SETUP) build
cd p2 && $(SETUP) copy
cd p2 && $(SETUP) register
'$(TEST_HC)' $(TEST_HC_OPTS) -package-db tmp1.d -package-db tmp2.d Main.hs
./Main
'$(TEST_HC)' $(TEST_HC_OPTS) -package-db tmp1.d -package-db tmp2.d -hide-all-packages -package base -package p Main.hs
./Main
ifneq "$(CLEANUP)" ""
$(MAKE) clean
endif
clean :
$(RM) -r tmp*.d inst-* *.o *.hi */*.o */*.hi */Setup$(exeext) */dist Setup$(exeext)
import Distribution.Simple
main = defaultMain
if default_testopts.cleanup != '':
cleanup = 'CLEANUP=1'
else:
cleanup = ''
test('cabal08',
normal,
run_command,
['$MAKE -s --no-print-directory cabal08 ' + cleanup])
[1 of 1] Compiling Main ( Main.hs, Main.o )
Linking Main ...
p2
[1 of 1] Compiling Main ( Main.hs, Main.o )
Linking Main ...
p2
# Revision history for p
## 0.1.0.0 -- YYYY-mm-dd
* First version. Released on an unsuspecting world.
Copyright (c) 2015, Edward Z. Yang
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Edward Z. Yang nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import Distribution.Simple
main = defaultMain
name: p
version: 0.1.0.0
license: BSD3
license-file: LICENSE
author: Edward Z. Yang
maintainer: ezyang@cs.stanford.edu
build-type: Simple
extra-source-files: ChangeLog.md
cabal-version: >=1.10
library
exposed-modules: P
build-depends: base, containers
default-language: Haskell2010
# Revision history for p
## 0.1.0.0 -- YYYY-mm-dd
* First version. Released on an unsuspecting world.
Copyright (c) 2015, Edward Z. Yang
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Edward Z. Yang nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import Distribution.Simple
main = defaultMain
name: p
version: 0.1.0.0
license: BSD3
license-file: LICENSE
author: Edward Z. Yang
maintainer: ezyang@cs.stanford.edu
build-type: Simple
extra-source-files: ChangeLog.md
cabal-version: >=1.10
library
exposed-modules: P
build-depends: base
default-language: Haskell2010
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment