Cross-platform convenience wrapper around fcsh (for fast incremental Flex builds)

For the impatient

fcshd is a convenient command line PHP based wrapper around fcsh shell. It works both in *nix and Windows. You can grab it from the downloads section of the flash-automation project. Just unzip it, enter the directory and run “php fcshc.php” in the shell to get the basic usage help.

The long boring story

I’m currently working on a client/server application which is going to have a flash based client side written with Flex SDK.

Since I’m a big fan of the build process automation it was such a relief to know that there is a cross-platform mxmlc command line tool which allows to build as3 sources into the final swf. I know, there are different IDEs for Flex which pretty much automate lots of things including the build process. However, I’m not a big fun of IDEs, I like simpler solutions made in the spirit of the “unix way”(many small highly specialized tools instead of the one big fat tool).

So far so good, I implemented the whole project build pipeline using my PHP library taskman(more on it on some other day). By the way, the cool thing about the total control of the build process is the fact I could inject a simple preprocessor support for as3 sources(this topic deserves its own blog post as well).

The build process worked just fine both on Linux and Windows boxes, the only thing which made me a little upset was the startup time of the mxmlc for incremental builds. There is an fcsh shell which speeds up the incremental builds by keeping in memory the heavy mxmlc java process, but it’s a complete pain to use it in the batch mode since it provides an interactive interface only.

After a little bit of googling I discovered a wrapper around fcsh - the fcshctl tool. It is almost ideal except several drawbacks:

  • *nix only. It requires a few GNU utilities normally not available on Windows(in theory it’s possible to setup cygwin and friends on Windows but it’s such a pain in the butt)
  • doesn’t flush the build cache once the mxmlc options change(e.g. you have to kill it running in the background whenever you change mxmlc compile options)
  • rare sporadic hang ups(I have observed this behavior on my box only though)

Actually, I could live with all of these drawbacks but one - *nix only. While I’m a *nix guy, there are other folks in the office who have their reasons to like Windows and I respect their choice :) Of course, I could use fcshctl for builds on Linux while use mxmlc on Windows and make them feel envy but I’m not that mean.

So I wrote my own cross-platform convenience wrapper around fcsh which was tested on Linux and Windows. Meet fcshd!(couldn’t think of a better name :) ) fcshd is a very thin wrapper which simply passes all arguments to fcsh and returns the execution results.

fcshd is written in PHP and consists of a simple server and a client. This is how it works:

  • frontend utility fcshc accepts client requests, passes them to the fcshd server. It also automatically starts the fcshd if it’s not running.
  • fcshd server listens on some port for client requests. It spawns the fcsh process and keeps it’s opened communicating with it via pipes.

Here is the usage help:

  fcshc [--host=host] [--port=port] [--noauto=1] -- <fcsh cmd>
  --host     - fcshd host( by default)
  --port     - fcshd port(8067 by default)
  --noauto   - don't try to spawn the fcshd daemon automatically
  <fcsh cmd> - command passed to fcsh(see its documentation),
               NOTE: additional mxmlcsmart command is supported,
                     whicn can be used instead of mxmlc/compile commands
                     for incremental builds

Let’s execute some simple fcsh command in a batch mode, say, help. Try the following in the shell(note, this should work without any changes both for *nix and Windows):

> fcshc -- help
start  "fcshd"  /MIN php fcshd.php --host= --port=8067
List of fcsh commands:
mxmlc arg1 arg2 ...      full compilation and optimization; return a target id
compc arg1 arg2 ...      full SWC compilation
compile id               incremental compilation
clear [id]               clear target(s)
info [id]                display compile target info
quit                     quit

fcshd.JPG Besides this result, on Windows you should see a separate window titled fcshd spawn and running minimized. This is an fcshd server window where you can see all internal fcsh communications. On the second and consequent runs of fcshc the server won’t be started again. Almost the same thing happens for *nix - the only difference is fcshd running in a hidden screen session(still you can attach to this session using the following command: screen -r -S fcshd).

fcshd supports all fcsh commands and also adds its own mxmlcsmart command which can be used instead of mxmlc/compile commands. In fcsh one has to initially create the compile target by invoking the mxmlc command, remember the compile target id and later use this id with compile command for incremental builds. The mxmlcsmart command does all of this hassle for you, just use it for painfree incremental builds.

Here is the typical usage of fcshd in a taskman powered build script:

 * @deps client_autogen,client_prepare_build,fla2swf
 * @alias cb
function task_client_build()
  global $PROJECT_ROOT;
  "php $PROJECT_ROOT/shared/utils/fcshd/fcshc.php " . 
  "--noauto=1 --host=$fcsh_host --port=$fcsh_port " . 
  "-- mxmlcsmart " .
  "-default-size 800 600 " . 
  get_client_shared_build_options() . 
  "-source-path $PROJECT_ROOT/client/src $PROJECT_ROOT/client/lib " .
  "-output $PROJECT_ROOT/client/build/app.swf " .
  "$PROJECT_ROOT/client/src/com/<skipped>/ "

Of course, fcshd has its own drawbacks:

  • requires PHP with sockets extension enabled(on *nix sockets are usually available by default, on Windows you have to enable it explicitly in php.ini)
  • written in PHP(while probably Python could be more appropriate for this task. I could write it in Python, it would just take me much longer to implement it and I needed a working solution ASAP)
  • there are probably bugs I’m not aware of yet

But it definitely works for me and, who knows, may come in handy for you as well.

P.S. Next time I’ll blog about a nifty fla2swf command line tool which acts as a server converting fla files into swf, stay tuned.

3 Responses to “Cross-platform convenience wrapper around fcsh (for fast incremental Flex builds)”

  1. andré felipe Says:

    Looks hot man, keep up!

    I am looking for a way to build SWFs online and this looks like a place to start, thanks!

  2. pachanga Says:

    Well, for your task you can simply use mxmlc since fcshd is more suited for incremental builds(which is not your case, I believe)

  3. My desperate life quest for efficiency » Blog Archive » fla2swf - command line .fla to .swf publishing utility Says:

    […] « Cross-platform convenience wrapper around fcsh (for fast incremental Flex builds) […]

Leave a Reply