6

I love the code search utility ack. It is smart enough to look through Makefiles, but doesn't know about the SConstruct and SConscript files that scons uses. How do I add those to the files that ack will look in?

jblocksom
  • 14,127
  • 5
  • 34
  • 30

3 Answers3

3

Here is a patch that treats SCons files like make files:

--- ~/bin/ack-old 2011-06-01 15:43:51.000000000 -0600
+++ ~/bin/ack     2011-06-01 15:42:09.000000000 -0600
@@ -1583,6 +1583,8 @@

     return 'skipped' unless is_searchable( $basename );

+    return ('python',TEXT)      if $basename eq 'SConstruct' || $basename eq 'SConscript';
+
     my $lc_basename = lc $basename;
     return ('make',TEXT)        if $lc_basename eq 'makefile' || $lc_basename eq 'gnumakefile';
     return ('rake','ruby',TEXT) if $lc_basename eq 'rakefile';
  • I'm running the deb package of ack version 1.92 on Ubuntu 10.04, and the same patch can be manually applied to /usr/share/perl5/App/Ack.pm at around line 476. – Matt Ball Jun 23 '11 at 14:28
2

This can't be done using ack's type sets. Makefiles and Rakefiles are hard-coded in the source. I thought you could add a scons type by modifying $HOME/.ackrc and adding --type-set=scons=SConstruct,SConscript, but that will search for a file that ends in ".SConstruct" or ".SConscript".

The easiest workaround is to add the -a (all file types) flag to ack.

If you just want ack to search and be able to filter the SConstruct somehow, then you could add #!/usr/bin/python as the first line of the SConstruct file. Ack will then treat the file as python source code, and you can filter with --python.

richq
  • 55,548
  • 20
  • 150
  • 144
  • That only seems to work for .scons files, not SConstruct or SConscript. – jblocksom Dec 28 '10 at 21:01
  • Gah, you're right. Just checked the source - "makefile" and "rakefile" are hard-coded exceptions. – richq Dec 28 '10 at 22:17
  • Thanks for looking that up. I was able to modify my local version to add SConstruct and SConscript in the same way makefiles are in there, maybe I'll submit a patch. I must say I'm not crazy about the scons design decision to use files w/out extensions, though I've seen other build systems that do the same. – jblocksom Dec 30 '10 at 08:50
1

A new ack2 is in development which will allow exact file matching in the .ackrc file. That will enable easier support for Scons and Jam.

Dave
  • 3,171
  • 1
  • 25
  • 23