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

main-is: inside two-way if/else: Ambiguous values for modulePath field #9659

Open
jwaldmann opened this issue Jan 25, 2024 · 6 comments
Open

Comments

@jwaldmann
Copy link

Describe the bug

cabal file containing

executable foo-bar
 if flag(wat)
     main-is: bar-foo.hs
 else
     main-is: foo-bar.hs

is rejected with

Ambiguous values for modulePath field: '"bar-foo.hs"' and '"foo-bar.hs"'
CallStack (from HasCallStack):
  error, called at src/Distribution/Types/UnqualComponentName.hs:128:7 in Cabal-syntax-3.11.0.0-inplace:Distribution.Types.UnqualComponentName

To Reproduce

$ cat foo.cabal
cabal-version: 3.0
name: foo
version: 0

flag wat
  default: False
  manual: True
     
executable foo-bar
 if flag(wat)
     main-is: bar-foo.hs
 else
     main-is: foo-bar.hs
 hs-source-dirs: src
 build-depends: base

$ cabal install

Expected behavior
builds

System information

6.6.12-200.fc39.x86_64  x86_64 GNU/Linux

cabal-install version 3.11.0.0
compiled using version 3.11.0.0 of the Cabal library 

ghc-9.6.3

Additional context

with cabal-install 3.10.2.1, the problem can be repaired with indenting else, see. ucsd-progsys/liquidhaskell#2258 (comment) but cabal-install-3.11 will reject that with

Warning: foo.cabal:12:4: invalid subsection "else"
Warning: foo.cabal:12:4: Inconsistent indentation. Indentation jumps at lines 12
@ffaf1
Copy link
Collaborator

ffaf1 commented Jan 25, 2024

Works here, cabal HEAD. Works with your .cabal too.

f@x270:/tmp/prova$ cat prova.cabal
cabal-version:   3.0
name:            prova
version:         0.1.0.0
license:         NONE
author:          Francesco Ariis
maintainer:      [email protected]
build-type:      Simple
extra-doc-files: CHANGELOG.md

flag wat

common warnings
    ghc-options: -Wall

executable prova
 import:           warnings
 if flag(wat)
     main-is: bar-foo.hs
 else
     main-is: foo-bar.hs
 build-depends:    base ^>=4.18.1.0
 hs-source-dirs:   app
 default-language: Haskell2010
f@x270:/tmp/prova$ tree app/
app/
├── bar-foo.hs
└── foo-bar.hs

1 directory, 2 files
f@x270:/tmp/prova$ cabal check
Warning: this is a debug build of cabal-install with assertions enabled.
These warnings will likely cause trouble when distributing the package:
Warning: [no-category] No 'category' field.
The following errors will cause portability problems on other environments:
Error: [no-syn-desc] No 'synopsis' or 'description' field.
Error: [license-none] The 'license' field is missing or is NONE.
Error: Hackage would reject this package.
f@x270:/tmp/prova$ cabal build
Warning: this is a debug build of cabal-install with assertions enabled.
Warning: The package list for 'hackage.haskell.org' is 33 days old.
Run 'cabal update' to get the latest list of available packages.
Resolving dependencies...
Build profile: -w ghc-9.6.3 -O1
In order, the following will be built (use -v for more details):
 - prova-0.1.0.0 (exe:prova) (first run)
Warning: this is a debug build of cabal-install with assertions enabled.
Configuring executable 'prova' for prova-0.1.0.0...
Warning: this is a debug build of cabal-install with assertions enabled.
Preprocessing executable 'prova' for prova-0.1.0.0...
Building executable 'prova' for prova-0.1.0.0...
[1 of 1] Compiling Main             ( app/bar-foo.hs, /tmp/prova/dist-newstyle/build/x86_64-linux/ghc-9.6.3/prova-0.1.0.0/x/prova/build/prova/prova-tmp/Main.o )
[2 of 2] Linking /tmp/prova/dist-newstyle/build/x86_64-linux/ghc-9.6.3/prova-0.1.0.0/x/prova/build/prova/prova
f@x270:/tmp/prova$ cabal --version
cabal-install version 3.11.0.0
compiled using version 3.11.0.0 of the Cabal library

@jwaldmann
Copy link
Author

my reproducer for 3.10.2.0 : https://git.imn.htwk-leipzig.de/waldmann/cabal-9659/-/jobs/39798

@gbaz
Copy link
Collaborator

gbaz commented Jan 26, 2024

Note, this does not appear to be a check error anymore:

Error: cabal: bar-foo.hsfoo-bar.hs doesn't exist

It looks like both sides of the conditional get evaluated and merged in the install command, not the check command. Maybe we're not evaluating conditionals right in that stanza?

@ffaf1
Copy link
Collaborator

ffaf1 commented Jan 26, 2024

Thanks for providing the reproducer.

Indeed I mistakenly thought the error was triggered by build/check, but it is not. It is cabal sdist (and cabal install) that fails:

/tmp/cabal-9659 (main)$ cabal --version
cabal-install version 3.11.0.0
compiled using version 3.11.0.0 of the Cabal library
/tmp/cabal-9659 (main)$ cabal sdist
Warning: this is a debug build of cabal-install with assertions enabled.
Ambiguous values for modulePath field: '"bar-foo.hs"' and '"foo-bar.hs"'
CallStack (from HasCallStack):
  error, called at src/Distribution/Types/UnqualComponentName.hs:128:7 in Cabal-syntax-3.11.0.0-inplace:Distribution.Types.UnqualComponentName
/tmp/cabal-9659 (main)$ ~/download/cabal --version
cabal-install version 3.10.2.0
compiled using version 3.10.2.1 of the Cabal library
/tmp/cabal-9659 (main)$ ~/download/cabal sdist
Error: cabal: bar-foo.hsfoo-bar.hs doesn't exist

Offending code is a broken Semigroup instance:

instance Semigroup Executable where
a <> b =
Executable
{ exeName = combineNames a b exeName "executable"
, modulePath = combineNames a b modulePath "modulePath"
, exeScope = combine exeScope
, buildInfo = combine buildInfo
}
where
combine field = field a `mappend` field b

b0cb3d4

which I suspect it is getting called via flattenPackageDescription.

@gbaz
Copy link
Collaborator

gbaz commented Jan 26, 2024

That sounds right. I was going to suggest we use finalizePD instead of flattenPackageDescription but in fact for sdist at least we really do need both sides of the conditional, since we need to add both to the tarball. We just need to ensure that we accumulate as lists of module names, not strings.

@ffaf1
Copy link
Collaborator

ffaf1 commented Feb 17, 2024

#9724 provides a possible workaround using extra-source-file.

@andreasabel andreasabel added the re: main Concerning the `main-is` field label Feb 25, 2024
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

4 participants