예제 #1
0
    def test_simple(self):
        simple_dict = {
            "schema": 1,
            "origin": {
                "description": "2D Graphics Library",
                "license": ["MPL-1.1", "LGPL-2.1"],
                "name": "cairo",
                "release": "version 1.6.4",
                "revision": "AA001122334455",
                "url": "https://www.cairographics.org/",
            },
            "bugzilla": {
                "component": "Graphics",
                "product": "Core",
            },
        }
        with mozfile.NamedTemporaryFile() as tf:
            tf.write(b"""
---
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
  revision: AA001122334455
bugzilla:
  product: Core
  component: Graphics
            """.strip())
            tf.flush()
            self.assertDictEqual(
                load_moz_yaml(tf.name, require_license_file=False),
                simple_dict)

        # as above, without the --- yaml prefix
        with mozfile.NamedTemporaryFile() as tf:
            tf.write(b"""
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
  revision: AA001122334455
bugzilla:
  product: Core
  component: Graphics
            """.strip())
            tf.flush()
            self.assertDictEqual(
                load_moz_yaml(tf.name, require_license_file=False),
                simple_dict)
예제 #2
0
 def test_json(self):
     with mozfile.NamedTemporaryFile() as tf:
         tf.write('{"origin": {"release": "version 1.6.4", "url": "https://w'
                  'ww.cairographics.org/", "description": "2D Graphics Libra'
                  'ry", "license": ["MPL-1.1", "LGPL-2.1"], "name": "cairo"}'
                  ', "bugzilla": {"product": "Core", "component": "Graphics"'
                  '}, "schema": 1}')
         tf.flush()
         load_moz_yaml(tf.name, require_license_file=False)
예제 #3
0
    def test_simple(self):
        simple_dict = {
            'schema': 1,
            'origin': {
                'description': '2D Graphics Library',
                'license': ['MPL-1.1', 'LGPL-2.1'],
                'name': 'cairo',
                'release': 'version 1.6.4',
                'url': 'https://www.cairographics.org/',
            },
            'bugzilla': {
                'component': 'Graphics',
                'product': 'Core',
            },
        }
        with mozfile.NamedTemporaryFile() as tf:
            tf.write("""
---
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
bugzilla:
  product: Core
  component: Graphics
            """.strip())
            tf.flush()
            self.assertDictEqual(
                load_moz_yaml(tf.name, require_license_file=False), simple_dict)

        # as above, without the --- yaml prefix
        with mozfile.NamedTemporaryFile() as tf:
            tf.write("""
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
bugzilla:
  product: Core
  component: Graphics
            """.strip())
            tf.flush()
            self.assertDictEqual(
                load_moz_yaml(tf.name, require_license_file=False), simple_dict)
예제 #4
0
 def process_test_vectors(self, test_vectors):
     index = 0
     for vector in test_vectors:
         print("Testing index", index)
         expected, yaml = vector
         with mozfile.NamedTemporaryFile() as tf:
             tf.write(yaml)
             tf.flush()
             if expected == "exception":
                 with self.assertRaises(MozYamlVerifyError):
                     load_moz_yaml(tf.name, require_license_file=False)
             else:
                 self.assertDictEqual(
                     load_moz_yaml(tf.name, require_license_file=False), expected
                 )
         index += 1
예제 #5
0
def vendor(
    command_context,
    library,
    revision,
    ignore_modified=False,
    check_for_update=False,
    add_to_exports=False,
    verify=False,
):
    """
    Vendor third-party dependencies into the source repository.

    Vendoring rust and python can be done with ./mach vendor [rust/python].
    Vendoring other libraries can be done with ./mach vendor [arguments] path/to/file.yaml
    """
    library = library[0]
    assert library not in ["rust", "python"]

    command_context.populate_logger()
    command_context.log_manager.enable_unstructured()
    if check_for_update:
        logging.disable(level=logging.CRITICAL)

    try:
        manifest = load_moz_yaml(library)
        if verify:
            print("%s: OK" % library)
            sys.exit(0)
    except MozYamlVerifyError as e:
        print(e)
        sys.exit(1)

    if not ignore_modified and not check_for_update:
        check_modified_files(command_context)
    if not revision:
        revision = "HEAD"

    from mozbuild.vendor.vendor_manifest import VendorManifest

    vendor_command = command_context._spawn(VendorManifest)
    vendor_command.vendor(library, manifest, revision, check_for_update,
                          add_to_exports)

    sys.exit(0)
예제 #6
0
    def test_updatebot(self):
        test_vectors = [
            (
                {
                    "schema": 1,
                    "origin": {
                        "description": "2D Graphics Library",
                        "license": ["MPL-1.1", "LGPL-2.1"],
                        "name": "cairo",
                        "release": "version 1.6.4",
                        "revision": "AA001122334455",
                        "url": "https://www.cairographics.org/",
                    },
                    "bugzilla": {
                        "component": "Graphics",
                        "product": "Core",
                    },
                    "updatebot": {
                        "maintainer-phab": "tjr",
                        "maintainer-bz": "*****@*****.**",
                    },
                },
                b"""
---
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
  revision: AA001122334455
bugzilla:
  product: Core
  component: Graphics
updatebot:
  maintainer-phab: tjr
  maintainer-bz: [email protected]
            """.strip(),
            ),
            # -------------------------------------------------
            (
                {
                    "schema": 1,
                    "origin": {
                        "description": "2D Graphics Library",
                        "license": ["MPL-1.1", "LGPL-2.1"],
                        "name": "cairo",
                        "release": "version 1.6.4",
                        "revision": "AA001122334455",
                        "url": "https://www.cairographics.org/",
                    },
                    "bugzilla": {
                        "component": "Graphics",
                        "product": "Core",
                    },
                    "vendoring": {
                        "url": "https://example.com",
                        "source-hosting": "gitlab",
                    },
                    "updatebot": {
                        "maintainer-phab": "tjr",
                        "maintainer-bz": "*****@*****.**",
                        "tasks": [{
                            "type": "commit-alert"
                        }],
                    },
                },
                b"""
---
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
  revision: AA001122334455
vendoring:
  url: https://example.com
  source-hosting: gitlab
bugzilla:
  product: Core
  component: Graphics
updatebot:
  maintainer-phab: tjr
  maintainer-bz: [email protected]
  tasks:
    - type: commit-alert
            """.strip(),
            ),
            # -------------------------------------------------
            (
                {
                    "schema": 1,
                    "origin": {
                        "description": "2D Graphics Library",
                        "license": ["MPL-1.1", "LGPL-2.1"],
                        "name": "cairo",
                        "release": "version 1.6.4",
                        "revision": "AA001122334455",
                        "url": "https://www.cairographics.org/",
                    },
                    "bugzilla": {
                        "component": "Graphics",
                        "product": "Core",
                    },
                    "vendoring": {
                        "url": "https://example.com",
                        "source-hosting": "gitlab",
                    },
                    "updatebot": {
                        "maintainer-phab":
                        "tjr",
                        "maintainer-bz":
                        "*****@*****.**",
                        "tasks": [
                            {
                                "type": "commit-alert"
                            },
                            {
                                "type": "vendoring",
                                "branch": "foo",
                                "enabled": False,
                                "cc": ["*****@*****.**"],
                                "needinfo": ["*****@*****.**"],
                            },
                        ],
                    },
                },
                b"""
---
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
  revision: AA001122334455
vendoring:
  url: https://example.com
  source-hosting: gitlab
bugzilla:
  product: Core
  component: Graphics
updatebot:
  maintainer-phab: tjr
  maintainer-bz: [email protected]
  tasks:
    - type: commit-alert
    - type: vendoring
      enabled: False
      branch: foo
      cc: ["*****@*****.**"]
      needinfo: ["*****@*****.**"]
            """.strip(),
            ),
            # -------------------------------------------------
            (
                {
                    "schema": 1,
                    "origin": {
                        "description": "2D Graphics Library",
                        "license": ["MPL-1.1", "LGPL-2.1"],
                        "name": "cairo",
                        "release": "version 1.6.4",
                        "revision": "AA001122334455",
                        "url": "https://www.cairographics.org/",
                    },
                    "bugzilla": {
                        "component": "Graphics",
                        "product": "Core",
                    },
                    "vendoring": {
                        "url": "https://example.com",
                        "source-hosting": "gitlab",
                    },
                    "updatebot": {
                        "maintainer-phab":
                        "tjr",
                        "maintainer-bz":
                        "*****@*****.**",
                        "tasks": [
                            {
                                "type": "vendoring",
                                "branch": "foo",
                                "enabled": False,
                                "cc": ["*****@*****.**", "*****@*****.**"],
                                "needinfo": ["*****@*****.**", "*****@*****.**"],
                            },
                            {
                                "type": "commit-alert",
                                "filter": "none",
                                "source-extensions": [".c", ".cpp"],
                            },
                        ],
                    },
                },
                b"""
---
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
  revision: AA001122334455
vendoring:
  url: https://example.com
  source-hosting: gitlab
bugzilla:
  product: Core
  component: Graphics
updatebot:
  maintainer-phab: tjr
  maintainer-bz: [email protected]
  tasks:
    - type: vendoring
      enabled: False
      branch: foo
      cc:
        - [email protected]
        - [email protected]
      needinfo:
        - [email protected]
        - [email protected]
    - type: commit-alert
      filter: none
      source-extensions:
        - .c
        - .cpp
            """.strip(),
            ),
            # -------------------------------------------------
            (
                "exception",
                b"""
---
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
  revision: AA001122334455
bugzilla:
  product: Core
  component: Graphics
updatebot:
  maintainer-phab: tjr
  maintainer-bz: [email protected]
  tasks:
    - type: vendoring
      enabled: False
      branch: foo
      cc:
        - [email protected]
        - [email protected]
    - type: commit-alert
      filter: none
      source-extensions:
        - .c
        - .cpp
            """.strip(),
            ),
            # -------------------------------------------------
            (
                "exception",
                b"""
---
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
bugzilla:
  product: Core
  component: Graphics
vendoring:
  url: https://example.com
  source-hosting: gitlab
updatebot:
  maintainer-phab: tjr
  maintainer-bz: [email protected]
  tasks:
    - type: vendoring
      enabled: False
      branch: foo
      cc:
        - [email protected]
        - [email protected]
    - type: commit-alert
      filter: none
      source-extensions:
        - .c
        - .cpp
            """.strip(),
            ),
            # -------------------------------------------------
            (
                "exception",
                b"""
---
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
  revision: AA001122334455
vendoring:
  url: https://example.com
  source-hosting: gitlab
bugzilla:
  product: Core
  component: Graphics
updatebot:
  maintainer-phab: tjr
  maintainer-bz: [email protected]
  tasks:
    - type: vendoring
      filter: none
            """.strip(),
            ),
            # -------------------------------------------------
            (
                "exception",
                b"""
---
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
  revision: AA001122334455
vendoring:
  url: https://example.com
  source-hosting: gitlab
bugzilla:
  product: Core
  component: Graphics
updatebot:
  maintainer-phab: tjr
  maintainer-bz: [email protected]
  tasks:
    - type: foo
            """.strip(),
            ),
            # -------------------------------------------------
            (
                "exception",
                b"""
---
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
  revision: AA001122334455
vendoring:
  url: https://example.com
  source-hosting: gitlab
bugzilla:
  product: Core
  component: Graphics
updatebot:
  maintainer-phab: tjr
  maintainer-bz: [email protected]
  tasks:
    - type: vendoring
      source-extensions:
        - .c
        - .cpp
            """.strip(),
            ),
            # -------------------------------------------------
            (
                "exception",
                b"""
---
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
  revision: AA001122334455
vendoring:
  url: https://example.com
  source-hosting: gitlab
bugzilla:
  product: Core
  component: Graphics
updatebot:
  maintainer-phab: tjr
  maintainer-bz: [email protected]
  tasks:
    - type: commit-alert
      filter: hogwash
            """.strip(),
            ),
            (
                "exception",
                b"""
---
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
  revision: AA001122334455
bugzilla:
  product: Core
  component: Graphics
vendoring:
  url: https://example.com
  source-hosting: gitlab
updatebot:
  maintainer-phab: tjr
  maintainer-bz: [email protected]
  tasks:
    - type: vendoring
      enabled: False
      branch: foo
      cc:
        - [email protected]
        - [email protected]
    - type: commit-alert
    - type: commit-alert
      filter: none
      source-extensions:
        - .c
        - .cpp""".strip(),
            ),
            (
                "exception",
                b"""
---
schema: 1
origin:
  name: cairo
  description: 2D Graphics Library
  url: https://www.cairographics.org/
  release: version 1.6.4
  license:
    - MPL-1.1
    - LGPL-2.1
  revision: AA001122334455
bugzilla:
  product: Core
  component: Graphics
vendoring:
  url: https://example.com
  source-hosting: gitlab
updatebot:
  maintainer-phab: tjr
  maintainer-bz: [email protected]
  tasks:
    - type: vendoring
      enabled: False
      branch: foo
      cc:
        - [email protected]
        - [email protected]
    - type: vendoring
    - type: commit-alert
      filter: none
      source-extensions:
        - .c
        - .cpp""".strip(),
            ),
        ]

        indx = 0
        for vector in test_vectors:
            print("Testing index", indx)
            expected, yaml = vector
            with mozfile.NamedTemporaryFile() as tf:
                tf.write(yaml)
                tf.flush()
                if expected == "exception":
                    with self.assertRaises(MozYamlVerifyError):
                        load_moz_yaml(tf.name, require_license_file=False)
                else:
                    self.assertDictEqual(
                        load_moz_yaml(tf.name, require_license_file=False),
                        expected)
            indx += 1
예제 #7
0
 def test_bad_schema(self):
     with mozfile.NamedTemporaryFile() as tf:
         tf.write(b"schema: 99")
         tf.flush()
         with self.assertRaises(MozYamlVerifyError):
             load_moz_yaml(tf.name, require_license_file=False)
예제 #8
0
 def test_bad_schema(self):
     with mozfile.NamedTemporaryFile() as tf:
         tf.write('schema: 99')
         tf.flush()
         load_moz_yaml(tf.name, require_license_file=False)
예제 #9
0
 def test_malformed(self):
     with mozfile.NamedTemporaryFile() as tf:
         tf.write('blah')
         tf.flush()
         load_moz_yaml(tf.name, require_license_file=False)