DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (495129e490bc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
#!/usr/bin/perl -w
# Run this from cron to update the glimpse database that lxr uses
# to do full-text searches.
# Created 12-Jun-98 by jwz.
# Updated 2-27-99 by endico. Added multiple tree support.

use Cwd;
use File::Basename;
use lib 'lib';
use LXR::Common;
use LXR::Config;
use LXR::Shell;

my @paths=qw(
/usr/local/bin
/opt/local/bin
/opt/cvs-tools/bin
/usr/ucb
/usr/local/apache/html/mxr/glimpse
/usr/local/glimpse-4.18.1p/bin
/usr/local/glimpse-3.6/bin
/home/build/glimpse-3.6.src/bin
);

my $STDERRTOSTDOUT = '2>&1';
my $TREE;
my %defaults = qw(
  TIME time
  UPTIME uptime
  DATE date
);

sub do_log {
  my $msg = shift;
  open LOG, '>>', $log;
  print LOG "$msg
";
  close LOG;
}

sub do_and_log {
  my $cmd = shift;
  do_log($cmd);
  system($cmd);
}

sub process_args {
  my $was_arg;
  do {
    $was_arg = 0;
    $TREE = shift;
    if ($TREE) {
      if ($TREE eq '-cron') {
        $was_arg = 1;
        $defaults{TIME} = $defaults{UPTIME} = '';
      }
      $TREE =~ s{/$}{};
    }
  } while ($TREE && $was_arg);
}

process_args(@ARGV);

check_defaults(\%defaults);
my $DATE = $defaults{DATE};
my $TIME = $defaults{TIME};
my $UPTIME = $defaults{UPTIME};

$ENV{'LANG'} = 'C';

# need to consider lxr.conf
$lxr_dir = '.';
die "can't find $lxr_dir" unless -d $lxr_dir;
my $lxr_conf = "$lxr_dir/lxr.conf";

unless (-f $lxr_conf) {
  die "could not find $lxr_conf";
}

my $src_dir;
my $script_prefix = './';
if (defined $TREE) {
  $script_prefix = "/$TREE/";
} else {
  # need to sniff lxr.conf
  open LXRCONF, "< $lxr_conf" || die "Could not open $lxr_conf";
  while ($line = <LXRCONF>) {
    warn "trailing whitespace on line $. {$line}" if $line =~ /^\w+:.*\w.*\s+\n$/;
    #since no tree is defined, assume sourceroot is defined the old way
    #grab sourceroot from config file indexing only a single tree where
    #format is "sourceroot: dirname"
    next unless $line =~ /^sourceroot:\s*(\S+)(\s+\S+|)$/;
    if ($2 ne '') {
      $TREE = $1;
      $ENV{'TREE'} = $TREE;
      $script_prefix = "/$TREE/";
    } else {
      $src_dir = $1;
    }
    last;
  }
  close LXRCONF;
}

# let LXR:: handle lxr.conf
$ENV{'SCRIPT_NAME'} = $script_prefix . basename($0);
my ($Conf, $HTTP, $Path, $head) = &init($0);

{
  my @trees = @{$Conf->{'trees'}};
  die "Could not find tree $TREE" if scalar @trees > 1 && !(grep /^\Q$TREE\E$/, @trees);
}
die "dbdir not set" unless defined $Conf->dbdir;
$db_dir = $Conf->dbdir;
$src_dir = $Conf->sourceroot;

if (defined $Conf->glimpsebin) {
  push @paths, $1 if ($Conf->glimpsebin =~ m{(.*)/([^/]*)$});
}

unless (defined $src_dir) {
  die "could not find sourceroot for tree $TREE";
}

my %pathmap=();
for my $mapitem (@paths) {
$pathmap{$mapitem} = 1;
}
for my $possible_path (keys %pathmap) {
$ENV{'PATH'} = "$possible_path:$ENV{'PATH'}" if -d $possible_path;
}

mkdir $db_dir unless -d $db_dir;
my $pid_lock = get_lock($db_dir, 'xref');
$log = "$db_dir/glimpseindex.log";
#exec > $log 2>&1
#XXX what does |set -x| mean?
#system ("set -x > $log");
=pod
              -e      Exit  immediately  if a simple command (see
                      SHELL GRAMMAR above) exits with a  non-zero
                      status.

              -x      After  expanding  each  simple command, for
                      command, case command, select  command,  or
                      arithmetic   for   command,   display   the
                      expanded value of PS4, followed by the com�
                      mand  and its expanded arguments or associ�
                      ated word list.
=cut

=pod
for my $envvar (keys %ENV) {
print LOG "$envvar=$ENV{$envvar}
";
}
=cut

#system ("date >> $log");
do_log ('date
'.localtime().'
');

unless (-d $src_dir) {
  do_log("$TREE src_dir $src_dir does not exist.");
  exit 4;
}

my $db_dir_tmp = "$db_dir/tmp";
unless (-d $db_dir_tmp) {
  do_log("mkdir $db_dir_tmp");
  unless (mkdir $db_dir_tmp) {
    do_log("mkdir $db_dir_tmp failed");
    exit 5;
  }
}

do_log("chdir $db_dir_tmp");
unless (chdir $db_dir_tmp) {
  do_log("chdir $db_dir_tmp failed");
  exit 6;
}

# do index everything in lxrroot
my @include_paths = qw (

);
unshift @include_paths, $db_dir;
push @include_paths, '';
open GLIMPSEINCLUDE, '>.glimpse_include';
print GLIMPSEINCLUDE join("\n", @include_paths);
close GLIMPSEINCLUDE;

# don't index VCS files
open GLIMPSEEXCLUDE, '>.glimpse_exclude';
my @exclude_paths = qw (
/CVS/
/.hg/
/.git/
/.svn/
/.bzr/
/_MTN/
);
push @exclude_paths, '';
print GLIMPSEEXCLUDE join("\n", @exclude_paths);
close GLIMPSEEXCLUDE;

#XXX what does |set -e| mean?
#system ("set -e >> $log");
#system("time", "glimpseindex", "-H", ".", "$src_dir");
my $cmd = "($TIME glimpseindex -o -n -f -B -M 128 -H . $src_dir $STDERRTOSTDOUT) >> $log";
do_and_log($cmd);
my $mxr_dir_tmp = "$db_dir_tmp/.mxr";
-d $mxr_dir_tmp || mkdir $mxr_dir_tmp;

$cmd = "ls -al >> $log
(cp .glimpse_filenames $mxr_dir_tmp/files $STDERRTOSTDOUT || echo failed to copy .glimpse_filenames) >> $log
ls .mxr -al >> $log
($TIME glimpseindex -H $mxr_dir_tmp $mxr_dir_tmp $STDERRTOSTDOUT) >> $log
";
do_and_log($cmd);
if (-f "$mxr_dir_tmp/.glimpse_filenames") {
  $cmd = "
perl -pi -e 's{tmp/\.mxr}{\.mxr}' $mxr_dir_tmp/.glimpse_filenames
glimpseindex -H $mxr_dir_tmp -R $STDERRTOSTDOUT >> $log";
  do_and_log($cmd);
} else {
  do_log("could not find .mxr/.glimpse_filenames");
}

# build filename index
# shared w/ update-root.pl
do_log('chmod -R a+r .');
system("chmod", "-R", "a+r", ".");
$cmd = "mv .glimpse* ../";
if (-d $mxr_dir_tmp) {
  $cmd = 'mv .glimpse* .mxr ../';
  if (-d '../.mxr') {
    $cmd = "
mv ../.mxr ../.mxr-old
$cmd
rm -rf ../.mxr-old
";
  }
}
do_and_log($cmd);

do_log('cd ../..');
chdir '../..';
do_log(
'date
'.localtime()."
$UPTIME
");
system ("$UPTIME >> $log") if $UPTIME =~ /\w/;

unlink $pid_lock;
exit 0;