Automating Module Discovery in a SCons Project

By Thursday, December 25, 2014 0 , , Permalink 0

This is the ninth post in my SCons series. The topic of this post is automating module discovery.

Up until now, the module directories were hardcoded in site_scons/site_config.py. This was a natural choice, because you needed to specify the modules in the correct order. In the previous episode, I implemented a solution that supports arbitrary modules order. Now it’s much more natural to automate the process of module discovery, over manual specification.

As a developer in the project, you know that when you create a new module you need to create a SConscript to describe how to build it. It makes sense that the build system will be able to locate all modules to build, by looking for the SConscript files recursively from the project base directory.

In this episode, I describe how I implemented module auto-discovery by walking the project directory tree.

My implementation also correctly handles common caveats:

  • Avoid walking the build directory.
  • Skip “hidden” directories (like .git, and .whatever from your favorite IDE metadata).

In addition, my implementation provides several useful features:

  • Ability to limit recursion depth.
  • Support for “stop marker files”. If a stop marker file (e.g. .noscons) exists in a project directory, the directory (and all sub-directories) will be skipped.

The episode builds on top of the previous episode. The final result is available on my GitHub scons-series repository.

Continue Reading…

Supporting Arbitrary Modules Order In SCons

By Thursday, December 18, 2014 2 , , Permalink 0

This is the eighth post in my SCons series. In this post, I describe how to support arbitrary modules order.

In an earlier episode, I presented the multi-module C++ SCons project. In that episode, I explained that modules need to be specified at the order of dependence.

This restriction can be annoying, and painfully limiting, once your project “gets serious”.

I promised a better solution, and now I provide one 🙂 . In a nutshell, the solution is based on a two-pass approach. In the first pass, all library-targets are processed and collected across all modules. In the second pass, all program-targets are processed, using the libraries already collected.

The rest of the post goes into further detail about the solution. The result, as usual, is available on my GitHub scons-series repository. It builds on top of the SCons shortcuts enhancement, in case you need to refresh your memory 🙂 .

Continue Reading…

How To Assign Keyboard Shortcuts For OS X Apps

As much as the trackpad is powerful on Mac, I still prefer not to leave the keyboard if I can. For that reason, I want to assign keyboard shortcuts to the rare few apps that deserve it. Imagine my surprise when I realized it’s not a straight forward action in OS X!

In this post I describe how to assign arbitrary keyboard shortcuts to launch OS X apps, without any third-party software or AppleScript. The solution is based on creating an Automator Service workflow to launch the desired app, and assigning a keyboard shortcut to that service.

I imagine there are simpler solutions that take advantage of some third party automation software or AppleScript. Feel free to let me know about your preferred solution, even if it involves such demons.

I am aware that I can use Spotlight to launch any application by typing the first letters of its name. Indeed, this is how I launch 99% of apps. There are very few cases where it makes sense to bypass Spotlight with a shorter key-combo – and this post is for these cases.

This is part of my Mac Power User Training series. Follow it to see how I try to go from Mac novice to a pro.

Continue Reading…

Shell Foo: Getting a cpplint Breakdown Report On All Project Source Files

You’re working on a non-trivial project, with multiple source files, in multiple languages. You want to use cpplint to get a “style report” for all C/C++ files in the project.

You don’t want to get bogged down with hundreds of style warnings – you just want the final summary of warnings count per category.

In addition, you want to run only on C/C++ files, and avoid duplicates resulting from the build-directory.

How do you accomplish that?

Shell-Foo is a series of fun ways to take advantage of the powers of the shell. In the series, I highlight shell one-liners that I found useful or interesting. Most of the entries should work on bash on Linux, OS X and other UNIX-variants. Some probably work with other shells as well. Your mileage may vary.

Feel free to suggest your own Shell-Foo one-liners!

Continue Reading…

Shell Foo: Listing All C/C++ Files In a Project, Excluding Build Dir

You’re working on a non-trivial project, with multiple source files, in multiple languages. You want to list all C/C++ source files in the project, recursively, but without getting duplicates from the build dir.

Assuming your C/C++ files are all .h or .cc files, and the build directory is build/ – how would you do it?

Here’s my preferred solution:

$ find . -name \*.h -or -name \*.cc | grep -vE "^\.\/build\/"

Shell-Foo credit for this one: Eyal Fink.

Shell-Foo is a series of fun ways to take advantage of the powers of the shell. In the series, I highlight shell one-liners that I found useful or interesting. Most of the entries should work on bash on Linux, OS X and other UNIX-variants. Some probably work with other shells as well. Your mileage may vary.

Feel free to suggest your own Shell-Foo one-liners!

Continue Reading…

Shell Foo: Printing the Nth Line of a File

You’re running a Python script from the command line, and it throws some exception in your face. You want to take a quick look at the line that raised the exception (say, 42). How would you print that line?

My favorite way (minimal typing):

$ sed -n 42p myscript.py

Shell-Foo credit for this one: Eyal Fink.

Shell-Foo is a series of fun ways to take advantage of the powers of the shell. In the series, I highlight shell one-liners that I found useful or interesting. Most of the entries should work on bash on Linux, OS X and other UNIX-variants. Some probably work with other shells as well. Your mileage may vary.

Feel free to suggest your own Shell-Foo one-liners!

Continue Reading…

Sort Your Include Files!

The Google C++ Style Guide defines a guideline for names and order of includes. It occurred to me that grouping and sorting include files is tedious and error prone, and a computer can do it much better. So I wrote a script that does exactly that 🙂 .

The nitpick script is available on my GitHub cpplint fork.

If you’re comfortable with Python, you can figure out the script straight from nitpick.py source code and the accompanying unit tests. You can also read the rest of the post for some plain English review 🙂 .

Continue Reading…

Teaching cpplint About External Libraries h-Files

The Google C++ Style Guide defines a guideline for names and order of includes. Unfortunately, the cpplint tool that automates style-guide checking isn’t consistent with that guideline, as far as “other libraries h files” are concerned.

In this post, I demonstrate the claimed inconsistency, and suggest an enhancement to cpplint to fix the inconsistent behavior.

The enhancement is available on my GitHub cpplint fork (including addition unit tests).

Continue Reading…

How To Migrate a WordPress Blog

By Monday, November 10, 2014 2 , Permalink 1

One of things I love about WordPress it that it’s an open content platform. Being open, the platform understands that the user owns the content within. Truly owning your content means you should be able to take it out of the platform, and do whatever you want with it. WordPress makes it easy!

This post is a how-to guide on migrating a WordPress site. It covers:

  1. Exporting all your content from a hosted WordPress.com site.
  2. Importing the content to a self hosted WordPress site.

The export part applies also to self-hosted WordPress sites. I write specifically about a WordPress.com-hosted site because this is what I use for the example.

Continue Reading…

Fixing Homebrew on OS X Yosemite

Homebrew is “The missing package manager for OS X”. It’s pretty great. Unfortunately, upgrading to OS X Yosemite might break it, as it did for me.

There are several paths for fixing it, depending on when you realize it’s broken. Here are a few possible fixes that you can use.

If you just want the bottom line, here it is:

  1. If you still haven’t upgraded to OS X Yosemite, run brew update before the OS X upgrade.
  2. If you already upgraded OS X and your Homebrew is broken, run git pull from /usr/local, and then run brew update.

Read on for more details on my experience with the break and fix.

Continue Reading…