From: Markus Armbruster Date: Tue, 3 Mar 2015 19:09:50 +0000 (+0100) Subject: tests: Fix for builds outside git-controlled source tree X-Git-Tag: v4.3.33~21 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=dc6cffa1314b6fe8409a3995621c221a4d30581d tests: Fix for builds outside git-controlled source tree We run "git ls-files" in the build tree. Doesn't work when the source directory isn't a git repository, or the build directory is outside the source directory. Broken in commit 71cb2d8. Find source files like Make.mk does: if the source tree is a git repository, use git ls-files, else use sources.mk. Signed-off-by: Markus Armbruster --- diff --git a/src/scripts/ls-sources.pl b/src/scripts/ls-sources.pl new file mode 100755 index 000000000..b34f8b0fd --- /dev/null +++ b/src/scripts/ls-sources.pl @@ -0,0 +1,82 @@ +#!/usr/bin/perl +# +# Empire - A multi-player, client/server Internet based war game. +# Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak, +# Ken Stevens, Steve McClure, Markus Armbruster +# +# Empire is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# --- +# +# See files README, COPYING and CREDITS in the root of the source +# tree for related information and legal notices. It is expected +# that future projects/authors will amend these files as needed. +# +# --- +# +# ls-sources.pl: List source files +# +# Known contributors to this file: +# Markus Armbruster, 2015 +# +# Usage: ls-sources.pl DIR REGEX +# +# List source files in DIR with names matching REGEX. If DIR is under +# version control, list version-controlled files. Else, list files in +# sources.mk. + +use warnings; +use strict; + +if ($#ARGV != 1) { + print STDERR "Usage: $0 DIR REGEX\n"; + exit 1; +} + +my $dir = $ARGV[0]; +my $regex = $ARGV[1]; + +my $srcdir = $dir; +my $subdir = ""; + +while (! -d "$srcdir/.git" and ! -r "$srcdir/sources.mk" + and $srcdir =~ m,^(.*)/([^/]*),) { + $srcdir = $1; + $subdir = "$2/$subdir"; +} + +my @sources; +if (-d "$srcdir/.git") { + open IN, "cd '$srcdir' && git ls-files '$subdir' | uniq |" + or die "can't run git ls-files: $!"; + while () { + chomp; + push @sources, $_; + } + close IN; +} elsif (-r "$srcdir/sources.mk") { + open IN, "<$srcdir/sources.mk" + or die "can't open $srcdir/sources.mk: $!"; + $_ = ; + s/.*=//; + @sources = grep m,^\Q$subdir\E,, split; + close IN; +} else { + print STDERR "Can't find source tree\n"; + exit 1; +} + +for (grep m/$regex/, @sources) { + print "$srcdir/$_\n"; +}