update-src.pl 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. #!/usr/bin/perl -w
  2. # Run this from cron to update the source tree that lxr sees.
  3. # Created 12-Jun-98 by jwz.
  4. # Updated 27-Feb-99 by endico. Added multiple tree support.
  5. use Cwd;
  6. use File::Basename;
  7. use List::MoreUtils qw(uniq);
  8. use lib 'lib';
  9. use LXR::Common;
  10. use LXR::Config;
  11. use LXR::Shell;
  12. my @paths=qw(
  13. /usr/local/bin
  14. );
  15. my $CVSROOT=':pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot';
  16. $ENV{PATH}='/usr/local/bin:'.$ENV{PATH};
  17. my ($lxr_dir, $lxr_conf, $db_dir, $src_dir, $Conf, $HTTP, $Path, $head);
  18. my $STDERRTOSTDOUT = '2>&1';
  19. my $STDERRTODEVNUL = '2>/dev/null';
  20. my $ERROR_OUTPUT = $STDERRTOSTDOUT;
  21. my $TIME;
  22. my $UPTIME;
  23. my $DATE;
  24. my $CVS = 'cvs ';
  25. my $CVSQUIETFLAGS = '-Q ';
  26. my $CVSROOTFLAGS = "-d $CVSROOT ";
  27. my $CVSCO = 'checkout ';
  28. my $CVSUP = 'update ';
  29. my $CVSCOMMAND = "$CVS $CVSQUIETFLAGS $CVSROOTFLAGS";
  30. my $SVN = 'svn ';
  31. my $SVNQUIETFLAGS = '--non-interactive ';
  32. my $SVNCO = 'checkout ';
  33. my $SVNUP = 'update ';
  34. my $SVNCOMMAND = "$SVN $SVNQUIETFLAGS";
  35. my $HGCOMMAND = 'timeout 1h hg ';
  36. my $HGCLONE = 'clone ';
  37. my $HGUP = 'up ';
  38. my $HGCHANGESET = 'parents --template="{node|short}\n"';
  39. sub hg_get_list
  40. {
  41. my ($dir) = @_;
  42. my @dirs;
  43. open LIST, "curl -s -f $dir|" || return @dirs;
  44. while (<LIST>) {
  45. if (m{class="list" href="[^"]*/([^"/]+)/"}) {
  46. push @dirs, $1;
  47. }
  48. }
  49. return @dirs;
  50. }
  51. sub hg_clone_cheap
  52. {
  53. my ($ver, $prefix, $base, $dest, $extra) = @_;
  54. $extra = '' unless defined $extra;
  55. my $orig = $Conf->{'treehash'}{$base}.$extra;
  56. my ($destextra, $prefixextra) = ($dest.$extra, $prefix.$extra);
  57. if (-d "$orig/.hg") {
  58. my $tag = $ver;
  59. $tag =~ s/\./_/g;
  60. $tag = 'GECKO_'.$tag.'_BASE';
  61. my $command =
  62. "[ -d $destextra ] && rmdir $destextra $STDERRTOSTDOUT; cd $orig;".
  63. "$TIME ($HGCOMMAND $HGCLONE .#$tag $destextra || $HGCOMMAND $HGCLONE . $destextra) $STDERRTOSTDOUT;".
  64. "cd $destextra;".
  65. "perl -pi -e 's!default =.*!default = https://hg.mozilla.org/releases/$prefixextra!' .hg/hgrc;".
  66. "$TIME $HGCOMMAND $HGUP $STDERRTOSTDOUT;";
  67. print LOG $command;
  68. print LOG `$command`;
  69. }
  70. unless (-d "$destextra/.hg") {
  71. my $src = basename($dest);
  72. print LOG `cd $src; $TIME $HGCOMMAND $HGCLONE https://hg.mozilla.org/releases/$prefixextra $STDERRTOSTDOUT`;
  73. }
  74. }
  75. sub hg_update {
  76. my ($dir, $branch, $origin) = @_;
  77. # If no branch argument is specified, 'default' is used
  78. $branch = 'default' unless defined $branch;
  79. # Unless empty is specified, we specify the branch (either default
  80. # or the one which was passed as branch).
  81. $branch = "-r $branch" if $branch;
  82. $origin = 'default' unless defined $origin;
  83. # $origin isn't used yet.
  84. print LOG `cd $dir; $TIME $HGCOMMAND pull $branch $STDERRTOSTDOUT || pwd; $HGCOMMAND update --clean $STDERRTOSTDOUT; $HGCOMMAND $HGCHANGESET`;
  85. }
  86. my $EACHONE = 'xargs -n1 ';
  87. my $BZR = 'bzr ';
  88. my $BZRQUIETFLAGS = '-q ';
  89. my $BZRUPDATE = 'update $BZRQUIETFLAGS';
  90. my $TREE;
  91. my %defaults = qw(
  92. TIME time
  93. UPTIME uptime
  94. DATE date
  95. );
  96. sub process_args {
  97. my $was_arg;
  98. do {
  99. $was_arg = 0;
  100. $TREE = shift;
  101. if ($TREE) {
  102. if ($TREE eq '-cron') {
  103. $was_arg = 1;
  104. $defaults{TIME} = $defaults{UPTIME} = '';
  105. $ERROR_OUTPUT = $STDERRTODEVNUL;
  106. }
  107. $TREE =~ s{/$}{};
  108. }
  109. } while ($TREE && $was_arg);
  110. }
  111. process_args(@ARGV);
  112. check_defaults(\%defaults);
  113. $DATE = $defaults{DATE};
  114. $TIME = $defaults{TIME};
  115. $UPTIME = $defaults{UPTIME};
  116. $lxr_dir = '.';
  117. die "can't find $lxr_dir" unless -d $lxr_dir;
  118. $lxr_conf = "$lxr_dir/lxr.conf";
  119. # let LXR:: handle lxr.conf
  120. if (defined $TREE) {
  121. $ENV{'SCRIPT_NAME'} = "/$TREE/" . basename($0);
  122. ($Conf, $HTTP, $Path, $head) = &init($0);
  123. $db_dir = $Conf->dbdir;
  124. $src_dir = $Conf->sourceroot;
  125. die "Could not find sourceroot for $TREE" unless defined $src_dir;
  126. if (defined $Conf->glimpsebin) {
  127. push @paths, $1 if ($Conf->glimpsebin =~ m{(.*)/([^/]*)$});
  128. }
  129. } else {
  130. open LXRCONF, '<', "$lxr_dir/lxr.conf" || die "can't open lxr.conf";
  131. my %sourceroot = ();
  132. do {
  133. #grab sourceroot from config file indexing only a single tree where
  134. #format is "sourceroot: dirname"
  135. #grab sourceroot from config file indexing multiple trees where
  136. #format is "sourceroot: treename dirname"
  137. $line = <LXRCONF>;
  138. $db_dir = "$1" if $line =~ /^dbdir:\s*(.*)$/;
  139. $sourceroot{$1} = $2 if $line =~ /^sourceroot:\s*(\S+ |)(.*)/;
  140. } until eof LXRCONF;
  141. die "could not find dbdir: directive" unless defined $db_dir;
  142. if (defined $TREE) {
  143. $db_dir .= "/$TREE" if $TREE ne '';
  144. } else {
  145. $TREE = '';
  146. }
  147. #since no tree is defined, assume sourceroot is defined the old way
  148. $src_dir = $sourceroot{$TREE ? "$TREE " : ''};
  149. }
  150. unless (defined $src_dir) {
  151. die "could not find matching sourceroot:" .($TREE ? " for $TREE" :'');
  152. }
  153. my %pathmap=();
  154. for my $mapitem (@paths) {
  155. $pathmap{$mapitem} = 1;
  156. }
  157. for my $possible_path (keys %pathmap) {
  158. $ENV{'PATH'} = "$possible_path:$ENV{'PATH'}" if -d $possible_path;
  159. }
  160. -d $db_dir || mkdir $db_dir;
  161. my $pid_lock = get_lock($db_dir, 'src');
  162. my $log="$db_dir/cvs.log";
  163. rename $log, "$log.old" if -f $log;
  164. open LOG, '>', $log || die "can't open $log";
  165. #print LOG `set -x`;
  166. print LOG `date`;
  167. print LOG `pwd`;
  168. # then update the Mozilla sources
  169. -d $src_dir || mkdir $src_dir;
  170. chdir dirname $src_dir;
  171. # endico: check out the source
  172. for ($TREE) {
  173. /^$/ && do {
  174. warn "You need to fill in your update script here. fixme!";
  175. last;
  176. };
  177. /^world-all$/ && do {
  178. print LOG `$TIME (echo */* | $EACHONE $SVNCOMMAND $SVNUP)`;
  179. last;
  180. };
  181. /^classic$/ && do {
  182. print LOG `$TIME $CVSCOMMAND $CVSCO -P -rMozillaSourceClassic_19981026_BRANCH MozillaSource $STDERRTOSTDOUT`;
  183. last;
  184. };
  185. /^chromium$/ && do {
  186. # http://dev.chromium.org/developers/how-tos/get-the-code
  187. # must have the depot-tools installed already
  188. # check for depot-tools, install if necessary
  189. if (-d "$src_dir/../depot_tools") {
  190. # update_depot_tools won't run as root; easier to run a
  191. # sed one-liner than natively. it will also complain if
  192. # you modify in-place and run
  193. chdir "$src_dir/../depot_tools";
  194. print LOG `sed -e '1!N; s/^.*Running depot tools as root is sad\\.\\n.*exit/ echo Running depot tools as root/' < update_depot_tools > update_depot_tools.root`;
  195. chmod 0755, "update_depot_tools.root";
  196. print LOG `./update_depot_tools.root`;
  197. } else {
  198. chdir "$src_dir/..";
  199. print LOG `git clone https://git.chromium.org/chromium/tools/depot_tools.git`;
  200. }
  201. chdir $src_dir;
  202. unless (-f "$src_dir/.gclient") {
  203. print "\nBREAK: check out manually by running the following in $src_dir:\n";
  204. print "../depot_tools/gclient config https://src.chromium.org/chrome/trunk/src https://chromium-status.appspot.com/lkgr\n";
  205. print "Then edit $src_dir/.gclient, per http://dev.chromium.org/developers/how-tos/get-the-code#TOC-Reducing-the-size-of-your-checkout\n";
  206. print "Not attempting to do this automatically... quitting here!\n\n";
  207. last;
  208. }
  209. print LOG `../depot_tools/gclient sync`;
  210. last;
  211. };
  212. /^gaia$/ && do {
  213. if (! -d "$src_dir/.git") {
  214. print LOG `git clone https://github.com/mozilla-b2g/gaia $src_dir $STDERRTOSTDOUT`;
  215. } else {
  216. chdir $src_dir;
  217. print LOG `git pull $STDERRTOSTDOUT`;
  218. print LOG `git gc $STDERRTOSTDOUT`;
  219. }
  220. last;
  221. };
  222. /^(rust|servo)$/ && do {
  223. my $repo = $1;
  224. if (! -d "$src_dir/.git") {
  225. print LOG `git clone https://github.com/mozilla/$repo $src_dir $STDERRTOSTDOUT`;
  226. } else {
  227. chdir $src_dir;
  228. print LOG `git pull $STDERRTOSTDOUT`;
  229. print LOG `git gc $STDERRTOSTDOUT`;
  230. }
  231. last;
  232. };
  233. /^js$/ && do {
  234. print LOG `$TIME $CVSCOMMAND $CVSCO -P mozilla/js mozilla/js2 mozilla/nsprpub $STDERRTOSTDOUT`;
  235. last;
  236. };
  237. /^security$/ && do {
  238. print LOG `$TIME $CVSCOMMAND $CVSCO -P mozilla/security mozilla/nsprpub mozilla/dbm $STDERRTOSTDOUT`;
  239. last;
  240. };
  241. /^webtools$/ && do {
  242. print LOG `$TIME $CVSCOMMAND $CVSCO -P mozilla/webtools $STDERRTOSTDOUT`;
  243. last;
  244. };
  245. /^bugzilla(\d.*|)$/ && do {
  246. my $ver = $1;
  247. my $dir = basename($src_dir);
  248. unless (-d "$src_dir/CVS") {
  249. chdir dirname $src_dir;
  250. if ($ver) {
  251. $ver =~ s/\.x//;
  252. $ver =~ s/\./_/g;
  253. $ver = "-r BUGZILLA-$ver-BRANCH";
  254. }
  255. print LOG `$TIME $CVSCOMMAND $CVSCO -P $ver -d $dir mozilla/webtools/bugzilla $STDERRTOSTDOUT`;
  256. } else {
  257. print LOG `$TIME $CVSCOMMAND $CVSUP -P -d $dir $STDERRTOSTDOUT`;
  258. }
  259. last;
  260. };
  261. /^(?:l10n|l10n-(?:mozilla1\.8|aviarybranch|mozilla1\.8\.0))$/ && do {
  262. print LOG `$TIME $CVS $CVSQUIETFLAGS -d ':pserver:anonymous\@cvs-mirror.mozilla.org:/l10n' $CVSUP -dP $STDERRTOSTDOUT`;
  263. last;
  264. };
  265. /^mobile-browser$/ && do {
  266. hg_update($src_dir);
  267. last;
  268. };
  269. /^mozilla$/ && do {
  270. print LOG `$TIME $CVSCOMMAND $CVSCO -P mozilla $STDERRTOSTDOUT`;
  271. last;
  272. };
  273. /^mozillasvn-all$/ && do {
  274. print LOG `$TIME $SVNCOMMAND $SVNUP svn.mozilla.org $STDERRTOSTDOUT`;
  275. last;
  276. };
  277. /^mozillausers-central$/ && do {
  278. my @dirs = <$src_dir/*/*>;
  279. foreach my $dir (@dirs) {
  280. hg_update($dir);
  281. }
  282. last;
  283. };
  284. /^(?:(build|incubator|l10n|labs|projects|services|webtools)-central|(l10n)-(mozilla-\D.*))$/ && do {
  285. my @dirs = <$src_dir/*>;
  286. my $fallback = defined $1 ? $1 : "releases/$2/$3";
  287. $fallback .= '-central' if $fallback eq 'l10n';
  288. $fallback = "https://hg.mozilla.org/$fallback";
  289. my $general_root;
  290. foreach my $dir (@dirs) {
  291. if ( -d $dir ) {
  292. unless (defined $general_root) {
  293. $general_root = `hg paths default -R $dir`;
  294. $general_root =~ s{/[^/]+/?\s*$}{};
  295. }
  296. hg_update($dir);
  297. }
  298. }
  299. $general_root = $fallback unless defined $general_root;
  300. chdir $src_dir;
  301. @dirs = hg_get_list($general_root);
  302. foreach my $dir (@dirs) {
  303. unless (-d $dir) {
  304. print LOG `$TIME $HGCOMMAND $HGCLONE $general_root/$dir $STDERRTOSTDOUT`;
  305. }
  306. }
  307. last;
  308. };
  309. /^(.*\.gitorious\.org)$/ && do {
  310. pull_gitorious($1);
  311. last;
  312. };
  313. /^nspr-cvs$/ && do {
  314. # Seems wrong, per bug 730010
  315. # print LOG `$TIME $CVSCOMMAND $CVSCO -P NSPR $STDERRTOSTDOUT`;
  316. print LOG `$TIME $CVSCOMMAND $CVSCO -P mozilla/nsprpub $STDERRTOSTDOUT`;
  317. last;
  318. };
  319. /^l10n-gaia(-v[\d_]+)?$/ && do {
  320. my $ver = defined $1 ? "/$1" : '';
  321. my $rel = defined $1 ? 'releases/' : '';
  322. $ver =~ s/-//;
  323. my $url = "https://hg.mozilla.org/${rel}gaia-l10n${ver}";
  324. my @ldirs = <$src_dir/*>;
  325. my @rdirs = hg_get_list($url);
  326. my @dirs = sort uniq(@ldirs, @rdirs);
  327. foreach my $dir (@dirs) {
  328. if ( -d $dir ) {
  329. hg_update($dir);
  330. } else {
  331. print LOG `$TIME $HGCOMMAND $HGCLONE $url/$dir $src_dir/$dir $STDERRTOSTDOUT`;
  332. }
  333. }
  334. last;
  335. };
  336. /^l10n-mozilla(1\.9.*|2\.0.*)$/ && do {
  337. my $ver = $1;
  338. my @dirs;
  339. {
  340. my $base = 'l10n-central';
  341. my $orig = $Conf->{'treehash'}{$base};
  342. @dirs = hg_get_list("https://hg.mozilla.org/releases/l10n-mozilla-$ver");
  343. foreach my $dir (@dirs) {
  344. hg_clone_cheap($ver, "l10n-mozilla-$ver", $base, $src_dir, "/" . basename $dir);
  345. }
  346. @dirs = <$src_dir/*>;
  347. }
  348. foreach my $dir (@dirs) {
  349. if ( -d $dir ) {
  350. hg_update($dir);
  351. }
  352. }
  353. last;
  354. };
  355. /^mozilla(1\.9.*|2\.0.*)$/ && do {
  356. my $ver = $1;
  357. unless (-d "$src_dir/.hg") {
  358. hg_clone_cheap($ver, "mozilla-$ver", 'mozilla-central', $src_dir, '');
  359. }
  360. hg_update($src_dir);
  361. last;
  362. };
  363. /^mozilla1\.7$/ && do {
  364. print LOG `$TIME $CVSCOMMAND $CVSCO -r MOZILLA_1_7_BRANCH mozilla/client.mk $STDERRTOSTDOUT`;
  365. print LOG `$TIME make -C mozilla -f client.mk pull_all MOZ_CO_PROJECT=all $STDERRTOSTDOUT`;
  366. print LOG `cat cvsco.log $STDERRTOSTDOUT`;
  367. last;
  368. };
  369. /^mozilla1\.8$/ && do {
  370. print LOG `$TIME $CVSCOMMAND $CVSCO -r MOZILLA_1_8_BRANCH mozilla/client.mk $STDERRTOSTDOUT`;
  371. print LOG `$TIME make -C mozilla -f client.mk pull_all MOZ_CO_PROJECT=all $STDERRTOSTDOUT`;
  372. print LOG `cat cvsco.log $STDERRTOSTDOUT`;
  373. last;
  374. };
  375. /^mozilla1\.8\.0$/ && do {
  376. print LOG `$TIME $CVSCOMMAND $CVSCO -r MOZILLA_1_8_0_BRANCH mozilla/client.mk $STDERRTOSTDOUT`;
  377. print LOG `$TIME make -C mozilla -f client.mk pull_all MOZ_CO_PROJECT=all $STDERRTOSTDOUT`;
  378. print LOG `cat cvsco.log $STDERRTOSTDOUT`;
  379. last;
  380. };
  381. /^seamonkey$/ && do {
  382. # does not pull from a specific branch/tag?
  383. print LOG `$TIME $CVSCOMMAND $CVSCO mozilla/client.mk $STDERRTOSTDOUT`;
  384. print LOG `$TIME make -C mozilla -f client.mk pull_all MOZ_CO_PROJECT=all $STDERRTOSTDOUT`;
  385. print LOG `cat cvsco.log $STDERRTOSTDOUT`;
  386. print LOG `cd mozilla; $TIME $CVSCOMMAND $CVSUP-d tools`;
  387. last;
  388. };
  389. /^aviarybranch$/ && do {
  390. print LOG `$TIME $CVSCOMMAND $CVSCO -r AVIARY_1_0_20040515_BRANCH mozilla/client.mk $STDERRTOSTDOUT`;
  391. print LOG `$TIME make -C mozilla -f client.mk pull_all MOZ_CO_PROJECT=all $STDERRTOSTDOUT`;
  392. print LOG `cat cvsco.log $STDERRTOSTDOUT`;
  393. last;
  394. };
  395. /^aviary101branch$/ && do {
  396. print LOG `$TIME $CVSCOMMAND $CVSCO -r AVIARY_1_0_1_20050124_BRANCH mozilla/client.mk $STDERRTOSTDOUT`;
  397. print LOG `$TIME make -C mozilla -f client.mk pull_all MOZ_CO_PROJECT=all $STDERRTOSTDOUT`;
  398. print LOG `cat cvsco.log $STDERRTOSTDOUT`;
  399. last;
  400. };
  401. /^comm-(?:central|1\.9\.\d+|2\.0|release|aurora|beta|esr10|esr17|esr24|esr31|esr38|esr45)$/ && do {
  402. print LOG `cd $src_dir; $TIME python ./client.py checkout $STDERRTOSTDOUT`;
  403. last;
  404. };
  405. /^(?:.*-(?:central|tracing)|(mozilla-\D.*))$/ && do {
  406. if (-d "$src_dir/.hg") {
  407. hg_update($src_dir);
  408. } else {
  409. my $dir = $1 ? "releases/$1" : basename($src_dir);
  410. print LOG `$TIME $HGCOMMAND $HGCLONE https://hg.mozilla.org/$dir $src_dir`;
  411. }
  412. last;
  413. };
  414. /^(mozilla-esr10|mozilla-esr17|mozilla-esr24|mozilla-esr31|mozilla-esr38|mozilla-esr45)$/ && do {
  415. if (-d "$src_dir/.hg") {
  416. hg_update($src_dir);
  417. } else {
  418. my $dir = $1 ? "releases/$1" : basename($src_dir);
  419. print LOG `$TIME $HGCOMMAND $HGCLONE https://hg.mozilla.org/$dir $src_dir`;
  420. }
  421. last;
  422. };
  423. /^mozilla-(b2g28_v1_3|b2g28_v1_3t|b2g30_v1_4|b2g32_v2_0|b2g34_v2_1|b2g37_v2_2)$/ && do {
  424. if (-d "$src_dir/.hg") {
  425. hg_update($src_dir);
  426. } else {
  427. my $dir = $1 ? "releases/$1" : basename($src_dir);
  428. print LOG `$TIME $HGCOMMAND $HGCLONE https://hg.mozilla.org/$dir $src_dir`;
  429. }
  430. last;
  431. };
  432. /^mozmill-tests$/ && do {
  433. if (-d "$src_dir/.hg") {
  434. hg_update($src_dir);
  435. } else {
  436. print LOG `$TIME $HGCOMMAND $HGCLONE https://hg.mozilla.org/qa/mozmill-tests $src_dir`;
  437. }
  438. last;
  439. };
  440. /^(nss|jss|nspr)$/ && do {
  441. if (-d "$src_dir/.hg") {
  442. hg_update($src_dir);
  443. } else {
  444. my $dir = $1 ? "projects/$1" : basename($src_dir);
  445. print LOG `$TIME $HGCOMMAND $HGCLONE https://hg.mozilla.org/$dir $src_dir`;
  446. }
  447. last;
  448. };
  449. /^(python-nss)$/ && do {
  450. if (-d "$src_dir/.hg") {
  451. hg_update($src_dir);
  452. } else {
  453. print LOG `$TIME $HGCOMMAND $HGCLONE https://hg.mozilla.org/projects/python-nss $src_dir`;
  454. }
  455. last;
  456. };
  457. /^firefox$/ && do {
  458. unless (-f 'client.mk') {
  459. print LOG `$TIME $CVSCOMMAND $CVSCO mozilla/client.mk $STDERRTOSTDOUT`;
  460. }
  461. print LOG `$TIME make -C mozilla -f client.mk pull_all MOZ_CO_PROJECT=browser $STDERRTOSTDOUT`;
  462. print LOG `cat cvsco.log $STDERRTOSTDOUT`;
  463. last;
  464. };
  465. /^firefox2$/ && do {
  466. unless (-f 'client.mk') {
  467. print LOG `$TIME $CVSCOMMAND $CVSCO -r MOZILLA_1_8_BRANCH mozilla/client.mk $STDERRTOSTDOUT`;
  468. }
  469. print LOG `$TIME make -C mozilla -f client.mk pull_all MOZ_CO_PROJECT=browser $STDERRTOSTDOUT`;
  470. print LOG `cat cvsco.log $STDERRTOSTDOUT`;
  471. last;
  472. };
  473. /^camino$/ && do {
  474. if (-d "$src_dir/.hg") {
  475. print LOG `cd $src_dir; cd ..; mkdir 0; mv camino 0; mv 0 camino`;
  476. }
  477. if (-d "$src_dir/camino/.hg") {
  478. hg_update("$src_dir/camino");
  479. } else {
  480. my $dir = basename($src_dir);
  481. print LOG `mkdir $src_dir/camino; $TIME $HGCOMMAND $HGCLONE https://hg.mozilla.org/$dir $src_dir/camino`;
  482. }
  483. last;
  484. };
  485. /^thunderbird.*$/ && do {
  486. unless (-f 'client.mk') {
  487. print LOG `$TIME $CVSCOMMAND $CVSCO mozilla/client.mk $STDERRTOSTDOUT`;
  488. }
  489. print LOG `$TIME make -C mozilla -f client.mk pull_all MOZ_CO_PROJECT=mail $STDERRTOSTDOUT`;
  490. print LOG `cat cvsco.log $STDERRTOSTDOUT`;
  491. last;
  492. };
  493. /^(?:.*)-bzr$/ && do {
  494. unless (`which $BZR`) {
  495. print LOG `which $BZR $STDERRTOSTDOUT`;
  496. close LOG;
  497. die "can't find $BZR";
  498. }
  499. print LOG `cd $src_dir; $TIME $BZR $BZRUPDATE $STDERRTOSTDOUT`;
  500. last;
  501. };
  502. /^(?:(?:bug|mo)zilla.*-.*)$/ && do {
  503. print LOG `cd $src_dir; $TIME $CVS $CVSQUIETFLAGS -d ':pserver:anonymous\@cvs-mirror.mozilla.org:/www' $CVSUP -dP * $STDERRTOSTDOUT`;
  504. last;
  505. };
  506. /^fuel$/ && do {
  507. print LOG `$TIME $CVSCOMMAND $CVSCO -P -d fuel -rFUEL_DEVEL_BRANCH mozilla/browser/fuel $STDERRTOSTDOUT`;
  508. last;
  509. };
  510. /^(?:.*)-all$/ && do {
  511. print LOG `$TIME $SVNCOMMAND $SVNUP $STDERRTOSTDOUT`;
  512. last;
  513. };
  514. /^addons$/ && do {
  515. print LOG `$TIME su - addons_update -c /home/addons_update/bin/rsync-addons.sh $STDERRTOSTDOUT`;
  516. last;
  517. };
  518. /^(?:.*)$/ && do {
  519. my @dirs = <$src_dir/*/CVS>;
  520. if (scalar @dirs) {
  521. foreach my $dir (@dirs) {
  522. $dir =~ s/CVS$//; $dir =~ s{//+}{/}g;
  523. print LOG `cd $dir; $TIME $CVS $CVSQUIETFLAGS $CVSUP-d $STDERRTOSTDOUT`;
  524. }
  525. last;
  526. }
  527. };
  528. warn "unrecognized tree. fixme!";
  529. }
  530. sub get_gitorious_repos {
  531. my ($root) = @_;
  532. open GITORIOUS, "curl -s $root|";
  533. my @repos = ();
  534. while (<GITORIOUS>) {
  535. next unless /^git clone/;
  536. push @repos, $_;
  537. }
  538. close GITORIOUS;
  539. return @repos;
  540. }
  541. sub get_gitorious_roots {
  542. my ($host) = @_;
  543. open GITORIOUS_ROOTS, "curl -s $host|";
  544. my $state = 0;
  545. while (<GITORIOUS_ROOTS>) {
  546. if ($state == 0) {
  547. next unless /site_overview/;
  548. $state = 1;
  549. } elsif ($state == 1) {
  550. if (/id="right"/) {
  551. $state = 2;
  552. next;
  553. }
  554. next unless m!<strong><a href="(/.*)">!;
  555. push @repos, "$host$1";
  556. }
  557. }
  558. close GITORIOUS_ROOTS;
  559. my @git_repos = ();
  560. foreach my $repo (@repos) {
  561. push @git_repos, get_gitorious_repos($repo);
  562. }
  563. return @git_repos;
  564. }
  565. sub pull_gitorious {
  566. my ($host) = @_;
  567. # $src_dir is a global variable
  568. chdir $src_dir;
  569. my @dirs = sort <*>;
  570. foreach my $dir (@dirs) {
  571. # we pass '' to mean "don't use 'default' with update magic"
  572. # we could try doing something fancier like master/origin
  573. hg_update($dir, '');
  574. }
  575. $host = "https://$host" unless $host =~ m!://!;
  576. my @git_cmds = get_gitorious_roots($host);
  577. foreach my $git_cmd (@git_cmds) {
  578. $git_cmd =~ /git clone (\S+)\s+(\S+)/;
  579. $dir = $2;
  580. my $repo = $1;
  581. next if -d $dir;
  582. if (-e $dir) {
  583. print LOG "Found object $dir while trying to git clone $repo\n";
  584. next;
  585. }
  586. if ($repo !~ m!\w+://(.*$)! ||
  587. "$1$dir" =~ m![^-+a-z0-9_./]!i) {
  588. print LOG "Unexpected characters for git clone $repo $dir\n";
  589. next;
  590. }
  591. print LOG `$TIME $HGCOMMAND $HGCLONE '$repo' '$dir' $STDERRTOSTDOUT`;
  592. }
  593. }
  594. print LOG `$DATE $STDERRTOSTDOUT`;
  595. print LOG `$UPTIME $STDERRTOSTDOUT` if $UPTIME =~ /\w/;
  596. close LOG;
  597. unlink $pid_lock;
  598. exit 0;