Jonathan Maw pushed to branch jonathan/workspace-fragment-guess-element at BuildStream / buildstream
Commits:
-
5ab99f79
by Jonathan Maw at 2018-11-15T16:37:56Z
3 changed files:
Changes:
... | ... | @@ -48,7 +48,7 @@ from .plugin import _plugin_lookup |
48 | 48 |
#
|
49 | 49 |
class Context():
|
50 | 50 |
|
51 |
- def __init__(self):
|
|
51 |
+ def __init__(self, workspace_locals=None):
|
|
52 | 52 |
|
53 | 53 |
# Filename indicating which configuration file was used, or None for the defaults
|
54 | 54 |
self.config_origin = None
|
... | ... | @@ -118,7 +118,7 @@ class Context(): |
118 | 118 |
self._projects = []
|
119 | 119 |
self._project_overrides = {}
|
120 | 120 |
self._workspaces = None
|
121 |
- self._workspace_locals = WorkspaceLocals()
|
|
121 |
+ self._workspace_locals = workspace_locals or WorkspaceLocals()
|
|
122 | 122 |
self._log_handle = None
|
123 | 123 |
self._log_filename = None
|
124 | 124 |
self.config_cache_quota = 'infinity'
|
... | ... | @@ -39,6 +39,7 @@ from .._stream import Stream |
39 | 39 |
from .._versions import BST_FORMAT_VERSION
|
40 | 40 |
from .. import _yaml
|
41 | 41 |
from .._scheduler import ElementJob
|
42 |
+from .._workspaces import WorkspaceLocals
|
|
42 | 43 |
|
43 | 44 |
# Import frontend assets
|
44 | 45 |
from . import Profile, LogLine, Status
|
... | ... | @@ -79,6 +80,7 @@ class App(): |
79 | 80 |
self._fail_messages = {} # Failure messages by unique plugin id
|
80 | 81 |
self._interactive_failures = None # Whether to handle failures interactively
|
81 | 82 |
self._started = False # Whether a session has started
|
83 |
+ self._workspace_locals = WorkspaceLocals() # A collection of workspace local data
|
|
82 | 84 |
|
83 | 85 |
# UI Colors Profiles
|
84 | 86 |
self._content_profile = Profile(fg='yellow')
|
... | ... | @@ -164,7 +166,7 @@ class App(): |
164 | 166 |
# Load the Context
|
165 | 167 |
#
|
166 | 168 |
try:
|
167 |
- self.context = Context()
|
|
169 |
+ self.context = Context(self._workspace_locals)
|
|
168 | 170 |
self.context.load(config)
|
169 | 171 |
except BstError as e:
|
170 | 172 |
self._error_exit(e, "Error loading user configuration")
|
... | ... | @@ -400,6 +402,21 @@ class App(): |
400 | 402 |
if self.stream:
|
401 | 403 |
self.stream.cleanup()
|
402 | 404 |
|
405 |
+ # guess_element()
|
|
406 |
+ #
|
|
407 |
+ # Attempts to interpret which element the user intended to run commands on
|
|
408 |
+ #
|
|
409 |
+ # Returns:
|
|
410 |
+ # (str) The name of the element, or an empty string
|
|
411 |
+ def guess_element(self):
|
|
412 |
+ directory = self._main_options['directory']
|
|
413 |
+ local = self._workspace_locals.get(directory)
|
|
414 |
+ if local.has_projects():
|
|
415 |
+ return local.get_default_element()
|
|
416 |
+ else:
|
|
417 |
+ return ""
|
|
418 |
+ |
|
419 |
+ |
|
403 | 420 |
############################################################
|
404 | 421 |
# Abstract Class Methods #
|
405 | 422 |
############################################################
|
... | ... | @@ -310,6 +310,12 @@ def build(app, elements, all_, track_, track_save, track_all, track_except, trac |
310 | 310 |
if track_save:
|
311 | 311 |
click.echo("WARNING: --track-save is deprecated, saving is now unconditional", err=True)
|
312 | 312 |
|
313 |
+ if not all_ and not elements:
|
|
314 |
+ # Attempt to divine the element from the workspace you're in
|
|
315 |
+ guessed_target = app.guess_element()
|
|
316 |
+ if guessed_target:
|
|
317 |
+ elements = (guessed_target,)
|
|
318 |
+ |
|
313 | 319 |
if track_all:
|
314 | 320 |
track_ = elements
|
315 | 321 |
|
... | ... | @@ -364,6 +370,12 @@ def fetch(app, elements, deps, track_, except_, track_cross_junctions): |
364 | 370 |
"Since tracking modifies the build plan, all elements will be tracked.", err=True)
|
365 | 371 |
deps = PipelineSelection.ALL
|
366 | 372 |
|
373 |
+ if not elements:
|
|
374 |
+ # Attempt to divine the element from the workspace you're in
|
|
375 |
+ guessed_target = app.guess_element()
|
|
376 |
+ if guessed_target:
|
|
377 |
+ elements = (guessed_target,)
|
|
378 |
+ |
|
367 | 379 |
with app.initialized(session_name="Fetch"):
|
368 | 380 |
app.stream.fetch(elements,
|
369 | 381 |
selection=deps,
|
... | ... | @@ -400,6 +412,12 @@ def track(app, elements, deps, except_, cross_junctions): |
400 | 412 |
none: No dependencies, just the specified elements
|
401 | 413 |
all: All dependencies of all specified elements
|
402 | 414 |
"""
|
415 |
+ if not elements:
|
|
416 |
+ # Attempt to divine the element from the workspace you're in
|
|
417 |
+ guessed_target = app.guess_element()
|
|
418 |
+ if guessed_target:
|
|
419 |
+ elements = (guessed_target,)
|
|
420 |
+ |
|
403 | 421 |
with app.initialized(session_name="Track"):
|
404 | 422 |
# Substitute 'none' for 'redirect' so that element redirections
|
405 | 423 |
# will be done
|
... | ... | @@ -436,6 +454,12 @@ def pull(app, elements, deps, remote): |
436 | 454 |
none: No dependencies, just the element itself
|
437 | 455 |
all: All dependencies
|
438 | 456 |
"""
|
457 |
+ if not elements:
|
|
458 |
+ # Attempt to divine the element from the workspace you're in
|
|
459 |
+ guessed_target = app.guess_element()
|
|
460 |
+ if guessed_target:
|
|
461 |
+ elements = (guessed_target,)
|
|
462 |
+ |
|
439 | 463 |
with app.initialized(session_name="Pull"):
|
440 | 464 |
app.stream.pull(elements, selection=deps, remote=remote)
|
441 | 465 |
|
... | ... | @@ -464,6 +488,11 @@ def push(app, elements, deps, remote): |
464 | 488 |
none: No dependencies, just the element itself
|
465 | 489 |
all: All dependencies
|
466 | 490 |
"""
|
491 |
+ if not elements:
|
|
492 |
+ # Attempt to divine the element from the workspace you're in
|
|
493 |
+ guessed_target = app.guess_element()
|
|
494 |
+ if guessed_target:
|
|
495 |
+ elements = (guessed_target,)
|
|
467 | 496 |
with app.initialized(session_name="Push"):
|
468 | 497 |
app.stream.push(elements, selection=deps, remote=remote)
|
469 | 498 |
|
... | ... | @@ -534,6 +563,12 @@ def show(app, elements, deps, except_, order, format_): |
534 | 563 |
bst show target.bst --format \\
|
535 | 564 |
$'---------- %{name} ----------\\n%{vars}'
|
536 | 565 |
"""
|
566 |
+ if not elements:
|
|
567 |
+ # Attempt to divine the element from the workspace you're in
|
|
568 |
+ guessed_target = app.guess_element()
|
|
569 |
+ if guessed_target:
|
|
570 |
+ elements = (guessed_target,)
|
|
571 |
+ |
|
537 | 572 |
with app.initialized():
|
538 | 573 |
dependencies = app.stream.load_selection(elements,
|
539 | 574 |
selection=deps,
|
... | ... | @@ -563,7 +598,7 @@ def show(app, elements, deps, except_, order, format_): |
563 | 598 |
help="Mount a file or directory into the sandbox")
|
564 | 599 |
@click.option('--isolate', is_flag=True, default=False,
|
565 | 600 |
help='Create an isolated build sandbox')
|
566 |
-@click.argument('element',
|
|
601 |
+@click.argument('element', required=False,
|
|
567 | 602 |
type=click.Path(readable=False))
|
568 | 603 |
@click.argument('command', type=click.STRING, nargs=-1)
|
569 | 604 |
@click.pass_obj
|
... | ... | @@ -594,6 +629,14 @@ def shell(app, element, sysroot, mount, isolate, build_, command): |
594 | 629 |
scope = Scope.RUN
|
595 | 630 |
|
596 | 631 |
with app.initialized():
|
632 |
+ if not element:
|
|
633 |
+ # Attempt to divine the element from the workspace you're in
|
|
634 |
+ guessed_target = app.guess_element()
|
|
635 |
+ if guessed_target:
|
|
636 |
+ element = guessed_target
|
|
637 |
+ else:
|
|
638 |
+ raise AppError('Error: Missing argument "ELEMENT".')
|
|
639 |
+ |
|
597 | 640 |
dependencies = app.stream.load_selection((element,), selection=PipelineSelection.NONE)
|
598 | 641 |
element = dependencies[0]
|
599 | 642 |
prompt = app.shell_prompt(element)
|