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