diff options
author | Martin Blanchard <martin.blanchard@codethink.co.uk> | 2018-07-31 12:23:48 +0100 |
---|---|---|
committer | Valentin David <valentin.david@gmail.com> | 2018-08-13 21:37:28 +0000 |
commit | 83710050accda8b1a0de1123fe831899236a7b26 (patch) | |
tree | ff69ba11b1c6cf519f4af9d2afb3c20af7a461d2 | |
parent | 41d97b7ef43039cb0f091a36dcb07408c2389864 (diff) | |
download | buildstream-83710050accda8b1a0de1123fe831899236a7b26.tar.gz |
complete.py: Ensure paths get completed from 'element-path'
Element paths should always be completed from the root element folder
defined by the element-path key in project.conf. Fix complete_path() to
always search into its given base_directory argument.
See issue BuildStream/buildstream#448
-rw-r--r-- | buildstream/_frontend/complete.py | 7 | ||||
-rw-r--r-- | tests/completions/completions.py | 4 | ||||
-rw-r--r-- | tests/completions/sub-folders/base/unwanted.bst | 4 | ||||
-rw-r--r-- | tests/completions/sub-folders/elements/base.bst | 5 | ||||
-rw-r--r-- | tests/completions/sub-folders/elements/base/wanted.bst | 4 | ||||
-rw-r--r-- | tests/completions/sub-folders/elements/hello.bst | 4 | ||||
-rw-r--r-- | tests/completions/sub-folders/project.conf | 4 |
7 files changed, 29 insertions, 3 deletions
diff --git a/buildstream/_frontend/complete.py b/buildstream/_frontend/complete.py index 79bb92758..97d6d45ec 100644 --- a/buildstream/_frontend/complete.py +++ b/buildstream/_frontend/complete.py @@ -68,9 +68,10 @@ def complete_path(path_type, incomplete, base_directory='.'): # If there was nothing on the left of the last separator, # we are completing files in the filesystem root base_path = os.path.join(base_directory, base_path) - - elif os.path.isdir(incomplete): - base_path = incomplete + else: + incomplete_base_path = os.path.join(base_directory, incomplete) + if os.path.isdir(incomplete_base_path): + base_path = incomplete_base_path try: if base_path: diff --git a/tests/completions/completions.py b/tests/completions/completions.py index 1ff026ea5..50b41f7b3 100644 --- a/tests/completions/completions.py +++ b/tests/completions/completions.py @@ -212,6 +212,10 @@ def test_option_directory(datafiles, cli, cmd, word_idx, expected, subdir): # Also try multi arguments together ('no-element-path', 'bst --directory ../ checkout t ', 4, ['target.bst '], 'files'), ('no-element-path', 'bst --directory ../ checkout target.bst ', 5, ['bin-files/', 'dev-files/'], 'files'), + + # When element-path have sub-folders + ('sub-folders', 'bst show base', 2, ['base/wanted.bst '], None), + ('sub-folders', 'bst show base/', 2, ['base/wanted.bst '], None), ]) def test_argument_element(datafiles, cli, project, cmd, word_idx, expected, subdir): cwd = os.path.join(str(datafiles), project) diff --git a/tests/completions/sub-folders/base/unwanted.bst b/tests/completions/sub-folders/base/unwanted.bst new file mode 100644 index 000000000..bd510513d --- /dev/null +++ b/tests/completions/sub-folders/base/unwanted.bst @@ -0,0 +1,4 @@ +kind: autotools +description: | + + Not auto-completed element diff --git a/tests/completions/sub-folders/elements/base.bst b/tests/completions/sub-folders/elements/base.bst new file mode 100644 index 000000000..4e97e8ac0 --- /dev/null +++ b/tests/completions/sub-folders/elements/base.bst @@ -0,0 +1,5 @@ +kind: stack +description: Base stack + +depends: +- base/wanted.bst diff --git a/tests/completions/sub-folders/elements/base/wanted.bst b/tests/completions/sub-folders/elements/base/wanted.bst new file mode 100644 index 000000000..57656210d --- /dev/null +++ b/tests/completions/sub-folders/elements/base/wanted.bst @@ -0,0 +1,4 @@ +kind: autotools +description: | + + Auto-completed element diff --git a/tests/completions/sub-folders/elements/hello.bst b/tests/completions/sub-folders/elements/hello.bst new file mode 100644 index 000000000..93fcaa04b --- /dev/null +++ b/tests/completions/sub-folders/elements/hello.bst @@ -0,0 +1,4 @@ +kind: autotools +description: | + + Hello world diff --git a/tests/completions/sub-folders/project.conf b/tests/completions/sub-folders/project.conf new file mode 100644 index 000000000..854e38693 --- /dev/null +++ b/tests/completions/sub-folders/project.conf @@ -0,0 +1,4 @@ +# Project config for frontend build test +name: test + +element-path: elements |