How can I automate the building of a Flex component library?
Asked Answered
H

3

8

I would like to build a flex library project automatically instead of the current process, which involves one of our developers compiling it on his machine and then us checking in the resulting .swc file. It's gross.

I am coming at this from the perspective of a java developer, so I'm having a hard time getting the hang of the compilation tools provided in the Flex Builder 3 application, but here's what I already have:

  1. I have created an ant file that loads the ant task library correctly, and can therefore execute <mxmlc/> and <compc/> tasks.
  2. I have located the source code that I need to build, and know what sort of .swc I want to end up with.

What I want is an ant script that will do the equivalent of these steps:

  1. We build all sources (actionscript and MXML) and assets in the project into an swc file.
  2. The library.swf file is extracted and optimized

So far I have this:

<target name="compile-component" depends="init">
  <compc output="${DEPLOY_DIR}/${SWC_NAME}.swc">
    <source-path path-element="${FLEX_HOME}/frameworks"/>
    <source-path path-element="${SRC_DIR}"/>
  </compc>
</target>

However, it's not including any content:

[compc] Loading configuration file /Applications/Adobe Flex Builder 3/sdks/3.2.0/frameworks/flex-config.xml
[compc] Adobe Compc (Flex Component Compiler)
[compc] Version 3.2.0 build 3958
[compc] Copyright (c) 2004-2007 Adobe Systems, Inc. All rights reserved.
[compc] 
[compc] Error: nothing was specified to be included in the library
[compc] 
[compc] Use 'compc -help' for information about using the command line.

It looks like I need to enumerate every class that I want to include in the library, which is... ludicrous. There must be a better way. How do I do this?

Harberd answered 8/9, 2009 at 19:27 Comment(1)
The command line MXMLC compiler, as far as I know, compiles only one file at a time (be great if I was wrong!). For an application with various .mxml files what we've ended up doing is creating an Ant target that iterates over each .mxml file (using the ant-contrib for task), and running the mxmlc task for each file in turn. I can provide our <target> code if you like, but it is slightly different to compiling a bunch of components into a single SWFYadirayaeger
C
12

You can do the following... it takes all the files from the source path and converts it to a format that the compc task can then use.

<fileset id="project.test.dir.fileset" dir="${project.test.dir}">
    <include name="**/*.as" />
    <include name="**/*.mxml" />
</fileset>
<property name="project.test.dir.fileset" refid="project.test.dir.fileset" />

<!-- Convert the test files into a compiler friendly format. -->
<pathconvert property="project.test.dir.path" pathsep=" " refid="project.test.dir.fileset">
    <compositemapper>
        <chainedmapper>
            <globmapper from="${project.test.dir}/*" to="*" handledirsep="true" />
            <mapper type="package" from="*.as" to="*" />
        </chainedmapper>
        <chainedmapper>
            <globmapper from="${project.test.dir}/*" to="*" handledirsep="true" />
            <mapper type="package" from="*.mxml" to="*" />
        </chainedmapper>
    </compositemapper>
</pathconvert>

<compc headless-server="true" default-frame-rate="${flex.default-frame-rate}" debug="${flex.compiler.debug.mode}" output="${build.swc.dir}/${test.component.name}.swc" include-classes="${project.test.dir.path}" directory="false">
    <source-path path-element="${project.test.dir}" />
    &dependencies;
</compc>

We use it to produce swcs for testing purposes.

Centillion answered 9/9, 2009 at 8:12 Comment(2)
Checkout Rick's answer which uses the include-sources element. Seems to be a more elegant solution.Sharpnosed
Since I found the documentation for compc lacking, I'd like to metion that the <library-path /> element also works for compc just like mxmlc and can be used to compile against existing swc libraries if your project requires any. With that minor addition, this worked great for me, thanks!Eelpout
R
10

Lucky for you I JUST solved this problem and was looking for the answer to another problem!

    <compc output="${basedir}/mySwc.swc" locale="en_US">
        <source-path path-element="${basedir}/src/main/flex"/>
        <include-sources dir="${basedir}/src/main/flex" includes="*" />
        <load-config filename="${basedir}/fb3config.xml" />
    </compc>

The source-path is necessary to tell it what to look at when trying to resolve various references. The include-sources tells it which sources to include (obviously in this case all of them). The load-config is just the -dump-config output from Flex Builder.

Hope this helps!!

Rolandrolanda answered 22/4, 2010 at 21:8 Comment(2)
Will this include assets such as images and CSS files?Harberd
... it turns out that yes, it tries to include images/CSS files, but that fails because they're not AS/mxml files. What a crock.Harberd
W
1

You can use Maven. It's a configuration management tool rather than just a build tool. It does rely on your project having a manifest file.

Whipsaw answered 26/1, 2010 at 9:48 Comment(1)
Can you provide a concrete example? Ideally one that integrates with FB4 for development.Harberd

© 2022 - 2024 — McMap. All rights reserved.