2 #############################################################################
4 ## Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ## All rights reserved.
6 ## Contact: Nokia Corporation (qt-info@nokia.com)
8 ## This file is part of the utilities of the Qt Toolkit.
10 ## $QT_BEGIN_LICENSE:LGPL$
11 ## GNU Lesser General Public License Usage
12 ## This file may be used under the terms of the GNU Lesser General Public
13 ## License version 2.1 as published by the Free Software Foundation and
14 ## appearing in the file LICENSE.LGPL included in the packaging of this
15 ## file. Please review the following information to ensure the GNU Lesser
16 ## General Public License version 2.1 requirements will be met:
17 ## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ## In addition, as a special exception, Nokia gives you certain additional
20 ## rights. These rights are described in the Nokia Qt LGPL Exception
21 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
23 ## GNU General Public License Usage
24 ## Alternatively, this file may be used under the terms of the GNU General
25 ## Public License version 3.0 as published by the Free Software Foundation
26 ## and appearing in the file LICENSE.GPL included in the packaging of this
27 ## file. Please review the following information to ensure the GNU General
28 ## Public License version 3.0 requirements will be met:
29 ## http://www.gnu.org/copyleft/gpl.html.
32 ## Alternatively, this file may be used in accordance with the terms and
33 ## conditions contained in a signed written agreement between you and Nokia.
41 #############################################################################
47 package Qt::InitRepository;
52 init-repository - initialize the Qt5 repository and all submodules
56 ./init-repository [options]
58 This script may be run after an initial `git clone' of Qt5 in order to check
70 Force initialization (even if the submodules are already checked out).
75 Be quiet. Will exit cleanly if the repository is already initialized.
86 Skip webkit and webkit examples submodules.
87 It may be desirable to skip these modules due to the large size of the webkit
90 =item --module-subset=<module1>,<module2>...
92 Only initialize the specified subset of modules given as the argument. Specified
93 modules must already exist in .gitmodules.
97 Skip the `git submodule update' command.
100 =item --ignore-submodules
102 Set git config to ignore submodules by default when doing operations on the
103 qt5 repo, such as `pull', `fetch', `diff' etc.
105 This option is default for --nokia-developer/--brisbane.
107 After using this option, pass `--ignore-submodules=none' to git to override
113 B<Repository options:>
117 =item --nokia-developer
119 Switch to internal Nokia URLs.
124 Switch to internal Nokia URLs and make use of the Brisbane git mirrors.
125 (Implies `--mirror' and `--mirror-webkit').
129 Switch to internal Nokia URLs and make use of the Berlin git mirrors.
130 (Implies `--mirror' and `--mirror-webkit').
135 Use the SSH protocol for git operations. This may be useful if the git
136 protocol is blocked by a firewall. Note that this requires a user account
137 with an uploaded SSH key on all servers used. (Implies `--nokia-developer').
139 The `--ssh' option does not affect the gerrit remotes.
144 Use the HTTP protocol for git operations. This may be useful if the git
145 protocol is blocked by a firewall. Note that this only works with the
146 external Gitorious server.
148 The `--http' option does not affect the gerrit remotes.
151 =item --codereview-username <Gerrit/JIRA username>
153 Specify the user name for the (potentially) writable `gerrit' remote
154 for each module, for use with the Gerrit code review tool.
156 If this option is omitted, the gerrit remote is created without a username
157 and port number, and thus relies on a correct SSH configuration.
160 =item --alternates <path to other Qt5 repo>
162 Adds alternates for each submodule to another full qt5 checkout. This makes
163 this qt5 checkout very small, as it will use the object store of the
164 alternates before unique objects are stored in its own object store.
166 This option has no effect when using `--no-update'.
168 B<NOTE:> This will make this repo dependent on the alternate, which is
169 potentially dangerous! The dependency can be broken by also using
170 the `--copy-objects' option, or by running C<git repack -a> in each
171 submodule, where required. Please read the note about the `--shared' option
172 in the documentation of `git clone' for more information.
177 When `--alternates' is used, automatically do a C<git repack -a> in each
178 submodule after cloning, to ensure that the repositories are independent
179 from the source used as a reference for cloning.
181 Note that this negates the disk usage benefits gained from the use of
185 =item --mirror <url-base>
187 Uses <url-base> as the base URL for submodule git mirrors.
191 --mirror user@machine:/foo/bar
193 ...will use the following as a mirror for qtbase:
195 user@machine:/foo/bar/qtbase.git
198 =item --mirror-webkit <url>
200 Uses <url> as the URL for the webkit git mirror.
202 =item --mirror-v8 <url>
204 Uses <url> as the URL for the V8 git mirror.
210 use Carp qw( confess );
211 use English qw( -no_match_vars );
212 use Getopt::Long qw( GetOptionsFromArray );
213 use Pod::Usage qw( pod2usage );
214 use Cwd qw( getcwd );
217 'internal' => 'git://scm.dev.nokia.troll.no/' ,
218 'ssh' => 'git@scm.dev.nokia.troll.no:' ,
219 'http' => 'http://git.gitorious.org/' ,
222 my %GERRIT_REPOS = map { $_ => "qt/$_" } qw(
247 qtwebkit-examples-and-demos
250 $GERRIT_REPOS{qtquick3d} = "qt/quick3d";
252 # Protocol-specific repo overrides, if they differ from the values set in the git submodule config
253 # (e.g. because public vs private names differ for whatever reason)
254 my %PROTOCOL_REPOS = (
256 internal => "qt/quick3d", # instead of qt-quick3d/qt-quick3d on gitorious
262 = 'ssh://@USER@codereview.qt-project.org@PORT@/';
264 my $BNE_MIRROR_URL_BASE
265 = 'git://bq-git.apac.nokia.com/qtsoftware/';
267 my $BNE_MIRROR_WEBKIT_URL
268 = 'git://bq-git.apac.nokia.com/qtsoftware/research/gitorious-org-webkit-qtwebkit-mirror.git';
270 my $BNE_MIRROR_V8_URL
271 = 'git://bq-git.apac.nokia.com/github/v8.git';
273 my $BER_MIRROR_URL_BASE
274 = 'git://ber-git.europe.nokia.com/';
276 my $BER_MIRROR_WEBKIT_URL
277 = 'git://ber-git.europe.nokia.com/qtwebkit/qtwebkit.git';
282 my ($class, @arguments) = @_;
286 $self->parse_arguments(@arguments);
291 # Like `system', but possibly log the command, and die on non-zero exit code
294 my ($self, @cmd) = @_;
296 if (!$self->{quiet}) {
300 if (system(@cmd) != 0) {
301 confess "@cmd exited with status $CHILD_ERROR";
309 my ($self, @args) = @_;
311 %{$self} = (%{$self},
313 'codereview-username' => "",
314 'detach-alternates' => 0 ,
316 'ignore-submodules' => 0 ,
318 'mirror-webkit-url' => "",
319 'mirror-v8-url' => "",
320 'nokia-developer' => 0 ,
324 'module-subset' => "",
327 GetOptionsFromArray(\@args,
328 'alternates=s' => \$self->{qw{ alternates }},
329 'codereview-username=s' => \$self->{qw{ codereview-username }},
330 'copy-objects' => \$self->{qw{ detach-alternates }},
331 'force' => \$self->{qw{ force }},
332 'ignore-submodules' => \$self->{qw{ ignore-submodules }},
333 'mirror-webkit=s' => \$self->{qw{ mirror-webkit-url }},
334 'mirror-v8=s' => \$self->{qw{ mirror-v8-url }},
335 'mirror=s' => \$self->{qw{ mirror-url }},
336 'nokia-developer' => \$self->{qw{ nokia-developer }},
337 'quiet' => \$self->{qw{ quiet }},
338 'update!' => \$self->{qw{ update }},
339 'webkit!' => \$self->{qw{ webkit }},
340 'module-subset=s' => \$self->{qw{ module-subset }},
342 'help|?' => sub { pod2usage(1); },
343 'http' => sub { $self->{protocol} = 'http'; },
344 'ssh|ssh-protocol' => sub { $self->{protocol} = 'ssh'; },
346 'brisbane|brisbane-nokia-developer' => sub {
347 $self->{'nokia-developer'} = 1;
348 $self->{'protocol'} = 'internal';
349 $self->{'mirror-url'} = $BNE_MIRROR_URL_BASE;
350 $self->{'mirror-v8-url'} = $BNE_MIRROR_V8_URL;
351 $self->{'mirror-webkit-url'} = $BNE_MIRROR_WEBKIT_URL;
352 $self->{'ignore-submodules'} = 1;
355 'berlin|berlin-nokia-developer' => sub {
356 $self->{'nokia-developer'} = 1;
357 $self->{'protocol'} = 'internal';
358 $self->{'mirror-url'} = $BER_MIRROR_URL_BASE;
359 $self->{'mirror-webkit-url'} = $BER_MIRROR_WEBKIT_URL;
362 'nokia-developer' => sub {
363 $self->{'nokia-developer'} = 1;
364 $self->{'protocol'} = 'internal';
365 $self->{'ignore-submodules'} = 1;
369 if ($self->{'nokia-developer'} && $self->{'protocol'} eq 'http') {
370 print "*** Ignoring use of HTTP protocol, as it's only usable with external server\n";
371 $self->{'protocol'} = '';
374 # Replace any double trailing slashes from end of mirror
375 $self->{'mirror-url'} =~ s{//+$}{/};
377 if ($self->{'module-subset'}) {
378 $self->{'module-subset'} = {
379 map { $_ => 1 } split(qr{,}, $self->{'module-subset'})
386 sub check_if_already_initialized
390 # We consider the repo as `initialized' if submodule.qtbase.url is set
391 if (qx(git config --get submodule.qtbase.url)) {
392 if ($self->{force}) {
393 my @configresult = qx(git config -l);
394 foreach (@configresult) {
395 # Example line: submodule.qtqa.url=git://gitorious.org/qt/qtqa.git
396 if (/(submodule\.[^.=]+)\.url=.*/) {
397 $self->exe('git', 'config', '--remove-section', $1);
402 exit 0 if ($self->{quiet});
403 print "Will not reinitialize already initialized repository (use -f to force)!\n";
411 sub git_submodule_init
416 if ($self->{quiet}) {
417 push @init_args, '--quiet';
419 $self->exe('git', 'submodule', 'init', @init_args);
421 my $template = getcwd()."/.commit-template";
423 $self->exe('git', 'config', 'commit.template', $template);
429 sub git_disable_webkit_submodule
433 $self->exe('git', 'config', '--remove', 'submodule.qtwebkit');
434 $self->exe('git', 'config', '--remove', 'submodule.qtwebkit-examples-and-demos');
439 sub git_prune_submodules
443 my @configresult = qx(git config -l);
444 foreach my $line (@configresult) {
445 if ($line =~ /submodule\.([^.=]+)\.url=/) {
446 my $module_name = $1;
447 if (!$self->{'module-subset'}{$module_name}) {
448 $self->exe('git', 'config', '--remove', "submodule.$module_name");
454 sub git_set_submodule_config
458 my @configresult = qx(git config -l);
459 my $protocol = $self->{protocol};
460 my $url_base_for_protocol = $PROTOCOLS{$protocol};
462 foreach my $line (@configresult) {
463 # Example line: submodule.qtqa.url=git://gitorious.org/qt/qtqa.git
464 next if ($line !~ /submodule\.([^.=]+)\.url=(.*)/);
470 # WebKit is special, and has only external link.
471 if ($key ne 'qtwebkit' and $key ne 'qt3d') {
472 # qt-labs projects are still hosted under qt internally.
473 if ($protocol ne 'http') {
474 $value =~ s,^git://gitorious\.org/qt-labs/,${url_base_for_protocol}qt/,;
477 if ($PROTOCOL_REPOS{$key}->{$protocol}) {
478 # If this repo has an explicitly set basename for this protocol, use it...
479 # e.g. 'git@example.com:' . 'qt/quick3d'
480 $value = $url_base_for_protocol . $PROTOCOL_REPOS{$key}->{$protocol};
483 # ...otherwise, assume the selected protocol uses same naming structure
485 # e.g. git://gitorious.org/qt/qt5 => git@example.com:qt/qt5
486 $value =~ s,^git://gitorious\.org/,$url_base_for_protocol,;
491 $self->exe('git', 'config', "submodule.$key.url", $value);
493 if ($self->{'ignore-submodules'}) {
494 $self->exe('git', 'config', "submodule.$key.ignore", 'all');
501 sub git_clone_all_submodules
505 # manually clone each repo here, so we can easily use reference repos, mirrors etc
506 my @configresult = qx(git config -l);
507 foreach my $line (@configresult) {
508 if ($line =~ /submodule\.([^.=]+)\.url=(.*)/) {
509 $self->git_clone_one_submodule($1, $2);
513 $self->exe('git', 'submodule', 'update', '--recursive');
520 my ($self, $repo_basename) = @_;
522 my $gerrit_repo_basename = $GERRIT_REPOS{$repo_basename};
523 if ($gerrit_repo_basename) {
526 # If given a username, make a "verbose" remote.
527 # Otherwise, rely on proper SSH configuration.
528 if ($self->{'codereview-username'}) {
529 $gerrit_repo_url = $GERRIT_SSH_BASE;
530 $gerrit_repo_url =~ s,\@USER\@,$self->{'codereview-username'}\@,;
531 $gerrit_repo_url =~ s,\@PORT\@,:29418,;
534 $gerrit_repo_url = $GERRIT_SSH_BASE;
535 $gerrit_repo_url =~ s,\@[^\@]+\@,,g;
538 $gerrit_repo_url .= $gerrit_repo_basename;
539 $self->exe('git', 'config', 'remote.gerrit.url', $gerrit_repo_url);
540 $self->exe('git', 'config', 'remote.gerrit.fetch', '+refs/heads/*:refs/remotes/gerrit/*');
546 sub git_clone_one_submodule
548 my ($self, $submodule, $url) = @_;
550 my $alternates = $self->{ 'alternates' };
551 my $mirror_url = $self->{ 'mirror-url' };
552 my $mirror_webkit_url = $self->{ 'mirror-webkit-url' };
553 my $mirror_v8_url = $self->{ 'mirror-v8-url' };
554 my $protocol = $self->{ 'protocol' };
556 # `--reference FOO' args for the clone, if any.
560 # alternates is a qt5 repo, so the submodule will be under that.
561 if (-d "$alternates/$submodule") {
562 @reference_args = ('--reference', "$alternates/$submodule");
565 print " *** $alternates/$submodule not found, ignoring alternate for this submodule\n";
570 if ($mirror_url && ($submodule ne 'qtwebkit')) {
571 $mirror = $mirror_url.( $PROTOCOL_REPOS{$submodule}->{internal} // "qt/$submodule" );
572 $mirror .= ".git" unless (-d $mirror); # Support local disk mirror
574 elsif ($mirror_webkit_url && ($submodule eq 'qtwebkit')) {
575 $mirror = $mirror_webkit_url;
577 if ($mirror && ($submodule eq 'qt3d')) {
578 $mirror =~ s/qtsoftware/gitorious/ ;
581 my $do_clone = (! -d "$submodule/.git");
583 $self->exe('git', 'clone', @reference_args, ($mirror ? $mirror : $url), $submodule);
586 chdir($submodule) or confess "chdir $submodule: $OS_ERROR";
588 $self->exe('git', 'config', 'remote.origin.url', $url);
590 $self->exe('git', 'config', 'remote.mirror.url', $mirror);
591 $self->exe('git', 'config', 'remote.mirror.fetch', '+refs/heads/*:refs/remotes/mirror/*');
595 $self->exe('git', 'fetch', ($mirror ? $mirror : $url));
598 my $template = getcwd()."/../.commit-template";
600 $self->exe('git', 'config', 'commit.template', $template);
603 $self->git_add_remotes($submodule);
605 if ($self->{'detach-alternates'}) {
606 $self->exe('git', 'repack', '-a');
608 my $alternates_path = '.git/objects/info/alternates';
609 unlink($alternates_path) || confess "unlink $alternates_path: $OS_ERROR";
612 if ($submodule eq "qtbase" || $submodule eq "qtdeclarative") { #Extra steps needed to setup base and declarative
613 $self->exe('git', 'submodule', 'init');
614 if ($mirror_v8_url || $protocol eq 'http') {
615 my @configresult = qx(git config -l);
617 foreach my $line (@configresult) {
618 # Example line: submodule.qtqa.url=git://gitorious.org/qt/qtqa.git
619 next if ($line !~ /submodule.src\/3rdparty\/v8.url=(.*)/);
624 if ($protocol eq 'http') {
625 # rewrite the git:// url to https://
626 if ($v8url =~ s{^git://github}{https://github}) {
627 $self->exe('git', 'config', 'submodule.src/3rdparty/v8.url', $v8url);
630 warn 'You requested git over http, but I could not figure out how to '
631 ."rewrite v8's giturl of $v8url";
635 if ($mirror_v8_url && $do_clone) {
636 chdir('src/3rdparty/') or confess "chdir $submodule/src/3rdparty: $OS_ERROR";
637 $self->exe('git', 'clone', $mirror_v8_url, 'v8');
638 chdir('v8') or confess "chdir $submodule/src/3rdparty/v8: $OS_ERROR";
639 $self->exe('git', 'config', 'remote.origin.url', $v8url);
640 chdir('../../..') or confess "cd ../../..: $OS_ERROR";
644 $self->exe('git', 'submodule', 'update');
647 chdir("..") or confess "cd ..: $OS_ERROR";
656 $self->check_if_already_initialized;
657 $self->git_submodule_init;
659 if (!$self->{webkit}) {
660 $self->git_disable_webkit_submodule;
663 if ($self->{'module-subset'}) {
664 $self->git_prune_submodules;
667 $self->git_set_submodule_config;
669 if ($self->{update}) {
670 $self->git_clone_all_submodules;
673 $self->git_add_remotes('qt5');
678 #==============================================================================
680 Qt::InitRepository->new(@ARGV)->run if (!caller);