Created
December 24, 2009 04:55
-
-
Save wolever/263024 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
function must_have_var() { | |
eval VAL=\$$1 | |
if [[ "$VAL" == "" ]] | |
then | |
echo "$1 must be set." | |
exit 1; | |
fi | |
} | |
must_have_var "FLEX_HOME" | |
CONFIG='-load-config="${FLEX_HOME}/frameworks/flex-config.xml"' | |
CMD="mxmlc $CONFIG `./fb_project.py .` src/testrunner.mxml -output='/tmp/testrunner.swf'" | |
echo $CMD | |
eval $CMD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from xml.dom.minidom import NodeList, Document, Text, parse | |
import re | |
import os | |
class DumbObject(object): | |
pass | |
def shellquote(s): | |
s = s.replace('"', r'\"') # Escape any quotes | |
return '"' + s + '"' | |
def filter_text_nodes(xml): | |
child_nodes = xml | |
if hasattr(xml, "childNodes"): | |
child_nodes = xml.childNodes | |
return [ child for child | |
in child_nodes | |
if not isinstance(child, Text) ] | |
def xml_get(xml, path, _patherr=None): | |
""" Get a value from an xml.dom.mindom.*. | |
>>> from xml.dom.minidom import parseString | |
>>> breakfast = parseString("<breakfast>" + | |
... "<eggs color='green' />" + | |
... "<ham />" + | |
... "<drink>no</drink>" + | |
... "</breakfast>") | |
>>> xml_get(breakfast, 'eggs/color') | |
u'green' | |
>>> xml_get(breakfast, 'drink/[text]') | |
u'no' | |
>>> [ item.tagName for item in xml_get(breakfast, 'breakfast') ] | |
[u'eggs', u'ham', u'drink'] | |
>>> """ | |
if _patherr is None: | |
_patherr = "Could not match portion %%r of %r" %(path) | |
part, rest = (path+"/").split("/", 1) | |
rest = rest.rstrip("/") | |
# If we get a NodeList, just consider the first item | |
if isinstance(xml, NodeList): | |
xml = filter_text_nodes(xml) | |
if len(xml) < 1: | |
raise Exception(_patherr %part) | |
xml = xml[0] | |
if rest: | |
elements = xml.getElementsByTagName(part) | |
if len(elements) == 0: | |
raise Exception(_patherr %part) | |
return xml_get(elements, rest, _patherr) | |
else: | |
if part == "[text]": | |
if len(xml.childNodes) < 1: | |
raise Exception(_patherr %part) | |
return xml.childNodes[0].data | |
if hasattr(xml, "hasAttribute") and xml.hasAttribute(part): | |
return xml.getAttribute(part) | |
xml = filter_text_nodes(xml.getElementsByTagName(part)) | |
if len(xml) < 1: | |
raise Exception(_patherr %part) | |
return filter_text_nodes(xml[0]) | |
def load_fb_project_directory(dir): | |
""" Load the FlexBuilder configuration from a particular directory. | |
Documenting the contents would be silly - just read the source. """ | |
project = DumbObject() | |
path = lambda *parts: os.path.join(dir, *parts) | |
project.path = path | |
# Load the .actionScriptProperties | |
asp = parse(path(".actionScriptProperties")) | |
project.asp_xml = asp | |
project.compiler_arg_str = xml_get(asp, "compiler/additionalCompilerArguments") | |
project.output_path = xml_get(asp, "compiler/outputFolderPath") | |
project.warnings = xml_get(asp, "compiler/warn") | |
# Find the source paths | |
project.source_paths = [ xml_get(asp, "compiler/sourceFolderPath") ] | |
project.source_paths += [ xml_get(cspe, "path") for cspe | |
in xml_get(asp, "compiler/compilerSourcePath") ] | |
project.main_source_path = project.source_paths[0] | |
# Find library paths | |
project.lib_paths = [] | |
for lpe in xml_get(asp, "compiler/libraryPath"): | |
if xml_get(lpe, "kind") == "4": | |
# The framework libraries | |
lib_path = "${FLEX_HOME}/frameworks/libs/" | |
else: | |
lib_path = xml_get(lpe, "path") | |
project.lib_paths.append(lib_path) | |
# And find the applications | |
project.applications = [ xml_get(app, "path") for app | |
in xml_get(asp, "applications") ] | |
# Load the .project | |
proj = parse(path(".project")) | |
project.proj_xml = proj | |
project.name = xml_get(proj, "projectDescription/name/[text]") | |
return project | |
def fb_project_to_mxmlc_args(project): | |
""" Figure out what compiler arguments 'mxmlc' would require to build | |
a given project the same way FlexBuilder would build that project. | |
Ideally, it should be possible to run: | |
> system("mxmlc " + fb_project_to_mxmlc_args(project) + " src/foo.mxml") | |
And 'foo.swf' will be built exactly the same way FlexBuilder would | |
do it. """ | |
args = [ project.compiler_arg_str ] | |
def add_arg(arg, value, joiner="=", is_path=True): | |
if value == '' or value is None: | |
return | |
if is_path: | |
if isinstance(value, unicode): | |
value = value.encode('utf-8') | |
value = shellquote(value) | |
args.append("%s%s%s" %(arg, joiner, value)) | |
add_arg('-warnings', project.warnings, is_path=False) | |
for source_path in project.source_paths: | |
add_arg('-source-path', source_path, '+=') | |
for lib_path in project.lib_paths: | |
add_arg('-library-path', lib_path, '+=') | |
return " ".join(args) | |
def fb_app_source_path(project, app): | |
return os.path.join(project.main_source_path, app) | |
if __name__ == "__main__": | |
import sys | |
if len(sys.argv) != 2: | |
print "Usage: %s FB_PROJECT_DIRECTORY" %(sys.argv[0]) | |
sys.exit(1) | |
project = load_fb_project_directory(sys.argv[1]) | |
print fb_project_to_mxmlc_args(project) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment