Skip to main content

Ekam No longer restricted to building self and can be taught new rules

Ekam No longer restricted to building self and can be taught new rules


Two big updates to Ekam this weekend! As always, the source code is at:

http://code.google.com/p/ekam/

Updates

Arbitrary Code

Ekam is no longer restricted to only building code in the "ekam" namespace. It will now build pretty much any C++ code you throw at it, so long as the code depends only on the standard C/C++ library. In fact, when I pointed Ekam at the Protocol Buffers source code, it successfully churned out protoc! (It didnt do as well compiling the tests, though.)

I ended up accomplishing this not by indexing libraries, as I had planned, but instead by changing the behavior when a dependency is not found. Now, if the link action cannot find any object files defining a particular symbol, it just goes ahead and tries to link anyway to see what happens. Only after failing does it decide to wait for the symbols to become available -- and it retries again every time a symbol for which it was waiting shows up. So, once all non-libc symbols are available, the link succeeds.

Now, this has the down side that Ekam will go through a lot of failed linker invocations. But, I look at this as an optimization problem, not a correctness problem. We can use heuristics to make Ekam avoid too many redundant link attempts. For example, we can remember what happened last time. Or, an easier approach would be to just make sure failed operations are not tried again until everything else is done.

Related to this change, Ekam will now re-run even a successful operation if dependencies that were not originally available become available. I talked about why youd want to do this last week.

Defining new rules

You can now implement new build rules by simply writing a shell script and putting it in the source tree, as I proposed last week. You can now see what the actual code for compiling C++ looks like (linking is not yet implemented as a script). Of course, you dont have to write these as shell scripts. Any executable whose name ends in .ekam-rule will be picked up by Ekam -- even binaries that were themselves compiled by Ekam.

Refactoring

I seem to spend a lot of time refactoring. Working on C++ outside of Google is almost like learning a whole new language. I get to use whatever style I want, including whatever C++ features I want. Ive been refining a very specific style, and I keep realizing ways to improve it that require going back and rewriting a bunch of stuff. Some key aspects of the style Im using:

  • Exceptions are allowed, but expected never to occur in normal usage.
  • Ownership of pointers, and passing of that ownership, is explicit. I have a template class called OwnedPtr for this. In fact, I never use new -- instead, I call OwnedPtr::allocate() (passing it the desired constructor parameters). Its not possible to release ownership of the pointer, except by moving it to another OwnedPtr. Thus, the only way for memory to become unreachable without being deleted is by creating an ownership cycle. Yet, I dont use reference counting, since it is notoriously slow in the presence of multiple cores.
  • Im using single-threaded event-driven I/O, since Ekam itself is just a dispatcher and does not need to utilize multiple cores. Events need to be cancelable. Originally, I had every asynchronous method optionally return a canceler object which could be called to cancel the operation. This got surprisingly hairy to implement, since the event effectively had to cancel the canceler when complete. Also, events owned their callbacks, which made a lot of things awkward and tended to lead to cyclic ownership (doh). What turned out to be much simpler was to simply have every asynchronous method return an object representing the ongoing operation. To cancel the operation, delete the object. With this approach, deleting a high-level object naturally causes everything it is doing to be canceled via cascading destructors, with no need to really keep track of cancellation.

Ideas

Currently, the compile action does not yet resolve header dependencies -- if you need to use special include directories you must specify CXXFLAGS manually. This is, of course, bad. But how can Ekam detect header dependencies?

One approach would be to attempt to compile and, if not successful, try to parse the error messages to determine missing includes. This is, of course, going to be pretty brittle -- it would need to understand every compilers output, possibly for every locale.

Another approach would be to write some sort of an "include scanner" which looks for #include directives. It would not necessarily have to evaluate branches (#ifdefs and such), since it could just conservatively look for all the headers that are mentioned and take whatever it can find. However, this would still be pretty complicated to write and slow to run, and it wouldnt be able to handle things like macro-derived header names (yes, you can do that).

So heres my idea: Run the compiler, but use LD_PRELOAD to inject into it a custom implementation of open(). This implementation will basically send an RPC to Ekam (using the already-implement plugin interface) asking where to find the file, then replace the path with what Ekam sends back. The injected open() could pay attention only to paths in a certain directory which would be added to the compilers include path. Problem solved! And better yet, this solution naturally extends to other kinds of actions and programming languages.

download file now

Popular posts from this blog

ElasticSearch query with AND and OR criteria

ElasticSearch query with AND and OR criteria Frequently when we will need to construct query to elasticsearch which bear AND and OR criteria similar to the following SQL statements: Statement 1: SELECT * FROM tblOrder WHERE orderDate=2015-01-01 14:00:00 AND customerID=29439; Statement 2: SELECT * FROM tblOrder WHERE orderDate=2015-01-01 14:00:00 OR customerID=29439; Statement 3: SELECT * FROM tblOrder WHERE orderDate <= 2015-01-01 14:00:00 AND customerID=29439; Statement 4: SELECT * FROM tblOrder WHERE (orderDate=2015-01-01 14:00:00 AND customerID=29439) OR customerID = 20991; Statement 5: SELECT * FROM tblOrder WHERE orderDate=2015-01-01 14:00:00 AND (customerID=29439 OR customerID = 20991); In ElasticSearch, we use "must" and "should" in place of AND and OR and "bool" in place of WHERE. Suppose in our ElasticSearch (at 179.168.0.1:9200), we have indexed documents having the following structures at index myOrder/myOrder: { "orderID" : xxxxx, ...

Endomondo Sports Tracker PRO v10 2 4 Full APK

Endomondo Sports Tracker PRO v10 2 4 Full APK ? Endomondo Sports Tracker PRO v10.2.4 Full APK. They mock fitness with this personal trainer and social fitness partner . Endomondo is the first application of its kind on Android and is ideal for running, cycling , hiking and other activities on the basis of distance. Join 10 million users and begin to free your endorphins ! This is the PRO version of the popular Endomondo Sports Tracker ! Please see What's New in Google Play for latest updates . PRO features : * Go programs : choose from three audio programs or create your own and let the coach guide * Graphics Card: graphics display your lap times , heart rate , speed and altitude throughout the workout * Beat you: Set a previous workout as target and the audio coach will help you perform better this time * The low power mode : Increase the battery timeout using this function for long workouts * Final goal : Choose a duration for your workout and the audio coach session will help...

download Lotto Heaven HD Lottery Game for free

download Lotto Heaven HD Lottery Game for free Lotto Heaven HD: Lottery Game Cards & Casino Download .apk Tired of the same old free card games? Try Lotto Heaven, the fun new lottery scratch-off card game. Its ridiculously addicting! While it wont make you lottery numbers luckier, it is a great way to wait for your powerball or megamillions lottery results to come in. Youre a scratch card millionaire waiting to happen! Download .apk If you live in Boston, Los Angeles, Philadelphia, Chicago, Seattle, New York, Kansas City, Toronto, San Francisco or London , you want to read this. However, we have the kick ass new poster for The Dark Knight debuted as part of the ongoing viral marketing game download Lotto Heaven HD: Lottery Game 1.101 apk . The site where it was discovered is on whysoserious.com / itsallpartoftheplan /. However, the website indicated that more would come and now its been updated. A new viral hunt is on Monday, said the 28th April in cities before and this time ...