| #!/usr/bin/env bash | |
| # Copyright 2021 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. | |
| # TODO(pascallouis): better automate this. | |
| set -euxo pipefail | |
| if [ ! -x "${FUCHSIA_DIR}" ]; then | |
| echo "error: did you fx exec? missing \$FUCHSIA_DIR" 1>&2 | |
| exit 1 | |
| fi | |
| if [ ! -x "${FUCHSIA_BUILD_DIR}" ]; then | |
| echo "error: did you fx exec? missing \$FUCHSIA_BUILD_DIR" 1>&2 | |
| exit 1 | |
| fi | |
| pushd "$FUCHSIA_DIR" | |
| FIDLC=$( fx list-build-artifacts --expect-one --name fidlc tools ) | |
| FIDLGEN_GO=$( fx list-build-artifacts --expect-one --name fidlgen_go tools ) | |
| fx ninja -C "${FUCHSIA_BUILD_DIR}" $FIDLC $FIDLGEN_GO | |
| tmpout=$(mktemp -d 2>/dev/null || mktemp -d -t 'tmpout') | |
| ir_file="${tmpout}/out.json" | |
| trap 'rm -rf -- "${tmpout}" && popd > /dev/null' EXIT | |
| declare -r repo=third_party/go | |
| # Parameters: | |
| # $1 = directory where fidl file is found. | |
| # $2 = output of subdirectory of syscall/zx | |
| # $3..n = additional arguments needed to generate this target. | |
| function generate_file { | |
| declare -r source_dir=$1 | |
| shift | |
| declare -r package_dir=$1 | |
| shift | |
| declare -r file=src/syscall/zx/"${package_dir}"/impl.go | |
| declare -r out_file=$repo/$file | |
| declare -r copyright_line=$(git -C ${repo} show HEAD:"${file}" | grep -E "^// Copyright [0-9]+" || \ | |
| echo "// Copyright $(date +%Y) The Fuchsia Authors. All rights reserved.") | |
| "${FUCHSIA_BUILD_DIR}"/$FIDLC \ | |
| --json "${ir_file}" \ | |
| "$@" \ | |
| --files "${source_dir}"/*.fidl | |
| "${FUCHSIA_BUILD_DIR}"/$FIDLGEN_GO \ | |
| -json "${ir_file}" \ | |
| -output-impl "${tmpout}/impl.go" | |
| declare -r tmpfile=$(mktemp "${tmpout}/tmp.XXXXXXXX") | |
| echo "${copyright_line}" > "${tmpfile}" | |
| cat << EOF >> "${tmpfile}" | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| // | |
| // Code generated by third_party/go/regen-fidl; DO NOT EDIT. | |
| EOF | |
| cat "${tmpout}"/impl.go >> "${tmpfile}" | |
| perl -pi -e 's|^// Code generated by fidlgen; DO NOT EDIT.\n$||' "${tmpfile}" | |
| perl -pi -e 's|fidl/fuchsia/|syscall/zx/|' "${tmpfile}" | |
| ./prebuilt/third_party/go/linux-x64/bin/gofmt -s -w "${tmpfile}" | |
| mv -- "${tmpfile}" "${out_file}" | |
| } | |
| # Ensure we don't leave stale files around. | |
| find $repo -path '*src/syscall/zx/*/impl.go' -exec rm {} \; | |
| generate_file {third_party/go/src/syscall/zx/,}fidl/internal/bindingstest \ | |
| --files zircon/vdso/zx_common.fidl zircon/vdso/rights.fidl | |
| generate_file sdk/fidl/fuchsia.unknown unknown \ | |
| --files zircon/vdso/zx_common.fidl zircon/vdso/rights.fidl | |
| generate_file sdk/fidl/fuchsia.io io \ | |
| --files zircon/vdso/zx_common.fidl zircon/vdso/rights.fidl \ | |
| --files sdk/fidl/fuchsia.unknown/*.fidl | |
| generate_file sdk/fidl/fuchsia.net net | |
| generate_file sdk/fidl/fuchsia.net.name net/name \ | |
| --files zircon/vdso/zx_common.fidl zircon/vdso/rights.fidl \ | |
| --files sdk/fidl/fuchsia.net/*.fidl | |
| generate_file sdk/fidl/fuchsia.posix posix | |
| generate_file sdk/fidl/fuchsia.posix.socket posix/socket \ | |
| --files zircon/vdso/zx_common.fidl zircon/vdso/rights.fidl \ | |
| --files sdk/fidl/fuchsia.unknown/*.fidl \ | |
| --files sdk/fidl/fuchsia.net/*.fidl \ | |
| --files sdk/fidl/fuchsia.hardware.network/*.fidl \ | |
| --files sdk/fidl/fuchsia.net.interfaces/*.fidl \ | |
| --files sdk/fidl/fuchsia.posix/*.fidl | |
| generate_file sdk/fidl/fuchsia.hardware.network hardware/network \ | |
| --files zircon/vdso/zx_common.fidl zircon/vdso/rights.fidl \ | |
| --files sdk/fidl/fuchsia.net/*.fidl | |
| generate_file sdk/fidl/fuchsia.net.interfaces net/interfaces \ | |
| --files zircon/vdso/zx_common.fidl zircon/vdso/rights.fidl \ | |
| --files sdk/fidl/fuchsia.net/*.fidl \ | |
| --files sdk/fidl/fuchsia.hardware.network/*.fidl | |
| generate_file sdk/fidl/fuchsia.mem mem \ | |
| --files zircon/vdso/zx_common.fidl zircon/vdso/rights.fidl | |
| generate_file sdk/fidl/fuchsia.diagnostics diagnostics \ | |
| --files zircon/vdso/zx_common.fidl zircon/vdso/rights.fidl \ | |
| --files sdk/fidl/fuchsia.mem/*.fidl | |
| generate_file sdk/fidl/fuchsia.logger logger \ | |
| --files zircon/vdso/zx_common.fidl zircon/vdso/rights.fidl \ | |
| --files sdk/fidl/fuchsia.mem/*.fidl \ | |
| --files sdk/fidl/fuchsia.diagnostics/*.fidl |