[Notes] [Git][BuildStream/buildstream][jonathan/workspace-fragment-create] 7 commits: sources: Don't redundantly document directory configuration



Title: GitLab

Jonathan Maw pushed to branch jonathan/workspace-fragment-create at BuildStream / buildstream

Commits:

26 changed files:

Changes:

  • buildstream/_stream.py
    ... ... @@ -509,6 +509,9 @@ class Stream():
    509 509
                 with target.timed_activity("Staging sources to {}".format(directory)):
    
    510 510
                     target._open_workspace()
    
    511 511
     
    
    512
    +        workspace_local = workspaces.create_workspace_local(directory)
    
    513
    +        workspace_local.write()
    
    514
    +
    
    512 515
             workspaces.save_config()
    
    513 516
             self._message(MessageType.INFO, "Saved workspace configuration")
    
    514 517
     
    
    ... ... @@ -533,6 +536,10 @@ class Stream():
    533 536
                     except OSError as e:
    
    534 537
                         raise StreamError("Could not remove  '{}': {}"
    
    535 538
                                           .format(workspace.get_absolute_path(), e)) from e
    
    539
    +        else:
    
    540
    +            # TODO: At some point, closing a workspace only deletes the file if no projects are using it.
    
    541
    +            workspace_local = workspaces.create_workspace_local(workspace.get_absolute_path())
    
    542
    +            workspace_local.delete()
    
    536 543
     
    
    537 544
             # Delete the workspace and save the configuration
    
    538 545
             workspaces.delete_workspace(element_name)
    

  • buildstream/_workspaces.py
    ... ... @@ -25,6 +25,81 @@ from ._exceptions import LoadError, LoadErrorReason
    25 25
     
    
    26 26
     
    
    27 27
     BST_WORKSPACE_FORMAT_VERSION = 3
    
    28
    +BST_WORKSPACE_LOCAL_FORMAT_VERSION = 1
    
    29
    +WORKSPACE_LOCAL_FILE = ".bstproject.yaml"
    
    30
    +
    
    31
    +
    
    32
    +# WorkspaceLocal()
    
    33
    +#
    
    34
    +# An object to contain various helper functions and data required for
    
    35
    +# referring from a workspace back to buildstream.
    
    36
    +#
    
    37
    +# Args:
    
    38
    +#    directory (str): The directory that the workspace exists in
    
    39
    +#    project_paths (list of str): The project paths used to refer back
    
    40
    +#                                 to buildstream projects.
    
    41
    +class WorkspaceLocal():
    
    42
    +    def __init__(self, directory, project_paths):
    
    43
    +        self._project_paths = project_paths
    
    44
    +        self._directory = directory
    
    45
    +
    
    46
    +    # get_default_path()
    
    47
    +    #
    
    48
    +    # Retrieves the default path to a project.
    
    49
    +    #
    
    50
    +    # Returns:
    
    51
    +    #    (str): The path to a project
    
    52
    +    def get_default_path(self):
    
    53
    +        return self._project_paths[0]
    
    54
    +
    
    55
    +    # to_dict()
    
    56
    +    #
    
    57
    +    # Turn the members data into a dict for serialization purposes
    
    58
    +    #
    
    59
    +    # Returns:
    
    60
    +    #    (dict): A dict representation of the WorkspaceLocal
    
    61
    +    #
    
    62
    +    def to_dict(self):
    
    63
    +        ret = {
    
    64
    +            'projects': self._project_paths,
    
    65
    +            'format-version': BST_WORKSPACE_LOCAL_FORMAT_VERSION,
    
    66
    +        }
    
    67
    +        return ret
    
    68
    +
    
    69
    +    # from_dict()
    
    70
    +    #
    
    71
    +    # Loads a new WorkspaceLocal from a simple dictionary
    
    72
    +    #
    
    73
    +    # Args:
    
    74
    +    #    directory (str): The directory that the workspace exists in
    
    75
    +    #   (dict) dictionary: The dict to generate a WorkspaceLocal from
    
    76
    +    #
    
    77
    +    # Returns:
    
    78
    +    #   (WorkspaceLocal): A newly instantiated WorkspaceLocal
    
    79
    +    def from_dict(cls, directory, dictionary):
    
    80
    +        # Only know how to handle one format-version at the moment.
    
    81
    +        assert dictionary['format-version'] == BST_WORKSPACE_LOCAL_FORMAT_VERSION
    
    82
    +
    
    83
    +        return cls(directory, dictionary['projects'])
    
    84
    +
    
    85
    +    # write()
    
    86
    +    #
    
    87
    +    # Writes the WorkspaceLocal to disk
    
    88
    +    def write(self):
    
    89
    +        os.makedirs(self._directory, exist_ok=True)
    
    90
    +        _yaml.dump(self.to_dict(), self._get_filename())
    
    91
    +
    
    92
    +    # delete()
    
    93
    +    #
    
    94
    +    # Deletes the WorkspaceLocal from disk, if it exists.
    
    95
    +    def delete(self):
    
    96
    +        try:
    
    97
    +            os.unlink(self._get_filename())
    
    98
    +        except FileNotFoundError:
    
    99
    +            pass
    
    100
    +
    
    101
    +    def _get_filename(self):
    
    102
    +        return os.path.join(self._directory, WORKSPACE_LOCAL_FILE)
    
    28 103
     
    
    29 104
     
    
    30 105
     # Workspace()
    
    ... ... @@ -302,6 +377,21 @@ class Workspaces():
    302 377
             _yaml.dump(_yaml.node_sanitize(config),
    
    303 378
                        self._get_filename())
    
    304 379
     
    
    380
    +    # create_workspace_local()
    
    381
    +    #
    
    382
    +    # Create a WorkspaceLocal in the given path.
    
    383
    +    #
    
    384
    +    # Args:
    
    385
    +    #    path (str): The path to the workspace
    
    386
    +    #
    
    387
    +    # Returns:
    
    388
    +    #    (WorkspaceLocal): The created WorkspaceLocal
    
    389
    +
    
    390
    +    def create_workspace_local(self, directory):
    
    391
    +        # TODO: Read existing WorkspaceLocal if it exists. Doesn't matter yet.
    
    392
    +        project_dir = self._toplevel_project.directory
    
    393
    +        return WorkspaceLocal(directory, [project_dir])
    
    394
    +
    
    305 395
         # _load_config()
    
    306 396
         #
    
    307 397
         # Loads and parses the workspace configuration
    

  • buildstream/buildelement.py
    ... ... @@ -23,6 +23,8 @@ BuildElement - Abstract class for build elements
    23 23
     The BuildElement class is a convenience element one can derive from for
    
    24 24
     implementing the most common case of element.
    
    25 25
     
    
    26
    +.. _core_buildelement_builtins:
    
    27
    +
    
    26 28
     Built-in functionality
    
    27 29
     ----------------------
    
    28 30
     
    

  • buildstream/plugins/elements/autotools.py
    ... ... @@ -50,6 +50,9 @@ Here is the default configuration for the ``autotools`` element in full:
    50 50
     
    
    51 51
       .. literalinclude:: ../../../buildstream/plugins/elements/autotools.yaml
    
    52 52
          :language: yaml
    
    53
    +
    
    54
    +See :ref:`built-in functionality documentation <core_buildelement_builtins>` for
    
    55
    +details on common configuration options for build elements.
    
    53 56
     """
    
    54 57
     
    
    55 58
     from buildstream import BuildElement
    

  • buildstream/plugins/elements/cmake.py
    ... ... @@ -49,6 +49,9 @@ Here is the default configuration for the ``cmake`` element in full:
    49 49
     
    
    50 50
       .. literalinclude:: ../../../buildstream/plugins/elements/cmake.yaml
    
    51 51
          :language: yaml
    
    52
    +
    
    53
    +See :ref:`built-in functionality documentation <core_buildelement_builtins>` for
    
    54
    +details on common configuration options for build elements.
    
    52 55
     """
    
    53 56
     
    
    54 57
     from buildstream import BuildElement
    

  • buildstream/plugins/elements/distutils.py
    ... ... @@ -26,6 +26,9 @@ python distutils
    26 26
     The distutils default configuration:
    
    27 27
       .. literalinclude:: ../../../buildstream/plugins/elements/distutils.yaml
    
    28 28
          :language: yaml
    
    29
    +
    
    30
    +See :ref:`built-in functionality documentation <core_buildelement_builtins>` for
    
    31
    +details on common configuration options for build elements.
    
    29 32
     """
    
    30 33
     
    
    31 34
     from buildstream import BuildElement
    

  • buildstream/plugins/elements/import.py
    ... ... @@ -28,6 +28,9 @@ some configuration data.
    28 28
     The empty configuration is as such:
    
    29 29
       .. literalinclude:: ../../../buildstream/plugins/elements/import.yaml
    
    30 30
          :language: yaml
    
    31
    +
    
    32
    +See :ref:`built-in functionality documentation <core_buildelement_builtins>` for
    
    33
    +details on common configuration options for build elements.
    
    31 34
     """
    
    32 35
     
    
    33 36
     import os
    

  • buildstream/plugins/elements/make.py
    ... ... @@ -31,6 +31,9 @@ Here is the default configuration for the ``make`` element in full:
    31 31
     
    
    32 32
       .. literalinclude:: ../../../buildstream/plugins/elements/make.yaml
    
    33 33
          :language: yaml
    
    34
    +
    
    35
    +See :ref:`built-in functionality documentation <core_buildelement_builtins>` for
    
    36
    +details on common configuration options for build elements.
    
    34 37
     """
    
    35 38
     
    
    36 39
     from buildstream import BuildElement
    

  • buildstream/plugins/elements/makemaker.py
    ... ... @@ -26,6 +26,9 @@ the Perl ExtUtil::MakeMaker build system
    26 26
     The MakeMaker default configuration:
    
    27 27
       .. literalinclude:: ../../../buildstream/plugins/elements/makemaker.yaml
    
    28 28
          :language: yaml
    
    29
    +
    
    30
    +See :ref:`built-in functionality documentation <core_buildelement_builtins>` for
    
    31
    +details on common configuration options for build elements.
    
    29 32
     """
    
    30 33
     
    
    31 34
     from buildstream import BuildElement
    

  • buildstream/plugins/elements/manual.py
    ... ... @@ -26,6 +26,9 @@ add custom build commands to the array understood by the :mod:`BuildElement <bui
    26 26
     The empty configuration is as such:
    
    27 27
       .. literalinclude:: ../../../buildstream/plugins/elements/manual.yaml
    
    28 28
          :language: yaml
    
    29
    +
    
    30
    +See :ref:`built-in functionality documentation <core_buildelement_builtins>` for
    
    31
    +details on common configuration options for build elements.
    
    29 32
     """
    
    30 33
     
    
    31 34
     from buildstream import BuildElement
    

  • buildstream/plugins/elements/meson.py
    ... ... @@ -46,6 +46,9 @@ Here is the default configuration for the ``meson`` element in full:
    46 46
     
    
    47 47
       .. literalinclude:: ../../../buildstream/plugins/elements/meson.yaml
    
    48 48
          :language: yaml
    
    49
    +
    
    50
    +See :ref:`built-in functionality documentation <core_buildelement_builtins>` for
    
    51
    +details on common configuration options for build elements.
    
    49 52
     """
    
    50 53
     
    
    51 54
     from buildstream import BuildElement
    

  • buildstream/plugins/elements/modulebuild.py
    ... ... @@ -26,6 +26,9 @@ the Perl Module::Build build system
    26 26
     The modulebuild default configuration:
    
    27 27
       .. literalinclude:: ../../../buildstream/plugins/elements/modulebuild.yaml
    
    28 28
          :language: yaml
    
    29
    +
    
    30
    +See :ref:`built-in functionality documentation <core_buildelement_builtins>` for
    
    31
    +details on common configuration options for build elements.
    
    29 32
     """
    
    30 33
     
    
    31 34
     from buildstream import BuildElement
    

  • buildstream/plugins/elements/pip.py
    ... ... @@ -26,6 +26,9 @@ Python modules with pip
    26 26
     The pip default configuration:
    
    27 27
       .. literalinclude:: ../../../buildstream/plugins/elements/pip.yaml
    
    28 28
          :language: yaml
    
    29
    +
    
    30
    +See :ref:`built-in functionality documentation <core_buildelement_builtins>` for
    
    31
    +details on common configuration options for build elements.
    
    29 32
     """
    
    30 33
     
    
    31 34
     from buildstream import BuildElement
    

  • buildstream/plugins/elements/qmake.py
    ... ... @@ -26,6 +26,9 @@ the qmake build system
    26 26
     The qmake default configuration:
    
    27 27
       .. literalinclude:: ../../../buildstream/plugins/elements/qmake.yaml
    
    28 28
          :language: yaml
    
    29
    +
    
    30
    +See :ref:`built-in functionality documentation <core_buildelement_builtins>` for
    
    31
    +details on common configuration options for build elements.
    
    29 32
     """
    
    30 33
     
    
    31 34
     from buildstream import BuildElement
    

  • buildstream/plugins/sources/bzr.py
    ... ... @@ -31,9 +31,6 @@ bzr - stage files from a bazaar repository
    31 31
        # Specify the bzr source kind
    
    32 32
        kind: bzr
    
    33 33
     
    
    34
    -   # Optionally specify a relative staging directory
    
    35
    -   # directory: path/to/stage
    
    36
    -
    
    37 34
        # Specify the bzr url. Bazaar URLs come in many forms, see
    
    38 35
        # `bzr help urlspec` for more information. Using an alias defined
    
    39 36
        # in your project configuration is encouraged.
    
    ... ... @@ -53,6 +50,8 @@ bzr - stage files from a bazaar repository
    53 50
        # revision number to the one on the tip of the branch specified in 'track'.
    
    54 51
        ref: 6622
    
    55 52
     
    
    53
    +See :ref:`built-in functionality doumentation <core_source_builtins>` for
    
    54
    +details on common configuration options for sources.
    
    56 55
     """
    
    57 56
     
    
    58 57
     import os
    

  • buildstream/plugins/sources/deb.py
    ... ... @@ -33,9 +33,6 @@ deb - stage files from .deb packages
    33 33
        # Specify the deb source kind
    
    34 34
        kind: deb
    
    35 35
     
    
    36
    -   # Optionally specify a relative staging directory
    
    37
    -   # directory: path/to/stage
    
    38
    -
    
    39 36
        # Specify the deb url. Using an alias defined in your project
    
    40 37
        # configuration is encouraged. 'bst track' will update the
    
    41 38
        # sha256sum in 'ref' to the downloaded file's sha256sum.
    
    ... ... @@ -47,6 +44,8 @@ deb - stage files from .deb packages
    47 44
        # Specify the basedir to return only the specified dir and its children
    
    48 45
        base-dir: ''
    
    49 46
     
    
    47
    +See :ref:`built-in functionality doumentation <core_source_builtins>` for
    
    48
    +details on common configuration options for sources.
    
    50 49
     """
    
    51 50
     
    
    52 51
     import tarfile
    

  • buildstream/plugins/sources/git.py
    ... ... @@ -32,9 +32,6 @@ git - stage files from a git repository
    32 32
        # Specify the git source kind
    
    33 33
        kind: git
    
    34 34
     
    
    35
    -   # Optionally specify a relative staging directory
    
    36
    -   # directory: path/to/stage
    
    37
    -
    
    38 35
        # Specify the repository url, using an alias defined
    
    39 36
        # in your project configuration is recommended.
    
    40 37
        url: upstream:foo.git
    
    ... ... @@ -74,6 +71,9 @@ git - stage files from a git repository
    74 71
            url: upstream:baz.git
    
    75 72
            checkout: False
    
    76 73
     
    
    74
    +See :ref:`built-in functionality doumentation <core_source_builtins>` for
    
    75
    +details on common configuration options for sources.
    
    76
    +
    
    77 77
     **Configurable Warnings:**
    
    78 78
     
    
    79 79
     This plugin provides the following configurable warnings:
    

  • buildstream/plugins/sources/local.py
    ... ... @@ -29,11 +29,11 @@ local - stage local files and directories
    29 29
        # Specify the local source kind
    
    30 30
        kind: local
    
    31 31
     
    
    32
    -   # Optionally specify a relative staging directory
    
    33
    -   # directory: path/to/stage
    
    34
    -
    
    35 32
        # Specify the project relative path to a file or directory
    
    36 33
        path: files/somefile.txt
    
    34
    +
    
    35
    +See :ref:`built-in functionality doumentation <core_source_builtins>` for
    
    36
    +details on common configuration options for sources.
    
    37 37
     """
    
    38 38
     
    
    39 39
     import os
    

  • buildstream/plugins/sources/ostree.py
    ... ... @@ -29,9 +29,6 @@ ostree - stage files from an OSTree repository
    29 29
        # Specify the ostree source kind
    
    30 30
        kind: ostree
    
    31 31
     
    
    32
    -   # Optionally specify a relative staging directory
    
    33
    -   # directory: path/to/stage
    
    34
    -
    
    35 32
        # Specify the repository url, using an alias defined
    
    36 33
        # in your project configuration is recommended.
    
    37 34
        url: upstream:runtime
    
    ... ... @@ -48,6 +45,9 @@ ostree - stage files from an OSTree repository
    48 45
        # For signed ostree repositories, specify a local project relative
    
    49 46
        # path to the public verifying GPG key for this remote.
    
    50 47
        gpg-key: keys/runtime.gpg
    
    48
    +
    
    49
    +See :ref:`built-in functionality doumentation <core_source_builtins>` for
    
    50
    +details on common configuration options for sources.
    
    51 51
     """
    
    52 52
     
    
    53 53
     import os
    

  • buildstream/plugins/sources/patch.py
    ... ... @@ -37,12 +37,11 @@ patch - apply locally stored patches
    37 37
        # Specify the project relative path to a patch file
    
    38 38
        path: files/somefile.diff
    
    39 39
     
    
    40
    -   # Optionally specify the root directory for the patch
    
    41
    -   # directory: path/to/stage
    
    42
    -
    
    43 40
        # Optionally specify the strip level, defaults to 1
    
    44 41
        strip-level: 1
    
    45 42
     
    
    43
    +See :ref:`built-in functionality doumentation <core_source_builtins>` for
    
    44
    +details on common configuration options for sources.
    
    46 45
     """
    
    47 46
     
    
    48 47
     import os
    

  • buildstream/plugins/sources/pip.py
    ... ... @@ -54,19 +54,18 @@ Downloaded tarballs will be stored in a directory called ".bst_pip_downloads".
    54 54
        packages:
    
    55 55
        - flake8
    
    56 56
     
    
    57
    -   # Optionally specify a relative staging directory
    
    58
    -   directory: path/to/stage
    
    59
    -
    
    60 57
        # Specify the ref. It is a list of strings of format
    
    61 58
        # "<package-name>==<version>", separated by "\\n".
    
    62 59
        # Usually this will be contents of a requirements.txt file where all
    
    63 60
        # package versions have been frozen.
    
    64 61
        ref: "flake8==3.5.0\\nmccabe==0.6.1\\npkg-resources==0.0.0\\npycodestyle==2.3.1\\npyflakes==1.6.0"
    
    65 62
     
    
    63
    +See :ref:`built-in functionality doumentation <core_source_builtins>` for
    
    64
    +details on common configuration options for sources.
    
    65
    +
    
    66 66
     .. note::
    
    67 67
     
    
    68 68
        The ``pip`` plugin is available since :ref:`format version 16 <project_format_version>`
    
    69
    -
    
    70 69
     """
    
    71 70
     
    
    72 71
     import errno
    

  • buildstream/plugins/sources/remote.py
    ... ... @@ -28,9 +28,6 @@ remote - stage files from remote urls
    28 28
        # Specify the remote source kind
    
    29 29
        kind: remote
    
    30 30
     
    
    31
    -   # Optionally specify a relative staging directory
    
    32
    -   # directory: path/to/stage
    
    33
    -
    
    34 31
        # Optionally specify a relative staging filename.
    
    35 32
        # If not specified, the basename of the url will be used.
    
    36 33
        # filename: customfilename
    
    ... ... @@ -47,12 +44,12 @@ remote - stage files from remote urls
    47 44
        # Specify the ref. It's a sha256sum of the file you download.
    
    48 45
        ref: 6c9f6f68a131ec6381da82f2bff978083ed7f4f7991d931bfa767b7965ebc94b
    
    49 46
     
    
    50
    -
    
    47
    +See :ref:`built-in functionality doumentation <core_source_builtins>` for
    
    48
    +details on common configuration options for sources.
    
    51 49
     
    
    52 50
     .. note::
    
    53 51
     
    
    54 52
        The ``remote`` plugin is available since :ref:`format version 10 <project_format_version>`
    
    55
    -
    
    56 53
     """
    
    57 54
     import os
    
    58 55
     from buildstream import SourceError, utils
    

  • buildstream/plugins/sources/tar.py
    ... ... @@ -32,9 +32,6 @@ tar - stage files from tar archives
    32 32
        # Specify the tar source kind
    
    33 33
        kind: tar
    
    34 34
     
    
    35
    -   # Optionally specify a relative staging directory
    
    36
    -   # directory: path/to/stage
    
    37
    -
    
    38 35
        # Specify the tar url. Using an alias defined in your project
    
    39 36
        # configuration is encouraged. 'bst track' will update the
    
    40 37
        # sha256sum in 'ref' to the downloaded file's sha256sum.
    
    ... ... @@ -53,6 +50,9 @@ tar - stage files from tar archives
    53 50
        # To extract the root of the tarball directly, this can be set
    
    54 51
        # to an empty string.
    
    55 52
        base-dir: '*'
    
    53
    +
    
    54
    +See :ref:`built-in functionality doumentation <core_source_builtins>` for
    
    55
    +details on common configuration options for sources.
    
    56 56
     """
    
    57 57
     
    
    58 58
     import os
    

  • buildstream/plugins/sources/zip.py
    ... ... @@ -28,9 +28,6 @@ zip - stage files from zip archives
    28 28
        # Specify the zip source kind
    
    29 29
        kind: zip
    
    30 30
     
    
    31
    -   # Optionally specify a relative staging directory
    
    32
    -   # directory: path/to/stage
    
    33
    -
    
    34 31
        # Specify the zip url. Using an alias defined in your project
    
    35 32
        # configuration is encouraged. 'bst track' will update the
    
    36 33
        # sha256sum in 'ref' to the downloaded file's sha256sum.
    
    ... ... @@ -50,11 +47,13 @@ zip - stage files from zip archives
    50 47
        # to an empty string.
    
    51 48
        base-dir: '*'
    
    52 49
     
    
    50
    +See :ref:`built-in functionality doumentation <core_source_builtins>` for
    
    51
    +details on common configuration options for sources.
    
    52
    +
    
    53 53
     .. attention::
    
    54 54
     
    
    55 55
        File permissions are not preserved. All extracted directories have
    
    56 56
        permissions 0755 and all extracted files have permissions 0644.
    
    57
    -
    
    58 57
     """
    
    59 58
     
    
    60 59
     import os
    

  • buildstream/source.py
    ... ... @@ -20,6 +20,8 @@
    20 20
     Source - Base source class
    
    21 21
     ==========================
    
    22 22
     
    
    23
    +.. _core_source_builtins:
    
    24
    +
    
    23 25
     Built-in functionality
    
    24 26
     ----------------------
    
    25 27
     
    

  • tests/frontend/workspace.py
    ... ... @@ -93,6 +93,13 @@ def open_workspace(cli, tmpdir, datafiles, kind, track, suffix='', workspace_dir
    93 93
     
    
    94 94
         result.assert_success()
    
    95 95
     
    
    96
    +    # Assert that a .bstproject.yaml file has been created
    
    97
    +    # and contains the path to the project
    
    98
    +    bstproject_path = os.path.join(workspace_dir, '.bstproject.yaml')
    
    99
    +    assert os.path.exists(bstproject_path)
    
    100
    +    with open(bstproject_path) as f:
    
    101
    +        assert project_path in f.read()
    
    102
    +
    
    96 103
         # Assert that we are now buildable because the source is
    
    97 104
         # now cached.
    
    98 105
         assert cli.get_element_state(project_path, element_name) == 'buildable'
    
    ... ... @@ -148,6 +155,10 @@ def test_open_force(cli, tmpdir, datafiles, kind):
    148 155
         # Assert the workspace dir still exists
    
    149 156
         assert os.path.exists(workspace)
    
    150 157
     
    
    158
    +    # Assert the bstproject doesn't exist
    
    159
    +    bstproject_path = os.path.join(workspace, '.bstproject.yaml')
    
    160
    +    assert not os.path.exists(bstproject_path)
    
    161
    +
    
    151 162
         # Now open the workspace again with --force, this should happily succeed
    
    152 163
         result = cli.run(project=project, args=[
    
    153 164
             'workspace', 'open', '--force', element_name, workspace
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]