Bug 1089446 - Reimplement build/unix/uniq.pl in Python, and remove its unit test. r=gps.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 28 Oct 2014 15:04:03 -0700
changeset 237339 693baa2d9ba934201894a20404a6243a566c013e
parent 237338 82e3c989ec643eaa336310457a62a0d504f9e16d
child 237340 134b583fd7abf41496478aa08f63ac8f47ee09ff
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1089446
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1089446 - Reimplement build/unix/uniq.pl in Python, and remove its unit test. r=gps.
build/unix/moz.build
build/unix/test/Makefile.in
build/unix/test/moz.build
build/unix/test/runtest
build/unix/test/uniq.tpl
build/unix/uniq.pl
build/unix/uniq.py
configure.in
--- a/build/unix/moz.build
+++ b/build/unix/moz.build
@@ -5,10 +5,8 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 if CONFIG['MOZ_LIBSTDCXX_TARGET_VERSION'] or CONFIG['MOZ_LIBSTDCXX_HOST_VERSION']:
     DIRS += ['stdc++compat']
 
 if CONFIG['USE_ELF_HACK']:
     DIRS += ['elfhack']
 
-TEST_DIRS += ['test']
-
deleted file mode 100644
--- a/build/unix/test/Makefile.in
+++ /dev/null
@@ -1,38 +0,0 @@
-# -*- makefile -*-
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-include $(topsrcdir)/config/rules.mk
-
-##################################################
-## Gather a list of tests, generate timestamp deps
-##################################################
-TS=.ts
-ifneq (,$(findstring check,$(MAKECMDGOALS)))
-          allsrc = $(wildcard $(srcdir)/*)
-       tests2run = $(notdir $(filter %.tpl,$(allsrc)))
-  check_targets += $(addprefix $(TS)/,$(tests2run))
-endif
-
-check:: $(TS) $(check_targets)
-
-#############################################
-# Only invoke tests when sources have changed
-#############################################
-$(TS)/%: $(srcdir)/%
-	$(PERL) $(srcdir)/runtest $<
-	@touch $@
-
-#####################################################
-## Extra dep needed to synchronize parallel execution
-#####################################################
-$(TS): $(TS)/.done
-$(TS)/.done:
-	$(MKDIR) -p $(dir $@)
-	touch $@
-
-GARBAGE_DIRS += $(TS)
-
-# EOF
deleted file mode 100644
--- a/build/unix/test/moz.build
+++ /dev/null
@@ -1,6 +0,0 @@
-# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
-# vim: set filetype=python:
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
deleted file mode 100644
--- a/build/unix/test/runtest
+++ /dev/null
@@ -1,95 +0,0 @@
-#!/usr/bin/env perl
-###########################################################################
-## Intent:
-##   Test::Harness is a testing wrapper that will process output
-##   from Test.pm module tests.  Sumarize results, report stats
-##   and exit with overall status for the testing suites.
-##
-## Run testing suite:
-##   % make clean test
-##   % perl runtest
-##
-## Run Individual tests
-##   % perl tUtils0
-###########################################################################
-
-##----------------------------##
-##---] CORE/CPAN INCLUDES [---##
-##----------------------------##
-use strict;
-use warnings;
-use Getopt::Long;
-
-use Test::Harness;
-
-##-------------------##
-##---]  EXPORTS  [---##
-##-------------------##
-our $VERSION = qw(1.0);
-use FindBin;
-
-##-------------------##
-##---]  GLOBALS  [---##
-##-------------------##
-my %argv;
-
-##----------------##
-##---]  MAIN  [---##
-##----------------##
-unless(GetOptions(\%argv,
-		  qw(debug|d)
-		 ))
-{
-    print "Usage: $0\n";
-    print "  --debug  Enable debug mode\n";
-    exit 1;
-}
-
-if (2 > $Test::Harness::VERSION)
-{
-    print "Unit tests will not be run, Test::Harness is too old\n"
-	if ($argv{debug});
-    exit 0;
-}
-
-
-my @tests;
-
-########################################
-## Gather a list of tests if none passed
-########################################
-unless (@tests = @ARGV)
-{
-  local *D;
-    opendir(D, '.');
-    while($_ = readdir(D)) {
-	next unless /.t\S+$/;
-	next if (/\.ts$/);
-	push(@tests, $_);
-    }
-    closedir(D);
-}
-
-###############################################
-## Glob a list of tests when directories passed
-###############################################
-my @tmp;
-foreach (@tests)
-{
-  local *D;
-    if (-d $_ && (my $dir = $_))
-    {
-        opendir(D, $_) || die "opendir(D) failed: $!";
-	my @tests = grep(/\.t[^\.\s]+/o, readdir(D));
-	closedir(D);
-	push(@tmp, map{ join('/', $dir, $_); } @tests);
-    } else {
-        push(@tmp, $_);
-    }
-}
-@tests = @tmp;
-
-print "$0: @ARGV\n" if ($argv{debug});
-runtests(@tests);
-
-# EOF
deleted file mode 100644
--- a/build/unix/test/uniq.tpl
+++ /dev/null
@@ -1,151 +0,0 @@
-#!/usr/bin/env perl
-###########################################################################
-## Intent: Unit test to verify uniq.pl
-###########################################################################
-
-##----------------------------##
-##---] CORE/CPAN INCLUDES [---##
-##----------------------------##
-use strict;
-use warnings;
-use Cwd;
-use Getopt::Long;  # GetOptions
-
-use Test;
-sub BEGIN { plan tests => 12 }
-
-##-------------------##
-##---]  EXPORTS  [---##
-##-------------------##
-our $VERSION = qw(1.0);
-
-##------------------##
-##---] INCLUDES [---##
-##------------------##
-use FindBin;
-
-##-------------------##
-##---]  GLOBALS  [---##
-##-------------------##
-my %argv;
-
-
-###########################################################################
-## Intent: Run the arch command for output
-##
-## Returns:
-##    0   on success
-##    $?  command shell exit status
-###########################################################################
-sub uniq_pl
-{
-    my $cmd = "perl $FindBin::RealBin/../uniq.pl @_";
-    print "Running: $cmd\n" if ($argv{debug});
-    my @tmp = `$cmd 2>&1`;
-    my @output = map{ split(/\s+/o); } @tmp;
-    wantarray ? @output : "@output";
-} # uniq_pl
-
-###########################################################################
-## Intent:
-##
-## Returns:
-##    0 on success
-###########################################################################
-sub check_uniq
-{
-    print STDERR "Running test: check_uniq\n" if ($argv{debug});
-
-    # TODO: improve test, uniq.pl regexpr handling not quite right
-
-    my @todo =
-      (
-       [ '', qw(a a/b a/b/c) ] => [  qw(a a/b a/b/c) ],
-       [ '', qw(a/b a a/b/c) ] => [ qw(a/b a a/b/c) ],
-       [ '', qw(a/b/c a/b a) ] => [ qw(a/b/c a/b a) ],
-
-       [ '', qw(a a/b a/b/c a/b a) ] => [  qw(a a/b a/b/c) ], # dup removal
-
-       [ '-s', qw(a a/b a/b/c) ] => [ qw(a a/b a/b/c)  ],
-       [ '-s', qw(a/b a a/b/c) ] => [ qw(a a/b a/b/c) ],
-       [ '-s', qw(a/b/c a/b a) ] => [ qw(a a/b a/b/c) ],
-
-       [ '-r', qw(a a/b a/b/c) ] => [ qw(a) ],
-       [ '-r', qw(a/b a a/b/c) ] => [ qw(a/b a) ],
-       [ '-r', qw(a/b/c a/b a) ] => [ qw(a/b/c a/b a) ],
-
-       [ '-r', qw(. .. a/b ../a aa/bb) ] => [ qw(. .. a/b aa/bb) ],
-       [ '-r', qw(.. a/b ../a . aa/bb) ] => [ qw(.. a/b . aa/bb) ],
-      );
-
-    my $ct=1;
-    while (@todo)
-    {
-        my ($a, $b) = splice(@todo, 0, 2);
-	my @args = @{ $a };
-	my @exp = @{ $b };
-
-	my @out = uniq_pl(@args);
-#	compareExp(\@out, \@exp, 'Failed on line ' . __LINE__ . ", dataset $ct");
-	if (0 && 7 == $ct)
-	  {
-	    print STDERR "\n";
-	    print STDERR map{ "args> $_\n" }@args;
-	    print STDERR "\n";
-	    print STDERR map{ "exp> $_\n" }@exp;
-	    print STDERR "\n";
-	    print STDERR map{ "out> $_\n" }@out;
-	  }
-
-	ok("@out", "@exp", 'Failed on line ' . __LINE__ . ", dataset $ct");
-	$ct++;
-    }
-
-} # check_uniq
-
-###########################################################################
-## Intent: Smoke tests for the unittests module
-###########################################################################
-sub smoke
-{
-    print STDERR "Running test: smoke()\n" if ($argv{debug});
-} # smoke()
-
-###########################################################################
-## Intent: Intitialize global test objects and consts
-###########################################################################
-sub init
-{
-    print "Running: init()\n" if ($argv{debug});
-#    testplan(24, 0);
-} # init()
-
-##----------------##
-##---]  MAIN  [---##
-##----------------##
-unless(GetOptions(\%argv,
-		  qw(
-		     debug|d
-                     manual
-		     test=s@
-		     verbose
-		     )))
-{
-    print "USAGE: $0\n";
-    print "  --debug    Enable script debug mode\n";
-    print "  --fail     Force a testing failure condition\n";
-    print "  --manual   Also run disabled tests\n";
-    print "  --smoke    Run smoke tests then exit\n";
-    print "  --test     Run a list of tests by function name\n";
-    print "  --verbose  Enable script verbose mode\n";
-    exit 1;
-}
-
-init();
-testbyname(@{ $argv{test} }) if ($argv{test});
-smoke();
-
-check_uniq();
-ok(1, 0, 'Forced failure by command line arg --fail') if ($argv{fail});
-
-# EOF
deleted file mode 100755
--- a/build/unix/uniq.pl
+++ /dev/null
@@ -1,91 +0,0 @@
-#!/usr/bin/env perl
-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-##----------------------------##
-##---] CORE/CPAN INCLUDES [---##
-##----------------------------##
-use strict;
-use warnings;
-use Getopt::Long;
-
-##-------------------##
-##---]  EXPORTS  [---##
-##-------------------##
-our $VERSION = qw(1.1);
-
-##-------------------##
-##---]  GLOBALS  [---##
-##-------------------##
-my %argv;
-my $modver = $Getopt::Long::VERSION || 0;
-my $isOldGetopt = ($modver eq '2.25') ? 1 : 0;
-
-###########################################################################
-## Intent: Script init function
-###########################################################################
-sub init
-{
-    if ($isOldGetopt)
-    {
-	# mozilla.build/mingw perl in need of an upgrade
-	# emulate Getopt::Long switch|short:init
-	foreach (qw(debug regex sort))
-	{
-	    if (defined($argv{$_}))
-	    {
-		$argv{$_} ||= 1;
-	    }
-	}
-    }
-} # init
-
-##----------------##
-##---]  MAIN  [---##
-##----------------##
-my @args = ($isOldGetopt)
-    ? qw(debug|d regex|r sort|s)
-    : qw(debug|d:1 regex|r:1 sort|s:1)
-    ;
-
-unless(GetOptions(\%argv, @args))
-{
-    print "Usage: $0\n";
-    print "  --sort   Sort list elements early\n";
-    print "  --regex  Exclude subdirs by pattern\n";
-}
-
-init();
-my $debug = $argv{debug} || 0;
-
-my %seen;
-my @out;
-my @in = ($argv{sort}) ? sort @ARGV : @ARGV;
-
-foreach my $d (@in)
-{
-    next if ($seen{$d}++);
-
-    print "   arg is $d\n" if ($debug);
-
-    if ($argv{regex})
-    {
-        my $found = 0;
-        foreach my $dir (@out)
-	{
-	    my $dirM = quotemeta($dir);
-            $found++, last if ($d eq $dir || $d =~ m!^${dirM}\/!);
-        }
-	print "Adding $d\n" if ($debug && !$found);
-        push @out, $d if (!$found);
-    } else {
-	print "Adding: $d\n" if ($debug);
-        push(@out, $d);
-    }
-}
-
-print "@out\n"
-
-# EOF
new file mode 100755
--- /dev/null
+++ b/build/unix/uniq.py
@@ -0,0 +1,10 @@
+#! /usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+'''Prints the given arguments in sorted order with duplicates removed.'''
+
+import sys
+
+print(' '.join(sorted(set(sys.argv[1:]))))
--- a/configure.in
+++ b/configure.in
@@ -6265,17 +6265,17 @@ fi
 
 if test `echo "$MOZ_EXTENSIONS" | grep -c gio` -ne 0; then
     MOZ_GIO_COMPONENT=1
     MOZ_EXTENSIONS=`echo $MOZ_EXTENSIONS | sed -e 's|gio||'`
 fi
 AC_SUBST(MOZ_GIO_COMPONENT)
 
 dnl Remove dupes
-MOZ_EXTENSIONS=`${PERL} ${srcdir}/build/unix/uniq.pl ${MOZ_EXTENSIONS}`
+MOZ_EXTENSIONS=`$PYTHON ${srcdir}/build/unix/uniq.py ${MOZ_EXTENSIONS}`
 
 dnl Ensure every extension exists, to avoid mostly-inscrutable error messages
 dnl when trying to build a nonexistent extension.
 for extension in $MOZ_EXTENSIONS; do
     if test ! -d "${srcdir}/extensions/${extension}"; then
         AC_MSG_ERROR([Unrecognized extension provided to --enable-extensions: ${extension}.])
     fi
 done
@@ -8347,17 +8347,17 @@ MOZ_ARG_ENABLE_STRING(necko-protocols,
         option=`echo $option | sed 's/^-//'`
         NECKO_PROTOCOLS=`echo "$NECKO_PROTOCOLS" | sed "s/ ${option}//"`
     else
         NECKO_PROTOCOLS="$NECKO_PROTOCOLS $option"
     fi
 done],
     NECKO_PROTOCOLS="$NECKO_PROTOCOLS_DEFAULT")
 dnl Remove dupes
-NECKO_PROTOCOLS=`${PERL} ${srcdir}/build/unix/uniq.pl ${NECKO_PROTOCOLS}`
+NECKO_PROTOCOLS=`$PYTHON ${srcdir}/build/unix/uniq.py ${NECKO_PROTOCOLS}`
 AC_SUBST_SET(NECKO_PROTOCOLS)
 for p in $NECKO_PROTOCOLS; do
     AC_DEFINE_UNQUOTED(NECKO_PROTOCOL_$p)
     _NON_GLOBAL_ACDEFINES="$_NON_GLOBAL_ACDEFINES NECKO_PROTOCOL_$p"
 done
 
 dnl
 dnl option to disable necko's wifi scanner