2 #############################################################################
4 ## Copyright (C) 2011 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 ## No Commercial Usage
12 ## This file contains pre-release code and may not be distributed.
13 ## You may use this file in accordance with the terms and conditions
14 ## contained in the Technology Preview License Agreement accompanying
17 ## GNU Lesser General Public License Usage
18 ## Alternatively, this file may be used under the terms of the GNU Lesser
19 ## General Public License version 2.1 as published by the Free Software
20 ## Foundation and appearing in the file LICENSE.LGPL included in the
21 ## packaging of this file. Please review the following information to
22 ## ensure the GNU Lesser General Public License version 2.1 requirements
23 ## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ## In addition, as a special exception, Nokia gives you certain additional
26 ## rights. These rights are described in the Nokia Qt LGPL Exception
27 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ## If you have questions regarding the use of this file, please contact
30 ## Nokia at qt-info@nokia.com.
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
93 Skip the `git submodule update' command.
96 =item --ignore-submodules
98 Set git config to ignore submodules by default when doing operations on the
99 qt5 repo, such as `pull', `fetch', `diff' etc.
101 This option is default for --nokia-developer/--brisbane.
103 After using this option, pass `--ignore-submodules=none' to git to override
109 B<Repository options:>
113 =item --nokia-developer
115 Switch to internal Nokia URLs.
120 Switch to internal Nokia URLs and make use of the Brisbane git mirrors.
121 (Implies `--mirror' and `--mirror-webkit').
125 Switch to internal Nokia URLs and make use of the Berlin git mirrors.
126 (Implies `--mirror' and `--mirror-webkit').
131 Use the SSH protocol for git operations. This may be useful if the git
132 protocol is blocked by a firewall. Note that this requires a user account
133 with an uploaded SSH key on all servers used. (Implies `--nokia-developer').
138 Use the HTTP protocol for git operations. This may be useful if the git
139 protocol is blocked by a firewall. Note that this only works with the
140 external Gitorious server.
143 =item --codereview-username <Gerrit/JIRA username>
145 Adds a gerrit alias to repos under Gerrit codereview management.
146 This requires a username for SSH access to the codereview.qt.nokia.com
147 server, which will be the same username you have for the bugtracker at
148 bugreports.qt.nokia.com.
151 =item --alternates <path to other Qt5 repo>
153 Adds alternates for each submodule to another full qt5 checkout. This makes
154 this qt5 checkout very small, as it will use the object store of the
155 alternates before unique objects are stored in its own object store.
157 This option has no effect when using `--no-update'.
159 B<NOTE:> This will make this repo dependent on the alternate, which is
160 potentially dangerous! The dependency can be broken by also using
161 the `--copy-objects' option, or by running C<git repack -a> in each
162 submodule, where required. Please read the note about the `--shared' option
163 in the documentation of `git clone' for more information.
168 When `--alternates' is used, automatically do a C<git repack -a> in each
169 submodule after cloning, to ensure that the repositories are independent
170 from the source used as a reference for cloning.
172 Note that this negates the disk usage benefits gained from the use of
176 =item --mirror <url-base>
178 Uses <url-base> as the base URL for submodule git mirrors.
182 --mirror user@machine:/foo/bar
184 ...will use the following as a mirror for qtbase:
186 user@machine:/foo/bar/qtbase.git
189 =item --mirror-webkit <url>
191 Uses <url> as the URL for the webkit git mirror.
197 use Carp qw( confess );
198 use English qw( -no_match_vars );
199 use Getopt::Long qw( GetOptionsFromArray );
200 use Pod::Usage qw( pod2usage );
201 use Cwd qw( getcwd );
204 'internal' => 'git://scm.dev.nokia.troll.no/' ,
205 'ssh' => 'git@scm.dev.nokia.troll.no:' ,
206 'http' => 'http://git.gitorious.org/' ,
209 my %STAGING_REPOS = map { $_ => "git://gitorious.org/qt/$_-staging.git" } qw(
223 qtwebkit-examples-and-demos
230 my %GERRIT_REPOS = map { $_ => "codereview.qt.nokia.com:qt/$_.git" } qw(
237 my $BNE_MIRROR_URL_BASE
238 = 'git://bq-git.apac.nokia.com/qtsoftware/qt/';
240 my $BNE_MIRROR_WEBKIT_URL
241 = 'git://bq-git.apac.nokia.com/qtsoftware/research/gitorious-org-webkit-qtwebkit-mirror.git';
243 my $BER_MIRROR_URL_BASE
244 = 'git://ber-git.europe.nokia.com/qt/';
246 my $BER_MIRROR_WEBKIT_URL
247 = 'git://ber-git.europe.nokia.com/qtwebkit/qtwebkit.git';
252 my ($class, @arguments) = @_;
256 $self->parse_arguments(@arguments);
261 # Like `system', but possibly log the command, and die on non-zero exit code
264 my ($self, @cmd) = @_;
266 if (!$self->{quiet}) {
270 if (system(@cmd) != 0) {
271 confess "@cmd exited with status $CHILD_ERROR";
279 my ($self, @args) = @_;
281 %{$self} = (%{$self},
283 'codereview-username' => "",
284 'detach-alternates' => 0 ,
286 'ignore-submodules' => 0 ,
288 'mirror-webkit-url' => "",
289 'nokia-developer' => 0 ,
295 GetOptionsFromArray(\@args,
296 'alternates=s' => \$self->{qw{ alternates }},
297 'codereview-username=s' => \$self->{qw{ codereview-username }},
298 'copy-objects' => \$self->{qw{ detach-alternates }},
299 'force' => \$self->{qw{ force }},
300 'ignore-submodules' => \$self->{qw{ ignore-submodules }},
301 'mirror-webkit=s' => \$self->{qw{ mirror-webkit-url }},
302 'mirror=s' => \$self->{qw{ mirror-url }},
303 'nokia-developer' => \$self->{qw{ nokia-developer }},
304 'quiet' => \$self->{qw{ quiet }},
305 'update!' => \$self->{qw{ update }},
306 'webkit!' => \$self->{qw{ webkit }},
308 'help|?' => sub { pod2usage(1); },
309 'http' => sub { $self->{protocol} = 'http'; },
310 'ssh|ssh-protocol' => sub { $self->{protocol} = 'ssh'; },
312 'brisbane|brisbane-nokia-developer' => sub {
313 $self->{'nokia-developer'} = 1;
314 $self->{'protocol'} = 'internal';
315 $self->{'mirror-url'} = $BNE_MIRROR_URL_BASE;
316 $self->{'mirror-webkit-url'} = $BNE_MIRROR_WEBKIT_URL;
317 $self->{'ignore-submodules'} = 1;
320 'berlin|berlin-nokia-developer' => sub {
321 $self->{'nokia-developer'} = 1;
322 $self->{'protocol'} = 'internal';
323 $self->{'mirror-url'} = $BER_MIRROR_URL_BASE;
324 $self->{'mirror-webkit-url'} = $BER_MIRROR_WEBKIT_URL;
327 'nokia-developer' => sub {
328 $self->{'nokia-developer'} = 1;
329 $self->{'protocol'} = 'internal';
330 $self->{'ignore-submodules'} = 1;
334 if ($self->{'nokia-developer'} && $self->{'protocol'} eq 'http') {
335 print "*** Ignoring use of HTTP protocol, as it's only usable with external server\n";
336 $self->{'protocol'} = '';
339 # Replace any double trailing slashes from end of mirror
340 $self->{'mirror-url'} =~ s{//+$}{/};
345 sub check_if_already_initialized
349 # We consider the repo as `initialized' if submodule.qtbase.url is set
350 if (qx(git config --get submodule.qtbase.url)) {
351 if ($self->{force}) {
352 my @configresult = qx(git config -l);
353 foreach (@configresult) {
354 # Example line: submodule.qtqa.url=git://gitorious.org/qt/qtqa.git
355 if (/(submodule\.[^.=]+)\.url=.*/) {
356 $self->exe('git', 'config', '--remove-section', $1);
361 exit 0 if ($self->{quiet});
362 print "Will not reinitialize already initialized repository (use -f to force)!\n";
370 sub git_submodule_init
375 if ($self->{quiet}) {
376 push @init_args, '--quiet';
378 $self->exe('git', 'submodule', 'init', @init_args);
380 my $template = getcwd()."/.commit-template";
382 $self->exe('git', 'config', 'commit.template', $template);
388 sub git_disable_webkit_submodule
392 $self->exe('git', 'config', '--remove', 'submodule.qtwebkit');
393 $self->exe('git', 'config', '--remove', 'submodule.qtwebkit-examples-and-demos');
398 sub git_set_submodule_config
402 my @configresult = qx(git config -l);
403 my $protocol = $self->{protocol};
404 my $url_base_for_protocol = $PROTOCOLS{$protocol};
406 foreach my $line (@configresult) {
407 # Example line: submodule.qtqa.url=git://gitorious.org/qt/qtqa.git
408 next if ($line !~ /(submodule\.[^.=]+\.url)=(.*)/);
414 # WebKit is special, and has only external link.
415 if ($key ne 'submodule.qtwebkit.url') {
416 # qt-labs projects are still hosted under qt internally.
417 if ($protocol ne 'http') {
418 $value =~ s,^git://gitorious\.org/qt-labs/,${url_base_for_protocol}qt/,;
420 $value =~ s,^git://gitorious\.org/,$url_base_for_protocol,;
424 $self->exe('git', 'config', $key, $value);
426 if ($self->{'ignore-submodules'}) {
427 $key =~ s,\.url,.ignore,;
428 $self->exe('git', 'config', $key, 'all');
435 sub git_clone_all_submodules
439 # manually clone each repo here, so we can easily use reference repos, mirrors and
440 # add all staging repos
441 my @configresult = qx(git config -l);
442 foreach my $line (@configresult) {
443 if ($line =~ /submodule\.([^.=]+)\.url=(.*)/) {
444 $self->git_clone_one_submodule($1, $2);
448 $self->exe('git', 'submodule', 'update');
455 my ($self, $repo_basename) = @_;
457 my $protocol = $self->{protocol};
458 my $url_base_for_protocol = $PROTOCOLS{$protocol};
461 for my $line (qx(git remote show)) {
463 $current_remotes{$line} = 1;
466 my @gerrit = grep { /^$repo_basename$/; } keys %GERRIT_REPOS;
467 if (!$current_remotes{'gerrit'} && $self->{'codereview-username'}) {
468 foreach my $gerrit_repo (@gerrit) {
469 my $gerrit_repo_url = $GERRIT_REPOS{$gerrit_repo};
470 $self->exe('git', 'remote', 'add', 'gerrit', $self->{'codereview-username'}."@".$gerrit_repo_url);
474 my @staging = grep { /^$repo_basename$/; } keys %STAGING_REPOS;
475 if (!$current_remotes{'staging'}) {
476 foreach my $staging_repo (@staging) {
477 my $staging_repo_url = $STAGING_REPOS{$staging_repo};
479 if ($protocol ne 'http') {
480 $staging_repo_url =~ s,^git://gitorious\.org/qt-labs/,${url_base_for_protocol}qt/,;
482 $staging_repo_url =~ s,^git://gitorious\.org/,$url_base_for_protocol,;
484 $self->exe('git', 'remote', 'add', 'staging', $staging_repo_url);
488 # if repo has no staging repo defined, alias it to gerrit or origin
489 if (!$current_remotes{'staging'} && !@staging) {
490 my @configresult = qx(git remote -v);
492 foreach (@configresult) {
493 if (/^gerrit\s+(\S+) \(fetch\)/) {
494 $self->exe('git', 'remote', 'add', 'staging', $1);
498 unless($staging_set) {
499 foreach (@configresult) {
500 if (/^origin\s+(\S+) \(fetch\)/) {
501 $self->exe('git', 'remote', 'add', 'staging', $1);
506 #if repo has no gerrit repo defined, alias it to whatever staging now points to (could be origin)
507 if (!$current_remotes{'gerrit'} && !@gerrit) {
508 my @configresult = qx(git remote -v);
509 foreach (@configresult) {
510 if (/^staging\s+(\S+) \(fetch\)/) {
511 $self->exe('git', 'remote', 'add', 'gerrit', $1);
519 sub git_clone_one_submodule
521 my ($self, $submodule, $url) = @_;
523 my $alternates = $self->{ 'alternates' };
524 my $mirror_url = $self->{ 'mirror-url' };
525 my $mirror_webkit_url = $self->{ 'mirror-webkit-url' };
527 # `--reference FOO' args for the clone, if any.
531 # alternates is a qt5 repo, so the submodule will be under that.
532 if (-d "$alternates/$submodule") {
533 @reference_args = ('--reference', "$alternates/$submodule");
536 print " *** $alternates/$submodule not found, ignoring alternate for this submodule\n";
541 if ($mirror_url && ($submodule ne 'qtwebkit')) {
542 $mirror = $mirror_url.$submodule;
543 $mirror .= ".git" unless (-d $mirror); # Support local disk mirror
545 elsif ($mirror_webkit_url && ($submodule eq 'qtwebkit')) {
546 $mirror = $mirror_webkit_url;
549 my $do_clone = (! -d "$submodule/.git");
551 $self->exe('git', 'clone', @reference_args, ($mirror ? $mirror : $url), $submodule);
554 chdir($submodule) or confess "chdir $submodule: $OS_ERROR";
557 $self->exe('git', 'fetch', ($mirror ? $mirror : $url));
560 my $template = getcwd()."/../.commit-template";
562 $self->exe('git', 'config', 'commit.template', $template);
566 $self->exe('git', 'config', 'remote.origin.url', $url);
568 # In `force' mode, remove the mirror if it already exists,
569 # since we may be reinitializing the module.
570 if ($self->{force}) {
571 eval { $self->exe('git', 'remote', 'rm', 'mirror'); }; # failure is OK
574 $self->exe('git', 'remote', 'add', 'mirror', $mirror);
577 $self->git_add_remotes($submodule);
579 if ($self->{'detach-alternates'}) {
580 $self->exe('git', 'repack', '-a');
582 my $alternates_path = '.git/objects/info/alternates';
583 unlink($alternates_path) || confess "unlink $alternates_path: $OS_ERROR";
586 if ($submodule eq "qtdeclarative") { #Extra step needed to setup declarative
587 $self->exe('git', 'submodule', 'init');
588 $self->exe('git', 'submodule', 'update');
591 chdir("..") or confess "cd ..: $OS_ERROR";
600 $self->check_if_already_initialized;
601 $self->git_submodule_init;
603 if (!$self->{webkit}) {
604 $self->git_disable_webkit_submodule;
607 $self->git_set_submodule_config;
609 if ($self->{update}) {
610 $self->git_clone_all_submodules;
613 $self->git_add_remotes('qt5');
618 #==============================================================================
620 Qt::InitRepository->new(@ARGV)->run if (!caller);