| #!/usr/bin/env bash |
| |
| set -euo pipefail |
| |
| if [[ ! -d "${FUCHSIA_BUILD_DIR}" ]]; then |
| echo "FUCHSIA_BUILD_DIR environment variable not a directory; are you running under fx exec?" 1>&2 |
| exit 1 |
| fi |
| |
| readonly GOFMT="${FUCHSIA_BUILD_DIR}/tools/goroot/bin/gofmt" |
| if [ ! -x "${GOFMT}" ]; then |
| echo "error: unable to find gofmt; did the path change?" 1>&2 |
| exit 1 |
| fi |
| |
| readonly FIDLC="${FUCHSIA_BUILD_DIR}/host_x64/fidlc" |
| if [ ! -x "${FIDLC}" ]; then |
| echo "error: fidlc missing; did you build?" 1>&2 |
| exit 1 |
| fi |
| |
| readonly FIDLGEN="${FUCHSIA_BUILD_DIR}/host_x64/fidlgen" |
| if [ ! -x "${FIDLGEN}" ]; then |
| echo "error: fidlgen missing; did you build?" 1>&2 |
| exit 1 |
| fi |
| |
| readonly GIDL="${FUCHSIA_BUILD_DIR}/tools/gidl" |
| if [ ! -x "${GIDL}" ]; then |
| echo "error: gidl missing; did you build?" 1>&2 |
| exit 1 |
| fi |
| |
| readonly \ |
| EXAMPLE_DIR="${FUCHSIA_DIR}/tools/fidl/gidl-conformance-suite" |
| |
| # TODO(FIDL-621): Support multiple .gidl sources. |
| readonly gidl_path="${EXAMPLE_DIR}/conformance.gidl" |
| |
| readonly tmpout="$( mktemp -d 2>/dev/null || mktemp -d -t 'tmpout' )" |
| trap "rm -rf ${tmpout}" EXIT |
| |
| readonly json_path="$( mktemp ${tmpout}/tmp.XXXXXXXX )" |
| fidlc_args="--json ${json_path} --files " |
| for fidl_path in "$(find "${EXAMPLE_DIR}" -name '*.fidl')"; do |
| fidlc_args="${fidlc_args} ${fidl_path}" |
| done |
| |
| ${FIDLC} ${fidlc_args} |
| |
| # Go requires the "// +build fuchsia" line to have a blank line afterwards. To |
| # enforce this with the shell's heredoc parsing rules, the heredoc below adds an |
| # extra non-blank "//" line after the blank line. |
| generated_source_header=$(cat << EOF |
| // Copyright 2019 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| // |
| // Code generated by tools/fidl/gidl-conformance-suite/regen.sh; DO NOT EDIT. |
| |
| // +build fuchsia |
| |
| // |
| EOF |
| ) |
| |
| # Go |
| ${FIDLGEN} \ |
| -generators go \ |
| -json "${json_path}" \ |
| -output-base "${tmpout}" \ |
| -include-base "${tmpout}" |
| readonly \ |
| GO_IMPL="${FUCHSIA_DIR}/third_party/go/src/syscall/zx/fidl/conformance/impl.go" |
| echo "$generated_source_header" > "${GO_IMPL}" |
| cat "${tmpout}/impl.go" >> "${GO_IMPL}" |
| ${GOFMT} -s -w "${GO_IMPL}" |
| readonly \ |
| GO_TEST_PATH="${FUCHSIA_DIR}/third_party/go/src/syscall/zx/fidl/fidl_test/conformance_test.go" |
| echo "$generated_source_header" > "${GO_TEST_PATH}" |
| ${GIDL} \ |
| -language go \ |
| -json "${json_path}" \ |
| -gidl "${gidl_path}" | ${GOFMT} >> "${GO_TEST_PATH}" |
| |
| # C++ |
| readonly \ |
| CPP_TEST_PATH="${FUCHSIA_DIR}/sdk/lib/fidl/cpp/conformance_test.cc" |
| echo "$generated_source_header" > "${CPP_TEST_PATH}" |
| ${GIDL} \ |
| -language cpp \ |
| -json "${json_path}" \ |
| -gidl "${gidl_path}" >> "${CPP_TEST_PATH}" |
| fx format-code --files="$CPP_TEST_PATH" |