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

Prepend hs-source-dir to match-component #6622 #6623

Closed
wants to merge 5 commits into from

Conversation

fendor
Copy link
Collaborator

@fendor fendor commented Mar 29, 2020

Why this change?
The function matchFile expects arguments of a form such as:

matchFile [("app/Main.hs", ()), ("test/Test.hs", ())]  "app/Main.hs"

but the old implementation produces the following:

[("Main.hs", ()), ("Test.hs", ())]

since it doesnt prepend in the hsSourceDirs for each other-module.


Please include the following checklist in your PR:

  • Patches conform to the coding conventions.
  • Any changes that could be relevant to users have been recorded in the changelog.
  • The documentation has been updated, if necessary.
  • If the change is docs-only, [ci skip] is used to avoid triggering the build bots.
  • [ ] Add tests for ambiguous filepath targets

Please also shortly describe how you tested your change. Bonus points for added tests!

closes #6622

@mpickering
Copy link
Collaborator

Is this feature of the repl documented in the manual? Now might be a good time to do so.

@fendor
Copy link
Collaborator Author

fendor commented Mar 29, 2020

I am happy to update any documentation for cabal repl. Where should the documentation be added?

@phadej
Copy link
Collaborator

phadej commented Mar 30, 2020

re docs, there are sections for v2 commands. For example https://cabal.readthedocs.io/en/latest/nix-local-build.html#cabal-v2-repl

There are also TargetSelector tests in cabal-install/tests/IntegrationTests2.hs. Please add one testing new scenario.

@fendor
Copy link
Collaborator Author

fendor commented Mar 30, 2020

target-syntax
This should be updated, since cabal build File.hs works.

@fendor fendor force-pushed the fix/6622/cabal-repl-filename branch 8 times, most recently from c374937 to 8a5003d Compare March 30, 2020 20:30
@fendor fendor requested review from phadej and fgaz March 30, 2020 21:12
@fendor
Copy link
Collaborator Author

fendor commented Mar 30, 2020

The windows error seems to be that the following works on windows:

$ cabal repl p:app\Main.hs

but this doesnt:

$ cabal repl p:app/Main.hs

However, both

$ cabal repl app/Main.hs

$ cabal repl app\Main.hs

work.

Is it ok to fix that in this PR, too?

EDIT: fixed it.

@fendor fendor force-pushed the fix/6622/cabal-repl-filename branch 4 times, most recently from 4f74695 to f494fe1 Compare April 1, 2020 19:46
Cabal/doc/nix-local-build.rst Outdated Show resolved Hide resolved
@fendor fendor force-pushed the fix/6622/cabal-repl-filename branch 2 times, most recently from 8b8c726 to 1a71c7d Compare April 5, 2020 15:22
fendor added 3 commits April 6, 2020 14:05
Add Integration test for Target Selecetors for files that
are part of other-modules in sub-directories.
@fendor
Copy link
Collaborator Author

fendor commented Apr 14, 2020

So, currently there is an internal error when the file target is ambiguous, e.g. target is part of two executables, therefore hard to actually test for. The bug-fix for that is relatively simple, however, I feel like this PR is already bigger than planned.
Should I push the bug-fix here, or rather create another issue and another PR, so at least the very helpful changes in this PR are merged?

@phadej
Copy link
Collaborator

phadej commented Apr 30, 2020

I'm on the fence with this. Something tells me that cabal repl Foo.hs should not pick the component Foo.hs is included but build all of the project (or none if outsde) and load Foo.hs.

#6149

@fendor
Copy link
Collaborator Author

fendor commented Apr 30, 2020

Shouldn't v2-build just build both?

Yeah, but it fails. I assume it is just some minor bug, somewhere in target matching.

I'm on the fence with this. Something tells me that cabal repl Foo.hs should not pick the component Foo.hs is included but build all of the project (or none if outsde) and load Foo.hs.

What is all of the project in the case of a library? Wouldnt "library" be the component to build?
Or do you mean additionally, we should load the module Foo into the ghci session?
Afaict, we could add :add Foo to the ghci-script passed to ghci to achieve this.

However, please note, that not behaviour is introduced by this patch. This patch only fixes two bugs regarding finding the component associated with the module.

@phadej
Copy link
Collaborator

phadej commented Apr 30, 2020

I imagine use case:

cd some-library            # go to library sources
vim ExampleBug.hs          # quickly hack some example file
cabal repl ExampleBug.hs   # load it into repl

This is very common workflow for myself, but I have to rely on local
environment files now.

Yet, I don't understand what is the motivation to be able to select
a component by an arbitrary source-file. Module name is somewhat in unclear,
also main-is: EntryPoint.hs. But arbitrary source file: not really.

OTOH out-of-package source file and in package source files should
be disjoint, so there is no ambiguity.

@mpickering
Copy link
Collaborator

@phadej The motivation to select a component by a source file is to implement an IDE which can create the right session given any FilePath.

This patch just fixes the existing behavior as far as I understand.

@fendor
Copy link
Collaborator Author

fendor commented Apr 30, 2020

This is very common workflow for myself, but I have to rely on local
environment files now.

Would this be accomplished by #6149? Or rather, could we accomplish it that way?

@phadej
Copy link
Collaborator

phadej commented Apr 30, 2020

@mpickering I see. That's enough for me for a motivation.

@fendor
Copy link
Collaborator Author

fendor commented May 6, 2020

So, is there anything blocking this for getting merged? I would be happy if this bug-fix can make it into the next release.

@fendor fendor force-pushed the fix/6622/cabal-repl-filename branch from 3fe7219 to 9fef1d6 Compare May 6, 2020 12:49
@fendor fendor requested a review from DanielG May 8, 2020 15:21
@fendor
Copy link
Collaborator Author

fendor commented May 10, 2020

Is it ok if I merge this? Ideally before #6774 is merged so this PR does not need to be rebased.

@m-renaud
Copy link
Collaborator

Assuming no major delays here I can hold off until this PR is merged.

@fendor
Copy link
Collaborator Author

fendor commented May 10, 2020

I am just waiting for approval (or requesting changes). Dont want to go over anyone's head.

@phadej
Copy link
Collaborator

phadej commented May 14, 2020

what happens if executable name is HLint (note case), and there is HLint module in a library.

Is that ambiguous, how to resolve ambiguity?

@phadej
Copy link
Collaborator

phadej commented May 14, 2020

I see

                                  ":pkg:q:lib:q:file:Q.y"
                                  ":pkg:p:exe:ppexe:file:app/Main.hs"

selectors in text but have no idea what they mean (by looking at the documentation changes).

@@ -247,9 +247,15 @@ testTargetSelectors reportSubCase = do
":pkg:p:lib:p:file:P.y"
, "q/QQ.hs", "q:QQ.lhs", "lib:q:QQ.hsc", "q:q:QQ.hsc",
":pkg:q:lib:q:file:QQ.y"
, "q/Q.hs", "q:Q.lhs", "lib:q:Q.hsc", "q:q:Q.hsc",
":pkg:q:lib:q:file:Q.y"
, "app/Main.hs", "p:app/Main.hs", "exe:ppexe:app/Main.hs", "p:ppexe:app/Main.hs",
Copy link
Collaborator

@phadej phadej May 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add a test that Main.hs should be ambiguous?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, an ambiguous target selector makes sense, going to update it asap!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, I am not sure I get what you are saying?
Do you mean to add a test for the case that Main.hs is ambiguous? Since it should be a filepath, I dont think it can be ambiguous?

@fendor
Copy link
Collaborator Author

fendor commented May 14, 2020

what happens if executable name is HLint (note case), and there is HLint module in a library.

I dont know a lot about the module syntax, but the current (3.2.0.0) behaviour is that the executable is chosen. If this is not clear enough, we can remove the module syntax from the documentation.

selectors in text but have no idea what they mean (by looking at the documentation changes).

That is mainly copied from the other test-cases. I read the latter as the most verbose version of a file-target syntax while the former is the same for .y files (which are generated from happy, I think?)

@fendor
Copy link
Collaborator Author

fendor commented May 17, 2020

what happens if executable name is HLint (note case), and there is HLint module in a library.

There exists a test for it already:

    -- local components shadow modules and files
    reportSubCase "unambiguous: cwd comp vs module, file"
    assertUnambiguous "Foo"
      (mkTargetComponent "bar" (CExeName "Foo"))
      [ mkpkg "bar" [mkexe "Foo"]
      , mkpkg "other" [ mkexe "other"  `withModules` ["Foo"]
                      , mkexe "other2" `withCFiles`  ["Foo"] ]
      ]

@fgaz fgaz removed their request for review May 19, 2020 14:06
@fendor
Copy link
Collaborator Author

fendor commented May 20, 2020

Merged via #6826

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.

Bug: cabal repl file fails for executable component
5 participants