Skip to content
Snippets Groups Projects
Commit 4502a6d9 authored by Chandan Singh's avatar Chandan Singh
Browse files

WIP: Introduce source command group

parent 2a0676c3
No related branches found
No related tags found
Loading
Pipeline #39369732 failed
......@@ -336,96 +336,6 @@ def build(app, elements, all_, track_, track_save, track_all, track_except, trac
build_all=all_)
##################################################################
# Fetch Command #
##################################################################
@cli.command(short_help="Fetch sources in a pipeline")
@click.option('--except', 'except_', multiple=True,
type=click.Path(readable=False),
help="Except certain dependencies from fetching")
@click.option('--deps', '-d', default='plan',
type=click.Choice(['none', 'plan', 'all']),
help='The dependencies to fetch (default: plan)')
@click.option('--track', 'track_', default=False, is_flag=True,
help="Track new source references before fetching")
@click.option('--track-cross-junctions', '-J', default=False, is_flag=True,
help="Allow tracking to cross junction boundaries")
@click.argument('elements', nargs=-1,
type=click.Path(readable=False))
@click.pass_obj
def fetch(app, elements, deps, track_, except_, track_cross_junctions):
"""Fetch sources required to build the pipeline
By default this will only try to fetch sources which are
required for the build plan of the specified target element,
omitting sources for any elements which are already built
and available in the artifact cache.
Specify `--deps` to control which sources to fetch:
\b
none: No dependencies, just the element itself
plan: Only dependencies required for the build plan
all: All dependencies
"""
from .._pipeline import PipelineSelection
if track_cross_junctions and not track_:
click.echo("ERROR: The --track-cross-junctions option can only be used with --track", err=True)
sys.exit(-1)
if track_ and deps == PipelineSelection.PLAN:
click.echo("WARNING: --track specified for tracking of a build plan\n\n"
"Since tracking modifies the build plan, all elements will be tracked.", err=True)
deps = PipelineSelection.ALL
with app.initialized(session_name="Fetch"):
app.stream.fetch(elements,
selection=deps,
except_targets=except_,
track_targets=track_,
track_cross_junctions=track_cross_junctions)
##################################################################
# Track Command #
##################################################################
@cli.command(short_help="Track new source references")
@click.option('--except', 'except_', multiple=True,
type=click.Path(readable=False),
help="Except certain dependencies from tracking")
@click.option('--deps', '-d', default='none',
type=click.Choice(['none', 'all']),
help='The dependencies to track (default: none)')
@click.option('--cross-junctions', '-J', default=False, is_flag=True,
help="Allow crossing junction boundaries")
@click.argument('elements', nargs=-1,
type=click.Path(readable=False))
@click.pass_obj
def track(app, elements, deps, except_, cross_junctions):
"""Consults the specified tracking branches for new versions available
to build and updates the project with any newly available references.
By default this will track just the specified element, but you can also
update a whole tree of dependencies in one go.
Specify `--deps` to control which sources to track:
\b
none: No dependencies, just the specified elements
all: All dependencies of all specified elements
"""
with app.initialized(session_name="Track"):
# Substitute 'none' for 'redirect' so that element redirections
# will be done
if deps == 'none':
deps = 'redirect'
app.stream.track(elements,
selection=deps,
except_targets=except_,
cross_junctions=cross_junctions)
##################################################################
# Pull Command #
##################################################################
......@@ -680,10 +590,108 @@ def checkout(app, element, location, force, deps, integrate, hardlinks, tar):
tar=tar)
##################################################################
# Source Command #
##################################################################
@cli.group(short_help="Manipulate sources for an element")
def source():
"""Manipulate sources for an element"""
pass
##################################################################
# Source Fetch Command #
##################################################################
@source.command(name="fetch", short_help="Fetch sources in a pipeline")
@click.option('--except', 'except_', multiple=True,
type=click.Path(readable=False),
help="Except certain dependencies from fetching")
@click.option('--deps', '-d', default='plan',
type=click.Choice(['none', 'plan', 'all']),
help='The dependencies to fetch (default: plan)')
@click.option('--track', 'track_', default=False, is_flag=True,
help="Track new source references before fetching")
@click.option('--track-cross-junctions', '-J', default=False, is_flag=True,
help="Allow tracking to cross junction boundaries")
@click.argument('elements', nargs=-1,
type=click.Path(readable=False))
@click.pass_obj
def source_fetch(app, elements, deps, track_, except_, track_cross_junctions):
"""Fetch sources required to build the pipeline
By default this will only try to fetch sources which are
required for the build plan of the specified target element,
omitting sources for any elements which are already built
and available in the artifact cache.
Specify `--deps` to control which sources to fetch:
\b
none: No dependencies, just the element itself
plan: Only dependencies required for the build plan
all: All dependencies
"""
from .._pipeline import PipelineSelection
if track_cross_junctions and not track_:
click.echo("ERROR: The --track-cross-junctions option can only be used with --track", err=True)
sys.exit(-1)
if track_ and deps == PipelineSelection.PLAN:
click.echo("WARNING: --track specified for tracking of a build plan\n\n"
"Since tracking modifies the build plan, all elements will be tracked.", err=True)
deps = PipelineSelection.ALL
with app.initialized(session_name="Fetch"):
app.stream.fetch(elements,
selection=deps,
except_targets=except_,
track_targets=track_,
track_cross_junctions=track_cross_junctions)
##################################################################
# Source Track Command #
##################################################################
@source.command(name="track", short_help="Track new source references")
@click.option('--except', 'except_', multiple=True,
type=click.Path(readable=False),
help="Except certain dependencies from tracking")
@click.option('--deps', '-d', default='none',
type=click.Choice(['none', 'all']),
help='The dependencies to track (default: none)')
@click.option('--cross-junctions', '-J', default=False, is_flag=True,
help="Allow crossing junction boundaries")
@click.argument('elements', nargs=-1,
type=click.Path(readable=False))
@click.pass_obj
def source_track(app, elements, deps, except_, cross_junctions):
"""Consults the specified tracking branches for new versions available
to build and updates the project with any newly available references.
By default this will track just the specified element, but you can also
update a whole tree of dependencies in one go.
Specify `--deps` to control which sources to track:
\b
none: No dependencies, just the specified elements
all: All dependencies of all specified elements
"""
with app.initialized(session_name="Track"):
# Substitute 'none' for 'redirect' so that element redirections
# will be done
if deps == 'none':
deps = 'redirect'
app.stream.track(elements,
selection=deps,
except_targets=except_,
cross_junctions=cross_junctions)
##################################################################
# Source Checkout Command #
##################################################################
@cli.command(name='source-checkout', short_help='Checkout sources for an element')
@source.command(name='checkout', short_help='Checkout sources for an element')
@click.option('--except', 'except_', multiple=True,
type=click.Path(readable=False),
help="Except certain dependencies")
......@@ -866,3 +874,54 @@ def source_bundle(app, element, force, directory,
force=force,
compression=compression,
except_targets=except_)
##################################################################
# DEPRECATED Commands #
##################################################################
# XXX: The following commands have been deprecated, but they are kept
# here along with all the options so that we can provide nice error
# messages when they are called.
# Also, note that these commands are hidden from the top-level help.
##################################################################
# Fetch Command #
##################################################################
@cli.command(short_help="Fetch sources in a pipeline", hidden=True)
@click.option('--except', 'except_', multiple=True,
type=click.Path(readable=False),
help="Except certain dependencies from fetching")
@click.option('--deps', '-d', default='plan',
type=click.Choice(['none', 'plan', 'all']),
help='The dependencies to fetch (default: plan)')
@click.option('--track', 'track_', default=False, is_flag=True,
help="Track new source references before fetching")
@click.option('--track-cross-junctions', '-J', default=False, is_flag=True,
help="Allow tracking to cross junction boundaries")
@click.argument('elements', nargs=-1,
type=click.Path(readable=False))
@click.pass_obj
def fetch(app, elements, deps, track_, except_, track_cross_junctions):
click.echo("This command has been deprecated. Use `bst source fetch` instead.", err=True)
sys.exit(1)
##################################################################
# Track Command #
##################################################################
@cli.command(short_help="Track new source references", hidden=True)
@click.option('--except', 'except_', multiple=True,
type=click.Path(readable=False),
help="Except certain dependencies from tracking")
@click.option('--deps', '-d', default='none',
type=click.Choice(['none', 'all']),
help='The dependencies to track (default: none)')
@click.option('--cross-junctions', '-J', default=False, is_flag=True,
help="Allow crossing junction boundaries")
@click.argument('elements', nargs=-1,
type=click.Path(readable=False))
@click.pass_obj
def track(app, elements, deps, except_, cross_junctions):
click.echo("This command has been deprecated. Use `bst source track` instead.", err=True)
sys.exit(1)
......@@ -346,7 +346,7 @@ setup(name='BuildStream',
# See issues #571 and #790.
'ruamel.yaml >= 0.15.41, < 0.15.52',
'pluginbase',
'Click',
'Click >= 7.0',
'jinja2 >= 2.10',
'protobuf >= 3.5',
'grpcio >= 1.10',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment