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

Parse list fields in cabal config file #6161

Merged
merged 4 commits into from
Jul 30, 2019
Merged

Conversation

gbaz
Copy link
Collaborator

@gbaz gbaz commented Jul 26, 2019

  • 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.

This changes parsing of cabal config files to be more uniform with parsing of cabal project files.

Specifically, "extra-include-dirs", "extra-lib-dirs", "extra-framework-dirs", "extra-prog-path", and "configure-options" are now parsed as comma separated fields rather than single strings. This should resolve #5420 by making the syntax for this portable across systems. It is an alternative approach to #6155. Rather than writing multiple lines in config files, it brings the parsing and printing into accord by allowing parsing of comma separation (which the emitting already assumes is possible).

The entire config parser stuff is pretty antiquated and needs a full rewrite. In the meantime, this just "patches" the parsing after the fact. It makes use of the same parsers as for cabal project files, to not introduce yet another duplicate path. To do so we had to move certain "local" combinators from the cabal project file parser into their "proper" home (where the comments indicated they already should be moved as a further cleanup step). I audited the use cases for when they replace existing combinators there, and they're strictly more correct, so we should be fine.

Tested against the full suite and added a test specifically against this as well.

@randen
Copy link
Contributor

randen commented Jul 27, 2019

Part of #5420 is that when cabal-install forks processes and sets environment variables (specifically, %PATH%), the concatenation of the paths used commas, rather than semi-colons, as required by Windows %PATH%. I have tested the changes in #6155 and the generated "extra-prog-path" appears to be properly comma-separated, and on a single line.

However, on the back-end of this, when cabal-install is making use of this extra-prog-path, to append/pre-pend those additional path(s) onto the PATH environment variable, is there a platform-specific PATH separator used? If so, then yes, this PR (and #6155) should fix #5420.

@gbaz
Copy link
Collaborator Author

gbaz commented Jul 27, 2019

@randen it would be good if you can check that empirically as well. my understanding of observed past behavior and the code is that it should work. cf this region of code:

let extraPath = fromNubList $ configProgramPathExtra flags
let cflagsEnv = maybe (unwords ccFlags) (++ (" " ++ unwords ccFlags))
$ lookup "CFLAGS" env
spSep = [searchPathSeparator]
pathEnv = maybe (intercalate spSep extraPath)
((intercalate spSep extraPath ++ spSep)++) $ lookup "PATH" env
overEnv = ("CFLAGS", Just cflagsEnv) :
[("PATH", Just pathEnv) | not (null extraPath)]
hp = hostPlatform lbi
maybeHostFlag = if hp == buildPlatform then [] else ["--host=" ++ show (pretty hp)]
args' = configureFile':args ++ ["CC=" ++ ccProgShort] ++ maybeHostFlag
shProg = simpleProgram "sh"
progDb = modifyProgramSearchPath
(\p -> map ProgramSearchPathDir extraPath ++ p) emptyProgramDb

In particular, in the past if we kept each entry on a distinct line it would work. The problem wasn't that it was using the wrong character to join them -- it was just treating the entire list as a single list and not joining things at all. (Note this also really screwed up the internal progdb search path, which always expected a full list afaik, and not a value-separated string)

@gbaz
Copy link
Collaborator Author

gbaz commented Jul 27, 2019

(nb the one test failure appears due to a travis timeout)

@gbaz gbaz requested review from phadej and hvr July 28, 2019 23:05
@@ -11,3 +11,7 @@ main = cabalTest $ do
withEnv [("CABAL_CONFIG", Just conf2)] $ do
cabal "user-config" ["init"]
shouldExist conf2
cabalG ["--config-file", conf] "user-config" ["update", "-f", "-a", "extra-prog-path: foo", "-a", "extra-prog-path: bar"]
assertFileDoesContain conf "foo,bar"
cabalG ["--config-file", conf] "user-config" ["update", "-f", "-a", "extra-prog-path: foo, bar"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

so if Windows user wants to write extra-prog-path they should use comma, semicolon is not accepted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. This patch is to allow the parser to handle comma separated fields. Semicolon was never accepted anywhere. It "just happened" to work on windows (and actually still does because this patch won't change it) because it reads in "foo; bar" as a single value, and appends that single value to the path, but the syntax matches. I.e., it works by doing an deliberate "injection" attack :-).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we change parser to recognise ; as a separator too for that field. Than I think I'll be happy.

Copy link
Collaborator

Choose a reason for hiding this comment

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

... and the entry to changelog.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

do you want it as a separator for all fields or just to special case this one? i'd like to keep uniform syntax...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As I mentioned on irc, changing the parser for filepath lists to handle ; seems unnecessary to fix this -- it just extends the already convoluted parser code still further, adding special cases not only for certain lists (we already have like four distinct list types even without this) but also tokens.

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.e. the docs already say
image

so this patch as is doesn't change the grammar. it just fixes the fact that the docs claimed a feature that was only partially implemented.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(and because, on unix and mac, the comma thing 'accidentally' worked, people didn't notice)

@gbaz gbaz merged commit 0d32892 into master Jul 30, 2019
@gbaz
Copy link
Collaborator Author

gbaz commented Jul 30, 2019

@23Skidoo can you backport into the 3.0 branch [assuming that's what's getting released with the new ghc]? (if you prefer, you can ask me to do it).

@23Skidoo 23Skidoo deleted the gb/parse-config-multiline branch July 31, 2019 03:02
23Skidoo pushed a commit that referenced this pull request Jul 31, 2019
Parse list fields in cabal config file

(cherry picked from commit 0d32892)
@23Skidoo
Copy link
Member

Cherry-picked to 3.0.

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.

Uses of 'extra-prog-path' from cabal config need to format it for the specific platform
4 participants