summaryrefslogtreecommitdiff
path: root/build-aux
diff options
context:
space:
mode:
authorBen Pfaff <blp@ovn.org>2017-11-20 09:40:45 -0800
committerBen Pfaff <blp@ovn.org>2017-11-26 16:12:07 -0800
commitde9872221647bf44179aff1adbb3e802e3c5b3db (patch)
tree07a37771e43419ece9c3d176b7b7f33dd8441ac1 /build-aux
parent74eaac06d61e918ce4bb82611c6f5905c77d94e4 (diff)
downloadopenvswitch-de9872221647bf44179aff1adbb3e802e3c5b3db.tar.gz
tests: Convert sodepends build tool from Perl to Python.
Perl is unfashionable and Python is more widely available and understood, so this commit converts one of the OVS uses of Perl into Python. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Aaron Conole <aconole@redhat.com>
Diffstat (limited to 'build-aux')
-rw-r--r--build-aux/automake.mk1
-rw-r--r--build-aux/sodepends.pl70
-rwxr-xr-xbuild-aux/sodepends.py67
3 files changed, 68 insertions, 70 deletions
diff --git a/build-aux/automake.mk b/build-aux/automake.mk
index 1003144fd..6baafab0e 100644
--- a/build-aux/automake.mk
+++ b/build-aux/automake.mk
@@ -2,4 +2,5 @@
FLAKE8_PYFILES += \
$(srcdir)/build-aux/xml2nroff \
build-aux/dpdkstrip.py \
+ build-aux/sodepends.py \
build-aux/soexpand.py
diff --git a/build-aux/sodepends.pl b/build-aux/sodepends.pl
deleted file mode 100644
index 333d037f2..000000000
--- a/build-aux/sodepends.pl
+++ /dev/null
@@ -1,70 +0,0 @@
-# Copyright (c) 2008, 2011 Nicira, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at:
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-use strict;
-use warnings;
-use Getopt::Long;
-
-our ($exit_code) = 0;
-
-our (@include_dirs);
-Getopt::Long::Configure ("bundling");
-GetOptions("I|include=s" => \@include_dirs) or exit(1);
-@include_dirs = ('.') if !@include_dirs;
-
-sub find_file {
- my ($name) = @_;
- foreach my $dir (@include_dirs, '.') {
- my $file = "$dir/$name";
- if (stat($file)) {
- return $file;
- }
- }
- print STDERR "$name not found in: ", join(' ', @include_dirs), "\n";
- $exit_code = 1;
- return;
-}
-
-print "# Generated automatically -- do not modify! -*- buffer-read-only: t -*-\n";
-for my $toplevel (sort(@ARGV)) {
- # Skip names that don't end in .in.
- next if $toplevel !~ /\.in$/;
-
- # Open file.
- my ($fn) = find_file($toplevel);
- next if !defined($fn);
- if (!open(OUTER, '<', $fn)) {
- print "$fn: open: $!\n";
- $exit_code = 1;
- next;
- }
-
- my (@dependencies);
- OUTER:
- while (<OUTER>) {
- if (my ($name) = /^\.so (\S+)$/) {
- push(@dependencies, $name) if find_file($name);
- }
- }
- close(OUTER);
-
- my ($output) = $toplevel;
- $output =~ s/\.in//;
-
- print "\n$output:";
- print " \\\n\t$_" foreach $toplevel, sort(@dependencies);
- print "\n";
- print "$_:\n" foreach $toplevel, sort(@dependencies);
-}
-exit $exit_code;
diff --git a/build-aux/sodepends.py b/build-aux/sodepends.py
new file mode 100755
index 000000000..90cfaa0f7
--- /dev/null
+++ b/build-aux/sodepends.py
@@ -0,0 +1,67 @@
+#! /usr/bin/env python
+
+# Copyright (c) 2008, 2011, 2017 Nicira, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from build import soutil
+import sys
+
+
+def sodepends(include_dirs, filenames, dst):
+ ok = True
+ print("# Generated automatically -- do not modify! "
+ "-*- buffer-read-only: t -*-")
+ for toplevel in sorted(filenames):
+ # Skip names that don't end in .in.
+ if not toplevel.endswith('.in'):
+ continue
+
+ # Open file.
+ fn = soutil.find_file(include_dirs, toplevel)
+ if not fn:
+ ok = False
+ continue
+ try:
+ outer = open(fn)
+ except IOError as e:
+ sys.stderr.write("%s: open: %s\n" % (fn, e.strerror))
+ ok = False
+ continue
+
+ dependencies = []
+ while True:
+ line = outer.readline()
+ if not line:
+ break
+
+ name = soutil.extract_include_directive(line)
+ if name:
+ if soutil.find_file(include_dirs, name):
+ dependencies.append(name)
+ else:
+ ok = False
+
+ dst.write("\n%s:" % toplevel[:-3])
+ for s in [toplevel] + sorted(dependencies):
+ dst.write(' \\\n\t%s' % s)
+ dst.write('\n')
+ for s in [toplevel] + sorted(dependencies):
+ dst.write('%s:\n' % s)
+ return ok
+
+
+if __name__ == '__main__':
+ include_dirs, args = soutil.parse_include_dirs()
+ error = not sodepends(include_dirs, args, sys.stdout)
+ sys.exit(1 if error else 0)