blob: b64bed8ef045d7ce1f1ccc76ce6d08a8ec057d81 [file] [log] [blame]
#!/usr/bin/env bash
# TODO(pascallouis): better automate this.
set -euxo pipefail
if [[ ! -d "${FUCHSIA_DIR}" ]]; then
echo "FUCHSIA_DIR environment variable not a directory"
exit 1
pushd "$FUCHSIA_DIR"
./scripts/fx build garnet/go/src/fidl
tmpout=$(mktemp -d 2>/dev/null || mktemp -d -t 'tmpout')
trap 'rm -rf -- "${tmpout}" && popd > /dev/null' EXIT
# 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 {
local source_dir=$1
local package_dir=$1
copyright_line=$(grep -E "^// Copyright [0-9]+" "${out_file}" || \
echo "// Copyright $(date +%Y) The Fuchsia Authors. All rights reserved.")
./out/default.zircon/tools/fidlc \
--json "${ir_file}" \
$@ \
--files "${source_dir}"/*.fidl
fx fidlgen \
--json "${ir_file}" \
--generators go \
--include-base notused \
--output-base "${tmpout}"
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.
// GENERATED FILE: Do not edit!
// To rebuild this file, invoke third_party/go/regen-fidl.
// +build fuchsia
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}"
perl -pi -e 's|package socket|package net|' "${tmpfile}"
./prebuilt/third_party/go/linux-x64/bin/gofmt -s -w "${tmpfile}"
mv -- "${tmpfile}" "${out_file}"
generate_file third_party/go/src/syscall/zx/fidl/bindingstest/ fidl/bindingstest
generate_file tools/fidl/gidl-conformance-suite/ fidl/conformance
generate_file zircon/system/fidl/fuchsia-mem mem
generate_file zircon/system/fidl/fuchsia-io io \
--files zircon/system/fidl/fuchsia-mem/*.fidl
generate_file zircon/system/fidl/fuchsia-posix-socket net \
--files zircon/system/fidl/fuchsia-mem/*.fidl \
--files zircon/system/fidl/fuchsia-io/*.fidl