File: build_backports.sh

package info (click to toggle)
chromium-browser 41.0.2272.118-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,189,132 kB
  • sloc: cpp: 9,691,462; ansic: 3,341,451; python: 712,689; asm: 518,779; xml: 208,926; java: 169,820; sh: 119,353; perl: 68,907; makefile: 28,311; yacc: 13,305; objc: 11,385; tcl: 3,186; cs: 2,225; sql: 2,217; lex: 2,215; lisp: 1,349; pascal: 1,256; awk: 407; ruby: 155; sed: 53; php: 14; exp: 11
file content (587 lines) | stat: -rwxr-xr-x 26,758 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
#!/bin/bash
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Script assumed to be run in native_client/
if [[ "x${OSTYPE}" = "xcygwin" ]]; then
  cd "$(cygpath "${PWD}")"
fi
if [[ ${PWD} != */native_client ]]; then
  echo "ERROR: must be run in native_client!"
  exit 1
fi

if [[ $# -ne 3 ]]; then
  echo "USAGE: $0 version_file win/mac/linux glibc/newlib"
  exit 2
fi

if [[ "${0:0:1}" = "/" ]]; then
  declare -r scriptname="$0"
else
  declare -r scriptname="$PWD/$0"
fi

cd tools/BACKPORTS

if [[ "$((sha1sum "$scriptname" "$1" || shasum "$scriptname" "$1") 2>/dev/null)" = "$(cat "$1.lastver")" ]]; then
  # Everything is already done
  exit 0
fi

set -x
set -e
set -u

declare -r GIT_BASE_URL=http://git.chromium.org/native_client

rm -f "$$.error"

# Checkout toolchain sources from git repo.  We'll need them later when we'll
# patch sources toolchain before calling build script.
for dirname in binutils gcc gdb glibc linux-headers-for-nacl newlib ; do
  repo="${dirname}"
  if [[ "$repo" != "linux-headers-for-nacl" ]]; then
    repo="nacl-${repo}"
  fi
  if [[ -d "$dirname" ]]; then (
    cd "$dirname"
    git pull --all ||
    (cd .. &&
     rm -rf "$dirname")
  ) fi
  if [[ ! -d "$dirname" ]]; then (
    git clone "${GIT_BASE_URL}/${repo}.git" "$dirname"
  ) fi || touch $$.error &
done

wait

# If we were unable to checkout some sources then it's time to stop.
if [[ -e "$$.error" ]]; then
  rm -f "$$.error"
  # Errors are reported by git above already
  exit 1
fi

# Here we'll checkout correct versions of all the sources for all supported
# ppapi versions.
while read name id comment ; do
  case "$name" in
    binutils | gcc | glibc | newlib | '' | \#*)
      # Skip this line
      ;;
    *)
      if [[ "$((sha1sum "$scriptname" "$1" || shasum "$scriptname" "$1") 2>/dev/null)" = "$(cat "$1.$name.lastver")" ]]; then
	# Everything is already done
	continue
      fi
      # First step is to use glient to sync sources.
      if [[ -d "$name" ]]; then
	cd "$name"
	if [[ "$2" = "win" ]]; then
	  # "gclient.bat revert" automatically calls "runhooks"… ⇒ it fails…
	  # "gclient runhooks" downloads toolchain then calls gyp… ⇒ it fails…
	  # "glient.bat runhooks" sees toolchain and simply calls gyp ⇒ success!
	  # Additional fun: error codes are lost somewhere in gclient.bat…
	  ( gclient.bat revert || true
	    gclient runhooks --force || true
	    gclient.bat runhooks --force || true
	  ) < /dev/null
	else
	  gclient revert < /dev/null
	fi
      else
	mkdir "$name"
	cd "$name"
	if [[ "$name" == ppapi17 ]]; then
	  cat >.gclient <<-END
	solutions = [
	  { "name"        : "native_client",
	    "url"         : "http://src.chromium.org/native_client/trunk/src/native_client@$id",
	    "deps_file"   : "DEPS",
	    "managed"     : True,
	    "custom_deps" : {
	      "third_party/jsoncpp/source/include": "http://svn.code.sf.net/p/jsoncpp/code/trunk/jsoncpp/include@246",
	      "third_party/jsoncpp/source/src/lib_json": "http://svn.code.sf.net/p/jsoncpp/code/trunk/jsoncpp/src/lib_json@246",
	    },
	    "safesync_url": "",
	  },
	]
	END
	elif [[ "$name" == ppapi1[89] ]] || [[ "$name" == ppapi2[0-6] ]]; then
	  cat >.gclient <<-END
	solutions = [
	  { "name"        : "native_client",
	    "url"         : "http://src.chromium.org/native_client/trunk/src/native_client@$id",
	    "deps_file"   : "DEPS",
	    "managed"     : True,
	    "custom_deps" : {
	      "third_party/jsoncpp/source/include": "http://svn.code.sf.net/p/jsoncpp/code/trunk/jsoncpp/include@248",
	      "third_party/jsoncpp/source/src/lib_json": "http://svn.code.sf.net/p/jsoncpp/code/trunk/jsoncpp/src/lib_json@248",
	    },
	    "safesync_url": "",
	  },
	]
	END
	else
	  cat >.gclient <<-END
	solutions = [
	  { "name"        : "native_client",
	    "url"         : "http://src.chromium.org/native_client/trunk/src/native_client@$id",
	    "deps_file"   : "DEPS",
	    "managed"     : True,
	    "custom_deps" : {
	    },
	    "safesync_url": "",
	  },
	]
	END
	fi
	if [[ "$2" = "win" ]]; then
	  # "gclient.bat revert" automatically calls "runhooks"… ⇒ it fails…
	  # "gclient runhooks" downloads toolchain then calls gyp… ⇒ it fails…
	  # "glient.bat runhooks" sees toolchain and simply calls gyp ⇒ success!
	  # Additional fun: error codes are lost somewhere in gclient.bat…
	  ( gclient.bat sync || true
	    gclient runhooks --force || true
	    gclient.bat runhooks --force || true
	  ) < /dev/null
	else
	  gclient sync < /dev/null
	fi
      fi
      # Now we need to change versions to officialy mark binaries.  We don't
      # show git revision because we combine different branches here.
      patch -p0 <<-END
	--- native_client/buildbot/buildbot_standard.py
	+++ native_client/buildbot/buildbot_standard.py
	@@ -148 +148,2 @@
	-  with Step('cleanup_temp', status):
	+  if False:
	+   with Step('cleanup_temp', status):
	--- native_client/tools/glibc_download.sh
	+++ native_client/tools/glibc_download.sh
	@@ -42 +42 @@
	-  for ((j=glibc_revision+1;j<glibc_revision+revisions_count;j++)); do
	+  for ((j=\${glibc_revision%~*}+1;j<\${glibc_revision%~*}+revisions_count;j++)); do
	--- native_client/tools/glibc_revision.sh
	+++ native_client/tools/glibc_revision.sh
	@@ -13 +13 @@
	-for i in REVISIONS glibc_revision.sh Makefile ; do
	+for i in ../../../VERSIONS ../../../build_backports.sh REVISIONS glibc_revision.sh Makefile ; do
	@@ -20 +20 @@
	-echo "\$REVISION"
	+echo "\$REVISION~$name"
	END
      if [[ "$name" = ppapi1? ]] || [[ "$name" = ppapi2[0-6] ]]; then
	patch -p0 <<-END
	--- native_client/tools/Makefile
	+++ native_client/tools/Makefile
	@@ -202,2 +202,4 @@
	-  CFLAGS="-m\$(HOST_TOOLCHAIN_BITS) \$(CFLAGS)" \\
	-  CXXFLAGS="-m\$(HOST_TOOLCHAIN_BITS) \$(CXXFLAGS)" \\
	+  CC="\$(GCC_CC)" \\
	+  CXX="\$(GCC_CXX)" \\
	+  CFLAGS="\$(CFLAGS)" \\
	+  CXXFLAGS="\$(CXXFLAGS)" \\
	@@ -363 +365,7 @@
	+ifeq (\$(PLATFORM), mac)
	+GCC_CC = clang -m\$(HOST_TOOLCHAIN_BITS) -fgnu89-inline
	+GCC_CXX = clang++ -m\$(HOST_TOOLCHAIN_BITS)
	+else
	 GCC_CC = gcc -m\$(HOST_TOOLCHAIN_BITS)
	+GCC_CXX = g++ -m\$(HOST_TOOLCHAIN_BITS)
	+endif
	END
      fi
      if [[ "$name" = ppapi1? ]] || [[ "$name" = ppapi2[0-7] ]]; then
	patch -p0 <<-END
	--- native_client/tools/glibc_download.sh
	+++ native_client/tools/glibc_download.sh
	@@ -20 +20 @@
	-declare -r glibc_url_prefix=http://gsdview.appspot.com/nativeclient-archive2/between_builders/x86_glibc/r
	+declare -r glibc_url_prefix=http://storage.googleapis.com/nativeclient-archive2/between_builders/x86_glibc/r
	END
      fi
      declare rev="$(native_client/tools/glibc_revision.sh)"
      if [[ "$name" = ppapi14 ]]; then
	patch -p0 <<-END
	--- native_client/tools/Makefile
	+++ native_client/tools/Makefile
	@@ -237 +237 @@
	-	sed -e s'|cloog_LDADD = \$(LDADD)|cloog_LDADD = \$(LDADD) -lstdc++ -lm |' \\
	+	sed -e s'|LIBS = @LIBS@|LIBS = @LIBS@ -lstdc++ -lm |' \\
	@@ -315,2 +315,2 @@
	-	  CC="gcc" \\
	-	  CFLAGS="-m\$(HOST_TOOLCHAIN_BITS) -O2 \$(CFLAGS)" \\
	+	  CC="\$(GCC_CC)" \\
	+	  CFLAGS="\$(CFLAGS)" \\
	@@ -847 +847 @@
	-	+#define BFD_VERSION_STRING  @bfd_version_package@ @bfd_version_string@ \\" \`LC_ALL=C svn info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1-\\2-\\3+'\` (Native Client r\`LC_ALL=C svnversion\`, Git Commit \`cd SRC/binutils ; LC_ALL=C git rev-parse HEAD\`)\\"\\n" |\\
	+	+#define BFD_VERSION_STRING  @bfd_version_package@ @bfd_version_string@ \\" \`cd ../../.. ; LC_ALL=C svn info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1-\\2-\\3+'\` (Native Client r$rev)\\"\\n" |\\
	@@ -849,2 +849,3 @@
	-	LC_ALL=C svn info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1-\\2-\\3+' > SRC/gcc/gcc/DATESTAMP
	-	echo "Native Client r\`LC_ALL=C svnversion\`, Git Commit \`cd SRC/gcc ; LC_ALL=C git rev-parse HEAD\`" > SRC/gcc/gcc/DEV-PHASE
	+	( cd ../../.. ; LC_ALL=C svn info ) | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1-\\2-\\3+' > SRC/gcc/gcc/DATESTAMP
	+	echo "Native Client r$rev" > SRC/gcc/gcc/DEV-PHASE
	+	cp -aiv SRC/gdb/gdb/version.in SRC/gdb/gdb/version.inT
	@@ -854 +855 @@
	-	+\`cat SRC/gdb/gdb/version.in\` \`LC_ALL=C svn info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1-\\2-\\3+'\` (Native Client r\`LC_ALL=C svnversion\`, Git Commit \`cd SRC/gdb ; LC_ALL=C git rev-parse HEAD\`)\\n" |\\
	+	+\`cat SRC/gdb/gdb/version.in\` \`cd ../../.. ; LC_ALL=C svn info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1-\\2-\\3+'\` (Native Client r$rev)\\n" |\\
	END
      elif [[ "$name" = ppapi15 ]]; then
	patch -p0 <<-END
	--- native_client/tools/Makefile
	+++ native_client/tools/Makefile
	@@ -237 +237 @@
	-	sed -e s'|cloog_LDADD = \$(LDADD)|cloog_LDADD = \$(LDADD) -lstdc++ -lm |' \\
	+	sed -e s'|LIBS = @LIBS@|LIBS = @LIBS@ -lstdc++ -lm |' \\
	@@ -315,2 +315,2 @@
	-	  CC="gcc" \\
	-	  CFLAGS="-m\$(HOST_TOOLCHAIN_BITS) -O2 \$(CFLAGS)" \\
	+	  CC="\$(GCC_CC)" \\
	+	  CFLAGS="\$(CFLAGS)" \\
	@@ -847 +847 @@
	-	+#define BFD_VERSION_STRING  @bfd_version_package@ @bfd_version_string@ \\" \`LC_ALL=C svn info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+'\` (Native Client r\`LC_ALL=C svnversion\`, Git Commit \`cd SRC/binutils ; LC_ALL=C git rev-parse HEAD\`)\\"\\n" |\\
	+	+#define BFD_VERSION_STRING  @bfd_version_package@ @bfd_version_string@ \\" \`cd ../../.. ; LC_ALL=C svn info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+'\` (Native Client r$rev)\\"\\n" |\\
	@@ -849,2 +849,3 @@
	-	LC_ALL=C svn info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+' > SRC/gcc/gcc/DATESTAMP
	-	echo "Native Client r\`LC_ALL=C svnversion\`, Git Commit \`cd SRC/gcc ; LC_ALL=C git rev-parse HEAD\`" > SRC/gcc/gcc/DEV-PHASE
	+	( cd ../../.. ; LC_ALL=C svn info ) | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+' > SRC/gcc/gcc/DATESTAMP
	+	echo "Native Client r$rev" > SRC/gcc/gcc/DEV-PHASE
	+	cp -aiv SRC/gdb/gdb/version.in SRC/gdb/gdb/version.inT
	@@ -854 +855 @@
	-	+\`cat SRC/gdb/gdb/version.in\` \`LC_ALL=C svn info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+'\` (Native Client r\`LC_ALL=C svnversion\`, Git Commit \`cd SRC/gdb ; LC_ALL=C git rev-parse HEAD\`)\\n" |\\
	+	+\`cat SRC/gdb/gdb/version.in\` \`cd ../../.. LC_ALL=C svn info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+'\` (Native Client r$rev)\\n" |\\
	END
      elif [[ "$name" = ppapi1? ]] || [[ "$name" = ppapi2[01] ]]; then
	patch -p0 <<-END
	--- native_client/tools/Makefile
	+++ native_client/tools/Makefile
	@@ -700,5 +700,5 @@
	-BINUTILS_PATCHNAME := naclbinutils-\$(BINUTILS_VERSION)-r\$(shell svnversion | tr : _)
	-GCC_PATCHNAME := naclgcc-\$(GCC_VERSION)-r\$(shell svnversion | tr : _)
	-#GDB_PATCHNAME := naclgdb-\$(GDB_VERSION)-r\$(shell svnversion | tr : _)
	-GLIBC_PATCHNAME := naclglibc-\$(GLIBC_VERSION)-r\$(shell svnversion | tr : _)
	-NEWLIB_PATCHNAME := naclnewlib-\$(NEWLIB_VERSION)-r\$(shell svnversion | tr : _)
	+BINUTILS_PATCHNAME := naclbinutils-\$(BINUTILS_VERSION)-r\$(shell ./glibc_revision.sh)
	+GCC_PATCHNAME := naclgcc-\$(GCC_VERSION)-r\$(shell ./glibc_revision.sh)
	+#GDB_PATCHNAME := naclgdb-\$(GDB_VERSION)-r\$(shell ./glibc_revision.sh)
	+GLIBC_PATCHNAME := naclglibc-\$(GLIBC_VERSION)-r\$(shell ./glibc_revision.sh)
	+NEWLIB_PATCHNAME := naclnewlib-\$(NEWLIB_VERSION)-r\$(shell ./glibc_revision.sh)
	@@ -847 +847 @@
	-	+#define BFD_VERSION_STRING  @bfd_version_package@ @bfd_version_string@ \\" \`LC_ALL=C svn info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+'\` (Native Client r\`LC_ALL=C svnversion\`, Git Commit \`cd SRC/binutils ; LC_ALL=C git rev-parse HEAD\`)\\"\\n" |\\
	+	+#define BFD_VERSION_STRING  @bfd_version_package@ @bfd_version_string@ \\" \`cd ../../.. ; LC_ALL=C svn info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+'\` (Native Client r$rev)\\"\\n" |\\
	@@ -849,2 +849,3 @@
	-	LC_ALL=C svn info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+' > SRC/gcc/gcc/DATESTAMP
	-	echo "Native Client r\`LC_ALL=C svnversion\`, Git Commit \`cd SRC/gcc ; LC_ALL=C git rev-parse HEAD\`" > SRC/gcc/gcc/DEV-PHASE
	+	( cd ../../.. ; LC_ALL=C svn info ) | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+' > SRC/gcc/gcc/DATESTAMP
	+	echo "Native Client r$rev" > SRC/gcc/gcc/DEV-PHASE
	+	cp -aiv SRC/gdb/gdb/version.in SRC/gdb/gdb/version.inT
	@@ -854 +855 @@
	-	+\`cat SRC/gdb/gdb/version.in\` \`LC_ALL=C svn info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+'\` (Native Client r\`LC_ALL=C svnversion\`, Git Commit \`cd SRC/gdb ; LC_ALL=C git rev-parse HEAD\`)\\n" |\\
	+	+\`cat SRC/gdb/gdb/version.in\` \`cd ../../.. LC_ALL=C svn info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+'\` (Native Client r$rev)\\n" |\\
	END
      else
	patch -p0 <<-END
	--- native_client/tools/Makefile
	+++ native_client/tools/Makefile
	@@ -700,5 +700,5 @@
	-BINUTILS_PATCHNAME := naclbinutils-\$(BINUTILS_VERSION)-r\$(shell \$(SVNVERSION) | tr : _)
	-GCC_PATCHNAME := naclgcc-\$(GCC_VERSION)-r\$(shell \$(SVNVERSION) | tr : _)
	-#GDB_PATCHNAME := naclgdb-\$(GDB_VERSION)-r\$(shell \$(SVNVERSION) | tr : _)
	-GLIBC_PATCHNAME := naclglibc-\$(GLIBC_VERSION)-r\$(shell \$(SVNVERSION) | tr : _)
	-NEWLIB_PATCHNAME := naclnewlib-\$(NEWLIB_VERSION)-r\$(shell \$(SVNVERSION) | tr : _)
	+BINUTILS_PATCHNAME := naclbinutils-\$(BINUTILS_VERSION)-r\$(shell ./glibc_revision.sh)
	+GCC_PATCHNAME := naclgcc-\$(GCC_VERSION)-r\$(shell ./glibc_revision.sh)
	+#GDB_PATCHNAME := naclgdb-\$(GDB_VERSION)-r\$(shell ./glibc_revision.sh)
	+GLIBC_PATCHNAME := naclglibc-\$(GLIBC_VERSION)-r\$(shell ./glibc_revision.sh)
	+NEWLIB_PATCHNAME := naclnewlib-\$(NEWLIB_VERSION)-r\$(shell ./glibc_revision.sh)
	@@ -847 +847 @@
	-	+#define BFD_VERSION_STRING  @bfd_version_package@ @bfd_version_string@ \\" \`LC_ALL=C \$(SVN) info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+'\` (Native Client r\`LC_ALL=C \$(SVNVERSION)\`, Git Commit \`cd SRC/binutils ; LC_ALL=C git rev-parse HEAD\`)\\"\\n" |\\
	+	+#define BFD_VERSION_STRING  @bfd_version_package@ @bfd_version_string@ \\" \`cd ../../.. ; LC_ALL=C \$(SVN) info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+'\` (Native Client r$rev)\\"\\n" |\\
	@@ -849,2 +849,3 @@
	-	LC_ALL=C \$(SVN) info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+' > SRC/gcc/gcc/DATESTAMP
	-	echo "Native Client r\`LC_ALL=C \$(SVNVERSION)\`, Git Commit \`cd SRC/gcc ; LC_ALL=C git rev-parse HEAD\`" > SRC/gcc/gcc/DEV-PHASE
	+	( cd ../../.. ; LC_ALL=C \$(SVN) info ) | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+' > SRC/gcc/gcc/DATESTAMP
	+	echo "Native Client r$rev" > SRC/gcc/gcc/DEV-PHASE
	+	cp -aiv SRC/gdb/gdb/version.in SRC/gdb/gdb/version.inT
	@@ -854 +855 @@
	-	+\`cat SRC/gdb/gdb/version.in\` \`LC_ALL=C \$(SVN) info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+'\` (Native Client r\`LC_ALL=C \$(SVNVERSION)\`, Git Commit \`cd SRC/gdb ; LC_ALL=C git rev-parse HEAD\`)\\n" |\\
	+	+\`cat SRC/gdb/gdb/version.in\` \`cd ../../.. LC_ALL=C \$(SVN) info | grep 'Last Changed Date' | sed -e s'+Last Changed Date: \\(....\\)-\\(..\\)-\\(..\\).*+\\1\\2\\3+'\` (Native Client r$rev)\\n" |\\
	END
      fi
      # The buildbot has become strict in enforcing tag names.
      # We used to emit STEP_SUCCESS, but it never got added to the annotator.
      # Dropping the tag in old versions.
      if [[ "$name" = ppapi1[0-9] ]] || [[ "$name" = ppapi2[0-9] ]] || \
         [[ "$name" = ppapi30 ]]; then
          patch -p0 <<-END
	--- native_client/buildbot/buildbot_lib.py
	+++ native_client/buildbot/buildbot_lib.py
	@@ -378,7 +378,6 @@ class Step(object):
	         raise StopBuild()
	     else:
	       self.status.ReportPass(self.name)
	-      print '@@@STEP_SUCCESS@@@'

	     # Suppress any exception that occurred.
	     return True
	END
      fi
      if [[ "$name" = ppapi19 ]] || [[ "$name" = ppapi20 ]]; then
	  patch -p0 <<-END
	--- native_client/tools/Makefile
	+++ native_client/tools/Makefile
	@@ -154,2 +154,2 @@
	-NEWLIB_VERSION = 1.18.0
	-NACL_NEWLIB_GIT_BASE = 65e6baefeb2874011001c2f843cf3083e771b62f
	+NEWLIB_VERSION = 1.20.0
	+NACL_NEWLIB_GIT_BASE = 151b2c72fb87849bbc6e3ef569718c6344eed2e6
	END
      fi
      patch -p0 <<-END
	--- native_client/buildbot/buildbot_lucid64-glibc-makefile.sh
	+++ native_client/buildbot/buildbot_lucid64-glibc-makefile.sh
	@@ -27 +27 @@
	-rm -rf scons-out tools/SRC/* tools/BUILD/* tools/out tools/toolchain \\
	+rm -rf scons-out tools/BUILD/* tools/out tools/toolchain \\
	--- native_client/buildbot/buildbot_lucid64-glibc-makefile.sh
	+++ native_client/buildbot/buildbot_lucid64-glibc-makefile.sh
	@@ -90 +90 @@
	-    make glibc-check
	+    true make glibc-check
	--- native_client/buildbot/buildbot_lucid64-glibc-makefile.sh
	+++ native_client/buildbot/buildbot_lucid64-glibc-makefile.sh
	@@ -109 +109 @@
	-  rev="\$(tools/glibc_revision.sh)"
	+  rev="$rev"
	--- native_client/buildbot/buildbot_lucid64-glibc-makefile.sh
	+++ native_client/buildbot/buildbot_lucid64-glibc-makefile.sh
	@@ -164 +164 @@
	-    make glibc-check
	+    true make glibc-check
	--- native_client/buildbot/buildbot_mac-glibc-makefile.sh
	+++ native_client/buildbot/buildbot_mac-glibc-makefile.sh
	@@ -28 +28 @@
	-rm -rf scons-out tools/SRC/* tools/BUILD/* tools/out/* tools/toolchain \\
	+rm -rf scons-out tools/BUILD/* tools/out/* tools/toolchain \\
	--- native_client/buildbot/buildbot_windows-glibc-makefile.sh
	+++ native_client/buildbot/buildbot_windows-glibc-makefile.sh
	@@ -40 +40 @@
	-rm -rf scons-out tools/SRC/* tools/BUILD/* tools/out tools/toolchain \\
	+rm -rf scons-out tools/BUILD/* tools/out tools/toolchain \\
	--- native_client/buildbot/gsutil.sh
	+++ native_client/buildbot/gsutil.sh
	@@ -29 +29 @@
	-  gsutil="\${SCRIPT_DIR_ABS}/../../../../../scripts/slave/gsutil.bat"
	+  gsutil="\${SCRIPT_DIR_ABS}/../../../../../../../../../scripts/slave/gsutil.bat"
	END
      mv native_client/buildbot/buildbot_windows-glibc-makefile.bat \
	native_client/buildbot/buildbot_windows-glibc-makefile.bat.orig
      sed -e s'/  ..\\..\\..\\..\\scripts\\slave\\gsutil/  ..\\..\\..\\..\\..\\..\\..\\..\\scripts\\slave\\gsutil/' \
	< native_client/buildbot/buildbot_windows-glibc-makefile.bat.orig \
	> native_client/buildbot/buildbot_windows-glibc-makefile.bat
      rm native_client/buildbot/buildbot_windows-glibc-makefile.bat.orig
      if [[ "$name" = ppapi14 ]]; then
	patch -p0 <<-END
	--- native_client/buildbot/buildbot_toolchain.sh
	+++ native_client/buildbot/buildbot_toolchain.sh
	@@ -36 +36 @@
	-rm -rf ../scons-out sdk-out sdk ../toolchain SRC/* BUILD/*
	+rm -rf ../scons-out sdk-out sdk ../toolchain BUILD/*
	@@ -61 +61 @@
	-      \${GS_BASE}/latest/naclsdk_\${PLATFORM}_x86.tgz
	+      \${GS_BASE}/latest~"$name"/naclsdk_\${PLATFORM}_x86.tgz
	END
      elif [[ "$name" = ppapi1[5-7] ]]; then
	patch -p0 <<-END
	--- native_client/buildbot/buildbot_toolchain.sh
	+++ native_client/buildbot/buildbot_toolchain.sh
	@@ -36 +36 @@
	-rm -rf ../scons-out sdk-out sdk ../toolchain SRC/* BUILD/*
	+rm -rf ../scons-out sdk-out sdk ../toolchain BUILD/*
	@@ -69 +69 @@
	-    for destrevision in \${BUILDBOT_GOT_REVISION} latest ; do
	+    for destrevision in \${BUILDBOT_GOT_REVISION} latest~"$name" ; do
	@@ -73 +73 @@
	-          \${GS_BASE}/\${destrevision}/naclsdk_\${PLATFORM}_x86.\${suffix}
	+          \${GS_BASE}/"\${destrevision}"/naclsdk_\${PLATFORM}_x86.\${suffix}
	END
      else
	patch -p0 <<-END
	--- native_client/buildbot/buildbot_toolchain.sh
	+++ native_client/buildbot/buildbot_toolchain.sh
	@@ -36 +36 @@
	-rm -rf ../scons-out sdk-out sdk ../toolchain/*_newlib SRC/* BUILD/*
	+rm -rf ../scons-out sdk-out sdk ../toolchain/*_newlib BUILD/*
	@@ -69 +69 @@
	-    for destrevision in \${BUILDBOT_GOT_REVISION} latest ; do
	+    for destrevision in \${BUILDBOT_GOT_REVISION} latest~"$name" ; do
	@@ -73 +73 @@
	-          \${GS_BASE}/\${destrevision}/naclsdk_\${PLATFORM}_x86.\${suffix}
	+          \${GS_BASE}/"\${destrevision}"/naclsdk_\${PLATFORM}_x86.\${suffix}
	END
      fi
      # Patch sources and build the toolchains.
      if [[ "$name" != "ppapi14" ]] || [[ "$3" != glibc ]]; then
	make -C native_client/tools clean
	rm -rf native_client/tools/SRC/*
	for i in binutils gcc gdb glibc linux-headers-for-nacl newlib ; do (
	  if [[ "$name" != "ppapi14" ]] || [[ "$i" != glibc ]]; then
	    rm -rf native_client/tools/SRC/"$i"
	    git clone ../"$i" native_client/tools/SRC/"$i"
	    cd native_client/tools/SRC/"$i"
	    . ../../REVISIONS
	    declare varname="NACL_$(echo "$i" | LC_ALL=C tr a-z A-Z)_COMMIT"
	    if [[ "$varname" = "NACL_LINUX-HEADERS-FOR-NACL_COMMIT" ]]; then
	      . ../../../../../../REVISIONS
	      git checkout "$LINUX_HEADERS_FOR_NACL_COMMIT"
	    else
	      git checkout "${!varname}"
	    fi
	    cd ../../../../..
	    ( while read n id comment && [[ "$n" != "$name" ]]; do
		: # Nothing
	      done
	      cd "$name/native_client/tools/SRC/$i"
	      while read tag id comment ; do
		if [[ "$i" = "$tag" ]]; then
		  if [[ "$name" = ppapi1[4-8] ]] && [[ "$i" = "newlib" ]] &&
		     [[ "$id" = "4353bc00936874bb78aa3ba21c648b4f4c3f946b" ]]; then
		    # Ignore error
		    git diff "$id"{^..,} | patch -p1 ||
		    ( rejfiles="$(find -name '*.rej')"
		      if [[ "$rejfiles" != "./newlib/libc/include/machine/setjmp.h.rej" ]]; then
			touch "../../../../../$$.error" "../../../../../$$.error.$name"
		      else
			rm ./newlib/libc/include/machine/setjmp.h.rej
		      fi
		    )
		  elif [[ "$name" = ppapi1[4-7] ]] &&
		       [[ "$id" = "f96a3cbfb8777e1e47471b357929b8a1e3340a23" ]]; then
		    patch -p0 <<-END
			--- gcc/config/i386/nacl.h
			+++ gcc/config/i386/nacl.h
			@@ -269,3 +269,6 @@
			 #define DWARF2_ADDR_SIZE \\
			     (TARGET_NACL ? (TARGET_64BIT ? 8 : 4) : \\
			                    (POINTER_SIZE / BITS_PER_UNIT))
			+
			+/* Profile counters are not available under Native Client. */
			+#define NO_PROFILE_COUNTERS 1
			END
		  elif [[ "$name" = ppapi1[5-9] || "$name" == ppapi2[0-7] ]] &&
		       [[ "$id" = "2324fd9e11f551e367cbe714ff49a4df3309396e" ]]; then
		    for ldscript in elf{,64}_nacl.x{,.static,s}; do
		      patch -p0 <<-END
			--- nacl/dyn-link/ldscripts/$ldscript
			+++ nacl/dyn-link/ldscripts/$ldscript
			@@ -50 +50,6 @@
			-  .note.gnu.build-id : { *(.note.gnu.build-id) } :seg_rodata
			+  .note.gnu.build-id :
			+  {
			+    PROVIDE_HIDDEN (__note_gnu_build_id_start = .);
			+    *(.note.gnu.build-id)
			+    PROVIDE_HIDDEN (__note_gnu_build_id_end = .);
			+  } :seg_rodata
			END
		    done
		  elif [[ "$name" != ppapi1[5-8] ]] ||
		       [[ "$id" != "8ec02f0e5af28bd478ce262f04d156e4ef09c4d9" ]]; then
		    git diff "$id"{^..,} | patch -p1 ||
		      touch "../../../../../$$.error" "../../../../../$$.error.$name"
		  fi
		fi
	      done
	    ) < "$1"
	  fi
	) done
	if [[ "$name" == ppapi1[45] ]]; then
	  patch -p0 <<-END
	--- native_client/tools/Makefile
	+++ native_client/tools/Makefile
	@@ -747,6 +747,7 @@
	 	  CC="\$\${CC}" \\
	 	  LDFLAGS="-s" \\
	 	  ../../SRC/gdb/configure \\
	+	    --disable-werror \\
	 	    --prefix=\$(SDKROOT) \\
	 	    \$\${BUILD} \\
	 	    --target=nacl
	END
	elif [[ "$name" == ppapi1[6-9] ]]; then
	  patch -p0 <<-END
	--- native_client/tools/Makefile
	+++ native_client/tools/Makefile
	@@ -747,6 +747,7 @@
	 	  CC="\$\${CC}" \\
	 	  LDFLAGS="-s" \\
	 	  ../../SRC/gdb/configure \\
	+	    --disable-werror \\
	 	    --prefix=\$(PREFIX) \\
	 	    \$\${BUILD} \\
	 	    --target=nacl
	END
	else
	  patch -p0 <<-END
	--- native_client/tools/SRC/gdb/gdb/doc/Makefile.in
	+++ native_client/tools/SRC/gdb/gdb/doc/Makefile.in
	@@ -306 +306 @@
	-	echo "@set GDBVN \`sed q \$(srcdir)/../version.in\`" > ./GDBvn.new
	+	echo "@set GDBVN \`sed q \$(srcdir)/../version.inT\`" > ./GDBvn.new
	END
	fi
	declare url_prefix=http://storage.googleapis.com/nativeclient-archive2
	if [[ "$3" = "glibc" ]]; then
	  declare url=$url_prefix/x86_toolchain/r"$rev"/toolchain_"$2"_x86.tar.gz
	else
	  declare url=$url_prefix/toolchain/"$rev"/naclsdk_"$2"_x86.tgz
	fi
	if [[ ! -e "../$$.error.$name" ]]; then
	  # If toolchain is already available then another try will not change anything
	  curl --fail --location --url "$url" -o /dev/null &&
	  (cd .. ; sha1sum "$scriptname" "$1" || shasum "$scriptname" "$1") >"../$1.$name.lastver" 2>/dev/null &&
	  rm -rf "../$name" ||
	  (
	    cd native_client
	    export BUILD_COMPATIBLE_TOOLCHAINS=no
	    export BUILDBOT_GOT_REVISION="$rev"
	    if [[ "$2" = "win" ]]; then (
	      # Use extended globbing (cygwin should always have it).
	      shopt -s extglob
	      # Filter out cygwin python (everything under /usr or /bin, or *cygwin*).
	      export PATH=${PATH/#\/bin*([^:])/}
	      export PATH=${PATH//:\/bin*([^:])/}
	      export PATH=${PATH/#\/usr*([^:])/}
	      export PATH=${PATH//:\/usr*([^:])/}
	      export PATH=${PATH/#*([^:])cygwin*([^:])/}
	      export PATH=${PATH//:*([^:])cygwin*([^:])/}
	      python_slave buildbot/buildbot_selector.py
	      (cd ../.. ; sha1sum "$scriptname" "$1" || shasum "$scriptname" "$1") >"../../$1.$name.lastver" 2>/dev/null
	      rm -rf "../../$name"
	    ) else
	      # PPAPI14 to PPAPI30 were designed to be built on Ubuntu Lucid,
	      # not on Ubuntu Precise
	      if [[ "$name" == ppapi[12]? ]] || [[ "$name" == ppapi30 ]]; then
		BUILDBOT_BUILDERNAME="${BUILDBOT_BUILDERNAME/precise64/lucid64}"
	      fi
	      python buildbot/buildbot_selector.py
	      (cd ../.. ; sha1sum "$scriptname" "$1" || shasum "$scriptname" "$1") >"../../$1.$name.lastver" 2>/dev/null
	      rm -rf "../../$name"
	    fi
	  )
	  cd ..
	fi
      else
	(cd .. ; sha1sum "$scriptname" "$1" || shasum "$scriptname" "$1") >"../$1.$name.lastver" 2>/dev/null &&
	rm -rf "../$name"
	cd ..
      fi
    ;;
  esac
done < "$1"

(sha1sum "$scriptname" "$1" || shasum "$scriptname" "$1") > "$1.lastver" 2>/dev/null