make/scripts/logger.sh
author chegar
Thu, 17 Oct 2019 20:27:44 +0100
branchdatagramsocketimpl-branch
changeset 58677 13588c901957
parent 47216 71c04702a3d5
permissions -rw-r--r--
Initial changes for datagramsocketimpl-branch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14111
2a82ecb35fc7 8000992: Update new build-infra makefiles
ohair
parents: 12801
diff changeset
     1
#!/bin/bash
12258
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     2
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     3
# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     4
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     5
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     6
# This code is free software; you can redistribute it and/or modify it
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     7
# under the terms of the GNU General Public License version 2 only, as
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     8
# published by the Free Software Foundation.
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
     9
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    10
# This code is distributed in the hope that it will be useful, but WITHOUT
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    12
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    13
# version 2 for more details (a copy is included in the LICENSE file that
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    14
# accompanied this code).
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    15
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    16
# You should have received a copy of the GNU General Public License version
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    17
# 2 along with this work; if not, write to the Free Software Foundation,
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    18
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    19
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    20
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    21
# or visit www.oracle.com if you need additional information or have any
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    22
# questions.
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    23
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    24
27595
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 14111
diff changeset
    25
# Usage: ./logger.sh theloggfile acommand arg1 arg2
12258
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    26
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    27
# Execute acommand with args, in such a way that
27595
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 14111
diff changeset
    28
# both stdout and stderr from acommand are appended to
12258
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    29
# theloggfile.
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    30
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    31
# Preserve stdout and stderr, so that the stdout
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    32
# from logger.sh is the same from acommand and equally
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    33
# for stderr.
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    34
#
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    35
# Propagate the result code from acommand so that
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    36
# ./logger.sh exits with the same result code.
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    37
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    38
# Create a temporary directory to store the result code from
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    39
# the wrapped command.
12801
948f8ad66ee7 7170079: Adjustments to build-infra makefiles
erikj
parents: 12258
diff changeset
    40
RCDIR=`mktemp -dt jdk-build-logger.tmp.XXXXXX` || exit $?
948f8ad66ee7 7170079: Adjustments to build-infra makefiles
erikj
parents: 12258
diff changeset
    41
trap "rm -rf \"$RCDIR\"" EXIT
12258
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    42
LOGFILE=$1
6ec26f6cc53e 7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff changeset
    43
shift
32345
ed4ddf0bdb63 8135014: logger.sh needs to handle commands with variable assignment prefixes
ihse
parents: 27595
diff changeset
    44
ed4ddf0bdb63 8135014: logger.sh needs to handle commands with variable assignment prefixes
ihse
parents: 27595
diff changeset
    45
# We need to handle command likes like "VAR1=val1 /usr/bin/cmd VAR2=val2".
ed4ddf0bdb63 8135014: logger.sh needs to handle commands with variable assignment prefixes
ihse
parents: 27595
diff changeset
    46
# Do this by shifting away prepended variable assignments, and export them
ed4ddf0bdb63 8135014: logger.sh needs to handle commands with variable assignment prefixes
ihse
parents: 27595
diff changeset
    47
# instead.
ed4ddf0bdb63 8135014: logger.sh needs to handle commands with variable assignment prefixes
ihse
parents: 27595
diff changeset
    48
is_prefix=true
ed4ddf0bdb63 8135014: logger.sh needs to handle commands with variable assignment prefixes
ihse
parents: 27595
diff changeset
    49
for opt; do
ed4ddf0bdb63 8135014: logger.sh needs to handle commands with variable assignment prefixes
ihse
parents: 27595
diff changeset
    50
  if [[ "$is_prefix" = true && "$opt" =~ ^.*=.*$ ]]; then
ed4ddf0bdb63 8135014: logger.sh needs to handle commands with variable assignment prefixes
ihse
parents: 27595
diff changeset
    51
    export $opt
ed4ddf0bdb63 8135014: logger.sh needs to handle commands with variable assignment prefixes
ihse
parents: 27595
diff changeset
    52
    shift
ed4ddf0bdb63 8135014: logger.sh needs to handle commands with variable assignment prefixes
ihse
parents: 27595
diff changeset
    53
  else
ed4ddf0bdb63 8135014: logger.sh needs to handle commands with variable assignment prefixes
ihse
parents: 27595
diff changeset
    54
    is_prefix=false
ed4ddf0bdb63 8135014: logger.sh needs to handle commands with variable assignment prefixes
ihse
parents: 27595
diff changeset
    55
  fi
ed4ddf0bdb63 8135014: logger.sh needs to handle commands with variable assignment prefixes
ihse
parents: 27595
diff changeset
    56
done
ed4ddf0bdb63 8135014: logger.sh needs to handle commands with variable assignment prefixes
ihse
parents: 27595
diff changeset
    57
12801
948f8ad66ee7 7170079: Adjustments to build-infra makefiles
erikj
parents: 12258
diff changeset
    58
(exec 3>&1 ; ("$@" 2>&1 1>&3; echo $? > "$RCDIR/rc") | tee -a $LOGFILE 1>&2 ; exec 3>&-) | tee -a $LOGFILE
948f8ad66ee7 7170079: Adjustments to build-infra makefiles
erikj
parents: 12258
diff changeset
    59
exit `cat "$RCDIR/rc"`