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

Filter out files that are not ending in .c from c-sources #9200

Merged

Conversation

Kleidukos
Copy link
Member

@Kleidukos Kleidukos commented Aug 23, 2023

This poc pre-filters file paths given in c-sources to only keep the ones ending in ".c", and outputs an appropriate message.

  1. Should we check if there are ".h" files explicitly and redirect to "includes"?
  2. Should we expand this to cxx-sources?

QA Notes

  1. Clone the repository https://github.com/jtdaugherty/vty-unix
  2. Remove from its cabal file the exported modules, dependencies and executable component
  3. Run cabal build -w ghc-9.2.8
  4. Make sure the output is the following:
Preprocessing library for repro-0.1.0.0..
Building library for repro-0.1.0.0..
Warning: The following files listed in the main library's c-sources will not
be used: cbits/gwinsz.h.
Header files should be in the 'include' or 'install-include' stanza.
See https://cabal.readthedocs.io/en/3.10/cabal-package.html#pkg-field-includes
Preprocessing library 'lib2' for repro-0.1.0.0..
Building library 'lib2' for repro-0.1.0.0..
Warning: The following files listed in library lib2's c-sources will not be
used: cbits/gwinsz.h.
Header files should be in the 'include' or 'install-include' stanza.
See https://cabal.readthedocs.io/en/3.10/cabal-package.html#pkg-field-includes
Preprocessing executable 'exec1' for repro-0.1.0.0..
Building executable 'exec1' for repro-0.1.0.0..
[1 of 1] Compiling Main             ( Main.hs, /home/hecate/Vrac/cabal-9190-repro/dist-newstyle/build/x86_64-linux/ghc-9.4.5/repro-0.1.0.0/x/exec1/build/exec1/exec1-tmp/Main.o )
Warning: The following files listed in exec1's c-sources will not be used:
cbits/gwinsz.h.
Header files should be in the 'include' or 'install-include' stanza.
See https://cabal.readthedocs.io/en/3.10/cabal-package.html#pkg-field-includes
[2 of 2] Linking /home/hecate/Vrac/cabal-9190-repro/dist-newstyle/build/x86_64-linux/ghc-9.4.5/repro-0.1.0.0/x/exec1/build/exec1/exec1
  1. Exit code should be 0 (you can check with echo $?

relates to #9190

@hasufell @mouse07410 @andreabedini @angerman

@Kleidukos Kleidukos force-pushed the hecate-9190-ignored-files-in-c-sources branch 2 times, most recently from 7e79a16 to 3a5774b Compare August 23, 2023 17:42
@Kleidukos Kleidukos marked this pull request as ready for review August 23, 2023 18:04
@Kleidukos Kleidukos force-pushed the hecate-9190-ignored-files-in-c-sources branch from 3a5774b to a275708 Compare August 23, 2023 18:18
@andreabedini
Copy link
Collaborator

@Kleidukos I thought there was somehing like this somewhere. Let's wait until we figure out what changed the behaviour and how it changed.

@Kleidukos
Copy link
Member Author

@andreabedini I'm not opposed to this for master but for 3.10 it's becoming a bit time-sensitive.

@andreabedini
Copy link
Collaborator

😞 I understand.

Copy link
Member

@Mikolaj Mikolaj left a comment

Choose a reason for hiding this comment

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

Thank you for adding the warning --- that's progress. Also, thank you for resisting the urge to deduplicate at the last moment before the releases. :)

@angerman
Copy link
Collaborator

I think the warning should suggest people to use the include or install-include section. And link to the cabal manual where it clearly says headers.

@@ -710,7 +710,10 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
let (cSrcs', others) = partition (\filepath -> ".c"`isSuffixOf` filepath) (cSources libBi)
unless (null others) $ do
let files = intercalate ", " others
warn verbosity $ "The following files listed in c-sources will not be used: " <> files
let libraryName = case libName lib of
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have showLibraryName

Copy link
Member Author

Choose a reason for hiding this comment

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

The output is unsatisfying. Especially because it is:

"library '" ++ prettyShow name ++ "'"

So the output would be:

"The following files listed in library 'lib2''s c-sources will not be used:

The double single quotes are not a mistake.

And if it's the main library, it only outputs "library", which breaks the flow of the sentence.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is

libraryNameStanza :: LibraryName -> String
libraryNameStanza LMainLibName       = "library"
libraryNameStanza (LSubLibName name) = "library " ++ prettyShow name

any better? Otherwise, it's ok.

Copy link
Member

@fgaz fgaz Aug 24, 2023

Choose a reason for hiding this comment

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

Or rephrase as "The following files listed in the c-sources of the library 'lib2' will not be used"

Copy link
Member Author

Choose a reason for hiding this comment

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

@fgaz I don't understand what this suggestion is addressing, sorry

Copy link
Member

Choose a reason for hiding this comment

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

If you phrase it like that, you can use showLibraryName

Copy link
Member Author

Choose a reason for hiding this comment

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

But we lose the "main" bit, which is fairly important.

Copy link
Member

Choose a reason for hiding this comment

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

Good point. I wonder if showLibraryName produces confusing messages elsewhere too. Maybe we should add "main" there too...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes indeed, we will have to formalise a bit more the presentation layer for cabal-install.

@@ -29,7 +29,7 @@ tests = testGroup "Distribution.Utils.Structured"
, testCase "GenericPackageDescription" $
md5Check (Proxy :: Proxy GenericPackageDescription) 0x8d8f340f10a58b8d8a87bf42213dac89
, testCase "LocalBuildInfo" $
md5Check (Proxy :: Proxy LocalBuildInfo) 0xbb22c3258d3092f31e992bc093d09170
md5Check (Proxy :: Proxy LocalBuildInfo) 0x618ab257e99d0b21c617e1f8c39a5a4b
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is LocalBuildInfo changing?

Copy link
Member Author

Choose a reason for hiding this comment

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

No idea

Copy link
Member

@fgaz fgaz Aug 24, 2023

Choose a reason for hiding this comment

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

Try rebasing, it should disappear

Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔

Copy link
Member

Choose a reason for hiding this comment

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

@andreabedini I'm saying that because this appears to be based on an old commit with a different structured hash (0xbb22... doesn't appear anywhere in HEAD)

Copy link
Member Author

Choose a reason for hiding this comment

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

@fgaz rebasing on current 3.10 you mean?

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, I grepped the wrong branch 🙈

@andreabedini
Copy link
Collaborator

@Kleidukos Could you add a test case too? something that has c-sources: file.h file.c. I think this PR will emit a warning (which we can capture), while with the old behaviour nothing was displayed. This would allow us to notice if something changes again.
🙏 🙇 ❤️

Copy link
Collaborator

Choose a reason for hiding this comment

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

I could reproduce with empty files too, if that makes it any easier

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah sure let's go with it 👍

@Kleidukos
Copy link
Member Author

@andreabedini would you mind running the cabal-test executable and accept the output? It never finishes on my machine.

@andreabedini
Copy link
Collaborator

@Kleidukos I took some liberties, I hope you are ok with it ☺️

@Kleidukos Kleidukos merged commit 47eb77b into haskell:3.10 Aug 24, 2023
@Kleidukos Kleidukos deleted the hecate-9190-ignored-files-in-c-sources branch August 24, 2023 15:54
@hamishmack
Copy link
Collaborator

This breaks the double-conversion package (uses .cc extension in c-sources).

Also the warning did not work because it is only reached if not (null cSrcs'). All the src files in double-conversions have .cc extensions. So everything is ignored and no warning is issued.

@angerman
Copy link
Collaborator

Well, .cc is c++, so this should be under cxx-sources not c-sources. Treating c++ files as c files is another one of those "often works" scenarios.

hamishmack added a commit to hamishmack/cabal that referenced this pull request Sep 25, 2023
haskell#9200 started filtering `.cc` files from `c-sources` and does not always issue a warning (there has to be at least one `.c` file present before it warns you it is ignoring the others).

Some packages in hackage (`double-conversion` for instance) rely on the ability to include `C++` source files in `c-sources`.  This is not ideal, but we should probably continue to support these packages.

This change will relax the filtering, so that only `.h` files are automatically excluded (with a warning).  It will also warn if other non `.c` files are present (suggesting the `cxx-sources` since C++ sources are the most likely to be used).

The bug that prevented warnings being displayed when no `.c` files were present is fixed.
@jasagredo
Copy link
Collaborator

Confirmed it works as expected on Mingw with cabal-3.10.2.0. I can confirm also that #9285 works on top of this one as expected:

Warning: The following header files listed in the main library's c-sources
will not be used: cbits/gwinsz.h.
Header files should be in the 'include' or 'install-include' stanza.
See https://cabal.readthedocs.io/en/3.10/cabal-package.html#pkg-field-includes
Warning: The following files listed in the main library's c-sources do not
have the expected '.c' extension cbits/gwinsz.cc.
C++ files should be in the 'cxx-sources' stanza.
See
https://cabal.readthedocs.io/en/3.10/cabal-package.html#pkg-field-cxx-sources

@jasagredo jasagredo added the tested-on: windows QA has been successful on Windows label Nov 19, 2023
@sternenseemann
Copy link

Getting a changelog entry on this (retroactively) would maybe be nice, since the warning does not seem to work at all, at least in Setup.hs builds. Just had a fun afternoon debugging this.

Also, I feel like in this sort of case, the chance of people accidentally relying on the »incorrect« behavior is big enough not to have this in a minor point release…

@mpscholten
Copy link

This change caused one of our dependencies to silently fail. It would have been nice if this was a hard fail.

mpscholten added a commit to mpscholten/nixpkgs that referenced this pull request Jul 24, 2024
Fixes NixOS#319365

Build of pdftotext was broken caused by a recent cabal change introduced via haskell/cabal#9200
flandweber pushed a commit to flandweber/nixpkgs that referenced this pull request Aug 28, 2024
Fixes NixOS#319365

Build of pdftotext was broken caused by a recent cabal change introduced via haskell/cabal#9200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
attention: needs-manual-qa PR is destined for manual QA attention: needs-review tested-on: windows QA has been successful on Windows
Projects
Status: To Test
Development

Successfully merging this pull request may close these issues.

9 participants