xref: /aosp_15_r20/external/flatbuffers/samples/dart_sample.sh (revision 890232f25432b36107d06881e0a25aaa6b473652)
1#!/bin/bash
2set -euo
3#
4# Copyright 2018 Dan Field. All rights reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18# Note: This script runs on Mac and Linux. It requires `Node.js` to be installed
19# and `flatc` to be built (using `cmake` in the root directory).
20
21sampledir=$(cd $(dirname $BASH_SOURCE) && pwd)
22rootdir=$(cd $sampledir/.. && pwd)
23currentdir=$(pwd)
24
25if [[ "$sampledir" != "$currentdir" ]]; then
26  echo Error: This script must be run from inside the $sampledir directory.
27  echo You executed it from the $currentdir directory.
28  exit 1
29fi
30
31# Run `flatc`. Note: This requires you to compile using `cmake` from the
32# root `/flatbuffers` directory.
33if [ -e ../flatc ]; then
34  ../flatc --dart -o ../dart/example/ monster.fbs
35elif [ -e ../Debug/flatc ]; then
36  ../Debug/flatc --dart -o ../dart/example/ monster.fbs
37else
38  echo 'flatc' could not be found. Make sure to build FlatBuffers from the \
39       $rootdir directory.
40  exit 1
41fi
42
43echo Running the Dart sample.
44
45# Execute the sample.
46dart ../dart/example/example.dart
47
48# Copy the source schema so it is distributed when published to pub.dev
49cp monster.fbs ../dart/example/