1#!/bin/bash 2 3# Copyright 2023 Google LLC 4# 5# Use of this source code is governed by a BSD-style license that can be 6# found in the LICENSE file. 7 8# Helper script to serve Bazel undeclared test outputs over HTTP. 9 10if [ $# -ne 1 ] 11then 12 echo "Usage: $0 <path to outputs.zip>" 13 echo 14 echo "This is a helper script to serve Bazel undeclared test outputs over HTTP. See the" 15 echo "TEST_UNDECLARED_OUTPUTS_DIR environment variable as described in" 16 echo "https://bazel.build/reference/test-encyclopedia#initial-conditions." 17 echo 18 echo "A typical use case is to view the PNG files produced by a GM executed with \"bazel test\"." 19 echo "However, this script works with any Bazel target that produces undeclared outputs." 20 echo 21 echo "Suppose //path/to:some_test is a Bazel target that produces undeclared test outputs. Its" 22 echo "undeclared test outputs are typically found inside a ZIP file named" 23 echo "bazel-testlogs/path/to/some_test/test.outputs/outputs.zip (relative to the repository's" 24 echo "root directory)." 25 echo 26 echo "Example session:" 27 echo 28 echo " $ bazel test //path/to:some_test" 29 echo " $ $0 bazel-testlogs/path/to/some_test/test.outputs/outputs.zip" 30 echo " Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ..." 31 echo 32 exit 1 33fi 34 35# Create a temporary directory where we will extract the ZIP file, and delete it on exit. 36TMP_DIR="$(mktemp -d)" 37trap "rm -rf $TMP_DIR" EXIT 38 39set -x -e 40 41unzip -d $TMP_DIR $1 42cd $TMP_DIR && python3 -m http.server 43