blob: bce7d895cc2b8bf884fda0d465f9a583e0a13942 [file] [log] [blame]
#!/usr/bin/env bash
set -euxo pipefail
if [[ ! -d "${FUCHSIA_BUILD_DIR}" ]]; then
echo "FUCHSIA_DIR environment variable not a directory"
exit 1
fi
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
FIDLC="${FUCHSIA_BUILD_DIR}/host_x64/fidlc"
if [ ! -x "${FIDLC}" ]; then
echo "error: fidlc missing; did you build?" 1>&2
exit 1
fi
FIDLGEN="${FUCHSIA_BUILD_DIR}/host_x64/fidlgen"
if [ ! -x "${FIDLGEN}" ]; then
echo "error: fidlgen missing; did you build?" 1>&2
exit 1
fi
GIDL="${FUCHSIA_BUILD_DIR}/tools/gidl"
if [ ! -x "${GIDL}" ]; then
echo "error: gidl missing; did you build?" 1>&2
exit 1
fi
EXAMPLE_DIR="${FUCHSIA_DIR}/tools/fidl/gidl-conformance-suite"
GO_LIB_DIR="${FUCHSIA_DIR}/third_party/go/src/syscall/zx/fidl/conformance"
GO_TEST_DIR="${FUCHSIA_DIR}/third_party/go/src/syscall/zx/fidl/fidl_test"
# TODO(FIDL-621): Support multiple .gidl sources.
gidl_path="${EXAMPLE_DIR}/conformance.gidl"
tmpout=$( mktemp -d 2>/dev/null || mktemp -d -t 'tmpout' )
trap "rm -rf ${tmpout}" EXIT
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}
${FIDLGEN} \
--generators go \
--json "${json_path}" \
--output-base "${tmpout}" \
--include-base "${tmpout}"
cat << EOF > "${GO_LIB_DIR}/impl.go"
// 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
cat "${tmpout}/impl.go" >> "${GO_LIB_DIR}/impl.go"
${GOFMT} -s -w "${GO_LIB_DIR}/impl.go"
cat << EOF > "${GO_TEST_DIR}/conformance_test.go"
// 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
${GIDL} \
--json "${json_path}" \
--gidl "${gidl_path}" | ${GOFMT} >> "${GO_TEST_DIR}/conformance_test.go"