Creating a swc library with selected packages in FDT

Sometimes you need to expose only part of your code library in a swc code library file. Maybe you work with propriety code, but also have the need to expose your framework to external developers, so you create some pretty interfaces that externals can use without exposing company code.

One way of distributing these interfaces can be to create a swc library file that only holds your public interfaces.

The compc compiler gives you some options to specify what classes, interfaces, namespaces or packages to include, but when using the Run-configurations that comes with FDT, FDT automatically adds the whole shebang. This is ok for a swc file with no secrets hidden (no mention to decompilers)

As I remember it, the Flex-plugin/editor gives you a nice ui to select what packages to include in your swc file, but FDT is a bit more old-skool.

In this example i use the -include-sources compiler option, but the compc compiler also has the -include-classes option which gives you fine-grained control over what classes and interfaces are exposed in your public swc library file.

In FDT this is one way to do it:

    1. Create a new “FDT AS3 Library” in “Run Configurations…”
    2. Select the “Compiler Arguments” panel and uncheck the checkboxes “Auto add project classpath to arguments” and “Auto add project SWCs to Arguments”. Auto add project classpath…” will insert classpaths to all your packages, which is not the intention, and the project swcs are only needed if your code relies on the definitions found inside the swcs
    3. Insert a -source-path option. Working on a PC for a change, I found that I had to use the full path, no quotation marks and with abbreviated folder names. This means that the path variable for the -source-path option looked like this:
      -source-path=c:/docume~1/<userna~1>/mydocu~1/eclips~1/<projna~1>/src
      

Also remember to use the equals sign

    1. Insert a -include-sources option for every package you want to expose using the same fill path syntax rules. This means that if I want to include my com.andkrup.externalmodules package, I need to add this:
      -include-sources=c:/docume~1/<userna~1>/mydocu~1/eclips~1/<projna~1>/src/com/andkrup/easygame/extern~1/
      
    2. Apply and run.

The <userna~1> indicates that you should exchange it with the abbrevciated name of your user-folder. The same goes for the <projna~1> which indicates that you should exchange it with the abbrevciated name of your project-folder.

FDT will add the output option based on your Output-setting in the “Main” panel.

On the PC I found the compc compiler to act extremely picky about the syntax, using eclipse/FDT. It was very easy to get compc to compile in the commandline, but it seems that you have to be careful about whitespace and line-breaks/returns when you add custom arguments in the “Compiler Arguments” panel in eclipse/FDT.

I was banging my head on the keys for a long time, trying to get compc to accept quoted paths as this:

“C:\Documents and Settings\…”

It seems that when you specify arguments in the “Compiler Arguments” panel, you have to use dos-abbreviated folder names in the path variable which also must not be quoted.

When I get back from the weekend, I’ll have to check how it works on the Mac.

You could also create an ant build file to do the same job, but this post was primarily about how to use the FDT AS3 Library Run configuration.

edit: Instead of using the full absolute path, FDT declares a project-path variable which makes the launch settings more portable. Please read the comments for more information

Advertisements

5 Responses to “Creating a swc library with selected packages in FDT”

  1. I know this not a recent post, but a very useful shortcut in FDT is doing:

    -include-source {project}/src

    Romu

  2. Scottae Says:

    Very helpful post…thank you. I think you have a typo. I think that ‘include-source’ needs to be ‘include-sources’.

    http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_22.html

    When I tried ‘include-source’ it does not work but ‘include-sources’ does.

    • andkrup Says:

      thx for commenting and pointing out the typo – should be fixed now

      I have switched to using apache ant with the compc task for some time now. It is much easier to work with as there is nothing of these quirks to consider.

  3. Thanks for posting, I tried getting this to work, but kept having issues getting the main class accepted. Then I found it is easier on the command line if it’s just about one package. Just one line. See http://stackoverflow.com/questions/2740374/compiling-swc-file-from-fdt

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: