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

Ignore source files that are used as main when inferring modules #416

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sol
Copy link
Owner

@sol sol commented Nov 12, 2020

(fixes #188)

@sol
Copy link
Owner Author

sol commented Nov 12, 2020

This PR attempts to address #188. However, this is non-trivial. I'm not even sure if there is a sound solution. Consider the following:

# source files:
#
#   linux/L.hs
#   windows/W.hs
#   src/L.hs

executable:
  when:
    condition: os(windows)
    then:
      source-dirs:
        - windows
        - src
      main: W.hs
    else:
      source-dirs: linux
      main: L.hs

With this PR we will get the following output:

executable foo
  if os(windows)
    main-is: W.hs
    hs-source-dirs:
        windows
        src
  else
    main-is: L.hs
    hs-source-dirs:
        linux

specifically, other-modules: L is not mentioned under if os(windows), while arguably, a user would want to have it there.

Ignoring any code for now, can we conceptually come up with an algorithm that produces sensible results?

One of the issues is that main-is and hs-source-dirs "interact" with each other, but they can be specified in different places. From what I understand, Cabal will evaluate the conditionals, eliminate everything that is false and then interpret the whole thing as if it were specified sequentially, adding a kind of procedural component to the mix (akin to what @quasicomputational already described in #255).

For the example above, we know that the two branches of the if-statement are mutually exclusive, giving us additional information that we could work with. But conceptually you could have something like:

when:
  - condition: ...
    main: ...
  - condition: ...
    source-dirs: ...
  - condition: ...
    ...

Here I don't think it is statically decidable how things interact. (statically == independent of a specific build configuration)

Base automatically changed from master to main January 19, 2021 21:43
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.

Filter main-is of other test-suites from others' other-modules.
1 participant