[Pkg-javascript-commits] [highlight.js] 04/04: Update patches and tests

Ximin Luo infinity0 at debian.org
Tue May 16 13:08:43 UTC 2017


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository highlight.js.

commit e7b155c014935d1a57e7b627be9f89b750533a15
Author: Ximin Luo <infinity0 at debian.org>
Date:   Tue May 16 15:06:39 2017 +0200

    Update patches and tests
---
 debian/changelog                                   |   7 +
 debian/control                                     |   4 +
 debian/patches/fixup-tests.patch                   |  16 +
 debian/patches/no-bluebird.patch                   | 178 ++++++++++
 debian/patches/no-jsdom.patch                      |  29 ++
 ...h => python-buildsystem-modify-build-dir.patch} |  23 +-
 debian/patches/python-buildsystem-update.patch     |  62 ++++
 .../patches/restore-old-python-buildsystem.patch   | 370 +++++++++++++++++++++
 debian/patches/series                              |   7 +-
 debian/rules                                       |  12 +-
 10 files changed, 698 insertions(+), 10 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index d4abc61..e6b5526 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+highlight.js (9.11.0-1) UNRELEASED; urgency=medium
+
+  * Import new upstream release.
+  * Run as many tests as possible.
+
+ -- Ximin Luo <infinity0 at debian.org>  Tue, 16 May 2017 13:20:23 +0200
+
 highlight.js (8.2+ds-5) unstable; urgency=medium
 
   * add new dependencies (Closes: #830189)
diff --git a/debian/control b/debian/control
index 04b126f..4bff3ef 100644
--- a/debian/control
+++ b/debian/control
@@ -6,6 +6,10 @@ Uploaders: Cédric Boutillier <boutil at debian.org>
           , Thorsten Alteholz <debian at alteholz.de>
 Build-Depends: debhelper (>= 9), node-uglify | yui-compressor, python3,
  python3-sphinx,
+ mocha <!nocheck>,
+ node-jsdom <!nocheck>,
+ node-lodash <!nocheck>,
+ node-should <!nocheck>,
  texlive-latex-base,
  texlive-latex-extra,
  texlive-fonts-recommended,
diff --git a/debian/patches/fixup-tests.patch b/debian/patches/fixup-tests.patch
new file mode 100644
index 0000000..f64ae45
--- /dev/null
+++ b/debian/patches/fixup-tests.patch
@@ -0,0 +1,16 @@
+Description: Disable failing tests
+Author: Ximin Luo <infinity0 at debian.org>
+Bug: https://github.com/isagalaev/highlight.js/issues/1522
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+Index: highlight.js/test/detect/index.js
+===================================================================
+--- highlight.js.orig/test/detect/index.js
++++ highlight.js/test/detect/index.js
+@@ -32,5 +32,5 @@ function testAutoDetection(language) {
+ describe('hljs.highlightAuto()', function() {
+   const languages = hljs.listLanguages();
+ 
+-  languages.forEach(testAutoDetection);
++  languages.filter(x => x != "javascript" && x != "java" && x != "coffeescript" && x != "fortran").forEach(testAutoDetection);
+ });
diff --git a/debian/patches/no-bluebird.patch b/debian/patches/no-bluebird.patch
new file mode 100644
index 0000000..2dd1429
--- /dev/null
+++ b/debian/patches/no-bluebird.patch
@@ -0,0 +1,178 @@
+Description: Don't use bluebird, it's not in Debian
+ Use synchronise operations instead, we really don't care about async in tests
+Author: Ximin Luo <infinity0 at debian.org>
+Forwarded: not-needed
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+Index: highlight.js/test/browser/plain.js
+===================================================================
+--- highlight.js.orig/test/browser/plain.js
++++ highlight.js/test/browser/plain.js
+@@ -1,9 +1,8 @@
+ 'use strict';
+ 
+-let bluebird = require('bluebird');
+-let jsdomEnv = bluebird.promisify(require('jsdom').env);
++let jsdomEnv = require('jsdom').env;
+ let utility  = require('../utility');
+-let glob     = bluebird.promisify(require('glob'));
++let glob     = require('glob');
+ 
+ describe('plain browser', function() {
+   before(function() {
+Index: highlight.js/test/browser/worker.js
+===================================================================
+--- highlight.js.orig/test/browser/worker.js
++++ highlight.js/test/browser/worker.js
+@@ -1,9 +1,8 @@
+ 'use strict';
+ 
+-let bluebird = require('bluebird');
+ let Worker   = require('tiny-worker');
+ let utility  = require('../utility');
+-let glob     = bluebird.promisify(require('glob'));
++let glob     = require('glob');
+ 
+ describe('web worker', function() {
+   before(function(done) {
+Index: highlight.js/test/detect/index.js
+===================================================================
+--- highlight.js.orig/test/detect/index.js
++++ highlight.js/test/detect/index.js
+@@ -1,7 +1,6 @@
+ 'use strict';
+ 
+-let bluebird = require('bluebird');
+-let fs       = bluebird.promisifyAll(require('fs'));
++let fs       = require('fs');
+ let hljs     = require('../../build');
+ let path     = require('path');
+ let utility  = require('../utility');
+@@ -10,18 +9,18 @@ function testAutoDetection(language) {
+   const languagePath = utility.buildPath('detect', language);
+ 
+   it(`should have test for ${language}`, function() {
+-    return fs.statAsync(languagePath)
+-      .then(path => path.isDirectory().should.be.true);
++    let path = fs.statSync(languagePath);
++    path.isDirectory().should.be.true;
+   });
+ 
+   it(`should be detected as ${language}`, function() {
+-    return fs.readdirAsync(languagePath)
++    return fs.readdirSync(languagePath)
+       .map(function(example) {
+         const filename = path.join(languagePath, example);
+ 
+-        return fs.readFileAsync(filename, 'utf-8');
++        return fs.readFileSync(filename, 'utf-8');
+       })
+-      .each(function(content) {
++      .forEach(function(content) {
+         const expected = language,
+               actual   = hljs.highlightAuto(content).language;
+ 
+Index: highlight.js/test/markup/index.js
+===================================================================
+--- highlight.js.orig/test/markup/index.js
++++ highlight.js/test/markup/index.js
+@@ -1,8 +1,7 @@
+ 'use strict';
+ 
+ let _        = require('lodash');
+-let bluebird = require('bluebird');
+-let fs       = bluebird.promisifyAll(require('fs'));
++let fs       = require('fs');
+ let glob     = require('glob');
+ let hljs     = require('../../build');
+ let path     = require('path');
+@@ -18,15 +17,13 @@ function testLanguage(language) {
+             sourceName = filename.replace(/\.expect/, '');
+ 
+       it(`should markup ${testName}`, function(done) {
+-        const sourceFile   = fs.readFileAsync(sourceName, 'utf-8'),
+-              expectedFile = fs.readFileAsync(filename, 'utf-8');
++        const source   = fs.readFileSync(sourceName, 'utf-8'),
++              expected = fs.readFileSync(filename, 'utf-8');
+ 
+-        bluebird.join(sourceFile, expectedFile, function(source, expected) {
+-          const actual = hljs.highlight(language, source).value;
++        const actual = hljs.highlight(language, source).value;
+ 
+-          actual.trim().should.equal(expected.trim());
+-          done();
+-        });
++        actual.trim().should.equal(expected.trim());
++        done();
+       });
+     });
+   });
+@@ -35,5 +32,5 @@ function testLanguage(language) {
+ describe('hljs.highlight()', function() {
+   let markupPath = utility.buildPath('markup');
+ 
+-  return fs.readdirAsync(markupPath).each(testLanguage);
++  return fs.readdirSync(markupPath).forEach(testLanguage);
+ });
+Index: highlight.js/test/utility.js
+===================================================================
+--- highlight.js.orig/test/utility.js
++++ highlight.js/test/utility.js
+@@ -1,8 +1,7 @@
+ 'use strict';
+ 
+ let _        = require('lodash');
+-let bluebird = require('bluebird');
+-let readFile = bluebird.promisify(require('fs').readFile);
++let fs       = require('fs');
+ let path     = require('path');
+ 
+ // Build a path relative to `test/`
+@@ -16,14 +15,12 @@ exports.buildPath = function() {
+ exports.numberToString = _.method('toString');
+ 
+ exports.expectedFile = function(filename, encoding, actual) {
+-  return readFile(filename, encoding)
+-    .then(expected => actual.trim().should.equal(expected.trim()));
++  let expected = fs.readFileSync(filename, encoding);
++  actual.trim().should.equal(expected.trim());
+ };
+ 
+ exports.setupFile = function(filename, encoding, that, testHTML) {
+-  return readFile(filename, encoding)
+-    .then(expected => {
+-      that.expected = expected.trim();
+-      that.blocks   = _.map(testHTML, 'innerHTML');
+-    });
++  let expected = fs.readFileSync(filename, encoding);
++  that.expected = expected.trim();
++  that.blocks   = _.map(testHTML, 'innerHTML');
+ };
+Index: highlight.js/test/special/index.js
+===================================================================
+--- highlight.js.orig/test/special/index.js
++++ highlight.js/test/special/index.js
+@@ -1,19 +1,17 @@
+ 'use strict';
+ 
+ let _        = require('lodash');
+-let bluebird = require('bluebird');
+ let hljs     = require('../../build');
+-let jsdomEnv = bluebird.promisify(require('jsdom').env);
+-let readFile = bluebird.promisify(require('fs').readFile);
++let jsdomEnv = require('jsdom').env;
++let fs       = require('fs');
+ let utility  = require('../utility');
+ 
+ describe('special cases tests', function() {
+   before(function() {
+     const filename = utility.buildPath('fixtures', 'index.html');
+ 
+-    return readFile(filename, 'utf-8')
+-      .then(page => jsdomEnv(page))
+-      .then(window => {
++    let page = fs.readFileSync(filename, 'utf-8');
++    jsdomEnv(page, function(errors, window) {
+         let blocks;
+ 
+         // Allows hljs to use document
diff --git a/debian/patches/no-jsdom.patch b/debian/patches/no-jsdom.patch
new file mode 100644
index 0000000..5c77f65
--- /dev/null
+++ b/debian/patches/no-jsdom.patch
@@ -0,0 +1,29 @@
+Description: Disable jsdom node tests, jsdom isn't in Debian
+Author: Ximin Luo <infinity0 at debian.org>
+Forwarded: not-needed
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+Index: highlight.js/test/special/index.js
+===================================================================
+--- highlight.js.orig/test/special/index.js
++++ highlight.js/test/special/index.js
+@@ -2,11 +2,11 @@
+ 
+ let _        = require('lodash');
+ let hljs     = require('../../build');
+-let jsdomEnv = require('jsdom').env;
++//let jsdomEnv = require('jsdom').env;
+ let fs       = require('fs');
+ let utility  = require('../utility');
+ 
+-describe('special cases tests', function() {
++/*describe('special cases tests', function() {
+   before(function() {
+     const filename = utility.buildPath('fixtures', 'index.html');
+ 
+@@ -40,4 +40,4 @@ describe('special cases tests', function
+   require('./buildClassName');
+   require('./useBr');
+   require('./endsWithParentVariants')
+-});
++});*/
diff --git a/debian/patches/modify_build_dir.patch b/debian/patches/python-buildsystem-modify-build-dir.patch
similarity index 57%
rename from debian/patches/modify_build_dir.patch
rename to debian/patches/python-buildsystem-modify-build-dir.patch
index 1b47ff8..d07d33c 100644
--- a/debian/patches/modify_build_dir.patch
+++ b/debian/patches/python-buildsystem-modify-build-dir.patch
@@ -3,9 +3,24 @@ Description: modify build_dir according to the target
 Author: Cédric Boutillier <boutil at debian.org>
 Last-Update: 2013-11-07
 
---- a/tools/build.py
-+++ b/tools/build.py
-@@ -287,8 +287,8 @@
+Index: highlight.js/tools/developer.html
+===================================================================
+--- highlight.js.orig/tools/developer.html
++++ highlight.js/tools/developer.html
+@@ -49,7 +49,7 @@
+     </div>
+   </div>
+ 
+-  <script src="../build/highlight.pack.js"></script>
++  <script src="../build_browser/highlight.js"></script>
+   <script src="../demo/jquery-2.1.1.min.js"></script>
+ 
+   <script>
+Index: highlight.js/tools/build.py
+===================================================================
+--- highlight.js.orig/tools/build.py
++++ highlight.js/tools/build.py
+@@ -327,8 +327,8 @@ def build_cdn(root, build_path, filename
          content = compress_content(tools_path, utf8_open(filename).read(), 'css')
          utf8_open(os.path.join(build_style_path, '%s.min.css' % style), 'w').write(content)
  
@@ -16,7 +31,7 @@ Last-Update: 2013-11-07
      if os.path.exists(build_path):
          shutil.rmtree(build_path)
      os.mkdir(build_path)
-@@ -315,4 +315,5 @@
+@@ -355,4 +355,5 @@ if __name__ == '__main__':
      args = parser.parse_args()
      buildfunc = locals()['build_%s' % args.target]
      root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
diff --git a/debian/patches/python-buildsystem-update.patch b/debian/patches/python-buildsystem-update.patch
new file mode 100644
index 0000000..3f7e446
--- /dev/null
+++ b/debian/patches/python-buildsystem-update.patch
@@ -0,0 +1,62 @@
+Description: Update old python buildsystem for 9.11.0
+Author: Ximin Luo <infinity0 at debian.org>
+Bug: https://github.com/isagalaev/highlight.js/issues/1521
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+Index: highlight.js/src/highlight.js
+===================================================================
+--- highlight.js.orig/src/highlight.js
++++ highlight.js/src/highlight.js
+@@ -12,7 +12,7 @@ https://highlightjs.org/
+   // Setup highlight.js for different environments. First is Node.js or
+   // CommonJS.
+   if(typeof exports !== 'undefined') {
+-    factory(exports);
++    return factory(exports);
+   } else if(globalObject) {
+     // Export hljs globally even when using AMD for cases when this script
+     // is loaded with others that may still expect a global hljs.
+@@ -24,6 +24,8 @@ https://highlightjs.org/
+         return globalObject.hljs;
+       });
+     }
++
++    return globalObject.hljs;
+   }
+ 
+ }(function(hljs) {
+Index: highlight.js/tools/build.py
+===================================================================
+--- highlight.js.orig/tools/build.py
++++ highlight.js/tools/build.py
+@@ -134,7 +134,7 @@ def parse_header(filename):
+     if not match:
+         return
+     headers = match.group(1).split('\n')
+-    headers = dict(h.strip().split(': ') for h in headers if ': ' in h)
++    headers = dict(h.strip().split(': ', 1) for h in headers if ': ' in h)
+     return headers if 'Language' in headers else None
+ 
+ def language_filenames(src_path, languages):
+@@ -201,10 +201,10 @@ def glue_files(hljs_filename, language_f
+     Glues files together for the browser build.
+     '''
+     if compressed:
+-        hljs = 'var hljs=new %s();' % strip_read(hljs_filename).rstrip(';')
++        hljs = 'var hljs=%s;' % strip_read(hljs_filename)
+         file_func = lambda f: utf8_open(f).read()
+     else:
+-        hljs = 'var hljs = new %s();\n' % strip_read(hljs_filename)
++        hljs = 'var hljs = %s;\n' % strip_read(hljs_filename)
+         file_func = strip_read
+     return ''.join([hljs] + [wrap_language(f, file_func(f), compressed) for f in language_filenames])
+ 
+@@ -260,7 +260,7 @@ def build_node(root, build_path, filenam
+     utf8_open(os.path.join(build_path, 'lib', 'highlight.js'), 'w').write(core)
+ 
+     print('Registering languages with the library...')
+-    hljs = "var Highlight = require('./highlight');\nvar hljs = new Highlight();"
++    hljs = "var hljs = require('./highlight');"
+     filenames = map(os.path.basename, filenames)
+     for filename in filenames:
+         hljs += '\nhljs.registerLanguage(\'%s\', require(\'./languages/%s\'));' % (lang_name(filename), filename)
diff --git a/debian/patches/restore-old-python-buildsystem.patch b/debian/patches/restore-old-python-buildsystem.patch
new file mode 100644
index 0000000..15c4646
--- /dev/null
+++ b/debian/patches/restore-old-python-buildsystem.patch
@@ -0,0 +1,370 @@
+Description: Restore old python buildsystem
+Origin: https://raw.githubusercontent.com/isagalaev/highlight.js/708c3ca6a7739cf826fda9ee8c929c7fcbdb2210/tools/build.py
+Bug: https://github.com/isagalaev/highlight.js/issues/1521
+Comment: The commit is the last one before it was removed, see
+ https://github.com/isagalaev/highlight.js/commits/master/tools/build.py
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+Index: highlight.js/tools/build.py
+===================================================================
+--- /dev/null
++++ highlight.js/tools/build.py
+@@ -0,0 +1,358 @@
++# -*- coding:utf-8 -*-
++'''
++Function for building whole packed version of highlight.js out of
++pre-packed modules.
++'''
++
++import os
++import shutil
++import re
++import argparse
++import subprocess
++import json
++import codecs
++from functools import partial
++
++REPLACES = {
++    'case_insensitive': 'cI',
++    'lexemes': 'l',
++    'contains': 'c',
++    'keywords': 'k',
++    'subLanguage': 'sL',
++    'className': 'cN',
++    'begin': 'b',
++    'beginKeywords': 'bK',
++    'end': 'e',
++    'endsWithParent': 'eW',
++    'illegal': 'i',
++    'excludeBegin': 'eB',
++    'excludeEnd': 'eE',
++    'returnBegin': 'rB',
++    'returnEnd': 'rE',
++    'relevance': 'r',
++    'variants': 'v',
++
++    'IDENT_RE': 'IR',
++    'UNDERSCORE_IDENT_RE': 'UIR',
++    'NUMBER_RE': 'NR',
++    'C_NUMBER_RE': 'CNR',
++    'BINARY_NUMBER_RE': 'BNR',
++    'RE_STARTERS_RE': 'RSR',
++    'BACKSLASH_ESCAPE': 'BE',
++    'APOS_STRING_MODE': 'ASM',
++    'QUOTE_STRING_MODE': 'QSM',
++    'PHRASAL_WORDS_MODE': 'PWM',
++    'C_LINE_COMMENT_MODE': 'CLCM',
++    'C_BLOCK_COMMENT_MODE': 'CBCM',
++    'HASH_COMMENT_MODE': 'HCM',
++    'NUMBER_MODE': 'NM',
++    'C_NUMBER_MODE': 'CNM',
++    'BINARY_NUMBER_MODE': 'BNM',
++    'CSS_NUMBER_MODE': 'CSSNM',
++    'REGEXP_MODE': 'RM',
++    'TITLE_MODE': 'TM',
++    'UNDERSCORE_TITLE_MODE': 'UTM',
++
++    'beginRe': 'bR',
++    'endRe': 'eR',
++    'illegalRe': 'iR',
++    'lexemesRe': 'lR',
++    'terminators': 't',
++    'terminator_end': 'tE',
++}
++
++CATEGORIES = {
++    'common': [
++        'apache', 'nginx',
++        'java', 'cs', 'cpp', 'objectivec',
++        'ini', 'diff', 'bash', 'makefile',
++        'sql', 'php', 'ruby', 'python', 'perl',
++        'css', 'xml', 'javascript', 'coffeescript', 'http', 'json',
++        'markdown',
++    ],
++}
++
++def lang_name(filename):
++    return os.path.splitext(os.path.basename(filename))[0]
++
++# This is used instead of plain `open` everywhere as there are apparently
++# "some systems" that don't use utf-8 as the default system encoding.
++# We should probably drop it in the better, brighter future.
++def utf8_open(filename, mode='r'):
++    return codecs.open(filename, mode, 'utf-8')
++
++def mapnonstrings(source, func):
++    result = []
++    pos = 0
++    quotes = re.compile('[\'"/]')
++    while pos < len(source):
++        match = quotes.search(source, pos)
++        end = match.start() if match else len(source)
++        result.append(func(source[pos:end]))
++        pos = end
++        if match:
++            terminator = re.compile(r'[%s\\]' % match.group(0))
++            start = pos
++            pos += 1
++            while True:
++                match = terminator.search(source, pos)
++                if not match:
++                    raise ValueError('Unmatched quote')
++                if match.group(0) == '\\':
++                    pos = match.start() + 2
++                else:
++                    pos = match.start() + 1
++                    result.append(source[start:pos])
++                    break
++    return ''.join(result)
++
++def compress_content(tools_path, content, filetype='js'):
++    if filetype == 'js':
++        for s, r in REPLACES.items():
++            content = mapnonstrings(content, partial(re.sub, r'\b%s\b' % s, r))
++        content = re.sub(r'(block|parentNode)\.cN', r'\1.className', content)
++
++    try:
++        args = ['java', '-jar', os.path.join(tools_path, 'yuicompressor.jar'), '--type', filetype]
++        p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
++    except FileNotFoundError as e:
++        raise RuntimeError('Couldn\'t find "%s" which is required for compression to work. You can skip compression with the `-n` option.' % args[0]) from e
++    p.stdin.write(content.encode('utf-8'))
++    p.stdin.close()
++    content = p.stdout.read().decode('utf-8')
++    p.stdout.close()
++
++    return content
++
++def parse_header(filename):
++    '''
++    Parses possible language description header from a file. If a header is found returns it
++    as dict, otherwise returns None.
++    '''
++    content = utf8_open(filename).read(1024)
++    match = re.search(r'^\s*/\*(.*?)\*/', content, re.S)
++    if not match:
++        return
++    headers = match.group(1).split('\n')
++    headers = dict(h.strip().split(': ') for h in headers if ': ' in h)
++    return headers if 'Language' in headers else None
++
++def language_filenames(src_path, languages):
++    '''
++    Resolves dependencies and returns the list of actual language filenames
++    '''
++    lang_path = os.path.join(src_path, 'languages')
++    filenames = [f for f in os.listdir(lang_path) if f.endswith('.js')]
++    headers = [parse_header(os.path.join(lang_path, f)) for f in filenames]
++    infos = [(h, f) for h, f in zip(headers, filenames) if h]
++
++    # Filtering infos based on list of languages and categories
++    if languages:
++        categories = {l for l in languages if l.startswith(':')}
++        languages = set(languages) - categories
++        categories = {c.strip(':') for c in categories}
++        cat_languages = {l for c, ls in CATEGORIES.items() if c in categories for l in ls}
++        languages |= cat_languages
++        infos = [
++            (i, f) for i, f in infos
++            if lang_name(f) in languages
++        ]
++
++    def append(filename):
++        if filename not in filenames:
++            filenames.append(filename)
++
++    filenames = []
++    for info, filename in infos:
++        if 'Requires' in info:
++            requires = [r.strip() for r in info['Requires'].split(',')]
++            for r in requires:
++                append(r)
++        append(filename)
++    return [os.path.join(lang_path, f) for f in filenames]
++
++def strip_read(filename):
++    s = utf8_open(filename).read()
++    pattern = re.compile(r'^\s*(/\*(.*?)\*/)?\s*', re.DOTALL)
++    s = pattern.sub('', s)
++    return s.strip()
++
++def wrap_language(filename, content, compressed):
++    '''
++    Wraps a language file content for the browser build. The "compressed" parameter
++    selects which wrapping code to use:
++
++    - If compressed is False the function expects source files to be uncompressed and
++      wraps them maintaining readability of the source.
++    - If compressed is True the function expects source files to be already compressed
++      individually and wraps them with the minimal code, effectively emulating
++      what yuicompressor does.
++    '''
++    name = lang_name(filename)
++    if compressed:
++        content = content.rstrip(';')
++        wrap = 'hljs.registerLanguage("%s",%s);'
++    else:
++        wrap = '\nhljs.registerLanguage(\'%s\', %s);\n'
++    return wrap % (name, content)
++
++def glue_files(hljs_filename, language_filenames, compressed):
++    '''
++    Glues files together for the browser build.
++    '''
++    if compressed:
++        hljs = 'var hljs=new %s();' % strip_read(hljs_filename).rstrip(';')
++        file_func = lambda f: utf8_open(f).read()
++    else:
++        hljs = 'var hljs = new %s();\n' % strip_read(hljs_filename)
++        file_func = strip_read
++    return ''.join([hljs] + [wrap_language(f, file_func(f), compressed) for f in language_filenames])
++
++def copy_docs(root, build_path):
++    build_docs_path = os.path.join(build_path, 'docs')
++    os.makedirs(build_docs_path)
++
++    docs_path = os.path.join(root, 'docs')
++    filenames = os.listdir(docs_path)
++    for filename in filenames:
++        if '.rst' in filename:
++            shutil.copyfile(
++                os.path.join(docs_path, filename),
++                os.path.join(build_docs_path, filename)
++            )
++
++def build_browser(root, build_path, filenames, options, is_amd=False, need_copy_docs=True):
++    src_path = os.path.join(root, 'src')
++    tools_path = os.path.join(root, 'tools')
++
++    print('Building %d files:\n%s' % (len(filenames), '\n'.join(filenames)))
++    content = glue_files(os.path.join(src_path, 'highlight.js'), filenames, False)
++    if is_amd:
++        content = 'define(function() {\n%s\nreturn hljs;\n});' % content # AMD wrap
++
++    print('Uncompressed size:', len(content.encode('utf-8')))
++    if options.compress:
++        print('Compressing...')
++        content = compress_content(tools_path, content)
++        print('Compressed size:', len(content.encode('utf-8')))
++    utf8_open(os.path.join(build_path, 'highlight.pack.js'), 'w').write(content)
++
++    if need_copy_docs:
++        print('Copying docs...')
++        copy_docs(root, build_path)
++
++def build_amd(root, build_path, filenames, options):
++    build_browser(root, build_path, filenames, options, True, False)
++
++def build_node(root, build_path, filenames, options):
++    src_path = os.path.join(root, 'src')
++    os.makedirs(os.path.join(build_path, 'lib', 'languages'))
++
++    print('Building %d files:' % len(filenames))
++    for filename in filenames:
++        print(filename)
++        content = 'module.exports = %s;' % strip_read(filename)
++        utf8_open(os.path.join(build_path, 'lib', 'languages', os.path.basename(filename)), 'w').write(content)
++    filename = os.path.join(src_path, 'highlight.js')
++    print(filename)
++    core = 'var Highlight = %s;' % strip_read(filename)
++    core += '\nmodule.exports = Highlight;'
++    utf8_open(os.path.join(build_path, 'lib', 'highlight.js'), 'w').write(core)
++
++    print('Registering languages with the library...')
++    hljs = "var Highlight = require('./highlight');\nvar hljs = new Highlight();"
++    filenames = map(os.path.basename, filenames)
++    for filename in filenames:
++        hljs += '\nhljs.registerLanguage(\'%s\', require(\'./languages/%s\'));' % (lang_name(filename), filename)
++    hljs += '\nmodule.exports = hljs;'
++    utf8_open(os.path.join(build_path, 'lib', 'index.js'), 'w').write(hljs)
++    if options.compress:
++        print('Notice: not compressing files for "node" target.')
++
++    print('Copying styles...')
++    build_style_path = os.path.join(build_path, 'styles')
++    src_style_path = os.path.join(src_path, 'styles')
++    os.mkdir(build_style_path)
++    styles = [os.path.join(src_style_path, f) for f in os.listdir(src_style_path) if f.endswith('.css')]
++    for style in styles:
++        print(style)
++        shutil.copy(style, build_style_path)
++
++    print('Copying over Metafiles...')
++    filenames = ['LICENSE', 'README.md']
++    for filename in filenames:
++        source = os.path.join(root, filename)
++        dest   = os.path.join(build_path, filename)
++        shutil.copyfile(source, dest)
++
++    print('Adding package.json...')
++    package = json.load(utf8_open(os.path.join(root, 'package.json')))
++    authors = utf8_open(os.path.join(root, 'AUTHORS.en.txt'))
++    matches = (re.match('^- (?P<name>.*) <(?P<email>.*)>$', a) for a in authors)
++    package['contributors'] = [m.groupdict() for m in matches if m]
++    content = json.dumps(package, indent=2, ensure_ascii=False)
++    utf8_open(os.path.join(build_path, 'package.json'), 'w').write(content)
++
++    print('Copying docs...')
++    copy_docs(root, build_path)
++
++def build_cdn(root, build_path, filenames, options):
++    src_path = os.path.join(root, 'src')
++    tools_path = os.path.join(root, 'tools')
++    if not options.compress:
++        print('Notice: forcing compression for "cdn" target')
++        options.compress = True
++
++    build_browser(root, build_path, filenames, options, False, False)
++    os.rename(os.path.join(build_path, 'highlight.pack.js'), os.path.join(build_path, 'highlight.min.js'))
++
++    print('Compressing all languages...')
++    lang_path = os.path.join(build_path, 'languages')
++    os.mkdir(lang_path)
++    all_filenames = language_filenames(src_path, [])
++    for filename in all_filenames:
++        print(filename)
++        content = compress_content(tools_path, strip_read(filename))
++        content = wrap_language(filename, content, True)
++        utf8_open(os.path.join(lang_path, '%s.min.js' % lang_name(filename)), 'w').write(content)
++
++    print('Compressing styles...')
++    build_style_path = os.path.join(build_path, 'styles')
++    src_style_path = os.path.join(src_path, 'styles')
++    os.mkdir(build_style_path)
++    styles = [lang_name(f) for f in os.listdir(src_style_path) if f.endswith('.css')]
++    for style in styles:
++        filename = os.path.join(src_style_path, '%s.css' % style)
++        print(filename)
++        content = compress_content(tools_path, utf8_open(filename).read(), 'css')
++        utf8_open(os.path.join(build_style_path, '%s.min.css' % style), 'w').write(content)
++
++def build(buildfunc, root, args):
++    build_path = os.path.join(root, 'build')
++    if os.path.exists(build_path):
++        shutil.rmtree(build_path)
++    os.mkdir(build_path)
++    filenames = language_filenames(os.path.join(root, 'src'), args.languages)
++    buildfunc(root, build_path, filenames, args)
++    print('Done.')
++
++if __name__ == '__main__':
++    parser = argparse.ArgumentParser(description='Build highlight.js for various targets')
++    parser.add_argument(
++        'languages', nargs='*',
++        help = 'language (the name of a language file without the .js extension) or :category (currently the only available category is ":common")',
++    )
++    parser.add_argument(
++        '-n', '--no-compress',
++        dest = 'compress', action = 'store_false', default = True,
++        help = 'Don\'t compress source files. Compression only works for the "browser" target.',
++    )
++    parser.add_argument(
++        '-t', '--target', dest = 'target',
++        choices = ['browser', 'node', 'cdn', 'amd'], default = 'browser',
++        help = 'Target format, default is "browser"',
++    )
++    args = parser.parse_args()
++    buildfunc = locals()['build_%s' % args.target]
++    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
++    build(buildfunc, root, args)
diff --git a/debian/patches/series b/debian/patches/series
index fc926bb..685c9d7 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,6 @@
-modify_build_dir.patch
+restore-old-python-buildsystem.patch
+python-buildsystem-modify-build-dir.patch
+python-buildsystem-update.patch
+no-bluebird.patch
+no-jsdom.patch
+fixup-tests.patch
diff --git a/debian/rules b/debian/rules
index b127a8f..be497c7 100755
--- a/debian/rules
+++ b/debian/rules
@@ -6,20 +6,22 @@ js-compressor := $(or $(notdir $(shell which uglifyjs)),yui-compressor)
 %:
 	dh $@
 
-override_dh_auto_build: build_doc
+override_dh_auto_build:
 	python3 tools/build.py -n
 	python3 tools/build.py -tnode
 	$(js-compressor) -o build_browser/highlight.min.js build_browser/highlight.pack.js
 	mv build_browser/highlight.pack.js build_browser/highlight.js
+	$(MAKE) -C docs/ html
+	$(MAKE) -C docs/ latexpdf
+
+override_dh_auto_test:
+	$(RM) build && ln -sf build_node/ build
+	mocha test/
 
 override_dh_clean:
 	dh_clean
 	rm -rf build_browser/ build_node/
 	rm -rf docs/_build/*
 
-build_doc:
-	$(MAKE) -C docs/ html
-	$(MAKE) -C docs/ latexpdf
-
 override_dh_installchangelogs:
 	dh_installchangelogs CHANGES.md

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/highlight.js.git



More information about the Pkg-javascript-commits mailing list