--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/build.py Thu Jul 28 14:48:36 2011 +0100
@@ -0,0 +1,228 @@
+#!/usr/bin/env python
+
+# -c == clean
+
+
+# Note that we have to change directory below to make sure that build output
+# goes in the 'build' directory, not in the 'master' directory. For that
+# reason it's important that we use absolute paths!
+
+'''
+'''
+
+all = """
+ index
+ eltindex
+ attindex
+ propidx
+ expanded-toc
+ intro
+ concepts
+ render
+ struct
+ types
+ styling
+ coords
+ paths
+ shapes
+ text
+ painting
+ color
+ pservers
+ masking
+ filters
+ interact
+ linking
+ script
+ animate
+ fonts
+ metadata
+ backward
+ extend
+ svgdom
+ idl
+ java
+ escript
+ implnote
+ conform
+ access
+ i18n
+ minimize
+ refs
+ feature
+ mimereg
+ changes
+""".split()
+
+tocopy = """
+ style
+ images
+ svg.idl
+""".split()
+
+
+
+import os, sys, signal
+from os.path import isfile, abspath, getmtime, exists, join, normpath
+
+def exit(code, *message):
+ if len(message):
+ if code == 0:
+ print message[0]
+ else:
+ sys.stderr.write(message[0] + '\n')
+ sys.exit(code)
+
+# could allow this to be passed in:
+repo_dir = os.getcwd()
+
+master_dir = join(repo_dir, 'master')
+build_dir = join(repo_dir, 'build')
+publish_dir = join(build_dir, 'publish')
+tools_dir = normpath(join(repo_dir, '..', 'svg2-tools'))
+
+if not exists(master_dir):
+ exit(1, 'FAIL: build.py must be run from the root of the \'svg2\' repository')
+
+if not exists(tools_dir):
+ exit(1, 'FAIL: the \'svg2-tools\' repository must be checked out alongside '
+ ' the \'svg2\' repository')
+
+if not exists(publish_dir):
+ assert os.pardir not in publish_dir
+ os.makedirs(publish_dir)
+
+# Add clean-up handler for SIGINT:
+
+def handle_SIGINT(signal, frame):
+ done();
+ sys.exit(1);
+
+signal.signal(signal.SIGINT, handle_SIGINT)
+
+# Utility functions:
+
+toremove = []
+
+def done():
+ global toremove
+ if toremove:
+ print "Error, removing " + " ".join(toremove)
+ for file in toremove:
+ os.remove(file)
+ return 1;
+
+built_something = False
+
+def run(cmd):
+ global built_something
+ print cmd
+ if os.system(cmd):
+ done();
+ sys.exit(1);
+ built_something = True
+
+# clean and exit if given -c option:
+
+if len(sys.argv) == 2 and sys.argv[1] == "-c":
+ # clean build (and publish) directory
+ readme = join(build_dir, 'README.txt')
+ for parent, dirs, files in os.walk(build_dir, topdown=False):
+ for file in files[:]:
+ file = join(parent, file)
+ if file != readme:
+ os.remove(file)
+ for dir in dirs[:]:
+ os.rmdir(join(parent, dir))
+ sys.exit(0)
+
+# Build svg.idlx and java-binding.zip as required:
+
+svg_idl = join(master_dir, "svg.idl")
+svg_idlx = join(build_dir, "svg.idlx")
+java_bind_zip = join(publish_dir, "java-binding.zip")
+idl2java = join(master_dir, "idl2java.xsl")
+
+if not isfile(svg_idlx) or getmtime(svg_idl) > getmtime(svg_idlx) or \
+ not isfile(java_bind_zip) or getmtime(svg_idl) > getmtime(java_bind_zip):
+ # change directory so the build output doesn't get dumped in the repo!
+ os.chdir(build_dir)
+ toremove = [svg_idlx]
+ run("java -classpath " + join(tools_dir, "idlparser", "idlparser.jar") +
+ " au.id.mcc.idlparser.IDLToXML " + svg_idl + ">" + svg_idlx)
+ toremove = [java_bind_zip]
+ run("java -classpath " + join(tools_dir, "saxonb", "saxon9.jar") +
+ " net.sf.saxon.Transform -ext:on " + svg_idlx + " " + idl2java)
+ run("zip -rq " + java_bind_zip + " org")
+ toremove = []
+ tocopy.append(java_bind_zip)
+ os.chdir(repo_dir) # chdir back
+
+# Build chapters as required:
+
+deps = [
+ svg_idlx,
+ join(master_dir, "publish.xml"),
+ join(master_dir, "definitions.xml"),
+ join(tools_dir, "publish.xsl")
+]
+deptimes = [getmtime(file) for file in deps]
+tobuild = []
+tobuild_names = []
+for name in all:
+ pub_path = join(publish_dir, name + ".html")
+ src_path = join(master_dir, name + ".html")
+ if not isfile(pub_path):
+ tobuild.append(pub_path)
+ tobuild_names.append(name)
+ continue
+ desttime = getmtime(pub_path)
+ for srctime in deptimes + [getmtime(src_path)]:
+ if srctime > desttime:
+ tobuild.append(pub_path)
+ tobuild_names.append(name)
+ break
+
+if tobuild:
+ toremove = tobuild
+ os.chdir(master_dir)
+ run("java -classpath " + join(tools_dir, 'saxonb', 'saxon9.jar') +
+ " net.sf.saxon.Transform -ext:on -dtd:off -expand:off -l:on " +
+ join(master_dir, "publish.xml") + " " + join(tools_dir, "publish.xsl")+
+ " chapters-to-build=\"" + " ".join(tobuild_names) + "\"")
+ toremove = []
+ os.chdir(repo_dir) # chdir back
+
+# Build single page spec as required:
+
+buildSinglePage = False
+single_page = join(publish_dir, "single-page.html")
+
+if not isfile(single_page):
+ buildSinglePage = True
+else:
+ singlePageTime = getmtime(single_page)
+ for name in all:
+ if getmtime(join(master_dir, name + ".html")) > singlePageTime:
+ buildSinglePage = True;
+ break
+
+if buildSinglePage:
+ chaptersNoIndex = " ".join(all[1:])
+ run("xsltproc --novalid --stringparam publish '" + publish_dir +
+ "' --stringparam chapters '" + chaptersNoIndex + "' " +
+ join(tools_dir, "single-page.xsl") + " " +
+ join(publish_dir, "index.html") + " > " + single_page)
+
+# Copy over anything else that needs to be copied to 'publish':
+
+tocopypaths = " ".join([join(master_dir, s) for s in tocopy])
+
+run("rsync -auC " + tocopypaths + " " + publish_dir);
+
+# Done:
+
+if not built_something:
+ print "Nothing to do."
+
+done()