From 51dff6bce67696bc824e3831ed7b9aa8f9896836 Mon Sep 17 00:00:00 2001 From: Jackson West Date: Wed, 11 Oct 2023 21:37:35 -0500 Subject: [PATCH] adds shell trace to common.mk (#2538) --- Common.mk | 5 +++-- Makefile | 7 +++++++ build/lib/make_shell_trace.sh | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100755 build/lib/make_shell_trace.sh diff --git a/Common.mk b/Common.mk index cc21cbb836..6706f88b78 100644 --- a/Common.mk +++ b/Common.mk @@ -1,7 +1,5 @@ # Disable built-in rules and variables MAKEFLAGS+=--no-builtin-rules --warn-undefined-variables -SHELL=bash -.SHELLFLAGS:=-eu -o pipefail -c .SUFFIXES: .SECONDEXPANSION: @@ -14,6 +12,9 @@ PROJECT_PATH?=$(subst $(BASE_DIRECTORY)/,,$(MAKE_ROOT)) BUILD_LIB=$(BASE_DIRECTORY)/build/lib OUTPUT_BIN_DIR?=$(OUTPUT_DIR)/bin/$(REPO) +SHELL_TRACE?=false +SHELL:=$(if $(filter true,$(SHELL_TRACE)),$(BUILD_LIB)/make_shell_trace.sh,bash) +.SHELLFLAGS:=$(if $(filter true,$(SHELL_TRACE)),-c,-eu -o pipefail -c) #################### AWS ########################### AWS_REGION?=us-west-2 AWS_ACCOUNT_ID?=$(shell aws sts get-caller-identity --query Account --output text) diff --git a/Makefile b/Makefile index 43267caef3..6e00063ad1 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,12 @@ +MAKEFLAGS+=--no-builtin-rules --warn-undefined-variables +.SUFFIXES: + BASE_DIRECTORY:=$(abspath .) BUILD_LIB=${BASE_DIRECTORY}/build/lib +SHELL_TRACE?=false +SHELL:=$(if $(filter true,$(SHELL_TRACE)),$(BUILD_LIB)/make_shell_trace.sh,bash) +.SHELLFLAGS:=$(if $(filter true,$(SHELL_TRACE)),-c,-eu -o pipefail -c) + AWS_ACCOUNT_ID?=$(shell aws sts get-caller-identity --query Account --output text) AWS_REGION?=us-west-2 IMAGE_REPO?=$(if $(AWS_ACCOUNT_ID),$(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com,localhost:5000) diff --git a/build/lib/make_shell_trace.sh b/build/lib/make_shell_trace.sh new file mode 100755 index 0000000000..6a5dc6b76a --- /dev/null +++ b/build/lib/make_shell_trace.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +# +# 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. + +set -o errexit +set -o nounset +set -o pipefail + +# remove -c passed by make +shift +>&2 echo "Shell trace: $@" +eval "$@"