[Notes] [Git][BuildStream/buildstream][jonathan/test-missing-workspace-guessing] 12 commits: _frontend/cli.py: Reinstate support for guessing targets



Title: GitLab

Jonathan Maw pushed to branch jonathan/test-missing-workspace-guessing at BuildStream / buildstream

Commits:

15 changed files:

Changes:

  • .gitlab-ci.yml
    ... ... @@ -6,7 +6,6 @@ cache:
    6 6
         - cache/
    
    7 7
     
    
    8 8
     stages:
    
    9
    -  - prepare
    
    10 9
       - test
    
    11 10
       - post
    
    12 11
     
    
    ... ... @@ -15,41 +14,6 @@ variables:
    15 14
       INTEGRATION_CACHE: "${CI_PROJECT_DIR}/cache/integration-cache"
    
    16 15
       TEST_COMMAND: "tox -- --color=yes --integration"
    
    17 16
     
    
    18
    -#####################################################
    
    19
    -#                  Prepare stage                    #
    
    20
    -#####################################################
    
    21
    -
    
    22
    -# Create a source distribution
    
    23
    -#
    
    24
    -source_dist:
    
    25
    -  stage: prepare
    
    26
    -  script:
    
    27
    -
    
    28
    -  # Generate the source distribution tarball
    
    29
    -  #
    
    30
    -  - python3 setup.py sdist
    
    31
    -  - tar -ztf dist/*
    
    32
    -  - tarball=$(cd dist && echo $(ls *))
    
    33
    -
    
    34
    -  # Verify that the source distribution tarball can be installed correctly
    
    35
    -  #
    
    36
    -  - pip3 install dist/*.tar.gz
    
    37
    -  - bst --version
    
    38
    -
    
    39
    -  # unpack tarball as `dist/buildstream` directory
    
    40
    -  - |
    
    41
    -    cat > dist/unpack.sh << EOF
    
    42
    -    #!/bin/sh
    
    43
    -    tar -zxf ${tarball}
    
    44
    -    mv ${tarball%.tar.gz} buildstream
    
    45
    -    EOF
    
    46
    -
    
    47
    -  # Make our helpers executable
    
    48
    -  - chmod +x dist/unpack.sh
    
    49
    -  artifacts:
    
    50
    -    paths:
    
    51
    -    - dist/
    
    52
    -
    
    53 17
     
    
    54 18
     #####################################################
    
    55 19
     #                    Test stage                     #
    
    ... ... @@ -72,8 +36,7 @@ source_dist:
    72 36
       - useradd -Um buildstream
    
    73 37
       - chown -R buildstream:buildstream .
    
    74 38
     
    
    75
    -  # Run the tests from the source distribution, We run as a simple
    
    76
    -  # user to test for permission issues
    
    39
    +  # Run the tests as a simple user to test for permission issues
    
    77 40
       - su buildstream -c "${TEST_COMMAND}"
    
    78 41
     
    
    79 42
       after_script:
    
    ... ... @@ -192,7 +155,8 @@ docs:
    192 155
         scheduler:
    
    193 156
           fetchers: 2
    
    194 157
         EOF
    
    195
    -  - (cd dist && ./unpack.sh && cd buildstream && pip3 install .)
    
    158
    +  - pip3 install -r requirements/requirements.txt -r requirements/plugin-requirements.txt
    
    159
    +  - pip3 install --no-index .
    
    196 160
       - pip3 install --user -e ${BST_EXT_URL}@${BST_EXT_REF}#egg=bst_ext
    
    197 161
       - git clone https://gitlab.com/freedesktop-sdk/freedesktop-sdk.git
    
    198 162
       - git -C freedesktop-sdk checkout ${FD_SDK_REF}
    
    ... ... @@ -275,13 +239,12 @@ coverage:
    275 239
       stage: post
    
    276 240
       coverage: '/TOTAL +\d+ +\d+ +(\d+\.\d+)%/'
    
    277 241
       script:
    
    278
    -    - cd dist && ./unpack.sh && cd buildstream
    
    279
    -    - pip3 install -r tools/requirements.txt -r tools/dev-requirements.txt
    
    242
    +    - pip3 install -r requirements/requirements.txt -r requirements/dev-requirements.txt
    
    280 243
         - pip3 install --no-index .
    
    281 244
         - mkdir report
    
    282 245
         - cd report
    
    283
    -    - cp ../../../coverage-unix/coverage.* .
    
    284
    -    - cp ../../../coverage-linux/coverage.* .
    
    246
    +    - cp ../coverage-unix/coverage.* .
    
    247
    +    - cp ../coverage-linux/coverage.* .
    
    285 248
         - ls coverage.*
    
    286 249
         - coverage combine --rcfile=../.coveragerc -a coverage.*
    
    287 250
         - coverage report --rcfile=../.coveragerc -m
    
    ... ... @@ -290,7 +253,6 @@ coverage:
    290 253
       - tests-fedora-27
    
    291 254
       - tests-fedora-28
    
    292 255
       - tests-unix
    
    293
    -  - source_dist
    
    294 256
       except:
    
    295 257
       - schedules
    
    296 258
     
    
    ... ... @@ -299,7 +261,6 @@ coverage:
    299 261
     pages:
    
    300 262
       stage: post
    
    301 263
       dependencies:
    
    302
    -  - source_dist
    
    303 264
       - docs
    
    304 265
       variables:
    
    305 266
         ACME_DIR: public/.well-known/acme-challenge
    

  • CONTRIBUTING.rst
    ... ... @@ -1736,10 +1736,8 @@ obtain profiles::
    1736 1736
           ForceCommand BST_PROFILE=artifact-receive cd /tmp && bst-artifact-receive --pull-url https://example.com/ /home/artifacts/artifacts
    
    1737 1737
     
    
    1738 1738
     
    
    1739
    -The MANIFEST.in and setup.py
    
    1740
    -----------------------------
    
    1741
    -When adding a dependency to BuildStream, it's important to update the setup.py accordingly.
    
    1742
    -
    
    1739
    +Managing data files
    
    1740
    +-------------------
    
    1743 1741
     When adding data files which need to be discovered at runtime by BuildStream, update setup.py accordingly.
    
    1744 1742
     
    
    1745 1743
     When adding data files for the purpose of docs or tests, or anything that is not covered by
    
    ... ... @@ -1749,3 +1747,23 @@ At any time, running the following command to create a source distribution shoul
    1749 1747
     creating a tarball which contains everything we want it to include::
    
    1750 1748
     
    
    1751 1749
       ./setup.py sdist
    
    1750
    +
    
    1751
    +
    
    1752
    +Updating BuildStream's Python dependencies
    
    1753
    +------------------------------------------
    
    1754
    +BuildStream's Python dependencies are listed in multiple
    
    1755
    +`requirements files <https://pip.readthedocs.io/en/latest/reference/pip_install/#requirements-file-format>`
    
    1756
    +present in the ``requirements`` directory.
    
    1757
    +
    
    1758
    +All ``.txt`` files in this directory are generated from the corresponding
    
    1759
    +``.in`` file, and each ``.in`` file represents a set of dependencies. For
    
    1760
    +example, ``requirements.in`` contains all runtime dependencies of BuildStream.
    
    1761
    +``requirements.txt`` is generated from it, and contains pinned versions of all
    
    1762
    +runtime dependencies (including transitive dependencies) of BuildStream.
    
    1763
    +
    
    1764
    +When adding a new dependency to BuildStream, or updating existing dependencies,
    
    1765
    +it is important to update the appropriate requirements file accordingly. After
    
    1766
    +changing the ``.in`` file, run the following to update the matching ``.txt``
    
    1767
    +file::
    
    1768
    +
    
    1769
    +   make -C requirements

  • MANIFEST.in
    ... ... @@ -32,12 +32,12 @@ include .pylintrc
    32 32
     recursive-include buildstream/_protos *.proto
    
    33 33
     
    
    34 34
     # Requirements files
    
    35
    -include tools/requirements.in
    
    36
    -include tools/requirements.txt
    
    37
    -include tools/dev-requirements.in
    
    38
    -include tools/dev-requirements.txt
    
    39
    -include tools/plugin-requirements.in
    
    40
    -include tools/plugin-requirements.txt
    
    35
    +include requirements/requirements.in
    
    36
    +include requirements/requirements.txt
    
    37
    +include requirements/dev-requirements.in
    
    38
    +include requirements/dev-requirements.txt
    
    39
    +include requirements/plugin-requirements.in
    
    40
    +include requirements/plugin-requirements.txt
    
    41 41
     
    
    42 42
     # Versioneer
    
    43 43
     include versioneer.py

  • buildstream/_frontend/app.py
    ... ... @@ -599,7 +599,7 @@ class App():
    599 599
                         click.echo("\nDropping into an interactive shell in the failed build sandbox\n", err=True)
    
    600 600
                         try:
    
    601 601
                             prompt = self.shell_prompt(element)
    
    602
    -                        self.stream.shell(element, Scope.BUILD, prompt, isolate=True)
    
    602
    +                        self.stream.shell(element, Scope.BUILD, prompt, isolate=True, usebuildtree=True)
    
    603 603
                         except BstError as e:
    
    604 604
                             click.echo("Error while attempting to create interactive shell: {}".format(e), err=True)
    
    605 605
                     elif choice == 'log':
    

  • buildstream/_frontend/cli.py
    ... ... @@ -719,6 +719,11 @@ def source_fetch(app, elements, deps, track_, except_, track_cross_junctions):
    719 719
             deps = PipelineSelection.ALL
    
    720 720
     
    
    721 721
         with app.initialized(session_name="Fetch"):
    
    722
    +        if not elements:
    
    723
    +            guessed_target = app.context.guess_element()
    
    724
    +            if guessed_target:
    
    725
    +                elements = (guessed_target,)
    
    726
    +
    
    722 727
             app.stream.fetch(elements,
    
    723 728
                              selection=deps,
    
    724 729
                              except_targets=except_,
    
    ... ... @@ -755,6 +760,11 @@ def source_track(app, elements, deps, except_, cross_junctions):
    755 760
             all:   All dependencies of all specified elements
    
    756 761
         """
    
    757 762
         with app.initialized(session_name="Track"):
    
    763
    +        if not elements:
    
    764
    +            guessed_target = app.context.guess_element()
    
    765
    +            if guessed_target:
    
    766
    +                elements = (guessed_target,)
    
    767
    +
    
    758 768
             # Substitute 'none' for 'redirect' so that element redirections
    
    759 769
             # will be done
    
    760 770
             if deps == 'none':
    

  • requirements/Makefile
    1
    +# Makefile for updating BuildStream's requirements files.
    
    2
    +#
    
    3
    +
    
    4
    +REQUIREMENTS_IN := $(wildcard *.in)
    
    5
    +REQUIREMENTS_TXT := $(REQUIREMENTS_IN:.in=.txt)
    
    6
    +PYTHON := python3
    
    7
    +VENV := $(PYTHON) -m venv
    
    8
    +
    
    9
    +VENV_PIP = $(VENVDIR)/bin/pip
    
    10
    +
    
    11
    +
    
    12
    +.PHONY: all
    
    13
    +
    
    14
    +all: $(REQUIREMENTS_TXT)
    
    15
    +
    
    16
    +%.txt: %.in
    
    17
    +	$(eval VENVDIR := $(shell mktemp -d $(CURDIR)/.bst-venv.XXXXXX))
    
    18
    +	$(VENV) $(VENVDIR)
    
    19
    +	$(VENV_PIP) install -r $^
    
    20
    +	$(VENV_PIP) freeze -r $^ > $@
    
    21
    +	rm -rf $(VENVDIR)

  • tools/dev-requirements.inrequirements/dev-requirements.in

  • tools/dev-requirements.txtrequirements/dev-requirements.txt

  • tools/plugin-requirements.inrequirements/plugin-requirements.in

  • tools/plugin-requirements.txtrequirements/plugin-requirements.txt

  • tools/requirements.inrequirements/requirements.in

  • tools/requirements.txtrequirements/requirements.txt

  • setup.py
    ... ... @@ -270,10 +270,10 @@ def get_cmdclass():
    270 270
     #####################################################
    
    271 271
     #               Gather requirements                 #
    
    272 272
     #####################################################
    
    273
    -with open('tools/dev-requirements.in') as dev_reqs:
    
    273
    +with open('requirements/dev-requirements.in') as dev_reqs:
    
    274 274
         dev_requires = dev_reqs.read().splitlines()
    
    275 275
     
    
    276
    -with open('tools/requirements.in') as install_reqs:
    
    276
    +with open('requirements/requirements.in') as install_reqs:
    
    277 277
         install_requires = install_reqs.read().splitlines()
    
    278 278
     
    
    279 279
     #####################################################
    

  • tests/frontend/workspace.py
    ... ... @@ -31,7 +31,7 @@ import shutil
    31 31
     import subprocess
    
    32 32
     from ruamel.yaml.comments import CommentedSet
    
    33 33
     from tests.testutils import cli, create_repo, ALL_REPO_KINDS, wait_for_cache_granularity
    
    34
    -from tests.testutils import create_artifact_share
    
    34
    +from tests.testutils import create_artifact_share, create_element_size
    
    35 35
     
    
    36 36
     from buildstream import _yaml
    
    37 37
     from buildstream._exceptions import ErrorDomain, LoadError, LoadErrorReason
    
    ... ... @@ -119,7 +119,7 @@ class WorkspaceCreater():
    119 119
             return element_tuples
    
    120 120
     
    
    121 121
         def open_workspaces(self, kinds, track, suffixs=None, workspace_dir=None,
    
    122
    -                        element_attrs=None):
    
    122
    +                        element_attrs=None, no_checkout=False):
    
    123 123
     
    
    124 124
             element_tuples = self.create_workspace_elements(kinds, track, suffixs, workspace_dir,
    
    125 125
                                                             element_attrs)
    
    ... ... @@ -130,6 +130,8 @@ class WorkspaceCreater():
    130 130
             args = ['workspace', 'open']
    
    131 131
             if track:
    
    132 132
                 args.append('--track')
    
    133
    +        if no_checkout:
    
    134
    +            args.append('--no-checkout')
    
    133 135
             if workspace_dir is not None:
    
    134 136
                 assert len(element_tuples) == 1, "test logic error"
    
    135 137
                 _, workspace_dir = element_tuples[0]
    
    ... ... @@ -140,23 +142,24 @@ class WorkspaceCreater():
    140 142
     
    
    141 143
             result.assert_success()
    
    142 144
     
    
    143
    -        for element_name, workspace_dir in element_tuples:
    
    144
    -            # Assert that we are now buildable because the source is
    
    145
    -            # now cached.
    
    146
    -            assert self.cli.get_element_state(self.project_path, element_name) == 'buildable'
    
    145
    +        if not no_checkout:
    
    146
    +            for element_name, workspace_dir in element_tuples:
    
    147
    +                # Assert that we are now buildable because the source is
    
    148
    +                # now cached.
    
    149
    +                assert self.cli.get_element_state(self.project_path, element_name) == 'buildable'
    
    147 150
     
    
    148
    -            # Check that the executable hello file is found in the workspace
    
    149
    -            filename = os.path.join(workspace_dir, 'usr', 'bin', 'hello')
    
    150
    -            assert os.path.exists(filename)
    
    151
    +                # Check that the executable hello file is found in the workspace
    
    152
    +                filename = os.path.join(workspace_dir, 'usr', 'bin', 'hello')
    
    153
    +                assert os.path.exists(filename)
    
    151 154
     
    
    152 155
             return element_tuples
    
    153 156
     
    
    154 157
     
    
    155 158
     def open_workspace(cli, tmpdir, datafiles, kind, track, suffix='', workspace_dir=None,
    
    156
    -                   project_path=None, element_attrs=None):
    
    159
    +                   project_path=None, element_attrs=None, no_checkout=False):
    
    157 160
         workspace_object = WorkspaceCreater(cli, tmpdir, datafiles, project_path)
    
    158 161
         workspaces = workspace_object.open_workspaces((kind, ), track, (suffix, ), workspace_dir,
    
    159
    -                                                  element_attrs)
    
    162
    +                                                  element_attrs, no_checkout)
    
    160 163
         assert len(workspaces) == 1
    
    161 164
         element_name, workspace = workspaces[0]
    
    162 165
         return element_name, workspace_object.project_path, workspace
    
    ... ... @@ -1068,25 +1071,35 @@ def test_multiple_failed_builds(cli, tmpdir, datafiles):
    1068 1071
     @pytest.mark.parametrize('subdir', [True, False], ids=["subdir", "no-subdir"])
    
    1069 1072
     @pytest.mark.parametrize("guess_element", [True, False], ids=["guess", "no-guess"])
    
    1070 1073
     def test_external_fetch(cli, datafiles, tmpdir_factory, subdir, guess_element):
    
    1071
    -    # Fetching from a workspace outside a project doesn't fail horribly
    
    1074
    +    # An element with an open workspace can't be fetched, but we still expect fetches
    
    1075
    +    # to fetch any dependencies
    
    1072 1076
         tmpdir = tmpdir_factory.mktemp('')
    
    1073
    -    element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
    
    1077
    +    depend_element = 'fetchable.bst'
    
    1078
    +
    
    1079
    +    # Create an element to fetch (local sources do not need to fetch)
    
    1080
    +    create_element_size(depend_element, str(datafiles), 'elements', [], 1024)
    
    1081
    +
    
    1082
    +    element_name, project, workspace = open_workspace(
    
    1083
    +        cli, tmpdir, datafiles, "git", False, no_checkout=True,
    
    1084
    +        element_attrs={'depends': [depend_element]}
    
    1085
    +    )
    
    1074 1086
         arg_elm = [element_name] if not guess_element else []
    
    1075 1087
     
    
    1076 1088
         if subdir:
    
    1077 1089
             call_dir = os.path.join(workspace, 'usr')
    
    1090
    +        os.makedirs(call_dir, exist_ok=True)
    
    1078 1091
         else:
    
    1079 1092
             call_dir = workspace
    
    1080 1093
     
    
    1094
    +    # Assert that the depended element is not fetched yet
    
    1095
    +    assert cli.get_element_state(str(datafiles), depend_element) == 'fetch needed'
    
    1096
    +
    
    1097
    +    # Fetch the workspaced element
    
    1081 1098
         result = cli.run(project=project, args=['-C', call_dir, 'source', 'fetch'] + arg_elm)
    
    1082 1099
         result.assert_success()
    
    1083 1100
     
    
    1084
    -    # We already fetched it by opening the workspace, but we're also checking
    
    1085
    -    # `bst show` works here
    
    1086
    -    result = cli.run(project=project,
    
    1087
    -                     args=['-C', call_dir, 'show', '--deps', 'none', '--format', '%{state}'] + arg_elm)
    
    1088
    -    result.assert_success()
    
    1089
    -    assert result.output.strip() == 'buildable'
    
    1101
    +    # Assert that the depended element has now been fetched
    
    1102
    +    assert cli.get_element_state(str(datafiles), depend_element) == 'buildable'
    
    1090 1103
     
    
    1091 1104
     
    
    1092 1105
     @pytest.mark.datafiles(DATA_DIR)
    
    ... ... @@ -1115,16 +1128,24 @@ def test_external_push_pull(cli, datafiles, tmpdir_factory, guess_element):
    1115 1128
     @pytest.mark.datafiles(DATA_DIR)
    
    1116 1129
     @pytest.mark.parametrize("guess_element", [True, False], ids=["guess", "no-guess"])
    
    1117 1130
     def test_external_track(cli, datafiles, tmpdir_factory, guess_element):
    
    1118
    -    # Tracking does not get horribly confused
    
    1119 1131
         tmpdir = tmpdir_factory.mktemp('')
    
    1120
    -    element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", True)
    
    1132
    +    element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
    
    1133
    +    element_file = os.path.join(str(datafiles), 'elements', element_name)
    
    1121 1134
         arg_elm = [element_name] if not guess_element else []
    
    1122 1135
     
    
    1123
    -    # The workspace is necessarily already tracked, so we only care that
    
    1124
    -    # there's no weird errors.
    
    1136
    +    # Delete the ref from the source so that we can detect if the
    
    1137
    +    # element has been tracked
    
    1138
    +    element_contents = _yaml.load(element_file)
    
    1139
    +    del element_contents['sources'][0]['ref']
    
    1140
    +    _yaml.dump(_yaml.node_sanitize(element_contents), element_file)
    
    1141
    +
    
    1125 1142
         result = cli.run(project=project, args=['-C', workspace, 'source', 'track'] + arg_elm)
    
    1126 1143
         result.assert_success()
    
    1127 1144
     
    
    1145
    +    # Element is tracked now
    
    1146
    +    element_contents = _yaml.load(element_file)
    
    1147
    +    assert 'ref' in element_contents['sources'][0]
    
    1148
    +
    
    1128 1149
     
    
    1129 1150
     @pytest.mark.datafiles(DATA_DIR)
    
    1130 1151
     def test_external_open_other(cli, datafiles, tmpdir_factory):
    

  • tox.ini
    ... ... @@ -5,9 +5,9 @@ skip_missing_interpreters = true
    5 5
     [testenv]
    
    6 6
     commands = pytest {posargs}
    
    7 7
     deps =
    
    8
    -    -rtools/requirements.txt
    
    9
    -    -rtools/dev-requirements.txt
    
    10
    -    -rtools/plugin-requirements.txt
    
    8
    +    -rrequirements/requirements.txt
    
    9
    +    -rrequirements/dev-requirements.txt
    
    10
    +    -rrequirements/plugin-requirements.txt
    
    11 11
     passenv =
    
    12 12
         BST_FORCE_BACKEND
    
    13 13
         GI_TYPELIB_PATH
    
    ... ... @@ -18,9 +18,9 @@ commands =
    18 18
         pycodestyle
    
    19 19
         pylint buildstream
    
    20 20
     deps =
    
    21
    -    -rtools/requirements.txt
    
    22
    -    -rtools/dev-requirements.txt
    
    23
    -    -rtools/plugin-requirements.txt
    
    21
    +    -rrequirements/requirements.txt
    
    22
    +    -rrequirements/dev-requirements.txt
    
    23
    +    -rrequirements/plugin-requirements.txt
    
    24 24
     
    
    25 25
     [testenv:docs]
    
    26 26
     commands =
    
    ... ... @@ -30,8 +30,8 @@ deps =
    30 30
         sphinx==1.7.9
    
    31 31
         sphinx-click
    
    32 32
         sphinx_rtd_theme
    
    33
    -    -rtools/requirements.txt
    
    34
    -    -rtools/plugin-requirements.txt
    
    33
    +    -rrequirements/requirements.txt
    
    34
    +    -rrequirements/plugin-requirements.txt
    
    35 35
     passenv =
    
    36 36
         BST_FORCE_SESSION_REBUILD
    
    37 37
         BST_SOURCE_CACHE
    



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