Use a pre-built minified CodeMirror in the release build

I've started to maintain a minified CodeMirror distribution at
https://www.npmjs.com/package/codemirror-minified. It is released
on both NPM and WebJars with a version number that matches the
current version of CodeMirror. It comes with all non-test
JavaScript and CSS files minified.

Commit 7b11d6ad30
(change I05d925c94a3c0368366e9d3ad109cf84492810fc) already turned off
CodeMirror obfuscation in non-release builds. With this further change,
we can avoid running Closure Compiler altogether.

Removed the special case for CodeMirror in
Documentation/gen_licenses.py since it's no longer needed.

Removed the now unused js_minify() rule and the rules for downloading
Closure Compiler and its externs. They will be re-added to tools/js for
minifying PolyGerrit.

Change-Id: I36b4c29e2300384f49d3660266cc7b89140c9faf
This commit is contained in:
Michael Zhou
2016-03-29 21:30:25 -04:00
parent 7b11d6ad30
commit 9a7f4493a7
6 changed files with 102 additions and 155 deletions

View File

@@ -1,159 +1,108 @@
include_defs('//lib/maven.defs')
include_defs('//lib/codemirror/cm.defs')
include_defs('//lib/codemirror/closure.defs')
REPO = MAVEN_CENTRAL
VERSION = '5.13.2'
SHA1 = '4a26f060aeca679fdf751d2b480499c8a5f71e47'
TOP = 'META-INF/resources/webjars/codemirror/%s' % VERSION
TOP_MINIFIED = 'META-INF/resources/webjars/codemirror-minified/%s' % VERSION
if REPO == MAVEN_CENTRAL:
URL = REPO + 'org/webjars/codemirror/%s/codemirror-%s.jar' % (VERSION, VERSION)
TOP = 'META-INF/resources/webjars/codemirror/%s' % VERSION
ZIP = 'codemirror-%s.jar' % VERSION
else:
URL = REPO + 'net/codemirror/codemirror-%s.zip' % VERSION
TOP = 'codemirror-%s' % VERSION
ZIP = 'codemirror-%s.zip' % VERSION
CLOSURE_VERSION = 'v20160315'
CLOSURE_COMPILER_ARGS = [
'--compilation_level SIMPLE_OPTIMIZATIONS',
'--language_out ECMASCRIPT5_STRICT',
'--warning_level QUIET'
]
genrule(
name = 'css',
cmd = ';'.join([
"echo '/** @license' >$OUT",
'unzip -p $(location :zip) %s/LICENSE >>$OUT' % TOP,
"echo '*/' >>$OUT",
] +
['unzip -p $(location :zip) %s/%s >>$OUT' % (TOP, n)
for n in CM_CSS]
),
out = 'cm.css',
maven_jar(
name = 'codemirror-minified',
id = 'org.webjars.npm:codemirror-minified:' + VERSION,
sha1 = '420b73c0dfa7885ff7f60df2dce7d2cbae4ffeef',
attach_source = False,
license = 'codemirror-minified',
visibility = [],
)
for n in CM_THEMES:
maven_jar(
name = 'codemirror-original',
id = 'org.webjars.npm:codemirror:' + VERSION,
sha1 = '4a26f060aeca679fdf751d2b480499c8a5f71e47',
attach_source = False,
license = 'codemirror-original',
visibility = [],
)
for archive, suffix, top in [('codemirror-original', '', TOP), ('codemirror-minified', '_r', TOP_MINIFIED)]:
# Main JavaScript and addons
genrule(
name = 'theme_%s' % n,
name = 'cm' + suffix,
cmd = ';'.join([
"echo '/** @license' >$OUT",
'unzip -p $(location :zip) %s/LICENSE >>$OUT' % TOP,
'unzip -p $(location :%s) %s/LICENSE >>$OUT' % (archive, top),
"echo '*/' >>$OUT",
'unzip -p $(location :zip) %s/theme/%s.css >>$OUT' % (TOP, n)
]
] +
['unzip -p $(location :%s) %s/%s >>$OUT' % (archive, top, n) for n in CM_JS] +
['unzip -p $(location :%s) %s/addon/%s >>$OUT' % (archive, top, n)
for n in CM_ADDONS]
),
out = 'theme_%s.css' % n,
out = 'cm%s.js' % suffix,
)
genrule(
name = 'cm-verbose',
cmd = ';'.join([
"echo '/** @license' >$OUT",
'unzip -p $(location :zip) %s/LICENSE >>$OUT' % TOP,
"echo '*/' >>$OUT",
] +
['unzip -p $(location :zip) %s/%s >>$OUT' % (TOP, n) for n in CM_JS] +
['unzip -p $(location :zip) %s/addon/%s >>$OUT' % (TOP, n)
for n in CM_ADDONS]
),
out = 'cm-verbose.js',
)
js_minify(
name = 'js',
generated = [':cm-verbose'],
compiler_args = CLOSURE_COMPILER_ARGS,
out = 'cm.js'
)
for n in CM_MODES:
genrule (
name = 'mode_%s_src' % n,
# Main CSS
genrule(
name = 'css' + suffix,
cmd = ';'.join([
"echo '/** @license' >$OUT",
'unzip -p $(location :zip) %s/LICENSE >>$OUT' % TOP,
"echo '*/' >>$OUT",
'unzip -p $(location :zip) %s/mode/%s/%s.js >>$OUT' % (TOP, n, n),
]),
out = 'mode_%s_src.js' %n,
)
js_minify(
name = 'mode_%s_js' % n,
generated = [':mode_%s_src' % n],
compiler_args = CLOSURE_COMPILER_ARGS,
out = 'mode_%s.js' % n,
"echo '/** @license' >$OUT",
'unzip -p $(location :%s) %s/LICENSE >>$OUT' % (archive, top),
"echo '*/' >>$OUT",
] +
['unzip -p $(location :%s) %s/%s >>$OUT' % (archive, top, n)
for n in CM_CSS]
),
out = 'cm%s.css' % suffix,
)
prebuilt_jar(
name = 'codemirror_r',
binary_jar = ':jar_r',
deps = [
':jar_r',
'//lib:LICENSE-codemirror',
],
visibility = ['PUBLIC'],
)
# Modes
for n in CM_MODES:
genrule (
name = 'mode_%s%s' % (n, suffix),
cmd = ';'.join([
"echo '/** @license' >$OUT",
'unzip -p $(location :%s) %s/LICENSE >>$OUT' % (archive, top),
"echo '*/' >>$OUT",
'unzip -p $(location :%s) %s/mode/%s/%s.js >>$OUT' % (archive, top, n, n),
]),
out = 'mode_%s%s.js' % (n, suffix),
)
prebuilt_jar(
name = 'codemirror',
binary_jar = ':jar',
deps = [
':jar',
'//lib:LICENSE-codemirror',
],
visibility = ['PUBLIC'],
)
# Themes
for n in CM_THEMES:
genrule(
name = 'theme_%s%s' % (n, suffix),
cmd = ';'.join([
"echo '/** @license' >$OUT",
'unzip -p $(location :%s) %s/LICENSE >>$OUT' % (archive, top),
"echo '*/' >>$OUT",
'unzip -p $(location :%s) %s/theme/%s.css >>$OUT' % (archive, top, n)
]
),
out = 'theme_%s%s.css' % (n, suffix),
)
for suffix, cm, mode_suffix in [('_r', ':js', '_js'), ('', ':cm-verbose', '_src')]:
# Jar packaging
genrule(
name = 'jar' + suffix,
cmd = ';'.join([
'cd $TMP',
'mkdir -p net/codemirror/{lib,mode,theme}',
'cp $(location :css) net/codemirror/lib',
'cp $(location %s) net/codemirror/lib/cm.js' % cm]
+ ['cp $(location :mode_%s%s) net/codemirror/mode/%s.js' % (n, mode_suffix, n)
'cp $(location :css%s) net/codemirror/lib/cm.css' % suffix,
'cp $(location :cm%s) net/codemirror/lib/cm.js' % suffix]
+ ['cp $(location :mode_%s%s) net/codemirror/mode/%s.js' % (n, suffix, n)
for n in CM_MODES]
+ ['cp $(location :theme_%s) net/codemirror/theme/%s.css' % (n, n)
+ ['cp $(location :theme_%s%s) net/codemirror/theme/%s.css' % (n, suffix, n)
for n in CM_THEMES]
+ ['zip -qr $OUT net/codemirror/{lib,mode,theme}']),
out = 'codemirror%s.jar' % suffix,
)
)
genrule(
name = 'zip',
cmd = '$(exe //tools:download_file)' +
' -o $OUT' +
' -u ' + URL +
' -v ' + SHA1,
out = ZIP,
)
prebuilt_jar(
name = 'codemirror' + suffix,
binary_jar = ':jar%s' % suffix,
deps = [
':jar' + suffix,
'//lib:LICENSE-' + archive,
],
visibility = ['PUBLIC'],
)
java_binary(
name = 'js_minifier',
main_class = 'com.google.javascript.jscomp.CommandLineRunner',
deps = [':compiler-jar']
)
maven_jar(
name = 'compiler-jar',
id = 'com.google.javascript:closure-compiler:' + CLOSURE_VERSION,
sha1 = 'f5b1a03f83a014e545db60a795fcf94db14a5ba2',
license = 'DO_NOT_DISTRIBUTE',
deps = [':closure-compiler-externs'],
visibility = [],
)
maven_jar(
name = 'closure-compiler-externs',
id = 'com.google.javascript:closure-compiler-externs:' + CLOSURE_VERSION,
sha1 = 'a0c252a8fced5f0a542302e3f03066c8144d7371',
license = 'Apache2.0',
visibility = [],
attach_source = False,
)

View File

@@ -1,18 +0,0 @@
def js_minify(
name,
out,
compiler_args = [],
srcs = [],
generated = []):
cmd = ['$(exe :js_minifier) --js_output_file $OUT'] + compiler_args
if srcs:
cmd.append('$SRCS')
if generated:
cmd.extend(['$(location %s)' % n for n in generated])
genrule(
name = name,
cmd = ' '.join(cmd),
srcs = srcs,
out = out,
)