File: get_version.sh

package info (click to toggle)
ns3 3.29%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 126,180 kB
  • sloc: cpp: 490,768; python: 367,771; perl: 8,720; ansic: 7,158; xml: 3,842; makefile: 2,035; sh: 771
file content (216 lines) | stat: -rwxr-xr-x 6,108 bytes parent folder | download | duplicates (2)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash

# Get the current repo name and version
# to format urls appropriately via Javascript
# variables for inclusion in html files.

# Use cases:
# 1.  Hosted on nsnam.org, tagged release.
# 2.  Hosted on nsnam.org, ns-3-dev.
# 3.  User repo, modified from a tagged release (or ns-3-dev).
# 4.  User repo, at a release tag.
# 5.  User repo, at a private tag.
# 6.  Private web host, at a tag (or ns-3-dev, or local mod).
#
# For case 1 and 2, we want the links to point to the nsnam.org
# publicly hosted pages.  For all other cases, we want to point
# to the built pages in the repo itself.
#
# For robustness, we attempt to identify cases 1 & 2
# automatically.  (There is also an explicit switch '-p'
# to force us into the public case.)
#
# The approach to identify cases 1 & 2 is to test:
# a.  We're on nsnam.org (actually, nsnam-www.coe-hosted.gatech.edu), and
# b.  We're in the tmp build directory, /tmp/daily-nsnam/
#     (This is the directory used by the update-* scripts
#     run by cron jobs.)
#
# If both a and b are true, we're building for public urls.
# (The newer update-docs script (through waf) sets
# NS3_WWW_URLS=public explicitly.)
# 
# The repo version is either a tag name or a commit (short) id.
#
# If we're building for nsnam.org, and at a tag, we use just
# the tag as the repo name/version string, e.g. 'ns-3.14'.
# Otherwise, we're building for ns-3-dev, and we use, e.g,
# 'ns-3-dev @ fd0f27a10eff'.
#
# If we're *not* building for nsnam.org, we use the repo
# directory name as the repo name.  (This will typically be
# a name meaningful to the user doing the build, perhaps a
# shorthand for the feature they are working on.)  For
# example, this script was developed in a repo named
# 'docs'.  We always use the repo version, resulting
# in document version strings like 'docs @ ns-3.15' or
# 'docs @ fd0f27a10eff'
#

me=`basename $0`
function say
{
    echo "$me: $*"
}

function usage
{
    cat <<-EOF
	Usage:  $me [-p]              normal versioning
	        $me [-n] [-d] [-t]    test options
	  -p  build public urls, NS3_WWW_URLS=public is an alternative

	Testing options:
	  -n  pretend we are on nsnam.org
	  -d  pretend we are in the automated build directory
	  -t  pretend we are at a repo tag
	    
EOF
    exit 1
}

# script arguments
say
say using doxygen: $(which doxygen) $(doxygen --version)
public=0
nsnam=0
daily=0
tag=0

while getopts :pndth option ; do
    case $option in
	(p)  public=1 ;;
	(n)  nsnam=1  ;;

	(d)  daily=1  ;;

	(t)  tag=1    ;;

	(h)  usage ;;
	(:)  say "Missing argument to -$OPTARG" ; usage ;;
	(\?) say "Invalid option: -$OPTARG"     ; usage ;;
    esac
done

# Hostname, fully qualified, e.g. nsnam-www.coe-hosted.gatech.edu
HOST=`hostname`
NSNAM="nsnam-www.coe-hosted.gatech.edu"

# Build directory
DAILY="^/tmp/daily-nsnam/"

if [ $nsnam -eq 1 ]; then
    HOST=$NSNAM
    say "-n forcing HOST = $HOST"
fi

if [ $daily -eq 1 ] ; then
    OLDPWD=$PWD
    PWD=/tmp/daily-nsnam/foo
    say "-d forcing PWD = $PWD"
fi

if [ $tag -eq 1 ]; then
    version="ns-3.14"
    say "-t forcing tagged version = $version"
fi

if  ((nsnam + daily + tag > 0)) ; then
    say
fi

if [[ ($public == 1) || \
    ("${NS3_WWW_URLS:-}" == "public") || \
    ( ($HOST == $NSNAM) && ($PWD =~ $DAILY) ) ]] ; then
    PUBLIC=1
    say "building public docs for nsnam.org"
else
    PUBLIC=0
    say "building private docs"
fi

if [ $daily -eq 1 ]; then
    PWD=$OLDPWD
fi

# Destination javascript file
outf="doc/ns3_html_theme/static/ns3_version.js"

# Distance from last tag
# Zero distance means we're at the tag
distance=`hg log -r tip --template '{latesttagdistance}'`

if [ $distance -eq 1 ]; then
    version=`hg log -r tip --template '{latesttag}'`
    say "at tag $version"

elif [ $tag -eq 1 ]; then
    distance=1
    # version previously set
    vers_href=

else
    version=`hg log -r tip --template '{node|short}'`
    # Check for uncommitted changes
    hg summary | grep 'commit:' | grep -q '(clean)'
    if [ ! $? ] ; then
	say "beyond latest tag, last commit: $version, dirty"
	dirty="(+)"
    else
	say "beyond latest tag, last commit: $version, clean"
	dirty=
    fi
fi

if [ $PUBLIC -eq 1 ]; then
    echo "// ns3_version.js:  automatically generated"       >  $outf
    echo "//  public urls"                                   >> $outf
    # Generate URL relative to server root
    echo "var ns3_host = \"/\";"                             >> $outf
    
    if [ $distance -eq 1 ]; then
	# Like "http://www.nsnam.org/ns-3-14"
	vers_href="http://www.nsnam.org/ns-3-${version#ns-3.}"
	vers_href="<a href=\\\"$vers_href\\\">$version$dirty</a>"
	
	echo "var ns3_version = \"Release $vers_href\";"     >> $outf
	echo "var ns3_release = \"docs/release/${version#ns-}/\";" >> $outf
    else
	# Like "http://code.nsnam.org/ns-3-dev/rev/<hash>"
	vers_href="http://code.nsnam.org/ns-3-dev/rev/$version"
	version="<a href=\\\"$vers_href\\\">$version$dirty</a>"
	
	echo "var ns3_version = \"ns-3-dev @ $version\";"    >> $outf
	echo "var ns3_release = \"docs/\";" >> $outf
    fi
    echo "var ns3_local = \"\";"                             >> $outf
    echo "var ns3_doxy  = \"doxygen/\";"                     >> $outf
    
else
    repo=`basename $PWD`
    echo "// ns3_version.js:  automatically generated"       >  $outf
    echo "//  private urls"                                  >> $outf
    echo "var ns3_host = \"file://$PWD/\";"                  >  $outf
    echo "var ns3_version = \"$repo @ $version$dirty\";"     >> $outf
    echo "var ns3_release = \"doc/\";"                       >> $outf
    echo "var ns3_local = \"build/\";"                       >> $outf
    echo "var ns3_doxy  = \"html/\";"                        >> $outf
fi

# Copy to html directories
# This seems not always done automatically
# by Sphinx when rebuilding
cd doc 2>&1 >/dev/null
for d in {manual,models,tutorial{,-pt-br}}/build/{single,}html/_static/ ; do
    if [ ! -d $d ]; then
	mkdir -p $d
    fi
    cp ns3_html_theme/static/ns3_version.js $d
done
cd - 2>&1 >/dev/null

# Show what was done
say
say "outf = $outf:"
cat -n $outf
say Done.