playing around with ant

cat-town
Dan Buch 15 years ago
parent 22ba96dbdd
commit 171ddc7c59

1
.gitignore vendored

@ -1,3 +1,4 @@
*.pyc
*.swf
*.swc
*.swf.cache

@ -0,0 +1,61 @@
<project name="LearningFlex" basedir="." default="build">
<property environment="env"/>
<property name="FLEX_HOME" value="${env.FLEX_HOME}"/>
<property name="APP_ROOT" value="${basedir}"/>
<taskdef resource="flexTasks.tasks" classpath="${env.FLEX_HOME}/ant/lib/flexTasks.jar"/>
<target name="build">
<mxmlc as3="true" file="./01-flickr/FlickrRIA.mxml"/>
<mxmlc as3="true" file="./01-flickr/FlickrThumbnail.mxml"/>
<mxmlc as3="true" file="./02-shipping/PlainText.mxml"/>
<mxmlc as3="true" file="./03a1-binding-and-modeling/YahooWeather.mxml"/>
<mxmlc as3="true" file="./03a2-crud-dynamic/CRUDDynamic.mxml"/>
<mxmlc as3="true" file="./03a3-crud-static/CRUDStatic.mxml"/>
<mxmlc as3="true" file="./03a4-external-interface/Main.mxml"/>
<mxmlc as3="true" file="./03a5-local-connections/BasicTaskReceiver.mxml"/>
<mxmlc as3="true" file="./03a5-local-connections/TaskSender.mxml"/>
<mxmlc as3="true" file="./03a6-shared-objects/SharedObjectExample.mxml"/>
<mxmlc as3="true" file="./03a7-validation-and-formatting/ValidatorsandFormattersExampleWithAreaCodeLookup.mxml"/>
<mxmlc as3="true" file="./03b-handling-events/TwitterTimeline.mxml"/>
<mxmlc as3="true" file="./03b1-event-listeners/VBoxDemo.mxml"/>
<mxmlc as3="true" file="./03b2-event-propagation/DemoApplication.mxml"/>
<mxmlc as3="true" file="./03b3-simple-ui-event/Example1.mxml"/>
<mxmlc as3="true" file="./03b3-simple-ui-event/Example2.mxml"/>
<mxmlc as3="true" file="./03c1-application-container/Demo.mxml"/>
<mxmlc as3="true" file="./03c2-box-model/HBoxExample.mxml"/>
<mxmlc as3="true" file="./03c2-box-model/VBoxExample.mxml"/>
<mxmlc as3="true" file="./03c2-box-model/VBoxHBoxCombo.mxml"/>
<mxmlc as3="true" file="./03c3-canvas-absolute/Example.mxml"/>
<mxmlc as3="true" file="./03c4-canvas-relative/Photo.mxml"/>
<mxmlc as3="true" file="./03c5-combined-layout/Combined.mxml"/>
<mxmlc as3="true" file="./03c6-form/CommentForm.mxml"/>
<mxmlc as3="true" file="./03c7-mxml-vs-as3/WithAs3.mxml"/>
<mxmlc as3="true" file="./03c7-mxml-vs-as3/WithMxml.mxml"/>
<mxmlc as3="true" file="./03c8-panel/Photo.mxml"/>
<mxmlc as3="true" file="./03d1-datagrid/DataGridExample.mxml"/>
<mxmlc as3="true" file="./03d2-item-renderers/HBoxWeatherDisplay.mxml"/>
<mxmlc as3="true" file="./03d2-item-renderers/WeatherDisplay.mxml"/>
<mxmlc as3="true" file="./03d3-lists/HorizontalListControl.mxml"/>
<mxmlc as3="true" file="./03d3-lists/ListControl.mxml"/>
<mxmlc as3="true" file="./03d4-tilelist/TileListExample.mxml"/>
<mxmlc as3="true" file="./03e1-accordion/Recipe.mxml"/>
<mxmlc as3="true" file="./03e2-tabbar-linkbar/LinkBar.mxml"/>
<mxmlc as3="true" file="./03e2-tabbar-linkbar/TabBarDemo.mxml"/>
<mxmlc as3="true" file="./03e3-tabnavigator/Shopping.mxml"/>
<mxmlc as3="true" file="./03e4-viewstack/ViewStackDemo.mxml"/>
<mxmlc as3="true" file="./03f1-custom-components/MainForm.mxml"/>
<mxmlc as3="true" file="./03f2-code-behind/CodeBehindDisplay.mxml"/>
<mxmlc as3="true" file="./03f2-code-behind/CodeExample.mxml"/>
<mxmlc as3="true" file="./03f3-composite-component/ComponentForm.mxml"/>
<mxmlc as3="true" file="./03f4-multiple-composite-components/Main.mxml"/>
<mxmlc as3="true" file="./03f5-mxml/MainForm.mxml"/>
<mxmlc as3="true" file="./03g1-debugging/Debugging.mxml"/>
<mxmlc as3="true" file="./custom-03d1-datagrid/Snarf.mxml"/>
<mxmlc as3="true" file="./custom-03d2-item-renderers/HBoxWeatherDisplay.mxml"/>
<mxmlc as3="true" file="./custom-03d2-item-renderers/WeatherDisplay.mxml"/>
<mxmlc as3="true" file="./custom-03d3-lists/ListControl.mxml"/>
<mxmlc as3="true" file="./custom-03d4-tilelist/TileListExample.mxml"/>
<mxmlc as3="true" file="./custom-03g1-debugging/Debugging.mxml"/>
<compc output="./custom-03g1-debugging/me/tests/TestSuite.swf" source-path="${basedir}"/>
</target>
</project>

@ -0,0 +1,182 @@
#!/usr/bin/env python
from __future__ import print_function
import os
import re
import sys
import glob
from io import BytesIO
from fnmatch import fnmatch
from itertools import ifilter
from os.path import join as pathjoin, relpath, dirname, \
abspath, basename, splitext, sep as pathsep
import lxml.etree as ET
HERE = dirname(abspath(__file__))
AUTOGEN_WARNING = ('<!-- ******** AUTOGENERATED by {0} ' +
('*' * 20) + '-->').format(basename(sys.argv[0]))
ROOT = BytesIO(''.join([_line.strip() for _line in """\
<project name="LearningFlex" basedir="." default="build">
<property environment="env" />
<property name="FLEX_HOME" value="${env.FLEX_HOME}" />
<property name="APP_ROOT" value="${basedir}" />
<taskdef resource="flexTasks.tasks" """
"""classpath="${env.FLEX_HOME}/ant/lib/flexTasks.jar" />
<target name="build" />
</project>
""".splitlines() if _line.strip()]))
# TARGET_FMT = '{target}:' + DEP_SEP + '{deps}'
# RULE_FMT = '\\\n\t'.join([
# '\t$(MXMLC) {primary_dep} ',
# '$(MXMLC_FLAGS) ',
# '-l+={parent_dir} ',
# '-l+={package_base} ',
# '-l+={flexunit} ',
# '-sp+={package_base} ',
# '-sp+={flexunit} ',
# '-o {target}',
# ])
def main(sysargs=sys.argv[:]):
build_xml = pathjoin(HERE, 'build.xml')
os.chmod(build_xml, 0600)
buildxml_maker = BuildXMLMaker(outstream=open(build_xml, 'wb'))
buildxml_maker.make()
os.chmod(build_xml, 0444)
return 0
class BuildXMLMaker(object):
_to_glob = (
pathjoin(HERE, '[0-9]*-*', '*.mxml'),
pathjoin(HERE, 'custom-*', '*.mxml'),
)
_source_fileexts = ('.mxml', '.as', '.css')
def __init__(self, outstream=sys.stdout):
self.outstream = outstream
self.targets = {'compc': {}, 'mxmlc': {}}
self.tree = ET.parse(ROOT)
self.root = self.tree.getroot()
self.build = self.tree.xpath('//target[@name="build"]')[0]
def make(self):
self._glob_for_top_level_mxml_targets()
self._find_test_suite_targets()
self._write_out_targets()
def _glob_for_top_level_mxml_targets(self):
for pattern in self._to_glob:
for mxml in glob.glob(pattern):
self._add_target_from_mxml(mxml)
def _find_test_suite_targets(self):
for dirpath, dirnames, filenames in os.walk(HERE):
filter_generated_dirs(dirnames)
for filename in filenames:
if is_test_suite(filename):
test_suite = pathjoin(dirpath, filename)
self._add_target_from_test_suite(test_suite)
def _add_target_from_test_suite(self, test_suite):
rel_class = relpath(test_suite, HERE)
self.targets['compc'][rel_class] = dict()
def _add_target_from_mxml(self, mxml):
rel_mxml = relpath(mxml, HERE)
self.targets['mxmlc'][rel_mxml] = {} #dict(sources='')
self._add_deps_from_alt_source_file_extensions(rel_mxml)
def _add_deps_from_alt_source_file_extensions(self, rel_mxml):
basedir = dirname(rel_mxml)
# sources = self.targets['mxmlc'][rel_mxml]['sources']
for dirpath, dirnames, filenames in os.walk(basedir):
filter_generated_dirs(dirnames)
filter_test_suitees(filenames)
for filename in filenames:
if ext(filename) in self._source_fileexts:
rel_source = relpath(pathjoin(dirpath, filename), HERE)
# sources += (' ' + rel_source)
def _write_out_targets(self):
for mxml in sorted(self.targets['mxmlc'].iterkeys()):
rel_target = './' + mxml.lstrip('./')
attrs = dict(file=rel_target, as3='true')
attrs.update(self.targets['mxmlc'][mxml])
ET.SubElement(self.build, 'mxmlc', **attrs)
for as3 in sorted(self.targets['compc'].iterkeys()):
rel_target = './' + as3.lstrip('./')
as_swf = re.sub('(.*).as$', '\\1.swf', rel_target)
attrs = {'output': as_swf, 'source-path': '${basedir}'}
attrs.update(self.targets['compc'][as3])
ET.SubElement(self.build, 'compc', **attrs)
print(ET.tostring(self.root, pretty_print=True),
file=self.outstream)
def _get_deps_for_target(self, target):
deps = []
for dep in reversed(sorted(list(self.targets[target]), key=ext)):
deps.append(dep)
return deps
def _get_primary_dep(self, target, deps):
primary_dep = deps[0]
for dependency in deps:
if fnmatch(target, namebase(dependency) + '.*'):
primary_dep = dependency
return primary_dep
def _get_pattern_rule_kwargs(self, primary_dep, target):
ret = dict(
primary_dep=primary_dep,
parent_dir=dirname(primary_dep),
package_base=primary_dep.strip('./').split(pathsep)[0],
target=target,
flexunit=FLEXUNIT
)
return ret
def ext(filename):
return splitext(filename)[-1]
def namebase(filename):
return splitext(filename)[0]
def filter_generated_dirs(dirnames):
for i, directory in enumerate(dirnames[:]):
if directory == 'generated':
dirnames[i] = None
dirnames[:] = list(ifilter(None, dirnames))
def filter_test_suitees(filenames):
for i, filename in enumerate(filenames[:]):
if is_test_suite(filename):
filenames[i] = None
filenames[:] = list(ifilter(None, filenames))
def is_test_suite(filename):
base_filename = basename(filename)
return base_filename.startswith('TestSuite') and \
ext(filename) == '.as'
if __name__ == '__main__':
sys.exit(main())
# vim:filetype=python
Loading…
Cancel
Save