blob: d8724f3cfc19559e5aa4b54150110a9e652223ef [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
fi
pushd $FUCHSIA_DIR
./scripts/fx build garnet/go/src/fidl
tmpout=$(mktemp -d 2>/dev/null || mktemp -d -t 'tmpout')
ir_file="${tmpout}/out.json"
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 fidl dependencies needed to generate this target.
function generate_file {
local source_dir=$1
shift
local package_dir=$1
shift
local additional_files=""
while (( "$#" )); do
additional_files+="--files $1"
shift
done
out_file=third_party/go/src/syscall/zx/"${package_dir}"/impl.go
copyright_line=$(grep -E "^// Copyright [0-9]+" "${out_file}" || \
echo "// Copyright $(date +%Y) The Fuchsia Authors. All rights reserved.")
./out/x64/host_x64/fidlc \
--json "${ir_file}" \
${additional_files} \
--files "${source_dir}"/*.fidl
./out/x64/host_x64/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
EOF
cat "${tmpout}"/impl.go >> "${tmpfile}"
perl -pi -e 's|^// WARNING: This file is machine generated by fidlgen.\n$||' "${tmpfile}"
perl -pi -e 's|fidl/fuchsia/mem|syscall/zx/mem|' "${tmpfile}"
./out/x64/tools/goroot/bin/gofmt -s -w "${tmpfile}"
mv -- "${tmpfile}" "${out_file}"
}
generate_file third_party/go/src/syscall/zx/fidl/bindingstest/ fidl/bindingstest
generate_file zircon/system/fidl/fuchsia-net net
generate_file zircon/system/fidl/fuchsia-mem mem
generate_file zircon/system/fidl/fuchsia-io io \
zircon/system/fidl/fuchsia-mem/*.fidl