Skip to content

Can’t specify --config multiple times #7

@sellout

Description

@sellout

Using henforcer-1.0.0.1

If --config is specified multiple times, I get the following error, which isn’t very clear (e.g., it doesn’t mention that this is an Henforcer option, not a GHC option).

Invalid option `--config=/dev/null'

Usage: ghc-9.10.3 [-c|--config ARG]
<no location info>: error: ExitFailure 1

My Cabal package looks like this:

common defaults
  build-depends:
    base ^>= {4.8.2, 4.9.0, 4.10.0, 4.11.0, 4.12.0, 4.13.0, 4.14.0, 4.15.0, 4.16.0, 4.17.0, 4.18.0, 4.19.0, 4.20.0, 4.21.0, 4.22.0},
    henforcer ^>= {1.0.0},
  ghc-options:
    -fplugin Henforcer
    -fplugin-opt Henforcer:--config=henforcer.toml
  …

library
  import: defaults
  …

library internal
  import: defaults
  …

test-suite tests
  import: defaults
  …

test-suite doctests
  import: defaults
  …
  ghc-options:
    -- Don’t run Henforcer on this target.
    -fplugin-opt Henforcer:--config=/dev/null

There is a common section that sets up a lot of stuff (including Henforcer). It’s imported by every stanza. However, one stanza involves files I don’t control, so I disable Henforcer (hackily) by setting its config to /dev/null (which is probably not portable, and I should use an empty.toml instead, but I don’t think that matters here).

However, since --config is already set in the common section, this second occurrence causes an error. I think that (as is common with command-line options) Henforcer should just use the last one provided. This also allows the config to be overridden (or disabled) per-module with
{-# OPTIONS_GHC -fplugin-opt Henforcer:--config=this-modules-config.toml #-} (although I get that the config file provides a different way to achieve that).

An alternative solution for my particular case would be to add an explicit --disable flag or something that tells Henforcer not to do anything (unfortunately, GHC doesn’t have something like -fno-plugin Henforcer to remove a previously-added plugin).

Oh, and my case works if I use the default config location (not passing --config) in general, and just use the --config=/dev/null for the override. I only ran into this because I was seeing some other odd behavior (not yet diagnosed) and added the default config to see if it behaved differently with that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions