diff options
author | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2018-12-05 11:10:53 +0000 |
---|---|---|
committer | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2018-12-11 12:56:32 +0000 |
commit | 496f0ab74c7955fb71754babc9561a16f8dfea1c (patch) | |
tree | e27ab7373c3588d5238948dd21321de6122cc29b | |
parent | 7deeb2c3cada7b3e779f69c5fd27069e2236f7ab (diff) | |
download | buildstream-496f0ab74c7955fb71754babc9561a16f8dfea1c.tar.gz |
_project.py: Find project from workspace if outside of a project
This is a part of #222
-rw-r--r-- | buildstream/_project.py | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/buildstream/_project.py b/buildstream/_project.py index a8962a022..90ed58e14 100644 --- a/buildstream/_project.py +++ b/buildstream/_project.py @@ -41,6 +41,7 @@ from .element import Element from ._message import Message, MessageType from ._includes import Includes from ._platform import Platform +from ._workspaces import WORKSPACE_PROJECT_FILE # Project Configuration file @@ -95,8 +96,10 @@ class Project(): # The project name self.name = None - # The project directory - self.directory = self._find_project_dir(directory) + self._context = context # The invocation Context, a private member + + # The project directory, and whether the element whose workspace it was invoked from + self.directory, self._invoked_from_workspace_element = self._find_project_dir(directory) # Absolute path to where elements are loaded from within the project self.element_path = None @@ -117,7 +120,6 @@ class Project(): # # Private Members # - self._context = context # The invocation Context self._default_mirror = default_mirror # The name of the preferred mirror. @@ -371,6 +373,14 @@ class Project(): self._load_second_pass() + # invoked_from_workspace_element() + # + # Returns the element whose workspace was used to invoke buildstream + # if buildstream was invoked from an external workspace + # + def invoked_from_workspace_element(self): + return self._invoked_from_workspace_element + # cleanup() # # Cleans up resources used loading elements @@ -661,18 +671,30 @@ class Project(): # Raises: # LoadError if project.conf is not found # + # Returns: + # (str) - the directory that contains the project, and + # (str) - the name of the element required to find the project, or None + # def _find_project_dir(self, directory): - directory = os.path.abspath(directory) - while not os.path.isfile(os.path.join(directory, _PROJECT_CONF_FILE)): - parent_dir = os.path.dirname(directory) - if directory == parent_dir: - raise LoadError( - LoadErrorReason.MISSING_PROJECT_CONF, - '{} not found in current directory or any of its parent directories' - .format(_PROJECT_CONF_FILE)) - directory = parent_dir + workspace_element = None + found_directory, filename = utils._search_upward_for_files( + directory, [_PROJECT_CONF_FILE, WORKSPACE_PROJECT_FILE] + ) + if filename == _PROJECT_CONF_FILE: + project_directory = found_directory + elif filename == WORKSPACE_PROJECT_FILE: + workspace_project_cache = self._context.get_workspace_project_cache() + workspace_project = workspace_project_cache.get(found_directory) + if workspace_project: + project_directory = workspace_project.get_default_project_path() + workspace_element = workspace_project.get_default_element() + else: + raise LoadError( + LoadErrorReason.MISSING_PROJECT_CONF, + '{} not found in current directory or any of its parent directories' + .format(_PROJECT_CONF_FILE)) - return directory + return project_directory, workspace_element def _load_plugin_factories(self, config, output): plugin_source_origins = [] # Origins of custom sources |