rev 10311 - scripts
Modestas Vainius
modax-guest at alioth.debian.org
Mon Apr 28 01:00:15 UTC 2008
Author: modax-guest
Date: 2008-04-28 01:00:13 +0000 (Mon, 28 Apr 2008)
New Revision: 10311
Modified:
scripts/autofixtll
Log:
autofixtll v0.3
* Deals more carefully with target_link_libraries() enclosed in IFs/WHILEs/etc.
* A few small bugfixes
Recommended usage is:
autofixtll -e
Modified: scripts/autofixtll
===================================================================
--- scripts/autofixtll 2008-04-27 23:24:03 UTC (rev 10310)
+++ scripts/autofixtll 2008-04-28 01:00:13 UTC (rev 10311)
@@ -105,7 +105,7 @@
#### Please add predefined libraries to load dynamic symbol from here.
# new Library(name, cmake_target, [path]). If path is not specified,
-# it's path=/usr/lib/$name.so. Use '' quotes.
+# it's /usr/lib/$name.so. Use '' quotes to avoid escaping $.
my @LIBS = (
new Library('QtDBus', '${QT_QTDBUS_LIBRARY}'),
new Library('QtNetwork', '${QT_QTNETWORK_LIBRARY}'),
@@ -195,7 +195,47 @@
return $self->{name} . " ( " . $self->{path} . " )";
}
+sub IgnoreStack::new {
+ return bless( { stack => [] }, shift() );
+}
+sub IgnoreStack::process_line {
+ my ($self, $line) = @_;
+ my $stack = $self->{stack};
+
+ if ($line =~ m/^\s*((end)?(foreach|function|if|macro|while))\s*[(]/i) {
+ my $isend = defined $2;
+ my $cmd = uc($3);
+
+ if ($isend) {
+ if (@$stack) {
+ my $s = pop @$stack;
+ print STDERR "$MSG_PREFIX There is something wrong with IgnoreStack:\n",
+ "$MSG_PREFIX stack top ($s) does not match end command ($cmd)\n" if $s ne $cmd;
+ } else {
+ print STDERR "$MSG_PREFIX IgnoreStack is empty but got 'end$cmd'. A bug probably.\n";
+ }
+ } else {
+ push @$stack, $cmd;
+ }
+ return 1; # Processed
+ } else {
+ return 0;
+ }
+}
+
+sub IgnoreStack::is_empty {
+ return scalar(@{shift()->{stack}}) == 0;
+}
+
+sub IgnoreStack::dump_stack {
+ my $self = shift;
+ print "Ignore stack dump:\n";
+ for my $e (@{$self->{stack}}) {
+ print " $e\n";
+ }
+}
+
sub determine_needed_libs {
my ($alllibs, $undefrefs) = @_;
my @_libs;
@@ -230,12 +270,17 @@
if (-r $cmakelists) {
my @contents;
+ my @ignored;
my $found = 0;
+ # Ignore directive inside if/endif, while/endwhile etc. blocks
+ my $ignstack = new IgnoreStack;
# Read and change
open(CMAKELISTS, "<$cmakelists");
while (<CMAKELISTS>) {
- if (!$found && m/(target_link_libraries\s*\(\s*$target\s+)(.*?)(\s*\).*)?$/i) {
+ if (!$found && !$ignstack->process_line($_) &&
+ m/^\s*(target_link_libraries\s*\(\s*$target\s+)(.*?)(\s*\).*)?$/i) {
+
# Fix it
my $newline = $1;
my $end = $3;
@@ -244,14 +289,35 @@
$newline .= $strlibs;
$newline .= $end if ($end);
$newline .= "\n";
- push @contents, $newline;
- $found = $.;
+
+ if ($ignstack->is_empty()) {
+ push @contents, $newline;
+ $found = $.;
+ } else {
+ # Save for later use
+ push @ignored, { found => $., newline => $newline };
+ push @contents, $_;
+ }
} else {
push @contents, $_;
}
}
close(CMAKELISTS);
+ if (!$ignstack->is_empty()) {
+ $ignstack->dump_stack();
+ print STDERR "$cmakelists has been processed but ignore stack is not empty. Probably a bug!\n";
+ }
+
+ if (!$found && @ignored == 1) {
+ # That's probably it as there were no other candidates. Replace
+ $found = ${ignored[0]}->{found};
+ my $newline = ${ignored[0]}->{newline};
+ $contents[$found-1] = $newline;
+ } else {
+ print "$MSG_PREFIX More (", scalar(@ignored), ") than 1 target_link_libraries() found in the IF/WHILE etc. blocks\n";
+ }
+
if (!$found) {
die "$MSG_PREFIX $cmakelists could not be corrected (needed '$strlibs' for target '$target'). Respective target_link_libraries() was not found $MSG_PREFIX";
} else {
@@ -313,7 +379,7 @@
die "Could not extract target from $bdir";
}
$bdir =~ s#/CMakeFiles/.*##;
- } elsif (m/^Linking (.*) (shared module|executable) /) {
+ } elsif (m/^Linking (.*) (shared (module|library)|executable) /) {
$link_cmd = 1;
} elsif (m/undefined reference to `(.*)'$/) {
# undefined reference to `QDBusMessage::createSignal(QString const&, QString const&, QString const&)'
@@ -328,6 +394,7 @@
chdir $sourcedir;
# Try to correct the error
+# print $MSG_PREFIX, $islderror, $bdir, $btarget, @undefrefs;
if ($islderror && $bdir && $btarget && @undefrefs) {
my $libs = determine_needed_libs(\@LIBS, \@undefrefs);
if (@$libs) {
@@ -386,10 +453,6 @@
"$MSG_PREFIX \$ $QUILT push $patchname\n" .
"$MSG_PREFIX \$ $QUILT new $patchname\n";
}
-
- if (! -d $builddir) {
- die "Build directory '$builddir' does not exist";
- }
}
sub get_gnu_build_type {
@@ -400,7 +463,7 @@
############## Main loop ##############################
-$main::VERSION = "0.2";
+$main::VERSION = "0.3";
my $sourcedir = Cwd::getcwd();
my $builddir = "obj-" . get_gnu_build_type();
More information about the pkg-kde-commits
mailing list