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

Add shorthand syntax in cli to specify host and build in 1 argument #14727

Merged
merged 18 commits into from
Oct 18, 2023

Conversation

AbrilRBS
Copy link
Member

@AbrilRBS AbrilRBS commented Sep 13, 2023

Changelog: Feature: Add shorthand syntax in cli to specify host and build in 1 argument
Docs: conan-io/docs#3439

There's some split preferences between possible names. This pr implements (for -pr, -s, -o, -c) -s:a (--settings:all), but other possible names we discussed are:

  • -s:hb (settings:hostbuild): Makes it more clear that this affects the host and build profiles
  • -s:h,b (settings:host,build): Separates both names with a comma (Which is not a special char in any terminal as far as I can see), maybe easier to read?

I'm open to change it to whatever everyone feels like a better one

The new profile args read like this:

$ conan build -h
usage: conan build [-h] [-v [V]] [--name NAME] [--version VERSION] [--user USER]
                   [--channel CHANNEL] [-g GENERATOR] [-of OUTPUT_FOLDER] [-d DEPLOYER]
                   [--deployer-folder DEPLOYER_FOLDER] [--build-require] [-b BUILD]
                   [-r REMOTE | -nr] [-u] [-pr PROFILE] [-pr:b PROFILE_BUILD]
                   [-pr:h PROFILE_HOST] [-pr:a PROFILE_ALL] [-o OPTIONS] [-o:b OPTIONS_BUILD]
                   [-o:h OPTIONS_HOST] [-o:a OPTIONS_ALL] [-s SETTINGS] [-s:b SETTINGS_BUILD]
                   [-s:h SETTINGS_HOST] [-s:a SETTINGS_ALL] [-c CONF] [-c:b CONF_BUILD]
                   [-c:h CONF_HOST] [-c:a CONF_ALL] [-l LOCKFILE] [--lockfile-partial]
                   [--lockfile-out LOCKFILE_OUT] [--lockfile-packages] [--lockfile-clean]
                   [--lockfile-overrides LOCKFILE_OVERRIDES]
                   [path]

Install dependencies and call the build() method.

positional arguments:
  path                  Path to a python-based recipe file or a folder containing a
                        conanfile.py recipe. conanfile.txt cannot be used with conan build.

options:
  -h, --help            show this help message and exit
  -v [V]                Level of detail of the output. Valid options from less verbose to more
                        verbose: -vquiet, -verror, -vwarning, -vnotice, -vstatus, -v or
                        -vverbose, -vv or -vdebug, -vvv or -vtrace
  --name NAME           Provide a package name if not specified in conanfile
  --version VERSION     Provide a package version if not specified in conanfile
  --user USER           Provide a user if not specified in conanfile
  --channel CHANNEL     Provide a channel if not specified in conanfile
  -g GENERATOR, --generator GENERATOR
                        Generators to use
  -of OUTPUT_FOLDER, --output-folder OUTPUT_FOLDER
                        The root output folder for generated and build files
  -d DEPLOYER, --deployer DEPLOYER
                        Deploy using the provided deployer to the output folder
  --deployer-folder DEPLOYER_FOLDER
                        Deployer output folder, base build folder by default if not set
  --build-require       Whether the provided path is a build-require
  -b BUILD, --build BUILD
                        Optional, specify which packages to build from source. Combining
                        multiple '--build' options on one command line is allowed. Possible
                        values: --build="*" Force build from source for all packages.
                        --build=never Disallow build for all packages, use binary packages or
                        fail if a binary package is not found, it cannot be combined with other
                        '--build' options. --build=missing Build packages from source whose
                        binary package is not found. --build=cascade Build packages from source
                        that have at least one dependency being built from source.
                        --build=[pattern] Build packages from source whose package reference
                        matches the pattern. The pattern uses 'fnmatch' style wildcards.
                        --build=~[pattern] Excluded packages, which will not be built from the
                        source, whose package reference matches the pattern. The pattern uses
                        'fnmatch' style wildcards. --build=missing:[pattern] Build from source
                        if a compatible binary does not exist, only for packages matching
                        pattern.
  -r REMOTE, --remote REMOTE
                        Look in the specified remote or remotes server
  -nr, --no-remote      Do not use remote, resolve exclusively in the cache
  -u, --update          Will check the remote and in case a newer version and/or revision of
                        the dependencies exists there, it will install those in the local
                        cache. When using version ranges, it will install the latest version
                        that satisfies the range. Also, if using revisions, it will update to
                        the latest revision for the resolved version range.
  -pr PROFILE, --profile PROFILE
                        Apply the specified profile. By default, or if specifying -pr:h
                        (--profile:host), it applies to the host context. Use -pr:b
                        (--profile:build) to specify the build context, or -pr:a
                        (--profile:all) to specify both contexts at once
  -pr:b PROFILE_BUILD, --pr:build PROFILE_BUILD
  -pr:h PROFILE_HOST, --pr:host PROFILE_HOST
  -pr:a PROFILE_ALL, --profile:all PROFILE_ALL
  -o OPTIONS, --options OPTIONS
                        Apply the specified profile. By default, or if specifying -o:h
                        (--options:host), it applies to the host context. Use -o:b
                        (--options:build) to specify the build context, or -o:a (--options:all)
                        to specify both contexts at once. Example: -o pkg:with_qt=true
  -o:b OPTIONS_BUILD, --o:build OPTIONS_BUILD
  -o:h OPTIONS_HOST, --o:host OPTIONS_HOST
  -o:a OPTIONS_ALL, --options:all OPTIONS_ALL
  -s SETTINGS, --settings SETTINGS
                        Apply the specified profile. By default, or if specifying -s:h
                        (--settings:host), it applies to the host context. Use -s:b
                        (--settings:build) to specify the build context, or -s:a
                        (--settings:all) to specify both contexts at once. Example: -s
                        compiler=gcc
  -s:b SETTINGS_BUILD, --s:build SETTINGS_BUILD
  -s:h SETTINGS_HOST, --s:host SETTINGS_HOST
  -s:a SETTINGS_ALL, --settings:all SETTINGS_ALL
  -c CONF, --conf CONF  Apply the specified profile. By default, or if specifying -c:h
                        (--conf:host), it applies to the host context. Use -c:b (--conf:build)
                        to specify the build context, or -c:a (--conf:all) to specify both
                        contexts at once. Example: -c
                        tools.cmake.cmaketoolchain:generator=Xcode
  -c:b CONF_BUILD, --c:build CONF_BUILD
  -c:h CONF_HOST, --c:host CONF_HOST
  -c:a CONF_ALL, --conf:all CONF_ALL
  -l LOCKFILE, --lockfile LOCKFILE
                        Path to a lockfile. Use --lockfile="" to avoid automatic use of
                        existing 'conan.lock' file
  --lockfile-partial    Do not raise an error if some dependency is not found in lockfile
  --lockfile-out LOCKFILE_OUT
                        Filename of the updated lockfile
  --lockfile-packages   Lock package-id and package-revision information
  --lockfile-clean      Remove unused entries from the lockfile
  --lockfile-overrides LOCKFILE_OVERRIDES
                        Overwrite lockfile overrides

Closes #14696

@AbrilRBS AbrilRBS added this to the 2.0.12 milestone Sep 13, 2023
@AbrilRBS AbrilRBS requested a review from memsharded September 13, 2023 13:24
@AbrilRBS AbrilRBS marked this pull request as draft September 13, 2023 22:36
@AbrilRBS AbrilRBS closed this Sep 14, 2023
@AbrilRBS AbrilRBS reopened this Sep 14, 2023
@AbrilRBS AbrilRBS marked this pull request as ready for review September 15, 2023 13:43
@AbrilRBS AbrilRBS marked this pull request as draft September 15, 2023 14:42
@AbrilRBS
Copy link
Member Author

Can't find a way to still show the -pr:b etc variations in the usage but not in the help

@AbrilRBS AbrilRBS marked this pull request as ready for review September 15, 2023 15:30
parser.add_argument("-c{}".format(short_suffix),
"--conf{}".format(long_suffix),
class ContextAllAction(argparse.Action):
def __init__(self,
Copy link
Member

Choose a reason for hiding this comment

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

Probably args/kwargs can be used to simplify code, both here and in super() code

Copy link
Member Author

Choose a reason for hiding this comment

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

I wish the append Action was public in argparse, so this could be

    class ContextAllAction(argparse._AppendAction):
        def __call__(self, action_parser, namespace, values, option_string=None):
            for context in contexts:
                items = getattr(namespace, self.dest + "_" + context, None)
                items = items[:] if items else []
                items.append(values)
                setattr(namespace, self.dest + "_" + context, items)

but alas

conan/cli/args.py Outdated Show resolved Hide resolved
@czoido czoido modified the milestones: 2.0.12, 2.0.13 Sep 26, 2023
@czoido czoido modified the milestones: 2.0.13, 2.0.14 Sep 28, 2023
@AbrilRBS AbrilRBS requested a review from memsharded October 18, 2023 11:24
@czoido czoido merged commit 91c5860 into conan-io:release/2.0 Oct 18, 2023
juansblanco added a commit that referenced this pull request Oct 19, 2023
Changelog: Fix: Fix help command for profile args
Docs: TODO: To be changed with #14727

Fixed minor bug found while looking around profile show command code
with @RubenRBS.
@AbrilRBS AbrilRBS deleted the rr/shorthand-cli-host&build branch October 26, 2023 12:07
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.

[feature] Same host and build profile option?
4 participants