27
Apr
Facebook-Matrix

This post is very developer-centric. If you don't write software or you aren't trying to fall asleep, turn back now. You have been warned.

When most of us think about Facebook, open source software probably isn't the first thing that jumps to mind. As it turns out, the social media titan has quite a few public contributions that we rarely hear about. Since Facebook went native, Android development has become a high priority within the company. Among the many pleasant results of this shift, some of the internal tools may find their way into the public domain. One such project is Buck, an alternative build system similar to Ant, but designed to be faster and more modular.

Features

Buck can help you do the following:

  • Speed up your Android builds. Buck builds independent artifacts in parallel to take advantage of multiple cores. Further, it reduces incremental build times by keeping track of unchanged resources so that the minimal set of resources is rebuilt.
  • Introduce ad-hoc build steps for building artifacts that are not supported out-of-the-box using the standard Ant build scripts for Android.
  • Keep the logic for generating build rules in the build system instead of requiring a separate system to generate build files.
  • Generate code-coverage metrics for your unit tests.
  • Generate an IntelliJ project based on your build rules. This makes Buck ideal for both local development builds in an IDE as well as headless builds on a continuous integration machine.
  • Make sense of your build dependencies.
  • Understand what is going on under the hood when building an APK.

Fundamentally, Buck is optimized to speed up large builds by using dependencies to determine which packages can be compiled simultaneously, something Ant was never designed for. Syntax is very similar to Javascript, breaking from the traditional XML format which is often criticized for being error prone and difficult to manage on larger projects. The tool expects all script files to be named BUCK and spread across directories, somewhat like Subversion's files.

These are some samples of BUCK scripts (copied from the website).

If you use IntelliJ for your Android development, it's possible to generate project files and build directly from the IDE. Unfortunately, there's no way to reverse that flow and create BUCK scripts from IntelliJ projects, so everything has to be written by hand. For Eclipse users, Buck won't get in your way, but using it from the IDE will require some extra setup steps.

While there are some benefits to this nifty little tool, one very notable drawback will probably stop most people from using it. Buck is only available on Mac and Linux, and it looks like Windows compatibility will not be coming. The mainstream open source community rarely adopts tools that completely exclude Windows unless it makes sense to do so. Several Ant competitors have turned up in the past, and most have failed to gain traction, so an OS-dependent alternative faces a very difficult uphill challenge. Of course, if a few members of the open source community see enough potential, we may see a Windows port and other enhancements in the future.

For small to medium-sized projects, build times are rarely an issue and most of the work is already done by IDEs. There is definitely potential for Buck to be an asset in larger applications where each compilation can take 15 seconds or longer, but given the limitations, I have my doubts that we will see very many projects relying on it. Still, it's great to see new battle-tested tools emerging as open source projects that may lead to better things down the road.

Github

Cody Toombs
Cody is a Software Engineer and Writer with a mildly overwhelming obsession with smartphones and the mobile world. If he’s been pulled away from the computer for any length of time, you might find him talking about cocktails and movies, sometimes resulting in the consumption of both.

  • http://www.Nave360.com Sebastian Gorgon

    Haha love the warning, thanks! i shall not read!

  • http://twitter.com/febb Felipe Barousse Boué

    Well, it is great that FB's build tool for Android "Buck" runs faster than others.... but, I truly hope it produces stable final products... not as own FB's apps !

    • Nevi_me

      Build Fast, Push Faster, Run Slow. It's probably gonna become a dev motto someday, at the rate that Facebook's going at.
      Heck We'll probably see it on Wikipedia with RERO (Release Early, Release Often)

    • ssj4Gogeta

      Well, unless you're being sarcastic, build tool doesn't affect how stable your application is (if they do, they're doing something funny and really wrong).

      • Pierre Gardin

        Thanks Captain Obvious.

    • http://www.androidpolice.com/author/cody-toombs/ Cody Toombs

      This won't have any effect on the quality of the final output. Build tools (Ant, Buck, etc.) are there to instruct the compiler and other tools to do tasks they would already be doing. They aren't much different than writing a shell script (linux) or batch file (windows), but a bit more portable and easier to manage.

  • http://profiles.google.com/bobloadmire Brad Stewart

    BLEEP BLOP BLOOP DEV STUFF

  • woj_tek

    uhm... "15s" compilation is so serious? are you compiling every added line? ;-)

    also - yuck at javascript-ish semantics (not, I don't have problems with xml) and yuck at pouting project with BUCK in every directory... even svn backed from this approach with 1.7 (they use single svn directory now!)

    • József Király

      I agree. XML is easier to handle and read than the javascript-like structure, and if the tool is written right, XML can be such as error-prone as anything else.

    • http://www.androidpolice.com/author/cody-toombs/ Cody Toombs

      Yeah, I figured 10 seconds is an annoying wait, 15 seconds will lead to this (thank you xkcd)

  • Mapekz

    Ant sucks terribly and Maven can be overkill for many projects (and is far from perfect) so I'll be looking into Buck and Google's Gradle. Thanks for the heads up, AP!

    • Richard

      Gradle isn't done by Google its done by Gradleware.

      • Mapekz

        Good call. Thanks.

  • selonmoi

    Sort of interesting, I guess, but it hardly seems like something that's going to catch fire.

    I mean, incremental compiling means you basically never have to wait for anything to build while you're doing development. And Android apps are pretty small, so an automated build is going to take seconds, minutes at worst, even without any parallelization.

    • http://www.androidpolice.com/author/cody-toombs/ Cody Toombs

      My thoughts exactly. In Eclipse, we are already used to having automatic background compiles every time a file is saved. I sorta feel like this solves a problem that very few people have.

      Of course, in the case of Facebook (and surely a few others), there is a ton of code from SEVERAL tiny libraries with the fingerprints of several people, and I'm sure every code push is going through an automated build process on the server. In that type of situation, there is some merit.

  • http://www.facebook.com/profile.php?id=1745689461 Hal Motley

    This is Facebook's equivalent of Buildbot then? Interesting and nice to see it open-sourced.

    Also good job to whoever added the Matrix-style ASCII rain to the icon.

    • http://www.androidpolice.com/author/cody-toombs/ Cody Toombs

      Thanks, that was my doing. I kinda rushed, but it turned out alright for a quick job.

  • The_Chlero

    You are right. I feel asleep last night while reading at this. This is better than tea or warm milk