views:

35

answers:

3

I'm looking for a way to collect the file dependencies from Flex ActionScript and MXML files. I was hoping that mxmlc could spit them out (like gcc's -M option), but its option list doesn't seem to have anything relevant. I could write a parser, but would prefer not to reinvent the wheel if it has already been done, particularly given the two very different languages involved. In particular, star imports and in-package implicit imports could be troublesome.

Is there a program available to do this for me?

A: 

i am suspecting that since mxmlc is pretty smart and handles dependencies correctly, few people would need to figure out the dependencies themselves, and so the tool may have not come into existence.

I guess parsing the import statements would be the way to go?

coolnalu
If only it were as simple as just import statements... There are also XML namespaces getting set to packages, and classes being implicitly imported within their packages, with the files in the packages being split across two source trees.
eswald
+1  A: 

Take a look at http://stackoverflow.com/questions/548830. There's an AS flavor for Structure101g, it doesn't support MXML yet but it's on the list! :)

pth
Thank you for the link. That question also points to ItDepends, which seems close to what I need.
eswald
A: 

The -link-report option of mxmlc produces a file containing most of the appropriate information, except that it reports fake file names for embedded assets, and ignores included source files. To collect everything, I now have the following in my makefile:

.deps/%.d: .deps/%.xml
    # $@: $<
    grep '<script name=./' $< | cut -f2 -d'"' | cut -f1 -d'(' | cut -f1 -d'$$' | sort -u  | sed -e "s|^$$(pwd)/||" > .deps/$*.f
    grep '\.mxml$$' .deps/$*.f | xargs grep -H 'mx:Script source' | sed -s 's|/[^/]*.mxml:.*source="\([^"]*\)".*|/\1|;' > .deps/$*.i
    for path in $$(grep -h '\.\(mxml\|as\|css\)$$' .deps/$*.[fi] | xargs grep '\bEmbed([^.)]' | \
        sed "s@\\(\\w\\+\\)/.*Embed([^'\")]*['\"][./]*\\([^'\"]*\\)['\"] *[,)].*@\\1/*/\\2@"); \
        do find */src -path "$$path"; done | sort -u > .deps/$*.e
    cat .deps/$*.[fie] | sed -e "s|^|$(flashpath)$*.swf $@ : |" > $@

# This includes targets, so should not be before the first target defined here.
built := $(wildcard .deps/*.xml)
include $(built:xml=d)

All of the mxmlc and compc commands in the makefile now have -link-report generating an appropriately-named .xml file in the .deps directory. I still have to search files for Embed and Script directives, but the hard part (determining which classes get included) has been done for me. I could use a real parser for each step, but grep, sed, and cut work well enough for the files as given.

eswald