Skip to content

Instantly share code, notes, and snippets.

@fendor
Last active February 20, 2022 16:04
Show Gist options
  • Save fendor/796b373aba26e12dbdecf7e40af78b32 to your computer and use it in GitHub Desktop.
Save fendor/796b373aba26e12dbdecf7e40af78b32 to your computer and use it in GitHub Desktop.

Cabal Status Command Specification

Describes how we expect the command cabal status to behave from a high-level perspective.

CompilerInfo

> cabal status --output-format=json --compiler | jq
{
  "cabal-version": "3.7.0.0",
  "compiler": {
    "flavour": "GHC",
    "compiler-id": "ghc-7.10.2",
    "path": "/usr/bin/ghc"
  }
}

Cli:

  • --output-format is mandatory. Only allowed value: json (may be extended in the future)
  • --compiler composable selector

Output explanations:

  • Mandatory: cabal-version denotes the output format version and follows the cabal-version scheme
  • compiler-id is standardised to: <Compiler-Name>-<Version>
  • path points to the same location cabal is using
  • flavour is one of: GHC | GHCJS

Do we care about more fields?

BuildInfo

Syntax:

> cabal status --output-format=json --target=./src/File.hs --target=./test/Main.hs --target=./non-existent/Main.hs | jq
{
  "cabal-version": "3.7.0.0",
  "target": [
    { 
      "target": "./src/File.hs",
      "unit-id": "foo-inplace"
    },
    { 
      "target": "./test/Main.hs",
      "unit-id": "foo-testsuite-inplace"
    },
    { 
      "target": "./non-existent/Main.hs",
      "unit-id": null
    }
  ]
}

Cli:

  • --output-format is mandatory. Only allowed value: json (may be extended in the future)
  • --target can be given multiple times
    • argument is expected to be a cabal target, thus we allow: components (in all valid specifications), file-targets

Output explanations:

  • Mandatory: cabal-version denotes the output format version and follows the cabal-version scheme
  • target, list of json object containing the relevant information
    • Original target parameter is the key in the json object
    • unit-id of the target string
    • If unit-id is null, no such target

More usage examples

Flags are composable and results are reported as one json object.

> cabal status --output-format=json --compiler --target=./src/File.hs --target=./test/Main.hs --target=./non-existent/Main.hs | jq
{
  "version": "3.7.0.0",
  "compiler": {
    "flavour": "GHC",
    "compiler-id": "ghc-7.10.2",
    "path": "/usr/bin/ghc"
  },
  "targets": [
    { 
      "target": "./src/File.hs",
      "unit-id": "foo-inplace"
    },
    { 
      "target": "./test/Main.hs",
      "unit-id": "foo-testsuite-inplace"
    },
    { 
      "target": "./non-existent/Main.hs",
      "unit-id": null
    }
  ]
}

Only one test

> cabal status --output-format=json --target=tests | jq
{
  "version": "3.7.0.0",
  "targets": [
    { 
      "target": "tests",
      "unit-id": "foo-tests-inplace"
    }
  ]
}

Multiple executables, thus exes resolves to multiple targets

> cabal status --output-format=json --target=exes | jq
{
  "version": "3.7.0.0",
  "compiler": {
    "flavour": "GHC",
    "compiler-id": "ghc-7.10.2",
    "path": "/usr/bin/ghc"
  },
  "targets": [
    { 
      "target": "exes",
      "unit-id": "foo-exe1-inplace"
    },
    { 
      "target": "exes",
      "unit-id": "foo-exe2-inplace"
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment