Skip to content

Make v2- commands respect verbose config/project file setting - #7999

Draft
bacchanalia wants to merge 1 commit into
haskell:masterfrom
bacchanalia:5956
Draft

bacchanalia wants to merge 1 commit into
haskell:masterfrom
bacchanalia:5956

Conversation

@bacchanalia

Copy link
Copy Markdown
Collaborator

WIP for #5956

I'm not completely satisfied with this approach because it effectively makes every command read all config files twice. One during the call to newCmdWithVerbosity to set the verbosity properly, then again by the actual commands. It might be possible to pass the ProjectConfig to the actions along with the command line options and disable the second read, but it doesn't seem straightforwards.

An alternative would be to pick up the verbosity in each command after the individual command reads the config, but

  1. It would be harder to implement consistently across all commands and test
  2. Some commands (like list-bin) make use of the verbosity before they read the config, and would therefore be hard to update properly.

The generic implementation doesn't work for clean or sdist because they don't use NixStyleFlags, so they need their own versions of newCmdWithVerbosity, which I still need to implement.

@bacchanalia
bacchanalia marked this pull request as draft February 21, 2022 02:56
@bacchanalia bacchanalia changed the title Make most v2- commands respect verbose setting Make v2- commands respect verbose setting Feb 21, 2022
@bacchanalia

Copy link
Copy Markdown
Collaborator Author

I'm thinking about converting v2-clean and v2-sdist to use NixStyleFlags for constancy with the rest of the v2-commands as a separate PR, which would then simplify this PR. Thoughts?

@fendor

fendor commented Feb 25, 2022 •

Copy link
Copy Markdown
Collaborator

Until #5346 is resolved, I believe it worsens cli significantly...

Compare:

> cabal clean --help
Clean the package store and remove temporary files.

Usage: cabal new-clean [FLAGS]

Removes all temporary files created during the building process (.hi, .o,
preprocessed sources, etc.) and also empties out the local caches (by
default).


Flags for clean:
 -h, --help                     Show this help text
 -v, --verbose[=n]              Control verbosity (n is 0--3, default
                                verbosity level is 1)
 --builddir=DIR                 The directory where Cabal puts generated build
                                files (default dist)
 --project-file=FILE            Set the name of the cabal.project file to
                                search for in parent directories
 -s, --save-config              Save configuration, only remove build
                                artifacts

To:

`cabal clean --help`
> cabal clean --help
Clean the package store and remove temporary files.

Usage: cabal new-clean [FLAGS]

Removes all temporary files created during the building process (.hi, .o,
preprocessed sources, etc.) and also empties out the local caches (by
default).


Flags for clean:
 -h, --help                     Show this help text
 -v, --verbose[=n]              Control verbosity (n is 0--3, default
                                verbosity level is 1)
 --builddir=DIR                 The directory where Cabal puts generated build
                                files (default dist)
 -g, --ghc                      compile with GHC
 --ghcjs                        compile with GHCJS
 --uhc                          compile with UHC
 --haskell-suite                compile with a haskell-suite compiler
 --cabal-file=PATH              use this Cabal file
 -w, --with-compiler=PATH       give the path to a particular compiler
 --with-hc-pkg=PATH             give the path to the package tool
 --prefix=DIR                   bake this prefix in preparation of
                                installation
 --bindir=DIR                   installation directory for executables
 --libdir=DIR                   installation directory for libraries
 --libsubdir=DIR                subdirectory of libdir in which libs are
                                installed
 --dynlibdir=DIR                installation directory for dynamic libraries
 --libexecdir=DIR               installation directory for program executables
 --libexecsubdir=DIR            subdirectory of libexecdir in which private
                                executables are installed
 --datadir=DIR                  installation directory for read-only data
 --datasubdir=DIR               subdirectory of datadir in which data files
                                are installed
 --docdir=DIR                   installation directory for documentation
 --htmldir=DIR                  installation directory for HTML documentation
 --haddockdir=DIR               installation directory for haddock interfaces
 --sysconfdir=DIR               installation directory for configuration files
 --program-prefix=PREFIX        prefix to be applied to installed executables
 --program-suffix=SUFFIX        suffix to be applied to installed executables
 --enable-library-vanilla       Enable Vanilla libraries
 --disable-library-vanilla      Disable Vanilla libraries
 -p, --enable-library-profiling
                                Enable Library profiling
 --disable-library-profiling    Disable Library profiling
 --enable-shared                Enable Shared library
 --disable-shared               Disable Shared library
 --enable-static                Enable Static library
 --disable-static               Disable Static library
 --enable-executable-dynamic    Enable Executable dynamic linking
 --disable-executable-dynamic   Disable Executable dynamic linking
 --enable-executable-static     Enable Executable fully static linking
 --disable-executable-static    Disable Executable fully static linking
 --enable-profiling             Enable Executable and library profiling
 --disable-profiling            Disable Executable and library profiling
 --enable-executable-profiling  Enable Executable profiling (DEPRECATED)
 --disable-executable-profiling
                                Disable Executable profiling (DEPRECATED)
 --profiling-detail=level       Profiling detail level for executable and
                                library (default, none, exported-functions,
                                toplevel-functions, all-functions).
 --library-profiling-detail=level
                                Profiling detail level for libraries only.
 -O, --enable-optimization[=n]  Build with optimization (n is 0--2, default is
                                1)
 --disable-optimization         Build without optimization
 --enable-debug-info[=n]        Emit debug info (n is 0--3, default is 0)
 --disable-debug-info           Don't emit debug info
 --enable-build-info            Enable build information generation during
                                project building
 --disable-build-info           Disable build information generation during
                                project building
 --enable-library-for-ghci      Enable compile library for use with GHCi
 --disable-library-for-ghci     Disable compile library for use with GHCi
 --enable-split-sections        Enable compile library code such that unneeded
                                definitions can be dropped from the final
                                executable (GHC 7.8+)
 --disable-split-sections       Disable compile library code such that
                                unneeded definitions can be dropped from the
                                final executable (GHC 7.8+)
 --enable-split-objs            Enable split library into smaller objects to
                                reduce binary sizes (GHC 6.6+)
 --disable-split-objs           Disable split library into smaller objects to
                                reduce binary sizes (GHC 6.6+)
 --enable-executable-stripping  Enable strip executables upon installation to
                                reduce binary sizes
 --disable-executable-stripping
                                Disable strip executables upon installation to
                                reduce binary sizes
 --enable-library-stripping     Enable strip libraries upon installation to
                                reduce binary sizes
 --disable-library-stripping    Disable strip libraries upon installation to
                                reduce binary sizes
 --configure-option=OPT         Extra option for configure
 --user                         Enable doing a per-user installation
 --global                       Disable doing a per-user installation
 --package-db=DB                Append the given package database to the list
                                of package databases used (to satisfy
                                dependencies and register into). May be a
                                specific file, 'global' or 'user'. The initial
                                list is ['global'], ['global', 'user'], or
                                ['global', $sandbox], depending on context.
                                Use 'clear' to reset the list to empty. See
                                the user guide for details.
 -f, --flags=FLAGS              Force values for the given flags in Cabal
                                conditionals in the .cabal file. E.g.,
                                --flags="debug -usebytestrings" forces the
                                flag "debug" to true and "usebytestrings" to
                                false.
 --extra-include-dirs=PATH      A list of directories to search for header
                                files
 --enable-deterministic         Enable Try to be as deterministic as possible
                                (used by the test suite)
 --disable-deterministic        Disable Try to be as deterministic as possible
                                (used by the test suite)
 --ipid=IPID                    Installed package ID to compile this package
                                as
 --cid=CID                      Installed component ID to compile this
                                component as
 --extra-lib-dirs=PATH          A list of directories to search for external
                                libraries
 --extra-lib-dirs-static=PATH   A list of directories to search for external
                                libraries when linking fully static
                                executables
 --extra-framework-dirs=PATH    A list of directories to search for external
                                frameworks (OS X only)
 --extra-prog-path=PATH         A list of directories to search for required
                                programs (in addition to the normal search
                                locations)
 --instantiate-with=NAME=MOD    A mapping of signature names to concrete
                                module instantiations.
 --enable-tests                 Enable dependency checking and compilation for
                                test suites listed in the package description
                                file.
 --disable-tests                Disable dependency checking and compilation
                                for test suites listed in the package
                                description file.
 --enable-coverage              Enable build package with Haskell Program
                                Coverage. (GHC only)
 --disable-coverage             Disable build package with Haskell Program
                                Coverage. (GHC only)
 --enable-library-coverage      Enable build package with Haskell Program
                                Coverage. (GHC only) (DEPRECATED)
 --disable-library-coverage     Disable build package with Haskell Program
                                Coverage. (GHC only) (DEPRECATED)
 --enable-benchmarks            Enable dependency checking and compilation for
                                benchmarks listed in the package description
                                file.
 --disable-benchmarks           Disable dependency checking and compilation
                                for benchmarks listed in the package
                                description file.
 --enable-relocatable           Enable building a package that is relocatable.
                                (GHC only)
 --disable-relocatable          Disable building a package that is
                                relocatable. (GHC only)
 --disable-response-files       enable workaround for old versions of programs
                                like "ar" that do not support @file arguments
 --allow-depending-on-private-libs
                                Allow depending on private libraries. If set,
                                the library visibility check MUST be done
                                externally.
 --with-PROG=PATH               give the path to PROG
 --PROG-option=OPT              give an extra option to PROG (no need to quote
                                options containing spaces)
 --PROG-options=OPTS            give extra options to PROG
 --cabal-lib-version=VERSION    Select which version of the Cabal lib to use
                                to build packages (useful for testing).
 --enable-append                Enable appending the new config to the old
                                config file
 --disable-append               Disable appending the new config to the old
                                config file
 --enable-backup                Enable the backup of the config file before
                                any alterations
 --disable-backup               Disable the backup of the config file before
                                any alterations
 -c, --constraint=CONSTRAINT    Specify constraints on a package (version,
                                installed/source, flags)
 --preference=CONSTRAINT        Specify preferences (soft constraints) on the
                                version of a package
 --solver=SOLVER                Select dependency solver to use (default:
                                modular). Choices: modular.
 --allow-older[=DEPS]           Ignore lower bounds in all dependencies or
                                DEPS
 --allow-newer[=DEPS]           Ignore upper bounds in all dependencies or
                                DEPS
 --write-ghc-environment-files=always|never|ghc8.4.4+
                                Whether to create a .ghc.environment file
                                after a successful build (v2-build only)
 --enable-documentation         Enable building of documentation
 --disable-documentation        Disable building of documentation
 --doc-index-file=TEMPLATE      A central index of haddock API documentation
                                (template cannot use $pkgid)
 --dry-run                      Do not install anything, only print what would
                                be installed.
 --only-download                Do not build anything, only fetch the
                                packages.
 --max-backjumps=NUM            Maximum number of backjumps allowed while
                                solving (default: 4000). Use a negative number
                                to enable unlimited backtracking. Use 0 to
                                disable backtracking completely.
 --reorder-goals                Try to reorder goals according to certain
                                heuristics. Slows things down on average, but
                                may make backtracking faster for some
                                packages.
 --count-conflicts              Try to speed up solving by preferring goals
                                that are involved in a lot of conflicts
                                (default).
 --fine-grained-conflicts       Skip a version of a package if it does not
                                resolve the conflicts encountered in the last
                                version, as a solver optimization (default).
 --minimize-conflict-set        When there is no solution, try to improve the
                                error message by finding a minimal conflict
                                set (default: false). May increase run time
                                significantly.
 --independent-goals            Treat several goals on the command line as
                                independent. If several goals depend on the
                                same package, different versions can be
                                chosen.
 --shadow-installed-packages    If multiple package instances of the same
                                version are installed, treat all but one as
                                shadowed.
 --strong-flags                 Do not defer flag choices (this used to be the
                                default in cabal-install <= 1.20).
 --allow-boot-library-installs  Allow cabal to install base, ghc-prim,
                                integer-simple, integer-gmp, and
                                template-haskell.
 --reject-unconstrained-dependencies=none|all
                                Require these packages to have constraints on
                                them if they are to be selected (default:
                                none).
 --reinstall                    Install even if it means installing the same
                                version again.
 --avoid-reinstalls             Do not select versions that would
                                destructively overwrite installed packages.
 --force-reinstalls             Reinstall packages even if they will most
                                likely break other installed packages.
 --upgrade-dependencies         Pick the latest version for all dependencies,
                                rather than trying to pick an installed
                                version.
 --only-dependencies            Install only the dependencies necessary to
                                build the given packages
 --dependencies-only            A synonym for --only-dependencies
 --index-state=STATE            Use source package index state as it existed
                                at a previous time. Accepts unix-timestamps
                                (e.g. '@1474732068'), ISO8601 UTC timestamps
                                (e.g. '2016-09-24T17:47:48Z'), or 'HEAD'
                                (default: 'HEAD').
 --root-cmd=COMMAND             (No longer supported, do not use.)
 --build-summary=TEMPLATE       Save build summaries to file (name template
                                can use $pkgid, $compiler, $os, $arch)
 --build-log=TEMPLATE           Log all builds to file (name template can use
                                $pkgid, $compiler, $os, $arch)
 --remote-build-reporting=LEVEL
                                Generate build reports to send to a remote
                                server (none, anonymous or detailed).
 --report-planning-failure      Generate build reports when the dependency
                                solver fails. This is used by the Hackage
                                build bot.
 --enable-per-component         Enable Per-component builds when possible
 --disable-per-component        Disable Per-component builds when possible
 --run-tests                    Run package test suites during installation.
 -j, --jobs[=NUM]               Run NUM jobs simultaneously (or '$ncpus' if no
                                NUM is given).
 --keep-going                   After a build failure, continue to build other
                                unaffected packages.
 --offline                      Don't download packages from the Internet.
 --haddock-hoogle               Generate a hoogle database
 --haddock-html                 Generate HTML documentation (the default)
 --haddock-html-location=URL    Location of HTML documentation for
                                pre-requisite packages
 --haddock-for-hackage          Collection of flags to generate documentation
                                suitable for upload to hackage
 --haddock-executables          Run haddock for Executables targets
 --haddock-tests                Run haddock for Test Suite targets
 --haddock-benchmarks           Run haddock for Benchmark targets
 --haddock-all                  Run haddock for all targets
 --haddock-internal             Run haddock for internal modules and include
                                all symbols
 --haddock-css=PATH             Use PATH as the haddock stylesheet
 --haddock-hyperlink-source     Hyperlink the documentation to the source code
 --haddock-quickjump            Generate an index for interactive
                                documentation navigation
 --haddock-hscolour-css=PATH    Use PATH as the HsColour stylesheet
 --haddock-contents-location=URL
                                Bake URL in as the location for the contents
                                page
 --test-log=TEMPLATE            Log all test suite results to file (name
                                template can use $pkgid, $compiler, $os,
                                $arch, $test-suite, $result)
 --test-machine-log=TEMPLATE    Produce a machine-readable log file (name
                                template can use $pkgid, $compiler, $os,
                                $arch, $result)
 --test-show-details=FILTER     'always': always show results of individual
                                test cases. 'never': never show results of
                                individual test cases. 'failures': show
                                results of failing test cases. 'streaming':
                                show results of test cases in real
                                time.'direct': send results of test cases in
                                real time; no log file.
 --test-keep-tix-files          keep .tix files for HPC between test runs
 --test-wrapper=FILE            Run test through a wrapper.
 --test-fail-when-no-test-suites
                                Exit with failure when no test suites are
                                found.
 --test-options=TEMPLATES       give extra options to test executables (name
                                templates can use $pkgid, $compiler, $os,
                                $arch, $test-suite)
 --test-option=TEMPLATE         give extra option to test executables (no need
                                to quote options containing spaces, name
                                template can use $pkgid, $compiler, $os,
                                $arch, $test-suite)
 --benchmark-options=TEMPLATES  give extra options to benchmark executables
                                (name templates can use $pkgid, $compiler,
                                $os, $arch, $benchmark)
 --benchmark-option=TEMPLATE    give extra option to benchmark executables (no
                                need to quote options containing spaces, name
                                template can use $pkgid, $compiler, $os,
                                $arch, $benchmark)
 --project-file=FILE            Set the name of the cabal.project file to
                                search for in parent directories
 -v, --verbose[=n]              Control verbosity (n is 0--3, default
                                verbosity level is 1)
 --builddir=DIR                 The directory where Cabal puts generated build
                                files (default dist)
 --project-file=FILE            Set the name of the cabal.project file to
                                search for in parent directories
 -s, --save-config              Save configuration, only remove build
                                artifacts

Especially since 95% of these options don't have any effect.

@Mikolaj

Mikolaj commented Feb 25, 2022

Copy link
Copy Markdown
Member

There is one more recent related ticket (can't remember or maybe I'm imagining) about splitting help into essential options and marginal options. Even if some options are fully or partially useless (with the current codebase; perhaps some may become useful at some point), there's not much harm if they are only listed with --extended-help.

I think even listing the major options first and the minor last would be a great improvement and would make this change acceptable.

@bacchanalia

Copy link
Copy Markdown
Collaborator Author

The change I had in mind was to keep the option parsers instead of using nixStyleOptions, just use the NixStyleFlags type to hold the options, that way the common options (ProjectFlags, verbosity, distDir) could be accessed in a uniform way. The downside would be a less descriptive type in regards to what options are actually used, but there shouldn't be a user facing change.

@fendor

fendor commented Feb 25, 2022 •

Copy link
Copy Markdown
Collaborator

The change I had in mind was to keep the option parsers instead of using nixStyleOptions, just use the NixStyleFlags type to hold the options, that way the common options (ProjectFlags, verbosity, distDir) could be accessed in a uniform way.

sounds like a good solution to me! If done correctly, won't have any user facing changes

bacchanalia added a commit to bacchanalia/cabal that referenced this pull request Feb 26, 2022
- Consistently use `NixStyleFlags` for all v2- commands.
- This will simplify future changes such as haskell#7999.
- Mostly keep option parsers unchanged with the following exceptions:
  - Reorder options to by consistent with nixStyleOptions
    ConfigFlags > ProjectFlags > ExtraFlags
  - Add --ignore-project to clean, which currently does nothing,
    but will be useful for future clean improvements.
bacchanalia added a commit to bacchanalia/cabal that referenced this pull request Feb 26, 2022
- Consistently use `NixStyleFlags` for all v2- commands.
- This will simplify future changes such as haskell#7999.
- Mostly keep option parsers unchanged with the following exceptions:
  - Reorder options to by consistent with nixStyleOptions
    ConfigFlags > ProjectFlags > ExtraFlags
  - Add --ignore-project to clean, which currently does nothing,
    but will be useful for future clean improvements.
@phadej

phadej commented Feb 26, 2022

Copy link
Copy Markdown
Collaborator

This PR seems to change something. If I have an invalid field in cabal.project, e.g. foo: Field, cabal-install-3.6 and master report about it:

% cabal build all --dry
Warning: /code/shared-haskell/servant/cabal.project: Unrecognized field 'foo'
on line 1

cabal build from this branch doesn't report the warning.

@phadej

phadej commented Feb 26, 2022

Copy link
Copy Markdown
Collaborator

Reading project file twice is bad. That doesn't make any sense. It's easy but wrong solution. Please raise a bar for quality.

@fgaz

fgaz commented Feb 26, 2022

Copy link
Copy Markdown
Member

iirc there is a proposal to pre-read the project file in a limited and faster way to make it possible to specify builddir in the file. That approach could be reused for this if it turns out reading the file only one time is not doable

@phadej

phadej commented Feb 26, 2022

Copy link
Copy Markdown
Collaborator

@fgaz even when reinterpreting the file multiple times, it's worth parsing it (to e.g. Field) only once.

@bacchanalia

Copy link
Copy Markdown
Collaborator Author

I agree that rereading the project file is bad. I opened this draft PR because I'm curious that people think the best way forward from here is. As I see it the options are:

  • Keep this more less as is (solves the problem, but feels klugey, @phadej is 👎 on this)
  • Keep going with the approach of reading all the project files early, but refactor to remove the second reading. This has the advantages of ensuring constancy across all commands and could be useful for not just verbosity, but also builddir as @fgaz mentioned, and possibly other things. The downside is that it's a significantly larger change.
  • Spread the logic logic out into the commands individually. I don't really like like this option because it adds a lot of similar code, while also requiring some restructuring of command code to to work properly.
  • Drop this ticket. It doesn't seem to be a feature people care about judging from how long it took to get a ticket on it. Maybe it's better simply to not.
  • A different approach?

@gbaz

gbaz commented Feb 26, 2022

Copy link
Copy Markdown
Collaborator

I imagine in most cases, doing it for each command individually is not so bad. I suggest that withProjectOrGlobalConfig be modified so its continuation also takes an explicit verbosity. Then just follow the types and anything which uses it should make use of that verbosity (which entails e.g. withContextAndSelectors also taking a continuation which takes a verbosity).

The general logic is that anything that calls this is reading the global config, and when it does so, it should explicitly start potentially using the verbosity from that global config if there is not an explicit command line override. It seems like a straightforward place to extend and likely following the types will highlight all the necessary places to be changed?

@bacchanalia

Copy link
Copy Markdown
Collaborator Author

Currently just as many commands don't use withProjectOrGlobalConfigas all as use it.
Use withProjectOrGlobalConfig: build, install, list-bin, repl, run, sdist
Don't: bench, clean, configure, exec, freeze, haddock
And of the ones that do, both list-bin and install make use of verbosity before they read the global config.

@mergify mergify Bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Sep 1, 2022
@ulysses4ever ulysses4ever removed the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Sep 3, 2022
@ulysses4ever ulysses4ever changed the title Make v2- commands respect verbose setting Make v2- commands respect verbose config/project file setting Apr 10, 2025
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.

7 participants