aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Drewry <drewry@google.com>2015-10-26 11:46:08 -0700
committerWill Drewry <drewry@google.com>2015-10-26 14:21:47 -0700
commitfe36d45eb6ecb86a8d452bfc7f34c1e395fb1322 (patch)
tree424ce181fb7eb9031f466607aca2edfd1a7c24e4
parentafb306e506d03623a92d1eaace760b39ac332dc2 (diff)
downloadbdk-fe36d45eb6ecb86a8d452bfc7f34c1e395fb1322.tar.gz
brunch: fix make passthrough
Submodule building was broken as HERE wasn't being populated automatically nor by brunch. This change fixes that. Additionally, argparse includes '--' in the REMAINDER even though it is required to pass in -<x> style arguments through. This change removes the first instance. This also fixes error code propagation beyond just returning 1. BUG=25226596,25227009,25226034,25225868 TEST=ensure command passthrough but doesn't test build system functionality. Change-Id: Idca16baa7518c362b54134bd6b5d90799b3f659f
-rw-r--r--brunch/lib/brunch.py4
-rw-r--r--brunch/lib/cli/climanager.py2
-rw-r--r--brunch/lib/commands/product/build.py16
-rw-r--r--brunch/lib/commands/product/provision.py5
-rw-r--r--brunch/lib/commands/product/tool.py3
-rw-r--r--brunch/lib/core/util.py10
-rw-r--r--brunch/tests/here.sh27
-rw-r--r--brunch/tests/make_args.sh38
-rw-r--r--brunch/tests/make_exit.sh27
-rw-r--r--brunch/tests/make_signalled.sh27
-rw-r--r--brunch/tests/tool_exit.sh30
-rw-r--r--brunch/tests/tool_signalled.sh30
-rw-r--r--build/wrap-common.mk6
-rw-r--r--build/wrap-product.mk2
14 files changed, 213 insertions, 14 deletions
diff --git a/brunch/lib/brunch.py b/brunch/lib/brunch.py
index 0763e6a..86a6590 100644
--- a/brunch/lib/brunch.py
+++ b/brunch/lib/brunch.py
@@ -54,10 +54,10 @@ def main():
brunch_cli.AddCommandGroup('product', CommandPath('product'))
# Process the command line.
- brunch_cli.Execute()
+ return brunch_cli.Execute()
if __name__ == '__main__':
try:
- main()
+ sys.exit(main())
except KeyboardInterrupt:
CtrlCHandler(None, None)
diff --git a/brunch/lib/cli/climanager.py b/brunch/lib/cli/climanager.py
index 9e7bca4..312a2ef 100644
--- a/brunch/lib/cli/climanager.py
+++ b/brunch/lib/cli/climanager.py
@@ -94,4 +94,4 @@ class Cli(object):
args = self.root_group.parser.parse_args()
command = args.command_type()
- command.Run(args)
+ return command.Run(args)
diff --git a/brunch/lib/commands/product/build.py b/brunch/lib/commands/product/build.py
index 7f847f2..9509b17 100644
--- a/brunch/lib/commands/product/build.py
+++ b/brunch/lib/commands/product/build.py
@@ -55,12 +55,18 @@ class Build(clicommand.Command):
if args.buildtype is None:
args.buildtype = 'eng'
+ # Don't pass along the first '--' since it was meant for argparse.
+ args.make_args.count('--') and args.make_args.remove('--')
+
if args.submodule == True:
print "Building submodule only . . ."
- os.system('make -f %s/tools/bdk/build/wrap-product.mk %s ENVCMD=mm BUILDTYPE=%s %s' %
- (sdk_path, no_java, args.buildtype, util.AsShellArgs(args.make_args)))
+ ret = os.system('make -f %s/tools/bdk/build/wrap-product.mk %s ' \
+ 'HERE="%s" ENVCMD=mm BUILDTYPE=%s %s' %
+ (sdk_path, no_java, os.getcwd(), args.buildtype,
+ util.AsShellArgs(args.make_args)))
else:
# Change to the product path and build the whole product.
- os.system('cd %s;make -f %s/tools/bdk/build/wrap-product.mk %s BUILDTYPE=%s %s' %
- (args.product_path, sdk_path, no_java, args.buildtype,
- util.AsShellArgs(args.make_args)))
+ ret = os.system('cd %s;make -f %s/tools/bdk/build/wrap-product.mk %s BUILDTYPE=%s %s' %
+ (args.product_path, sdk_path, no_java, args.buildtype,
+ util.AsShellArgs(args.make_args)))
+ return util.GetExitCode(ret)
diff --git a/brunch/lib/commands/product/provision.py b/brunch/lib/commands/product/provision.py
index ad2bbf9..7edfd9d 100644
--- a/brunch/lib/commands/product/provision.py
+++ b/brunch/lib/commands/product/provision.py
@@ -49,5 +49,6 @@ class Provision(clicommand.Command):
return 1
# We have to export the host tools because provision-device
# expects them in its path.
- os.system('export PATH=%s:$PATH; %s %s' %
- (host_tools, tool_path, util.AsShellArgs(args.args)))
+ ret = os.system('export PATH=%s:$PATH; %s %s' %
+ (host_tools, tool_path, util.AsShellArgs(args.args)))
+ return util.GetExitCode(ret)
diff --git a/brunch/lib/commands/product/tool.py b/brunch/lib/commands/product/tool.py
index 85bac18..1509160 100644
--- a/brunch/lib/commands/product/tool.py
+++ b/brunch/lib/commands/product/tool.py
@@ -53,4 +53,5 @@ class Tool(clicommand.Command):
if not os.path.isfile(tool_path):
print "The product must be built once prior to using %s." % args.tool
return 1
- os.system('%s %s' % (tool_path, util.AsShellArgs(args.args)))
+ ret = os.system('%s %s' % (tool_path, util.AsShellArgs(args.args)))
+ return util.GetExitCode(ret)
diff --git a/brunch/lib/core/util.py b/brunch/lib/core/util.py
index 80cf68b..d234d3b 100644
--- a/brunch/lib/core/util.py
+++ b/brunch/lib/core/util.py
@@ -76,3 +76,13 @@ def GetProductDir():
def AsShellArgs(args):
return ' '.join(['"%s"' % a.replace('"', '\\"') for a in args])
+
+def GetExitCode(status):
+ """Convert an os.wait status code to a shell return value"""
+ if os.WIFEXITED(status):
+ return os.WEXITSTATUS(status)
+ if os.WIFSTOPPED(status):
+ return 128+os.WSTOPSIG(status)
+ if os.WIFSIGNALED(status):
+ return 128+os.WTERMSIG(status)
+ return 1
diff --git a/brunch/tests/here.sh b/brunch/tests/here.sh
new file mode 100644
index 0000000..bca9c0b
--- /dev/null
+++ b/brunch/tests/here.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# Copyright (C) 2015 The Android Open Source Project
+#
+# 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.
+
+. tests/test_helpers
+
+setup_working_path
+
+echo "Testing that HERE is passed along"
+$BRUNCH product create product board
+cd product
+stub_make
+. ./envsetup.sh
+
+mm -j20 | grep -- HERE=${PWD}
diff --git a/brunch/tests/make_args.sh b/brunch/tests/make_args.sh
new file mode 100644
index 0000000..3603bde
--- /dev/null
+++ b/brunch/tests/make_args.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+# Copyright (C) 2015 The Android Open Source Project
+#
+# 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.
+
+. tests/test_helpers
+
+setup_working_path
+
+echo "Testing that the first -- is dropped."
+$BRUNCH product create product board
+cd product
+stub_make
+. ./envsetup.sh
+
+echo 'Make sure the argument immediately after the fixed ones is -j20'
+test "$(brunch product build -- -j20 | head -6 | tail -1)" == "-j20"
+echo 'Make sure the last argument is --'
+test "$(brunch product build -- -j20 -- | head -7 | tail -1)" == "--"
+echo 'Make sure the same is true for m'
+test "$(m -h | head -6 | tail -1)" == "-h"
+test "$(m help | head -6 | tail -1)" == "help"
+test "$(m -j20 -- | head -7 | tail -1)" == "--"
+echo 'Make sure the same is true for mm'
+test "$(mm -h | head -8 | tail -1)" == "-h"
+test "$(mm help | head -8 | tail -1)" == "help"
+test "$(mm -j20 -- | head -9 | tail -1)" == "--"
diff --git a/brunch/tests/make_exit.sh b/brunch/tests/make_exit.sh
new file mode 100644
index 0000000..7cf5236
--- /dev/null
+++ b/brunch/tests/make_exit.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# Copyright (C) 2015 The Android Open Source Project
+#
+# 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.
+
+. tests/test_helpers
+
+setup_working_path
+
+echo "Make sure that wrapped tool error codes are returned"
+$BRUNCH product create product board
+cd product
+stub_make
+echo "exit 12" >> stubs/make
+. ./envsetup.sh
+brunch product build || test $? -eq 12
diff --git a/brunch/tests/make_signalled.sh b/brunch/tests/make_signalled.sh
new file mode 100644
index 0000000..a66614f
--- /dev/null
+++ b/brunch/tests/make_signalled.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# Copyright (C) 2015 The Android Open Source Project
+#
+# 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.
+
+. tests/test_helpers
+
+setup_working_path
+
+echo "Make sure that wrapped tool trap codes are returned"
+$BRUNCH product create product board
+cd product
+stub_make
+echo 'kill -ABRT $$' >> stubs/make
+. ./envsetup.sh
+brunch product build || test $? -eq $((128+6))
diff --git a/brunch/tests/tool_exit.sh b/brunch/tests/tool_exit.sh
new file mode 100644
index 0000000..66390f1
--- /dev/null
+++ b/brunch/tests/tool_exit.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+# Copyright (C) 2015 The Android Open Source Project
+#
+# 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.
+
+. tests/test_helpers
+
+setup_working_path
+
+echo "Make sure that make's error code is passed all the way back up"
+$BRUNCH product create product board
+cd product
+stub_make
+echo "exit 12" >> stubs/make
+stub_tools
+. ./envsetup.sh
+provision || test $? -eq 12
+adb || test $? -eq 12
+fastboot || test $? -eq 12
diff --git a/brunch/tests/tool_signalled.sh b/brunch/tests/tool_signalled.sh
new file mode 100644
index 0000000..22de094
--- /dev/null
+++ b/brunch/tests/tool_signalled.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+# Copyright (C) 2015 The Android Open Source Project
+#
+# 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.
+
+. tests/test_helpers
+
+setup_working_path
+
+echo "Handle signal death"
+$BRUNCH product create product board
+cd product
+stub_make
+echo 'kill -KILL $$' >> stubs/make
+stub_tools
+. ./envsetup.sh
+provision || test $? -eq $((128+9))
+adb || test $? -eq $((128+9))
+fastboot || test $? -eq $((128+9))
diff --git a/build/wrap-common.mk b/build/wrap-common.mk
index 6a18cb5..cff50a5 100644
--- a/build/wrap-common.mk
+++ b/build/wrap-common.mk
@@ -112,7 +112,7 @@ define build-product
add_lunch_combo "$(3)-$(6)" && \
lunch "$(3)-$(6)" && \
PATH=$(2)/java/bin:$$PATH $(MAKE) $(MAKECMDGOALS) "OUT_DIR=$(5)/out-$(4)" KATI_EMULATE_FIND=false || \
- exit 1) 2>&1 | tee "$(5)/last_build.log"
+ exit $?) 2>&1 | tee "$(5)/last_build.log"
endef
# Calls the android build in the current directory mapped under the shadow BDK
@@ -126,9 +126,9 @@ define build-product-here
source build/envsetup.sh && \
add_lunch_combo "$(3)-$(6)" && \
lunch "$(3)-$(6)" && \
- cd "$(7)" && \
+ cd "product/$(PRODUCT_MANUFACTURER)/$(PRODUCT_NAME)/$(subst $(PRODUCT_DIR)/,,$(7))" && \
PATH=$(2)/java/bin:$$PATH \
MAKEFLAGS="$(MAKEFLAGS)" OUT_DIR="$(5)/out-$(4)" \
KATI_EMULATE_FIND=false $(8) || \
- exit 1) 2>&1 | tee "$(5)/last_build.log"
+ exit $?) 2>&1 | tee "$(5)/last_build.log"
endef
diff --git a/build/wrap-product.mk b/build/wrap-product.mk
index c81d554..e8b939c 100644
--- a/build/wrap-product.mk
+++ b/build/wrap-product.mk
@@ -113,6 +113,8 @@ BUILDTYPE ?= eng
# By default, Android build expects Java.
BRILLO_NO_JAVA ?=
+HERE ?= $(PWD)
+
# Create the shadow BDK in the product out directory. Use a dot path to
# discourage accidental damage.
PRODUCT_BDK := $(PRODUCT_OUT)/.bdk