2014-07-05 09:39:12 +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
|
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
|
|
|
|
|
|
|
In order to build the complete ANTLR4 product with Java, Python 2, and Python 3
|
|
|
|
targets, do the following from a UNIX command line. Windows build using this script
|
|
|
|
is not yet supported. Please use the mvn build or ant build.
|
|
|
|
|
2014-07-17 03:17:50 +08:00
|
|
|
!!!You must set path values in test_properties dictionary below to ensure Python
|
|
|
|
tests run.!!!
|
|
|
|
|
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
|
|
|
|
git clone git@github.com:parrt/antlr4.git
|
|
|
|
git clone git@github.com:parrt/antlr4-python3.git
|
|
|
|
git clone git@github.com:parrt/antlr4-python2.git
|
|
|
|
# git clone git@github.com:antlr/antlr4-csharp.git not quite ready use:
|
|
|
|
# https://github.com/tunnelvisionlabs/antlr4cs/releases/tag/v4.3.0
|
|
|
|
cd antlr4
|
|
|
|
./bild.py tests
|
|
|
|
"""
|
|
|
|
|
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 *
|
|
|
|
|
2014-07-02 12:33:26 +08:00
|
|
|
VERSION = "4.4"
|
2014-07-06 10:13:05 +08:00
|
|
|
JAVA_TARGET = "."
|
2014-07-04 02:46:28 +08:00
|
|
|
PYTHON2_TARGET = "../antlr4-python2"
|
|
|
|
PYTHON3_TARGET = "../antlr4-python3"
|
2014-07-10 06:53:57 +08:00
|
|
|
CSHARP_TARGET = "../antlr4-csharp"
|
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 = {
|
|
|
|
"antlr-python2-python":"/usr/local/Cellar/python/2.7.5/bin/python2.7",
|
|
|
|
"antlr-python2-runtime":uniformpath(PYTHON2_TARGET)+"/src",
|
|
|
|
"antlr-python3-python":"/usr/local/Cellar/python3/3.4.1/bin/python3",
|
|
|
|
"antlr-python3-runtime":uniformpath(PYTHON3_TARGET)+"/src",
|
|
|
|
}
|
|
|
|
|
|
|
|
TARGETS = {"Java":uniformpath(JAVA_TARGET),
|
|
|
|
"Python2":uniformpath(PYTHON2_TARGET),
|
|
|
|
"Python3":uniformpath(PYTHON3_TARGET),
|
2014-07-17 01:28:38 +08:00
|
|
|
#"CSharp":uniformpath(CSHARP_TARGET)
|
|
|
|
}
|
2014-07-02 09:18:17 +08:00
|
|
|
|
|
|
|
def parsers():
|
2014-07-11 09:07:24 +08:00
|
|
|
antlr3("tool/src/org/antlr/v4/parse", "gen3", package="org.antlr.v4.parse")
|
|
|
|
antlr3("tool/src/org/antlr/v4/codegen", "gen3", package="org.antlr.v4.codegen", args=["-lib",uniformpath("gen3/org/antlr/v4/parse")])
|
|
|
|
antlr4("runtime/Java/src/org/antlr/v4/runtime/tree/xpath", "gen4", package="org.antlr.v4.runtime.tree.xpath")
|
2014-07-02 09:18:17 +08:00
|
|
|
|
|
|
|
def compile():
|
2014-07-04 02:46:28 +08:00
|
|
|
require(parsers)
|
|
|
|
cp = uniformpath("out")+os.pathsep+ \
|
|
|
|
os.path.join(JARCACHE,"antlr-3.5.1-complete.jar")+os.pathsep+ \
|
2014-07-13 08:03:23 +08:00
|
|
|
"runtime/Java/lib/org.abego.treelayout.core.jar"+os.pathsep
|
|
|
|
if os.path.exists(JARCACHE+"/antlr-4.4-complete.jar"):
|
|
|
|
cp += JARCACHE+"/antlr-4.4-complete.jar"
|
2014-07-11 09:07:24 +08:00
|
|
|
srcpath = ["gen3", "gen4", "runtime/JavaAnnotations/src", "runtime/Java/src", "tool/src"]
|
|
|
|
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)
|
2014-07-04 02:46:28 +08:00
|
|
|
# pull in targets
|
|
|
|
for t in TARGETS:
|
2014-07-04 02:58:57 +08:00
|
|
|
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-07-04 02:46:28 +08:00
|
|
|
require(compile)
|
2014-07-10 06:53:03 +08:00
|
|
|
copytree(src="tool/resources", trg="out") # messages, Java code gen, etc...
|
2014-07-04 02:46:28 +08:00
|
|
|
manifest = \
|
2014-07-07 00:21:46 +08:00
|
|
|
"""Main-Class: org.antlr.v4.Tool
|
|
|
|
Implementation-Vendor: ANTLR
|
|
|
|
Implementation-Title: ANTLR 4 Tool
|
|
|
|
Implementation-Version: %s
|
|
|
|
Built-By: %s
|
|
|
|
Build-Jdk: 1.6
|
|
|
|
Created-By: http://www.bildtool.org
|
|
|
|
""" % (VERSION,os.getlogin())
|
2014-07-04 02:46:28 +08:00
|
|
|
# unjar required libraries
|
|
|
|
unjar("runtime/Java/lib/org.abego.treelayout.core.jar", trgdir="out")
|
2014-07-17 04:34:29 +08:00
|
|
|
v3runtime = "antlr-3.5.2-runtime.jar"
|
|
|
|
download("http://www.antlr3.org/download/"+v3runtime, JARCACHE)
|
|
|
|
unjar(os.path.join(JARCACHE, v3runtime), trgdir="out")
|
|
|
|
STruntime = "ST-4.0.8-no-antlr3-runtime.jar"
|
|
|
|
download("http://www.stringtemplate.org/download/"+STruntime, JARCACHE)
|
|
|
|
unjar(os.path.join(JARCACHE, STruntime), trgdir="out")
|
2014-07-04 02:46:28 +08:00
|
|
|
# pull in target templates
|
|
|
|
for t in TARGETS:
|
2014-07-06 23:46:47 +08:00
|
|
|
trgdir = "out/org/antlr/v4/tool/templates/codegen/"+t
|
|
|
|
mkdir(trgdir)
|
2014-07-04 02:46:28 +08:00
|
|
|
copyfile(TARGETS[t]+"/tool/resources/org/antlr/v4/tool/templates/codegen/"+t+"/"+t+".stg",
|
2014-07-06 23:46:47 +08:00
|
|
|
trgdir)
|
2014-07-11 12:44:54 +08:00
|
|
|
jarfile = "dist/antlr-"+VERSION+"-complete.jar"
|
|
|
|
jar(jarfile, srcdir="out", manifest=manifest)
|
|
|
|
print "Generated "+jarfile
|
2014-07-07 00:21:46 +08:00
|
|
|
|
2014-07-11 12:44:54 +08:00
|
|
|
def mkjar_runtime():
|
2014-07-07 00:21:46 +08:00
|
|
|
# out/... dir is full of tool-related stuff, make special dir out/runtime
|
2014-07-13 08:03:23 +08:00
|
|
|
# unjar required library
|
|
|
|
unjar("runtime/Java/lib/org.abego.treelayout.core.jar", trgdir="out/runtime")
|
2014-07-07 00:21:46 +08:00
|
|
|
cp = uniformpath("out/runtime")+os.pathsep+ \
|
|
|
|
"runtime/Java/lib/org.abego.treelayout.core.jar"
|
|
|
|
args = ["-Xlint", "-Xlint:-serial", "-g"]
|
2014-07-13 08:03:23 +08:00
|
|
|
srcpath = ["gen4", "runtime/JavaAnnotations/src", "runtime/Java/src"]
|
2014-07-11 09:07:24 +08:00
|
|
|
args = ["-Xlint", "-Xlint:-serial", "-g", "-sourcepath", string.join(srcpath, os.pathsep)]
|
|
|
|
for sp in srcpath:
|
2014-07-17 04:34:29 +08:00
|
|
|
javac(sp, "out/runtime", version="1.6", cp=cp, args=args)
|
2014-07-07 00:21:46 +08:00
|
|
|
manifest = \
|
|
|
|
"""Implementation-Vendor: ANTLR
|
|
|
|
Implementation-Title: ANTLR 4 Runtime
|
|
|
|
Implementation-Version: %s
|
|
|
|
Built-By: %s
|
|
|
|
Build-Jdk: 1.6
|
|
|
|
Created-By: http://www.bildtool.org
|
|
|
|
""" % (VERSION,os.getlogin())
|
2014-07-11 12:44:54 +08:00
|
|
|
jarfile = "dist/antlr-runtime-" + VERSION + ".jar"
|
|
|
|
jar(jarfile, srcdir="out/runtime", manifest=manifest)
|
|
|
|
print "Generated "+jarfile
|
2014-07-07 00:21:46 +08:00
|
|
|
|
2014-07-11 12:44:54 +08:00
|
|
|
def mkjar():
|
|
|
|
mkjar_complete()
|
|
|
|
# put it in JARCARCHE too so bild can find it during antlr4()
|
|
|
|
copyfile(src="dist/antlr-4.4-complete.jar", trg=JARCACHE)
|
|
|
|
# rebuild/bootstrap XPath with 4.4 so it can use 4.4 runtime (gen'd with 4.3 at this point)
|
|
|
|
rmdir("gen4/org/antlr/v4/runtime/tree/xpath") # kill 4.3-generated version
|
|
|
|
antlr4("runtime/Java/src/org/antlr/v4/runtime/tree/xpath", "gen4", version="4.4", package="org.antlr.v4.runtime.tree.xpath")
|
|
|
|
compile()
|
|
|
|
mkjar_complete() # make it again with up to date XPath lexer
|
|
|
|
mkjar_runtime() # now build the runtime jar
|
2014-07-07 00:21:46 +08:00
|
|
|
|
2014-07-05 09:39:12 +08:00
|
|
|
def tests():
|
2014-07-06 10:13:05 +08:00
|
|
|
require(mkjar)
|
2014-07-05 09:39:12 +08:00
|
|
|
junit_jar, hamcrest_jar = load_junitjars()
|
2014-07-06 10:15:36 +08:00
|
|
|
cp = uniformpath("dist/antlr-"+VERSION+"-complete.jar")+os.pathsep+ \
|
2014-07-06 10:13:05 +08:00
|
|
|
uniformpath("out/test/Java")+os.pathsep+ \
|
|
|
|
junit_jar+os.pathsep+hamcrest_jar
|
|
|
|
properties = ["-D%s=%s" % (p, test_properties[p]) for p in test_properties]
|
2014-07-05 09:39:12 +08:00
|
|
|
args = ["-Xlint", "-Xlint:-serial", "-g"]
|
2014-07-06 10:13:05 +08:00
|
|
|
javac("tool/test", "out/test/Java", version="1.6", cp=cp, args=args) # all targets can use org.antlr.v4.test.*
|
|
|
|
for t in TARGETS:
|
|
|
|
print "Test %7s --------------" % t
|
2014-07-17 01:20:54 +08:00
|
|
|
# Prefix CLASSPATH with individual target tests
|
|
|
|
cp = uniformpath(TARGETS[t]+"/tool/test") + os.pathsep + cp
|
2014-07-06 10:13:05 +08:00
|
|
|
javac(TARGETS[t]+"/tool/test", "out/test/"+t, version="1.6", cp=cp, args=args)
|
|
|
|
junit("out/test/"+t, cp=cp, verbose=False, args=properties)
|
2014-07-05 09:39:12 +08:00
|
|
|
|
2014-07-02 09:18:17 +08:00
|
|
|
def all():
|
2014-07-04 02:46:28 +08:00
|
|
|
mkjar()
|
2014-07-05 09:39:12 +08:00
|
|
|
tests()
|
|
|
|
mkdoc()
|
2014-07-02 09:18:17 +08:00
|
|
|
|
|
|
|
def clean():
|
2014-07-04 02:46:28 +08:00
|
|
|
rmdir("out")
|
2014-07-11 09:07:24 +08:00
|
|
|
rmdir("gen3")
|
|
|
|
rmdir("gen4")
|
2014-07-04 02:46:28 +08:00
|
|
|
rmdir("doc")
|
2014-07-03 09:31:38 +08:00
|
|
|
|
|
|
|
def mkdoc():
|
2014-07-04 02:46:28 +08:00
|
|
|
mkdir("doc/Java")
|
|
|
|
mkdir("doc/JavaTool")
|
2014-07-17 03:07:17 +08:00
|
|
|
javadoc(srcdir=["runtime/Java/src","runtime/JavaAnnotations/src"],
|
|
|
|
trgdir="doc/Java", packages="org.antlr.v4.runtime")
|
2014-07-06 10:13:05 +08:00
|
|
|
toolsrc = [TARGETS[t]+"/tool/src" for t in TARGETS]
|
2014-07-04 02:58:57 +08:00
|
|
|
toolsrc = string.join(toolsrc, ":")
|
|
|
|
javadoc(srcdir=toolsrc, trgdir="doc/JavaTool", packages="org.antlr.v4")
|
2014-07-04 02:46:28 +08:00
|
|
|
# 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")
|
|
|
|
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")
|
|
|
|
zip("doc/antlr4-runtime.zip", "doc/Java")
|
|
|
|
zip("doc/antlr4-tool.zip", "doc/JavaTool")
|
2014-07-03 10:10:36 +08:00
|
|
|
|
|
|
|
processargs(globals()) # E.g., "python bild.py all"
|