build: remove GNU time dependency
authorJo-Philipp Wich <jo@mein.io>
Sat, 4 Aug 2018 22:06:27 +0000 (00:06 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 18 Dec 2018 10:01:54 +0000 (11:01 +0100)
Replace the GNU time program invocation with a simple Perl script reporting
the timing values. Since we require Perl anyway for the build system, we can
as well use that instead of requiring a random GNU utility rarely installed
by default.

Fixes: ff6e62b288 ("build: log time taken by each packages/steps")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(backported from d3ddf6631e491a831617a5ae8b3d7924e47a275a)

include/prereq-build.mk
include/subdir.mk
scripts/time.pl [new file with mode: 0755]

index 029249f69cb0e835c1b4a4a0408b0b85a87d823f..a416a2d2320990ef1888b621691246cf4eea4af1 100644 (file)
@@ -138,11 +138,6 @@ $(eval $(call SetupHostCommand,bzip2,Please install 'bzip2', \
 $(eval $(call SetupHostCommand,wget,Please install GNU 'wget', \
        wget --version | grep GNU))
 
-$(eval $(call SetupHostCommand,time,Please install GNU 'time' or BusyBox 'time' that supports -f, \
-       gtime --version 2>&1 | grep GNU, \
-       time --version 2>&1 | grep GNU, \
-       busybox time 2>&1 | grep -- '-f FMT'))
-
 $(eval $(call SetupHostCommand,perl,Please install Perl 5.x, \
        perl --version | grep "perl.*v5"))
 
index dde3e50b0bea12bee1744b0a469fde66c354635c..6512e24c2e6ed1191e774d211f08c88a870d0ff9 100644 (file)
@@ -43,7 +43,7 @@ log_make = \
         $(if $(BUILD_LOG), \
                set -o pipefail; \
                mkdir -p $(BUILD_LOG_DIR)/$(1)$(if $(4),/$(4));) \
-       env time -f "time: $(1)$(if $(4),/$(4))/$(if $(3),$(3)-)$(2)\#%U\#%S\#%e" -- \
+       $(SCRIPT_DIR)/time.pl "time: $(1)$(if $(4),/$(4))/$(if $(3),$(3)-)$(2)" \
        $$(SUBMAKE) $(subdir_make_opts) $(if $(3),$(3)-)$(2) \
                $(if $(BUILD_LOG),SILENT= 2>&1 | tee $(BUILD_LOG_DIR)/$(1)$(if $(4),/$(4))/$(if $(3),$(3)-)$(2).txt)
 
diff --git a/scripts/time.pl b/scripts/time.pl
new file mode 100755 (executable)
index 0000000..cdc5824
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Time::HiRes qw(gettimeofday);
+
+if (@ARGV < 2) {
+       die "Usage: $0 <prefix> <command...>\n";
+}
+
+my ($prefix, @cmd) = @ARGV;
+my ($sec, $msec) = gettimeofday();
+my $pid = fork();
+
+if (!defined($pid)) {
+       die "$0: Failure to fork(): $!\n";
+}
+elsif ($pid == 0) {
+       exec(@cmd);
+       die "$0: Failure to exec(): $!\n";
+}
+else {
+       $SIG{'INT'} = 'IGNORE';
+       $SIG{'QUIT'} = 'IGNORE';
+
+       if (waitpid($pid, 0) == -1) {
+               die "$0: Failure to waitpid(): $!\n";
+       }
+
+       my $exitcode = $? >> 8;
+       my ($sec2, $msec2) = gettimeofday();
+       my (undef, undef, $cuser, $csystem) = times();
+
+       printf STDERR "%s#%.2f#%.2f#%.2f\n",
+               $prefix, $cuser, $csystem,
+               ($sec2 - $sec) + ($msec2 - $msec) / 1000000;
+
+       $SIG{'INT'} = 'DEFAULT';
+       $SIG{'QUIT'} = 'DEFAULT';
+
+       exit $exitcode;
+}