2014-12-17 08:47:19 +08:00
#!/usr/bin/env python
2014-07-02 09:18:17 +08:00
import os
2014-07-06 10:13:05 +08:00
import string
2015-01-11 13:51:11 +08:00
from collections import OrderedDict
2015-01-23 09:29:28 +08:00
import shutil
2014-07-02 09:18:17 +08:00
2014-07-17 01:28:38 +08:00
"""
2014-07-17 03:17:50 +08:00
This script uses my experimental build tool http : / / www . bildtool . org
2014-07-17 01:28:38 +08:00
2014-11-23 02:06:47 +08:00
In order to build the complete ANTLR4 product with Java , CSharp , Python 2 / 3 , and JavaScript
2014-07-17 01:28:38 +08:00
targets , do the following from a UNIX command line . Windows build using this script
2015-01-17 03:52:14 +08:00
is not yet supported .
2014-07-17 01:28:38 +08:00
2014-11-23 02:06:47 +08:00
You will also need python 2.7 , python 3.4 , node . js and mono ( on Mac / Linux )
2015-01-11 09:40:01 +08:00
! ! ! You might need to set path values in test_properties dictionary below to ensure non Java targets tests run . ! ! !
2014-07-17 03:17:50 +08:00
2014-07-17 01:28:38 +08:00
mkdir - p / usr / local / antlr # somewhere appropriate where you want to install stuff
cd / usr / local / antlr
2014-11-23 02:06:47 +08:00
git clone git @github.com : antlr / antlr4 . git
git clone git @github.com : antlr / antlr4 - python3 . git
git clone git @github.com : antlr / antlr4 - python2 . git
git clone git @github.com : antlr / antlr4 - csharp . git
git clone git @github.com : antlr / antlr4 - javascript . git
2014-07-17 01:28:38 +08:00
cd antlr4
. / bild . py tests
2015-01-17 03:52:14 +08:00
This script must be run from the main antlr4 directory .
2014-07-17 01:28:38 +08:00
"""
2014-07-10 03:00:36 +08:00
# bootstrap by downloading bilder.py if not found
import urllib
2014-07-11 09:07:24 +08:00
import os
2014-07-10 03:00:36 +08:00
if not os . path . exists ( " bilder.py " ) :
print " bootstrapping; downloading bilder.py "
urllib . urlretrieve (
" https://raw.githubusercontent.com/parrt/bild/master/src/python/bilder.py " ,
" bilder.py " )
# assumes bilder.py is in current directory
2014-07-02 09:18:17 +08:00
from bilder import *
2015-02-15 08:16:20 +08:00
BOOTSTRAP_VERSION = " 4.5 "
VERSION = " 4.5.1 "
2014-11-09 22:09:34 +08:00
JAVA_TARGET = " . "
PYTHON2_TARGET = " ../antlr4-python2 "
PYTHON3_TARGET = " ../antlr4-python3 "
CSHARP_TARGET = " ../antlr4-csharp "
2014-11-23 02:06:47 +08:00
JAVASCRIPT_TARGET = " ../antlr4-javascript "
2014-07-04 02:46:28 +08:00
2014-07-06 10:13:05 +08:00
# Properties needed to run Python[23] tests
test_properties = {
2014-11-09 22:09:34 +08:00
" antlr-python2-runtime " : uniformpath ( PYTHON2_TARGET ) + " /src " ,
" antlr-python3-runtime " : uniformpath ( PYTHON3_TARGET ) + " /src " ,
2014-11-23 02:06:47 +08:00
" antlr-javascript-runtime " : uniformpath ( JAVASCRIPT_TARGET ) + " /src " ,
" antlr-csharp-runtime-project " : uniformpath ( CSHARP_TARGET ) + " /runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.mono.csproj "
2014-11-09 22:09:34 +08:00
}
2015-01-11 13:51:11 +08:00
TARGETS = OrderedDict ( [
( " Java " , uniformpath ( JAVA_TARGET ) ) ,
( " CSharp " , uniformpath ( CSHARP_TARGET ) ) ,
( " Python2 " , uniformpath ( PYTHON2_TARGET ) ) ,
( " Python3 " , uniformpath ( PYTHON3_TARGET ) ) ,
( " JavaScript " , uniformpath ( JAVASCRIPT_TARGET ) )
] )
2014-07-06 10:13:05 +08:00
2014-07-02 09:18:17 +08:00
def parsers ( ) :
2015-05-19 03:20:02 +08:00
antlr3 ( " tool/src/org/antlr/v4/parse " , " gen3 " , version = " 3.5.2 " , package = " org.antlr.v4.parse " )
antlr3 ( " tool/src/org/antlr/v4/codegen " , " gen3 " , version = " 3.5.2 " , package = " org.antlr.v4.codegen " ,
2014-11-09 22:09:34 +08:00
args = [ " -lib " , uniformpath ( " gen3/org/antlr/v4/parse " ) ] )
2014-12-17 10:44:00 +08:00
antlr4 ( " runtime/Java/src/org/antlr/v4/runtime/tree/xpath " , " gen4 " ,
version = BOOTSTRAP_VERSION , package = " org.antlr.v4.runtime.tree.xpath " )
2014-11-09 22:09:34 +08:00
2014-07-02 09:18:17 +08:00
def compile ( ) :
2014-11-09 22:09:34 +08:00
require ( parsers )
cp = uniformpath ( " out " ) + os . pathsep + \
2015-05-19 03:20:02 +08:00
os . path . join ( JARCACHE , " antlr-3.5.2-complete.jar " ) + os . pathsep + \
2014-11-09 22:09:34 +08:00
" runtime/Java/lib/org.abego.treelayout.core.jar " + os . pathsep
2015-01-23 06:34:51 +08:00
srcpath = [ " gen3 " , " gen4 " , " runtime/Java/src " , " tool/src " ]
2014-11-09 22:09:34 +08:00
args = [ " -Xlint " , " -Xlint:-serial " , " -g " , " -sourcepath " , string . join ( srcpath , os . pathsep ) ]
for sp in srcpath :
javac ( sp , " out " , version = " 1.6 " , cp = cp , args = args )
# pull in targets
for t in TARGETS :
javac ( TARGETS [ t ] + " /tool/src " , " out " , version = " 1.6 " , cp = cp , args = args )
2014-07-02 09:18:17 +08:00
2014-07-11 12:44:54 +08:00
def mkjar_complete ( ) :
2014-11-09 22:09:34 +08:00
require ( compile )
copytree ( src = " tool/resources " , trg = " out " ) # messages, Java code gen, etc...
manifest = \
2014-11-23 02:06:47 +08:00
" Main-Class: org.antlr.v4.Tool \n " + \
" Implementation-Title: ANTLR 4 Tool \n " + \
" Implementation-Version: %s \n " + \
" Implementation-Vendor: ANTLR \n " + \
" Implementation-Vendor-Id: org.antlr \n " + \
" Built-By: %s \n " + \
" Build-Jdk: 1.6 \n " + \
" Created-By: http://www.bildtool.org \n " + \
" \n "
manifest = manifest % ( VERSION , os . getlogin ( ) )
2014-11-09 22:09:34 +08:00
# unjar required libraries
unjar ( " runtime/Java/lib/org.abego.treelayout.core.jar " , trgdir = " out " )
2015-05-19 03:20:02 +08:00
download ( " http://www.antlr3.org/download/antlr-3.5.2-runtime.jar " , JARCACHE )
unjar ( os . path . join ( JARCACHE , " antlr-3.5.2-runtime.jar " ) , trgdir = " out " )
2014-11-23 02:06:47 +08:00
download ( " http://www.stringtemplate.org/download/ST-4.0.8.jar " , JARCACHE )
unjar ( os . path . join ( JARCACHE , " ST-4.0.8.jar " ) , trgdir = " out " )
2014-11-09 22:09:34 +08:00
# pull in target templates
for t in TARGETS :
trgdir = " out/org/antlr/v4/tool/templates/codegen/ " + t
mkdir ( trgdir )
copyfile ( TARGETS [ t ] + " /tool/resources/org/antlr/v4/tool/templates/codegen/ " + t + " / " + t + " .stg " ,
trgdir )
jarfile = " dist/antlr4- " + VERSION + " -complete.jar "
jar ( jarfile , srcdir = " out " , manifest = manifest )
2015-01-23 09:29:28 +08:00
print_and_log ( " Generated " + jarfile )
2014-11-09 22:09:34 +08:00
2014-07-07 00:21:46 +08:00
2014-07-11 12:44:54 +08:00
def mkjar_runtime ( ) :
2014-11-09 22:09:34 +08:00
# out/... dir is full of tool-related stuff, make special dir out/runtime
# unjar required library
unjar ( " runtime/Java/lib/org.abego.treelayout.core.jar " , trgdir = " out/runtime " )
cp = uniformpath ( " out/runtime " ) + os . pathsep + \
" runtime/Java/lib/org.abego.treelayout.core.jar "
2015-01-23 06:34:51 +08:00
srcpath = [ " gen4 " , " runtime/Java/src " ]
2014-11-23 02:06:47 +08:00
args = [ " -nowarn " , " -Xlint " , " -Xlint:-serial " , " -g " , " -sourcepath " , string . join ( srcpath , os . pathsep ) ]
2014-11-09 22:09:34 +08:00
for sp in srcpath :
2014-11-23 02:06:47 +08:00
javac ( sp , " out/runtime " , version = " 1.6 " , cp = cp , args = args )
2015-01-16 10:14:38 +08:00
# Prefix of Bundle- is OSGi cruft; it's not everything so we wrap with make_osgi_ready()
# Declan Cox describes osgi ready jar https://github.com/antlr/antlr4/pull/689.
2014-11-09 22:09:34 +08:00
manifest = \
2014-11-23 02:06:47 +08:00
" Implementation-Vendor: ANTLR \n " + \
" Implementation-Vendor-Id: org.antlr \n " + \
" Implementation-Title: ANTLR 4 Runtime \n " + \
" Implementation-Version: %s \n " + \
" Built-By: %s \n " + \
2015-01-16 10:14:38 +08:00
" Build-Jdk: %s \n " + \
2014-11-23 02:06:47 +08:00
" Created-By: http://www.bildtool.org \n " + \
2015-01-16 10:14:38 +08:00
" Bundle-Description: The ANTLR 4 Runtime \n " + \
" Bundle-DocURL: http://www.antlr.org \n " + \
" Bundle-License: http://www.antlr.org/license.html \n " + \
" Bundle-Name: ANTLR 4 Runtime \n " + \
2015-01-17 00:58:54 +08:00
" Bundle-SymbolicName: org.antlr.antlr4-runtime-osgi \n " + \
2015-01-16 10:14:38 +08:00
" Bundle-Vendor: ANTLR \n " + \
" Bundle-Version: %s \n " + \
2014-12-17 10:44:00 +08:00
" \n "
2015-01-16 10:14:38 +08:00
manifest = manifest % ( VERSION , os . getlogin ( ) , get_java_version ( ) , VERSION )
2014-11-09 22:09:34 +08:00
jarfile = " dist/antlr4- " + VERSION + " .jar "
jar ( jarfile , srcdir = " out/runtime " , manifest = manifest )
print " Generated " + jarfile
2015-01-16 10:14:38 +08:00
osgijarfile = " dist/antlr4- " + VERSION + " -osgi.jar "
make_osgi_ready ( jarfile , osgijarfile )
2015-05-23 04:08:02 +08:00
os . remove ( jarfile ) # delete target for Windows compatibility
2015-01-16 10:14:38 +08:00
os . rename ( osgijarfile , jarfile ) # copy back onto old jar
2015-01-23 09:29:28 +08:00
print_and_log ( " Made jar OSGi-ready " + jarfile )
2015-01-16 10:14:38 +08:00
2014-11-09 22:09:34 +08:00
2015-01-22 09:14:33 +08:00
def mkjar ( ) : # if called as root target
2015-01-20 08:13:00 +08:00
rmdir ( " out " )
2015-01-22 09:14:33 +08:00
_mkjar ( )
2015-01-23 08:27:19 +08:00
2015-01-22 09:14:33 +08:00
def _mkjar ( ) : # don't wipe out out dir if we know it's done like from all()
2014-11-09 22:09:34 +08:00
mkjar_complete ( )
# put it in JARCARCHE too so bild can find it during antlr4()
2014-12-17 10:44:00 +08:00
copyfile ( src = " dist/antlr4- " + VERSION + " -complete.jar " , trg = JARCACHE + " /antlr- " + VERSION + " -complete.jar " ) # note mvn wants antlr4-ver-... but I want antlr-ver-...
2015-01-20 08:13:00 +08:00
2014-12-17 10:44:00 +08:00
# rebuild/bootstrap XPath with this version so it can use current runtime (gen'd with previous ANTLR at this point)
2015-01-20 08:13:00 +08:00
log ( " rebuilding XPath with " + VERSION )
print ( " rebuilding XPath with " + VERSION )
# kill previous-version-generated code
os . remove ( " out/org/antlr/v4/runtime/tree/xpath/XPathLexer.class " )
os . remove ( " gen4/org/antlr/v4/runtime/tree/xpath/XPathLexer.java " )
2014-11-09 22:09:34 +08:00
antlr4 ( " runtime/Java/src/org/antlr/v4/runtime/tree/xpath " , " gen4 " , version = VERSION ,
package = " org.antlr.v4.runtime.tree.xpath " )
2015-01-20 08:13:00 +08:00
args = [ " -Xlint " , " -Xlint:-serial " , " -g " , " -sourcepath " , " gen4 " ]
javac ( " gen4 " , " out " , version = " 1.6 " , cp = uniformpath ( " out " ) , args = args ) # force recompile of XPath stuff
2014-11-09 22:09:34 +08:00
mkjar_complete ( ) # make it again with up to date XPath lexer
2014-12-17 10:44:00 +08:00
mkjar_runtime ( ) # now build the runtime jar
2014-11-09 22:09:34 +08:00
2014-07-07 00:21:46 +08:00
2015-01-23 08:27:19 +08:00
def javascript ( ) :
2015-01-17 03:52:14 +08:00
# No build to do. Just zip up the sources
2015-01-23 07:14:23 +08:00
srcpath = uniformpath ( JAVASCRIPT_TARGET + " /src " )
srcfiles = allfiles ( srcpath , " *.js " ) + allfiles ( srcpath , " *.json " )
zipfile = " dist/antlr-javascript-runtime- " + VERSION + " .zip "
if not isstale ( src = newest ( srcfiles ) , trg = zipfile ) :
return
zip ( zipfile , srcpath )
2015-01-23 09:29:28 +08:00
print_and_log ( " Generated " + zipfile )
2015-01-17 03:52:14 +08:00
2015-01-23 08:27:19 +08:00
def csharp ( ) :
2015-01-17 03:52:14 +08:00
# For C#, there are 2 equivalent projects: a VisualStudio one and a Xamarin one.
# You can build on windows using msbuild and on mono using xbuild and pointing to the corresponding runtime project.
2015-01-23 08:27:19 +08:00
# kill previous ones manually as "xbuild /t:Clean" didn't seem to do it
bindll = uniformpath ( CSHARP_TARGET ) + " /runtime/CSharp/Antlr4.Runtime/bin/net20/Release/Antlr4.Runtime.dll "
objdll = uniformpath ( CSHARP_TARGET ) + " /runtime/CSharp/Antlr4.Runtime/obj/net20/Release/Antlr4.Runtime.dll "
rmfile ( bindll )
rmfile ( objdll )
# now build
projfile = uniformpath ( CSHARP_TARGET ) + " /runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.mono.csproj "
cmd = [ " xbuild " , " /p:Configuration=Release " , projfile ]
exec_and_log ( cmd )
# zip it up to get a version number in there
zipfile = " dist/antlr-csharp-runtime- " + VERSION + " .zip "
rmfile ( zipfile )
cmd = [ " zip " , " --junk-paths " , zipfile , bindll ]
exec_and_log ( cmd )
2015-01-23 09:29:28 +08:00
print_and_log ( " Generated " + zipfile )
2015-01-17 03:52:14 +08:00
2015-01-23 08:27:19 +08:00
def python_sdist ( ) :
2015-01-17 03:52:14 +08:00
cmd = [ " python " , " setup.py " , " sdist " ]
savedir = os . getcwd ( )
try :
os . chdir ( uniformpath ( PYTHON2_TARGET ) )
exec_and_log ( cmd )
os . chdir ( uniformpath ( PYTHON3_TARGET ) )
exec_and_log ( cmd )
finally :
os . chdir ( savedir )
2015-01-23 08:27:19 +08:00
# copy over Python 2
gzfile = " antlr4-python2-runtime- " + VERSION + " .tar.gz "
artifact = uniformpath ( PYTHON2_TARGET ) + " /dist/ " + gzfile
copyfile ( artifact , " dist/ " + gzfile )
2015-01-23 09:29:28 +08:00
print_and_log ( " Generated " + " dist/ " + gzfile )
2015-01-23 08:27:19 +08:00
# copy over Python 3
gzfile = " antlr4-python3-runtime- " + VERSION + " .tar.gz "
artifact = uniformpath ( PYTHON3_TARGET ) + " /dist/ " + gzfile
copyfile ( artifact , " dist/ " + gzfile )
2015-01-23 09:29:28 +08:00
print_and_log ( " Generated " + " dist/ " + gzfile )
2015-01-23 08:27:19 +08:00
2015-01-17 03:52:14 +08:00
2015-01-22 09:14:33 +08:00
def regen_tests ( ) :
require ( _mkjar )
2014-11-09 22:09:34 +08:00
junit_jar , hamcrest_jar = load_junitjars ( )
2014-11-23 02:06:47 +08:00
cp = uniformpath ( " dist/antlr4- " + VERSION + " -complete.jar " ) \
2015-01-22 09:14:33 +08:00
+ os . pathsep + uniformpath ( " out/test " ) \
2014-11-23 02:06:47 +08:00
+ os . pathsep + junit_jar \
+ os . pathsep + hamcrest_jar
args = [ " -nowarn " , " -Xlint " , " -Xlint:-serial " , " -g " ]
2015-01-22 09:14:33 +08:00
javac ( " tool/test " , " out/test " , version = " 1.6 " , cp = cp , args = args ) # all targets can use org.antlr.v4.test.*
2015-05-19 03:57:32 +08:00
java ( classname = " org.antlr.v4.test.rt.gen.Generator " , cp = " out/test:dist/antlr4- " + VERSION + " -complete.jar " )
2015-01-23 09:29:28 +08:00
print_and_log ( " test generation complete " )
2015-01-22 09:14:33 +08:00
2015-01-23 07:01:17 +08:00
2015-01-22 09:14:33 +08:00
def tests ( ) :
require ( regen_tests )
2014-11-09 22:09:34 +08:00
for t in TARGETS :
2015-01-22 09:14:33 +08:00
test_target ( t )
2015-01-22 12:59:04 +08:00
def test_java ( ) :
test_target ( " Java " )
2015-01-22 09:14:33 +08:00
def test_python2 ( ) :
test_target ( " Python2 " )
2015-01-22 12:59:04 +08:00
def test_python3 ( ) :
test_target ( " Python3 " )
def test_csharp ( ) :
test_target ( " CSharp " )
def test_javascript ( ) :
test_target ( " JavaScript " )
2015-01-22 09:14:33 +08:00
def test_target ( t ) :
require ( regen_tests )
cp = uniformpath ( " dist/antlr4- " + VERSION + " -complete.jar " ) \
+ os . pathsep + uniformpath ( " out/test " )
juprops = [ " -D %s = %s " % ( p , test_properties [ p ] ) for p in test_properties ]
args = [ " -nowarn " , " -Xlint " , " -Xlint:-serial " , " -g " ]
2015-01-23 09:29:28 +08:00
print_and_log ( " Testing %s ... " % t )
2015-01-22 09:14:33 +08:00
try :
test ( t , cp , juprops , args )
print t + " tests complete "
except :
print t + " tests failed "
2014-11-23 02:06:47 +08:00
2015-01-23 09:29:28 +08:00
2014-11-23 02:06:47 +08:00
def test ( t , cp , juprops , args ) :
2015-01-22 09:14:33 +08:00
junit_jar , hamcrest_jar = load_junitjars ( )
2014-11-23 02:06:47 +08:00
srcdir = uniformpath ( TARGETS [ t ] + " /tool/test " )
dstdir = uniformpath ( " out/test/ " + t )
# Prefix CLASSPATH with individual target tests
thiscp = dstdir + os . pathsep + cp
2015-01-22 09:14:33 +08:00
thisjarwithjunit = thiscp + os . pathsep + hamcrest_jar + os . pathsep + junit_jar
2014-11-23 02:06:47 +08:00
skip = [ ]
if t == ' Java ' :
# don't test generator
skip = [ " /org/antlr/v4/test/rt/gen/ " , " TestPerformance " ]
elif t == ' Python2 ' :
# need BaseTest located in Py3 target
base = uniformpath ( TARGETS [ ' Python3 ' ] + " /tool/test " )
skip = [ " /org/antlr/v4/test/rt/py3/ " ]
2015-01-22 09:14:33 +08:00
javac ( base , " out/test/ " + t , version = " 1.6 " , cp = thisjarwithjunit , args = args , skip = skip )
2014-11-23 02:06:47 +08:00
skip = [ ]
elif t == ' JavaScript ' :
# don't test browsers automatically, this is overkilling and unreliable
browsers = [ " safari " , " chrome " , " firefox " , " explorer " ]
2015-01-22 12:59:04 +08:00
skip = [ uniformpath ( srcdir + " /org/antlr/v4/test/rt/js/ " + b ) for b in browsers ]
2015-01-22 09:14:33 +08:00
javac ( srcdir , trgdir = " out/test/ " + t , version = " 1.6 " , cp = thisjarwithjunit , args = args , skip = skip )
2014-11-23 02:06:47 +08:00
# copy resource files required for testing
files = allfiles ( srcdir )
for src in files :
if not " .java " in src and not " .stg " in src and not " .DS_Store " in src :
dst = src . replace ( srcdir , uniformpath ( " out/test/ " + t ) )
# only copy files from test dirs
if os . path . exists ( os . path . split ( dst ) [ 0 ] ) :
shutil . copyfile ( src , dst )
junit ( " out/test/ " + t , cp = thiscp , verbose = False , args = juprops )
2014-11-09 22:09:34 +08:00
2015-01-23 08:27:19 +08:00
2015-01-23 09:29:28 +08:00
def install ( ) : # mvn installed locally in ~/.m2, java jar to /usr/local/lib if present
2015-01-22 09:14:33 +08:00
require ( _mkjar )
2015-01-14 09:29:38 +08:00
require ( mksrc )
require ( mkdoc )
2015-01-23 09:29:28 +08:00
jarfile = " dist/antlr4- " + VERSION + " -complete.jar "
2015-01-24 06:48:58 +08:00
print_and_log ( " Maven installing " + jarfile + " and *-sources.jar, *-javadoc.jar " )
2015-01-24 13:38:46 +08:00
mvn_install ( binjar = jarfile ,
srcjar = " dist/antlr4- " + VERSION + " -complete-sources.jar " ,
docjar = " dist/antlr4- " + VERSION + " -complete-javadoc.jar " ,
groupid = " org.antlr " ,
artifactid = " antlr4 " ,
version = VERSION )
2015-01-23 09:29:28 +08:00
runtimejarfile = " dist/antlr4- " + VERSION + " .jar "
2015-01-24 06:48:58 +08:00
print_and_log ( " Maven installing " + runtimejarfile + " and *-sources.jar, *-javadoc.jar " )
2015-01-24 13:38:46 +08:00
mvn_install ( binjar = runtimejarfile ,
srcjar = " dist/antlr4- " + VERSION + " -sources.jar " ,
docjar = " dist/antlr4- " + VERSION + " -javadoc.jar " ,
groupid = " org.antlr " ,
artifactid = " antlr4-runtime " ,
version = VERSION )
2015-01-23 09:29:28 +08:00
if os . path . exists ( " /usr/local/lib " ) :
libjar = " /usr/local/lib/antlr- " + VERSION + " -complete.jar "
print_and_log ( " Installing " + libjar )
shutil . copyfile ( jarfile , libjar )
2015-01-14 09:29:38 +08:00
2014-11-09 22:09:34 +08:00
def mksrc ( ) :
srcpath = " runtime/Java/src/org "
2015-01-23 09:29:28 +08:00
srcfiles = allfiles ( srcpath , " *.java " )
2014-11-09 22:09:34 +08:00
jarfile = " dist/antlr4- " + VERSION + " -sources.jar "
2015-01-15 05:08:08 +08:00
if not isstale ( src = newest ( srcfiles ) , trg = jarfile ) :
return
2014-11-09 22:09:34 +08:00
zip ( jarfile , srcpath )
2015-01-23 09:29:28 +08:00
print_and_log ( " Generated " + jarfile )
2015-01-15 05:08:08 +08:00
2015-01-23 06:34:51 +08:00
srcpaths = [ srcpath , " gen3/org " , " gen4/org " , " tool/src/org " ]
2015-01-23 09:29:28 +08:00
srcfiles = allfiles ( srcpaths , " *.java " )
2015-01-15 05:08:08 +08:00
jarfile = " dist/antlr4- " + VERSION + " -complete-sources.jar "
if not isstale ( src = newest ( srcfiles ) , trg = jarfile ) :
return
2014-11-09 22:09:34 +08:00
zip ( jarfile , srcpaths )
2015-01-23 09:29:28 +08:00
print_and_log ( " Generated " + jarfile )
2014-07-02 09:18:17 +08:00
2014-07-03 09:31:38 +08:00
def mkdoc ( ) :
2015-01-15 05:08:08 +08:00
require ( mksrc )
2014-11-09 22:09:34 +08:00
# add a few source dirs to reduce the number of javadoc errors
# JavaDoc needs antlr annotations source code
2015-01-14 09:29:38 +08:00
runtimedoc = " dist/antlr4- " + VERSION + " -javadoc.jar "
tooldoc = " dist/antlr4- " + VERSION + " -complete-javadoc.jar "
2015-01-15 05:08:08 +08:00
runtime_source_jarfile = " dist/antlr4- " + VERSION + " -sources.jar "
tool_source_jarfile = " dist/antlr4- " + VERSION + " -complete-sources.jar "
if not isstale ( src = runtime_source_jarfile , trg = runtimedoc ) and \
not isstale ( src = tool_source_jarfile , trg = tooldoc ) :
2015-01-14 09:29:38 +08:00
return
2014-11-09 22:09:34 +08:00
# JavaDoc needs abego treelayout source code
mkdir ( " out/TreeLayout " )
download ( " http://search.maven.org/remotecontent?filepath=org/abego/treelayout/org.abego.treelayout.core/1.0.1/org.abego.treelayout.core-1.0.1-sources.jar " , " out/TreeLayout " )
unjar ( " out/TreeLayout/org.abego.treelayout.core-1.0.1-sources.jar " , trgdir = " out/TreeLayout " )
# JavaDoc needs antlr runtime 3.5.2 source code
mkdir ( " out/Antlr352Runtime " )
download ( " http://search.maven.org/remotecontent?filepath=org/antlr/antlr-runtime/3.5.2/antlr-runtime-3.5.2-sources.jar " , " out/Antlr352Runtime " )
unjar ( " out/Antlr352Runtime/antlr-runtime-3.5.2-sources.jar " , trgdir = " out/Antlr352Runtime " )
# JavaDoc needs antlr ST4 source code
mkdir ( " out/ST4 " )
download ( " http://search.maven.org/remotecontent?filepath=org/antlr/ST4/4.0.8/ST4-4.0.8-sources.jar " , " out/ST4 " )
unjar ( " out/ST4/ST4-4.0.8-sources.jar " , trgdir = " out/ST4 " )
# go!
mkdir ( " doc/Java " )
mkdir ( " doc/JavaTool " )
dirs = [ " runtime/Java/src " ]
dirs + = [ " out/TreeLayout " ]
2015-02-15 08:16:20 +08:00
dirs + = [ " gen4 " ]
exclude = [
" org/antlr/runtime " ,
" org/abego " ,
" org/stringtemplate " ,
" org/antlr/stringtemplate " ]
2014-11-09 22:09:34 +08:00
javadoc ( srcdir = dirs , trgdir = " doc/Java " , packages = " org.antlr.v4.runtime " , exclude = exclude )
dirs + = [ " gen3 " ]
dirs + = [ TARGETS [ t ] + " /tool/src " for t in TARGETS ]
javadoc ( srcdir = dirs , trgdir = " doc/JavaTool " , packages = " org.antlr.v4 " , exclude = exclude )
# build stack merge PredictionContext and ATNState images from DOT
# DOT Images are in runtime/Java/src/main/dot/org/antlr/v4/runtime/atn/images/
# Gen into E.g., doc/Java/org/antlr/v4/runtime/atn/images/SingletonMerge_DiffRootSamePar.svg
mkdir ( " doc/Java/org/antlr/v4/runtime/atn/images " )
2015-02-15 08:16:20 +08:00
mkdir ( " doc/JavaTool/org/antlr/v4/runtime/atn/images " )
2014-11-09 22:09:34 +08:00
for f in glob . glob ( " runtime/Java/src/main/dot/org/antlr/v4/runtime/atn/images/*.dot " ) :
dot ( f , " doc/Java/org/antlr/v4/runtime/atn/images " , format = " svg " )
2015-02-15 08:16:20 +08:00
dot ( f , " doc/JavaTool/org/antlr/v4/runtime/atn/images " , format = " svg " )
2015-01-14 09:29:38 +08:00
zip ( runtimedoc , " doc/Java " )
zip ( tooldoc , " doc/JavaTool " )
2014-11-09 22:09:34 +08:00
2015-01-23 08:27:19 +08:00
def target_artifacts ( ) :
javascript ( )
python_sdist ( )
csharp ( )
2015-01-17 03:52:14 +08:00
def clean ( dist = False ) :
if dist :
rmdir ( " dist " )
rmdir ( " out " )
rmdir ( " gen3 " )
rmdir ( " gen4 " )
rmdir ( " doc " )
2015-01-14 09:29:38 +08:00
def all ( ) :
clean ( True )
2015-01-22 09:14:33 +08:00
_mkjar ( )
2015-01-23 08:27:19 +08:00
target_artifacts ( )
2015-01-14 09:29:38 +08:00
tests ( )
mkdoc ( )
mksrc ( )
install ( )
clean ( )
2014-11-09 22:09:34 +08:00
processargs ( globals ( ) ) # E.g., "python bild.py all"