From bec0f45d96be92114cdf4c4f9af7c23bc79e6ea0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 28 Oct 2014 15:04:03 -0700 Subject: [PATCH] Bug 1089446 - Reimplement build/unix/uniq.pl in Python, and remove its unit test. r=gps. --HG-- extra : rebase_source : 5e7ebf7a59a5966b1af5c8a3165b53bb7bd42770 --- build/unix/moz.build | 2 - build/unix/test/Makefile.in | 38 ------- build/unix/test/runtest | 95 ---------------- build/unix/test/uniq.tpl | 151 ------------------------- build/unix/uniq.pl | 91 --------------- build/unix/{test/moz.build => uniq.py} | 8 +- configure.in | 4 +- 7 files changed, 8 insertions(+), 381 deletions(-) delete mode 100644 build/unix/test/Makefile.in delete mode 100644 build/unix/test/runtest delete mode 100644 build/unix/test/uniq.tpl delete mode 100755 build/unix/uniq.pl rename build/unix/{test/moz.build => uniq.py} (56%) mode change 100644 => 100755 diff --git a/build/unix/moz.build b/build/unix/moz.build index 1da5d7ed66d..2b009b7c249 100644 --- a/build/unix/moz.build +++ b/build/unix/moz.build @@ -10,5 +10,3 @@ if CONFIG['MOZ_LIBSTDCXX_TARGET_VERSION'] or CONFIG['MOZ_LIBSTDCXX_HOST_VERSION' if CONFIG['USE_ELF_HACK']: DIRS += ['elfhack'] -TEST_DIRS += ['test'] - diff --git a/build/unix/test/Makefile.in b/build/unix/test/Makefile.in deleted file mode 100644 index 87ba72435ef..00000000000 --- 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 diff --git a/build/unix/test/runtest b/build/unix/test/runtest deleted file mode 100644 index 3a53b0682bc..00000000000 --- 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 diff --git a/build/unix/test/uniq.tpl b/build/unix/test/uniq.tpl deleted file mode 100644 index ae692ab5cbf..00000000000 --- 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 diff --git a/build/unix/uniq.pl b/build/unix/uniq.pl deleted file mode 100755 index 301240e0310..00000000000 --- 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 diff --git a/build/unix/test/moz.build b/build/unix/uniq.py old mode 100644 new mode 100755 similarity index 56% rename from build/unix/test/moz.build rename to build/unix/uniq.py index 895d11993cf..e3afbbaf0f3 --- a/build/unix/test/moz.build +++ b/build/unix/uniq.py @@ -1,6 +1,10 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: +#! /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:])))) diff --git a/configure.in b/configure.in index d672510e768..652f321c509 100644 --- a/configure.in +++ b/configure.in @@ -6270,7 +6270,7 @@ 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. @@ -8352,7 +8352,7 @@ MOZ_ARG_ENABLE_STRING(necko-protocols, 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)