This project is mirrored from https://github.com/haskell/Cabal. Pull mirroring updated .
  1. 07 Mar, 2017 18 commits
    • Duncan Coutts's avatar
      Simplify IntegrationTests2 using overloaded strings · 1c46df4a
      Duncan Coutts authored
      We now have IsString instances for ModuleName, PackageName,
      UnqualifiedComponentName. We also have a local instance for PackageId.
      Using these makes the test case code shorter and clearer.
      1c46df4a
    • Duncan Coutts's avatar
      Remove done TODO about no targets in the Cmd* modules · c5cc3b9a
      Duncan Coutts authored
      The case of there being no targets at all is now handled by the target
      selector stage.
      c5cc3b9a
    • Duncan Coutts's avatar
      Tweak selectPackageTargets for haddock command · 4216aab1
      Duncan Coutts authored
      When reporting the case that no targets are enabled, transform targets
      that were not selected because of the lack of a haddock --executables
      and similar flags so that they're marked as TargetDisabledByUser rather
      than the confusing status of TargetBuildable (it's confusing since one
      may reasnably ask if it's buildable why do we still say it's disabled).
      
      This will be used later in error message construction.
      4216aab1
    • Duncan Coutts's avatar
      Adjust multiple target error case for run and repl commands · 2dc23405
      Duncan Coutts authored
      The run and repl commands only work with a single component as targets.
      When the user gives multiple target selectors that refer to distinct
      targets then we must report an error. It turns out that the information
      we already had was not really sufficient to construct a helpful error
      message. The information we had was the component targets that were
      actually selected, but we actually want to know the target selectors
      that gave rise to the selection of multiple targets.
      
      So this patch extends the information we collect in the resolveTargets
      function and stashes this info in the TargetProblemMultipleTargets
      constructor, which will enable construction of useful error messages.
      2dc23405
    • Duncan Coutts's avatar
      Split TargetSelectorNoTargets case into two sub-cases · 5dd6a76f
      Duncan Coutts authored
      In resolveTargetSelectors we return [TargetSelectorProblem] which
      includes a case TargetSelectorNoTargets. We split this into two cases:
      TargetSelectorNoTargetsInCwd and TargetSelectorNoTargetsInProject.
      
      The latter covers the important special case when there are no targets
      in the project as a whole. The former covers the same remaining cases as
      the original.
      
      This is a useful special case since it corresponds to running commands
      in a directory where there is no .cabal files and that is not underneath
      a project. Add a hopefully useful error message for this case.
      
      Also adjust the integration tests covering this case, which now split
      into two separate cases.
      5dd6a76f
    • Duncan Coutts's avatar
      Adjust target matching behaviour of repl and haddock commands · fa47eec5
      Duncan Coutts authored
      Normally a target like "pkg" does not select tests, benchmarks etc
      (though this can be overridden by other configuration), but when a user
      asks to repl/haddock "pkg:tests" then we should select tests
      irrespective of defaults since that's the clear user intention.
      
      This brings the repl and haddock commands into line with the build
      command in this respect.
      fa47eec5
    • Duncan Coutts's avatar
      Add sub-component check for test, bench, run commands · b2381e5d
      Duncan Coutts authored
      Asking to test/bench/run a file or module does not make sense.
      Users can only ask for a whole component.
      b2381e5d
    • Duncan Coutts's avatar
      Rewrite and document the selectPackageTargets for each command · 0a0dff33
      Duncan Coutts authored
      This is the function that implements the semantics of the target
      selector matching for each command.
      
      Introduce and use utils for target filtering and selection.
      
      Rename several of the error constructors to be consistent. For the test,
      bench and run commands, add a distinction between there being no targets
      at all and none of the right kind.
      
      Document the selectPackageTargets top level and cases, and
      selectComponentTarget. Also document the TargetProblem and constructors.
      0a0dff33
    • Duncan Coutts's avatar
      Add a number of TargetSelector tests · eb4783d4
      Duncan Coutts authored
      We already had tests covering valid syntax. This adds tests for invalid
      syntax and ambigious cases. Also cases for empty projects, or when there
      is no cwd package.
      eb4783d4
    • Duncan Coutts's avatar
      Adjust args to selectComponentTarget functions · 8072ee82
      Duncan Coutts authored
      Previously they took a TargetSelector that would always be a
      TargetComponent constructor, which meant that if we were interested in
      the content then we'd have to do partial pattern matching. Instead they
      now take all the contents of the TargetComponent as separate args which
      means no partial patterns and easy access to the parts.
      
      Also where relevant, put the TargetComponent contents into the
      TargetProblemCommon and TargetProblem constructors.
      8072ee82
    • Duncan Coutts's avatar
      In resolveTargets, represent two error cases explicitly · 9df5f4a3
      Duncan Coutts authored
      It's true that in the way the Cmd* modules use readTargetSelectors with
      resolveTargets, that these cases would be internal errors, it's more modular
      for resolveTargets not to make that assumption and to report them like
      other problems. We can report them as internal errors just as easily in the
      Cmd* error reporting code.
      9df5f4a3
    • Duncan Coutts's avatar
      Rename TargetProblem types and change a few related things · a8489be7
      Duncan Coutts authored
      Each Cmd* module defines its own type for representing the error
      conditions in selecting package and component targets. Each one has a
      constructor for the problems that are common to them all, which is
      shared in the ProjectOrchestration module.
      
      Rename these types so that ProjectOrchestration defines the type
      TargetProblemCommon and each of the others defines their own local type
      each named TargetProblem.
      
      Also make one step closer to proper error reporting for all these types
      by using die' and verbosity appropriately. Remove the old unused and
      incomplete error reproting code for TargetProblemCommon.
      
      Add a few Eq and Ord instances while we're at it. They'll be needed for
      testing and other things.
      a8489be7
    • Duncan Coutts's avatar
      Change TargetSelector to remove TargetCwdPackage · 34e0d5cd
      Duncan Coutts authored
      Refactor so that instead of two constructors TargetPackage and
      TargetCwdPackage we have just TargetPackage with an extra bool-like field to
      distinguish the two.
      
      This simplifies things in the consumers of TargetSelector which
      typically have to treat TargetPackage and TargetCwdPackage in the same
      way.
      
      Also eliminate the list field in TargetCwdPackage. We don't yet support
      multiple .cabal files in one dir, and when we do we'll do the same for
      the cwd targets as for other explicit targets. The only annoying thing
      here is that we need to use a dummy package info value because the
      representation does not allow for not having one. The tradeoff is still
      worth it in terms of less verbose consumers.
      
      Also adjust tests.
      34e0d5cd
    • Duncan Coutts's avatar
      Add positive tests for reading target selectors · ac006b4d
      Duncan Coutts authored
      So this covers most cases that are expected to work. Still need to do
      cases that are invalid syntax, unrecognised, or ambigious.
      
      Also added a note about a bit of an inconsistency in how we treat source
      file targets.
      ac006b4d
    • Duncan Coutts's avatar
      Make module name targets shadow file name targets · fbe691e1
      Duncan Coutts authored
      Generally these two are not ambigious with each other, e.g. "P" vs
      "P.hs" or "Data.P" vs "Data/P", but since we allow matching file names
      independent of file extension then for single-component module names
      then we have an ambiguity between module "P" and file name root "P". But
      these of course refer to the same thing, so the ambiguity is not useful.
      So we shadow these cases so it refers to the module name.
      fbe691e1
    • Duncan Coutts's avatar
      Avoid Showing TargetSelector's Package/ComponentInfo · 4f0a00e1
      Duncan Coutts authored
      We can't show these because we make them cyclic, and so it's not helpful
      to put them into the TargetSelectorProblem since we really want to be
      able to show that.
      
      This also allows TargetSelectorProblem to be given an Eq instance.
      
      These changes aid testing/debugging
      4f0a00e1
    • Duncan Coutts's avatar
      Generalise readTargetSelectors over Dir IO actions · 725587ba
      Duncan Coutts authored
      This makes it easier to test since it allows removing a dependence on
      the CWD or even IO. It may potentially be useful to not be in IO later
      too for other reasons
      725587ba
    • Duncan Coutts's avatar
      Adjust rel/abs path semantics in defaultDistDirLayout · af96c089
      Duncan Coutts authored
      In the ProjectRootExplicit case, findProjectRoot actually returns an
      absolute directory but a project file name that is relative to that.
      
      This seems to be the sensible thing to do, so we change what ProjectRoot
      is declared to be to match this, and adjust defaultDistDirLayout
      accordingly.
      
      This only makes a difference when a custom relative project file is
      specified.
      af96c089
  2. 27 Feb, 2017 22 commits
    • Duncan Coutts's avatar
      elaborate impl of findProjectRoot · 5b1eca08
      Duncan Coutts authored
      Take an extra arg to control where to start searching, not just process
      current directory. This is mainly to make it easier to test without
      having to mutate the cwd but is potentially useful generally for
      cwd-independence.
      
      Return more detailed info: not just the directory but return if it's an
      implicit or an explict project root with a cabal.project file. In the
      latter case also return the cabal.project file since its name can be
      overridden. Then also adjust defaultDistDirLayout to take this more
      detailed ProjectRoot type, thus avoiding having to duplicate the logic
      about the location of the cabal.project file.
      
      Change the behaviour so that if an explicit cabal.project file name is
      given and it is not found then fail, rather than falling back to an
      implicit project root style. This would seem to make most sense: if the
      user specifies an explict cabal.project file then it'd be odd if we
      silently ignore that if the user misspells it or something. The implicit
      root default is really for the really simple case, not when users are
      explicitly specifying stuff.
      
      Also add a couple simple tests for findProjectRoot.
      5b1eca08
    • Duncan Coutts's avatar
      Extend DistDirLayout with project root and cabal.project · 2b26e75b
      Duncan Coutts authored
      So the DistDirLayout now contains the root dir of the project as a
      whole, which eliminates the need to pass it separately in several cases.
      It also contains the location of the cabal.project file, which again
      avoids having to pass it around.
      
      In part these changes were to allow the elimination of uses of the
      legacy config types in the new-build code. The idea is that the legacy
      config types are only used by conversion into the new config types, and
      then only the new types are used in the new code.
      2b26e75b
    • Duncan Coutts's avatar
      Spelling and grammar in comments · 8be0062c
      Duncan Coutts authored
      8be0062c
    • Duncan Coutts's avatar
      Share a bit of repeated command line --help text · f033164f
      Duncan Coutts authored
      The stuff about the new-build/nix-local-build beta
      f033164f
    • Duncan Coutts's avatar
      Update a couple tests · ad424609
      Duncan Coutts authored
      Due to a change in behaviour: giving no target no longer means build
      everything, instead there is an explicit 'all' target.
      ad424609
    • Duncan Coutts's avatar
      Add and improve a couple comments · 942fc0e5
      Duncan Coutts authored
      942fc0e5
    • Duncan Coutts's avatar
      Add support for component-filters in target selectors · faa355ed
      Duncan Coutts authored
      This means we can say things like:
      cabal build tests     -- for the tests in the package in the cwd
      cabal build foo:tests -- for the tests in package foo
      cabal build all:benchmarks -- benchmarks in all packages in the project
      faa355ed
    • Duncan Coutts's avatar
      Update target resolving error logic after matching changes · 0b20257a
      Duncan Coutts authored
      The target selector matching now only returns packages that are local to
      the project. This means that when resolving packages later, if a lookup
      for the details of a package fails, then it's an internal error whereas
      previously it just meant it was a package outside of the project.
      0b20257a
    • Duncan Coutts's avatar
      Improve the way we default to the cwd package when no targets specified · bb74e3bd
      Duncan Coutts authored
      Do it by constructing special output rather than constructing special
      input. It's a bit clearer and more robust to refactoring this way.
      bb74e3bd
    • Duncan Coutts's avatar
      Do some internal renaming in the target selector code · 8a51c3c9
      Duncan Coutts authored
      Talk about cwd / current dir package rather than primary package.
      8a51c3c9
    • Duncan Coutts's avatar
      More regular fully qualified syntax for target selectors · 7add9d9c
      Duncan Coutts authored
      The command line target syntax has two main use cases: humans who prefer
      short forms and can deal with occasional ambiguity, and programs/scripts
      which need unambiguous syntax but it's ok if it's a big long.
      
      This patch changes the syntax for the long unambiguous form. It makes
      sure we have a fully qualified form for each target kind, and makes them
      consistent with each other. This is the syntax that will need to be
      documented for script authors (possibly in the --help in addition to the
      user guide).
      7add9d9c
    • Duncan Coutts's avatar
      Reduce shadowing in target selector syntactic forms · 51cd8dc8
      Duncan Coutts authored
      Make our policy be to use ambiguity by default, and then use shadowing
      where that really makes sense.
      
      In practice that means the 2, 3 and 4-component forms are part of the
      top level ambiguousAlternatives list, rather than nested within groups
      using shadowingAlternatives.
      
      For the fully qualified forms this makes no difference since they are
      not ambigious with each other. For the 2 & 3-component forms, in rare
      cases they can be ambigious with each other and so we'll now report
      that ambiguity rather than hiding it with explicit shadowing.
      
      Also add comments to this effect.
      51cd8dc8
    • Duncan Coutts's avatar
      Add a new 'all' form of target selector · df8ccce1
      Duncan Coutts authored
      Extend TargetSelector with a TargetAllPackages constructor with the
      corresponding concrete command line syntax 'all'. The interpretation of
      this is extended for all commands to be the same as if the list of all
      packages local to the project were given.
      
      Since the concrete syntax for the meta-target 'all' can in principle
      clash with a package 'all' or a component 'all', this short form of
      syntax is made to be ambigious with the existing short forms for
      packages or components, and new more qualified forms are added.
      
      This means that a user writing 'cabal build all' in a project where
      there is a local package 'all' or a component 'all' in the package in
      the cwd (but not any package 'all' as a dependency or any component
      'all' in any package other than the one in the cwd), will be informed
      that the syntax is ambigious and will be told the more qualified forms
      of the possible targets. These would be ':all' and 'pkg:all'. The use of
      the usual ':' separator with an empty string is the explicit indicator
      of a meta namespace. Since 'pkg:all' itself is also potentially
      ambigious with a package named 'pkg' containing a component 'all' then
      there is a further qualified form ':pkg:all' to select the package named
      'all'.
      
      This more qualified syntax need only be used in these highly unusual
      ambigious cases and the user will be informed. The intention, as has
      been the case previously, is to allow a normal syntax that is short and
      convenient but potentially ambigious in rare cases, while still allowing
      all cases to be expressed unambigiously.
      df8ccce1
    • Duncan Coutts's avatar
      Remove util buildTargetPackage as it is obsolete · 0c45cf41
      Duncan Coutts authored
      It was being used in one error message, in a place that will shortly be
      replaced, and it would not make sense with upcomming changes to the
      TargetSelector representation. So it's better to remove it now and fix
      the place where it was being used later.
      0c45cf41
    • Duncan Coutts's avatar
      c74eb192
    • Duncan Coutts's avatar
      Tidy up BuildTarget docs, messages and internal naming · 130e44a6
      Duncan Coutts authored
      Demote TargetString document TargetSelector. Reorder TargetString
      section. Rename use of userTarget naming convention to match new type
      names.
      
      Drop use of term "build" from error messages since these errors will
      appear for many commands, not just the build command.
      130e44a6
    • Duncan Coutts's avatar
      Rename things within the BuildTarget module · 39c184cb
      Duncan Coutts authored
      Rename UserBuildTarget to TargetString, to match the previous renaming
      of BuildTarget to TargetSelector. Also rename the corresponding
      functions.
      39c184cb
    • Duncan Coutts's avatar
      Consolodate error reporting in readTargetSelectors · d0b7cce7
      Duncan Coutts authored
      So there's now just one error type rather than two, and errors are
      returned rather than reported directly.
      
      Now that we have squashed together the two phases of the target
      selector parsing and resolving, we also want to do the same with the
      error reporting for the two phases. And to make it possible to customise
      the error messages for different commands we have the reporting being
      done explicitly and separately.
      d0b7cce7
    • Duncan Coutts's avatar
      607fe7c0
    • Duncan Coutts's avatar
      Move target selector reading before project planning · e2738469
      Duncan Coutts authored
      This means that in the majority of cases we can report errors in the
      command line arguments prior to running the solver. This is a much
      better state of affairs. Previously we had to wait many seconds (or
      sometime more) before being able to report problems. Worse, with the
      previous scheme the solver may fail to find a solution and so we'd
      end up reporting that rather than the problem with the user's target.
      e2738469
    • Duncan Coutts's avatar
      Minor: move debug logging of parallel build threads · e345be88
      Duncan Coutts authored
      Reduce it from info to debug and put it in a more sensible place where
      we can also report if it's parallel or serial more easily.
      e345be88
    • Duncan Coutts's avatar
      Split early steps out of runProjectPreBuildPhase · 692d6878
      Duncan Coutts authored
      This is part of the refactoring to resolve command line build targets
      without first having to run the solver and produce the elaborated
      install plan.
      
      Previously runProjectPreBuildPhase would do all the early steps
      including finding the project root and establishing the project
      config and the local packages. This patch splits those early steps
      out into a separate pass in the project orchestration. It also
      eliminates the need for the hookPrePlanning and since there's then
      only one hook left we don't bother to name the PreBuildHooks.
      692d6878