Example #1
0
    def open(self):
        output = BytesIO()
        minify = JavascriptMinify(self._file.open(),
                                  output,
                                  quote_chars="'\"`")
        minify.minify()
        output.seek(0)

        if not self._verify_command:
            return output

        input_source = self._file.open().read()
        output_source = output.getvalue()

        with NamedTemporaryFile() as fh1, NamedTemporaryFile() as fh2:
            fh1.write(input_source)
            fh2.write(output_source)
            fh1.flush()
            fh2.flush()

            try:
                args = list(self._verify_command)
                args.extend([fh1.name, fh2.name])
                subprocess.check_output(args, stderr=subprocess.STDOUT)
            except subprocess.CalledProcessError as e:
                errors.warn('JS minification verification failed for %s:' %
                            (getattr(self._file, 'path', '<unknown>')))
                # Prefix each line with "Warning:" so mozharness doesn't
                # think these error messages are real errors.
                for line in e.output.splitlines():
                    errors.warn(line)

                return self._file.open()

        return output
Example #2
0
    def open(self):
        output = BytesIO()
        minify = JavascriptMinify(self._file.open(), output, quote_chars="'\"`")
        minify.minify()
        output.seek(0)

        if not self._verify_command:
            return output

        input_source = self._file.open().read()
        output_source = output.getvalue()

        with NamedTemporaryFile() as fh1, NamedTemporaryFile() as fh2:
            fh1.write(input_source)
            fh2.write(output_source)
            fh1.flush()
            fh2.flush()

            try:
                args = list(self._verify_command)
                args.extend([fh1.name, fh2.name])
                subprocess.check_output(args, stderr=subprocess.STDOUT)
            except subprocess.CalledProcessError as e:
                errors.warn('JS minification verification failed for %s:' %
                    (getattr(self._file, 'path', '<unknown>')))
                # Prefix each line with "Warning:" so mozharness doesn't
                # think these error messages are real errors.
                for line in e.output.splitlines():
                    errors.warn(line)

                return self._file.open()

        return output
Example #3
0
 def test_multiple_errors(self):
     with self.assertRaises(AccumulatedErrors):
         with errors.accumulate():
             errors.error('foo')
             for i in range(3):
                 if i == 2:
                     errors.warn('%d' % i)
                 else:
                     errors.error('%d' % i)
             errors.error('bar')
     self.assertEquals(self.get_output(),
                       ['Error: foo', 'Error: 0', 'Error: 1',
                        'Warning: 2', 'Error: bar'])
Example #4
0
 def test_multiple_errors(self):
     with self.assertRaises(AccumulatedErrors):
         with errors.accumulate():
             errors.error("foo")
             for i in range(3):
                 if i == 2:
                     errors.warn("%d" % i)
                 else:
                     errors.error("%d" % i)
             errors.error("bar")
     self.assertEquals(
         self.get_output(),
         ["Error: foo", "Error: 0", "Error: 1", "Warning: 2", "Error: bar"],
     )
Example #5
0
    def add_manifest(self, entry):
        # Store manifest entries in a single manifest per directory, named
        # after their parent directory, except for root manifests, all named
        # chrome.manifest.
        if entry.base:
            name = mozpath.basename(entry.base)
        else:
            name = 'chrome'
        path = mozpath.normpath(mozpath.join(entry.base, '%s.manifest' % name))
        if not self.copier.contains(path):
            # Add a reference to the manifest file in the parent manifest, if
            # the manifest file is not a root manifest.
            if entry.base:
                parent = mozpath.dirname(entry.base)
                relbase = mozpath.basename(entry.base)
                relpath = mozpath.join(relbase,
                                       mozpath.basename(path))
                self.add_manifest(Manifest(parent, relpath))
            self.copier.add(path, ManifestFile(entry.base))

        if isinstance(entry, ManifestChrome):
            data = self._chrome_db.setdefault(entry.name, {})
            if isinstance(entry, ManifestMultiContent):
                entries = data.setdefault(entry.type, {}) \
                              .setdefault(entry.id, [])
            else:
                entries = data.setdefault(entry.type, [])
            for e in entries:
                # Ideally, we'd actually check whether entry.flags are more
                # specific than e.flags, but in practice the following test
                # is enough for now.
                if entry == e:
                    errors.warn('"%s" is duplicated. Skipping.' % entry)
                    return
                if not entry.flags or e.flags and entry.flags == e.flags:
                    errors.fatal('"%s" overrides "%s"' % (entry, e))
            entries.append(entry)

        self.copier[path].add(entry)
Example #6
0
    def open(self):
        output = six.StringIO()
        minify = JavascriptMinify(codecs.getreader("utf-8")(self._file.open()),
                                  output,
                                  quote_chars="'\"`")
        minify.minify()
        output.seek(0)
        output_source = six.ensure_binary(output.getvalue())
        output = BytesIO(output_source)

        if not self._verify_command:
            return output

        input_source = self._file.open().read()

        with NamedTemporaryFile("wb+") as fh1, NamedTemporaryFile(
                "wb+") as fh2:
            fh1.write(input_source)
            fh2.write(output_source)
            fh1.flush()
            fh2.flush()

            try:
                args = list(self._verify_command)
                args.extend([fh1.name, fh2.name])
                subprocess.check_output(args,
                                        stderr=subprocess.STDOUT,
                                        universal_newlines=True)
            except subprocess.CalledProcessError as e:
                errors.warn("JS minification verification failed for %s:" %
                            (getattr(self._file, "path", "<unknown>")))
                # Prefix each line with "Warning:" so mozharness doesn't
                # think these error messages are real errors.
                for line in e.output.splitlines():
                    errors.warn(line)

                return self._file.open()

        return output
Example #7
0
    def add_manifest(self, entry):
        # Store manifest entries in a single manifest per directory, named
        # after their parent directory, except for root manifests, all named
        # chrome.manifest.
        if entry.base:
            name = mozpath.basename(entry.base)
        else:
            name = 'chrome'
        path = mozpath.normpath(mozpath.join(entry.base, '%s.manifest' % name))
        if not self.copier.contains(path):
            # Add a reference to the manifest file in the parent manifest, if
            # the manifest file is not a root manifest.
            if entry.base:
                parent = mozpath.dirname(entry.base)
                relbase = mozpath.basename(entry.base)
                relpath = mozpath.join(relbase,
                                            mozpath.basename(path))
                self.add_manifest(Manifest(parent, relpath))
            self.copier.add(path, ManifestFile(entry.base))

        if isinstance(entry, ManifestChrome):
            data = self._chrome_db.setdefault(entry.name, {})
            if isinstance(entry, ManifestMultiContent):
                entries = data.setdefault(entry.type, {}) \
                              .setdefault(entry.id, [])
            else:
                entries = data.setdefault(entry.type, [])
            for e in entries:
                # Ideally, we'd actually check whether entry.flags are more
                # specific than e.flags, but in practice the following test
                # is enough for now.
                if entry == e:
                    errors.warn('"%s" is duplicated. Skipping.' % entry)
                    return
                if not entry.flags or e.flags and entry.flags == e.flags:
                    errors.fatal('"%s" overrides "%s"' % (entry, e))
            entries.append(entry)

        self.copier[path].add(entry)
Example #8
0
 def test_no_error(self):
     with errors.accumulate():
         errors.warn('1')
Example #9
0
 def test_ignore_errors(self):
     errors.ignore_errors()
     errors.warn('foo')
     errors.error('bar')
     self.assertRaises(ErrorMessage, errors.fatal, 'foo')
     self.assertEquals(self.get_output(), ['Warning: foo', 'Warning: bar'])
Example #10
0
 def test_plain_error(self):
     errors.warn('foo')
     self.assertRaises(ErrorMessage, errors.error, 'foo')
     self.assertRaises(ErrorMessage, errors.fatal, 'foo')
     self.assertEquals(self.get_output(), ['Warning: foo'])
Example #11
0
 def test_ignore_errors(self):
     errors.ignore_errors()
     errors.warn("foo")
     errors.error("bar")
     self.assertRaises(ErrorMessage, errors.fatal, "foo")
     self.assertEquals(self.get_output(), ["Warning: foo", "Warning: bar"])
Example #12
0
 def test_plain_error(self):
     errors.warn("foo")
     self.assertRaises(ErrorMessage, errors.error, "foo")
     self.assertRaises(ErrorMessage, errors.fatal, "foo")
     self.assertEquals(self.get_output(), ["Warning: foo"])