-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh.in
92 lines (83 loc) · 3.69 KB
/
setup.sh.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh
# BSD 3-Clause License
#
# Copyright (c) 2022, Woven Planet. All rights reserved.
# Copyright (c) 2017-2022, Toyota Research Institute. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# A function to add a new item (needle) to the passed environment variable, only
# if the new item is not already in the environment variable. The function
# expects the elements of the environment variable to be separated via ':'.
add_if_not_in_var() {
var=$1
needle=$2
# Get the current list of items in the variable using the "two-pass"
# bash trick. In the first pass (before the eval), $var (using the inner
# dollar) is expanded to the name of the environment variable. Then the
# eval is run, and the outer dollar expands to the contents of the named
# variable. Note that we have to escape the outer one so it doesn't get
# expanded by the first shell.
current=$( eval echo \$"$var" )
# Iterate over every item in the environment variable, looking to see
# if the needle is already in there. Note that we do it this way instead
# of a substring because the substring can have some false positives (think
# about the case where "foobar" is already there while trying to add
# "foo").
IFS_PREV_VAL=$IFS
if [ -z ${IFS+x} ]; then
IFS_WAS_SET=0
else
IFS_WAS_SET=1
fi
found=0
for addr in $current; do
if [ "$addr" = "$needle" ]; then
found=1
break
fi
done
# If we didn't find the needle in the list, add it here.
if [ "$found" -eq 0 ]; then
if [ "$current" = "" ]; then
export "$var"="$needle"
else
export "$var"="$( eval echo \$$var )":"$needle"
fi
fi
if [ "$IFS_WAS_SET" -eq 0 ]; then
unset IFS
else
IFS="$IFS_PREV_VAL"
fi
}
# Path to various resources used by shell/python scripts and demos
# e.g. configuration files, protos, road geometries
add_if_not_in_var DELPHYNE_RESOURCE_ROOT $COLCON_PREFIX_PATH/delphyne/share/delphyne
# Paths to resources used for rendering (see RenderWidget.hh/.cc)
# e.g. sdf/urdf/obj/dae/textures
add_if_not_in_var DELPHYNE_PACKAGE_PATH @drake_RESOURCE_ROOT@/automotive/models
# Path to descriptors of custom ignition messages (nec. for topic introspection)
add_if_not_in_var IGN_DESCRIPTOR_PATH $COLCON_PREFIX_PATH/delphyne/include/delphyne/protobuf