• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3# Copyright 2015 Google Inc. All rights reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17# Note: This script runs on Mac and Linux. It requires `go` to be installed
18# and 'flatc' to be built (using `cmake` in the root directory).
19
20sampledir=$(cd $(dirname $BASH_SOURCE) && pwd)
21rootdir=$(cd $sampledir/.. && pwd)
22currentdir=$(pwd)
23
24if [[ "$sampledir" != "$currentdir" ]]; then
25  echo Error: This script must be run from inside the $sampledir directory.
26  echo You executed it from the $currentdir directory.
27  exit 1
28fi
29
30# Run `flatc`. Note: This requires you to compile using `cmake` from the
31# root `/flatbuffers` directory.
32if [ -e ../flatc ]; then
33  ../flatc --go monster.fbs
34elif [ -e ../Debug/flatc ]; then
35  ../Debug/flatc --go monster.fbs
36else
37  echo 'flatc' could not be found. Make sure to build FlatBuffers from the \
38       $rootdir directory.
39 exit 1
40fi
41
42echo Compiling and running the Go sample.
43
44# Go requires a particular layout of files in order to link the necessary
45# packages. Copy these files to the respective directores to compile the
46# sample.
47mkdir -p ${sampledir}/go_gen/src/MyGame/Sample
48mkdir -p ${sampledir}/go_gen/src/github.com/google/flatbuffers/go
49cp MyGame/Sample/*.go ${sampledir}/go_gen/src/MyGame/Sample/
50cp ${sampledir}/../go/* ${sampledir}/go_gen/src/github.com/google/flatbuffers/go
51
52# Export the `GOPATH`, so that `go` will know which directories to search for
53# the libraries.
54export GOPATH=${sampledir}/go_gen/
55
56# Compile and execute the sample.
57go build -o go_sample sample_binary.go
58./go_sample
59
60# Clean up the temporary files.
61rm -rf MyGame/
62rm -rf ${sampledir}/go_gen/
63rm go_sample
64