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 #############################################################################
46 package Qt::InitRepository;
51 init-repository - initialize the Qt5 repository and all submodules
55 ./init-repository [options]
57 This script may be run after an initial `git clone' of Qt5 in order to check
69 Force initialization (even if the submodules are already checked out).
74 Be quiet. Will exit cleanly if the repository is already initialized.
85 Skip webkit and webkit examples submodules.
86 It may be desirable to skip these modules due to the large size of the webkit
92 Skip the `git submodule update' command.
95 =item --ignore-submodules
97 Set git config to ignore submodules by default when doing operations on the
98 qt5 repo, such as `pull', `fetch', `diff' etc.
100 After using this option, pass `--ignore-submodules=none' to git to override
106 B<Repository options:>
110 =item --nokia-developer
112 Switch to internal Nokia URLs.
117 Switch to internal Nokia URLs and make use of the Brisbane git mirrors.
118 (Implies `--mirror' and `--mirror-webkit').
123 Use the SSH protocol for git operations. This may be useful if the git
124 protocol is blocked by a firewall. Note that this requires a user account
125 with an uploaded SSH key on all servers used. (Implies `--nokia-developer').
130 Use the HTTP protocol for git operations. This may be useful if the git
131 protocol is blocked by a firewall. Note that this only works with the
132 external Gitorious server.
135 =item --alternates <path to other Qt5 repo>
137 Adds alternates for each submodule to another full qt5 checkout. This makes
138 this qt5 checkout very small, as it will use the object store of the
139 alternates before unique objects are stored in its own object store.
141 This option has no effect when using `--no-update'.
143 B<NOTE:> This will make this repo dependent on the alternate, which is
144 potentially dangerous! The dependency can be broken by also using
145 the `--copy-objects' option, or by running C<git repack -a> in each
146 submodule, where required. Please read the note about the `--shared' option
147 in the documentation of `git clone' for more information.
152 When `--alternates' is used, automatically do a C<git repack -a> in each
153 submodule after cloning, to ensure that the repositories are independent
154 from the source used as a reference for cloning.
156 Note that this negates the disk usage benefits gained from the use of
160 =item --mirror <url-base>
162 Uses <url-base> as the base URL for submodule git mirrors.
166 --mirror user@machine:/foo/bar
168 ...will use the following as a mirror for qtbase:
170 user@machine:/foo/bar/qtbase.git
173 =item --mirror-webkit <url>
175 Uses <url> as the URL for the webkit git mirror.
181 use Carp qw( confess );
182 use English qw( -no_match_vars );
183 use Getopt::Long qw( GetOptionsFromArray );
184 use Pod::Usage qw( pod2usage );
185 use Cwd qw( getcwd );
188 'internal' => 'git://scm.dev.nokia.troll.no/' ,
189 'ssh' => 'git@scm.dev.nokia.troll.no:' ,
190 'http' => 'http://git.gitorious.org/' ,
193 my %STAGING_REPOS = map { $_ => "git://gitorious.org/qt/$_.git" } qw(
199 qtdeclarative-staging
207 qttranslations-staging
208 qtwebkit-examples-and-demos-staging
209 qtxmlpatterns-staging
213 my $BNE_MIRROR_URL_BASE
214 = 'git://bq-git.apac.nokia.com/qtsoftware/qt/';
216 my $BNE_MIRROR_WEBKIT_URL
217 = 'git://bq-git.apac.nokia.com/qtsoftware/research/gitorious-org-webkit-qtwebkit-mirror.git';
221 my ($class, @arguments) = @_;
225 $self->parse_arguments(@arguments);
230 # Like `system', but possibly log the command, and die on non-zero exit code
233 my ($self, @cmd) = @_;
235 if (!$self->{quiet}) {
239 if (system(@cmd) != 0) {
240 confess "@cmd exited with status $CHILD_ERROR";
248 my ($self, @args) = @_;
250 %{$self} = (%{$self},
252 'detach-alternates' => 0 ,
254 'ignore-submodules' => 0 ,
256 'mirror-webkit-url' => "",
257 'nokia-developer' => 0 ,
263 GetOptionsFromArray(\@args,
264 'alternates=s' => \$self->{qw{ alternates }},
265 'copy-objects' => \$self->{qw{ detach-alternates }},
266 'force' => \$self->{qw{ force }},
267 'ignore-submodules' => \$self->{qw{ ignore_submodules }},
268 'mirror-webkit=s' => \$self->{qw{ mirror-webkit-url }},
269 'mirror=s' => \$self->{qw{ mirror-url }},
270 'nokia-developer' => \$self->{qw{ nokia-developer }},
271 'quiet' => \$self->{qw{ quiet }},
272 'update!' => \$self->{qw{ update }},
273 'webkit!' => \$self->{qw{ webkit }},
275 'help|?' => sub { pod2usage(1); },
276 'http' => sub { $self->{protocol} = 'http'; },
277 'ssh|ssh-protocol' => sub { $self->{protocol} = 'ssh'; },
279 'brisbane|brisbane-nokia-developer' => sub {
280 $self->{'nokia-developer'} = 1;
281 $self->{'protocol'} = 'internal';
282 $self->{'mirror-url'} = $BNE_MIRROR_URL_BASE;
283 $self->{'mirror-webkit-url'} = $BNE_MIRROR_WEBKIT_URL;
286 'nokia-developer' => sub {
287 $self->{'nokia-developer'} = 1;
288 $self->{'protocol'} = 'internal';
292 if ($self->{'nokia-developer'} && $self->{'protocol'} eq 'http') {
293 print "*** Ignoring use of HTTP protocol, as it's only usable with external server\n";
294 $self->{'protocol'} = '';
297 # Replace any double trailing slashes from end of mirror
298 $self->{'mirror-url'} =~ s{//+$}{/};
303 sub check_if_already_initialized
307 # We consider the repo as `initialized' if submodule.qtbase.url is set
308 if (qx(git config --get submodule.qtbase.url)) {
309 if ($self->{force}) {
310 my @configresult = qx(git config -l);
311 foreach (@configresult) {
312 # Example line: submodule.qtqa.url=git://gitorious.org/qt/qtqa.git
313 if (/(submodule\.[^.=]+)\.url=.*/) {
314 $self->exe('git', 'config', '--remove-section', $1);
319 exit 0 if ($self->{quiet});
320 print "Will not reinitialize already initialized repository (use -f to force)!\n";
328 sub git_submodule_init
333 if ($self->{quiet}) {
334 push @init_args, '--quiet';
336 $self->exe('git', 'submodule', 'init', @init_args);
338 my $template = getcwd()."/.commit-template";
340 $self->exe('git', 'config', 'commit.template', $template);
346 sub git_disable_webkit_submodule
350 $self->exe('git', 'config', '--remove', 'submodule.qtwebkit');
351 $self->exe('git', 'config', '--remove', 'submodule.qtwebkit-examples-and-demos');
356 sub git_set_submodule_config
360 my @configresult = qx(git config -l);
361 my $protocol = $self->{protocol};
362 my $url_base_for_protocol = $PROTOCOLS{$protocol};
365 foreach my $line (@configresult) {
366 # Example line: submodule.qtqa.url=git://gitorious.org/qt/qtqa.git
367 next GITCONFIG if ($line !~ /(submodule\.[^.=]+\.url)=(.*)/);
373 # WebKit is special, and has only external link.
374 if ($key ne 'submodule.qtwebkit.url') {
375 # qt-labs projects are still hosted under qt internally.
376 if ($protocol ne 'http') {
377 $value =~ s,^git://gitorious\.org/qt-labs/,${url_base_for_protocol}qt/,;
379 $value =~ s,^git://gitorious\.org/,$url_base_for_protocol,;
383 $self->exe('git', 'config', $key, $value);
385 if ($self->{'ignore-submodules'}) {
386 $key =~ s,\.url,.ignore,;
387 $self->exe('git', 'config', $key, 'all');
394 sub git_clone_all_submodules
398 # manually clone each repo here, so we can easily use reference repos, mirrors and
399 # add all staging repos
400 my @configresult = qx(git config -l);
401 foreach my $line (@configresult) {
402 if ($line =~ /submodule\.([^.=]+)\.url=(.*)/) {
403 $self->git_clone_one_submodule($1, $2);
407 $self->exe('git', 'submodule', 'update');
412 sub git_add_staging_remote
414 my ($self, $repo_basename) = @_;
416 my $protocol = $self->{protocol};
417 my $url_base_for_protocol = $PROTOCOLS{$protocol};
420 for my $line (qx(git remote show)) {
422 $current_remotes{$line} = 1;
425 # We assume that any staging starting with `$repo_basename-' relates to this
426 # repo. For example, for the `qtbase' module, `qtbase-staging'
427 # and `qtbase-earth-staging' are considered as related staging repos.
428 my @staging = grep { /^\Q$repo_basename\E-/; } keys %STAGING_REPOS;
431 foreach my $staging_repo (@staging) {
432 # nothing to do if remote already exists
433 next STAGING if ($current_remotes{$staging_repo});
435 my $staging_repo_url = $STAGING_REPOS{$staging_repo};
437 if ($protocol ne 'http') {
438 $staging_repo_url =~ s,^git://gitorious\.org/qt-labs/,${url_base_for_protocol}qt/,;
440 $staging_repo_url =~ s,^git://gitorious\.org/,$url_base_for_protocol,;
442 $self->exe('git', 'remote', 'add', $staging_repo, $staging_repo_url);
448 sub git_clone_one_submodule
450 my ($self, $submodule, $url) = @_;
452 my $alternates = $self->{ 'alternates' };
453 my $mirror_url = $self->{ 'mirror-url' };
454 my $mirror_webkit_url = $self->{ 'mirror-webkit-url' };
456 # `--reference FOO' args for the clone, if any.
460 # alternates is a qt5 repo, so the submodule will be under that.
461 if (-d "$alternates/$submodule") {
462 @reference_args = ('--reference', "$alternates/$submodule");
465 print " *** $alternates/$submodule not found, ignoring alternate for this submodule\n";
470 if ($mirror_url && ($submodule ne 'qtwebkit')) {
471 $mirror = $mirror_url.$submodule;
472 $mirror .= ".git" unless (-d $mirror); # Support local disk mirror
474 elsif ($mirror_webkit_url && ($submodule eq 'qtwebkit')) {
475 $mirror = $mirror_webkit_url;
478 my $do_clone = (! -d "$submodule/.git");
480 $self->exe('git', 'clone', @reference_args, ($mirror ? $mirror : $url), $submodule);
483 chdir($submodule) or confess "chdir $submodule: $OS_ERROR";
486 $self->exe('git', 'fetch', ($mirror ? $mirror : $url));
489 my $template = getcwd()."/../.commit-template";
491 $self->exe('git', 'config', 'commit.template', $template);
495 $self->exe('git', 'config', 'remote.origin.url', $url);
497 # In `force' mode, remove the mirror if it already exists,
498 # since we may be reinitializing the module.
499 if ($self->{force}) {
500 eval { $self->exe('git', 'remote', 'rm', 'mirror'); }; # failure is OK
503 $self->exe('git', 'remote', 'add', 'mirror', $mirror);
506 $self->git_add_staging_remote($submodule);
508 if ($self->{'detach-alternates'}) {
509 $self->exe('git', 'repack', '-a');
511 my $alternates_path = '.git/objects/info/alternates';
512 unlink($alternates_path) || confess "unlink $alternates_path: $OS_ERROR";
515 chdir("..") or confess "cd ..: $OS_ERROR";
524 $self->check_if_already_initialized;
525 $self->git_submodule_init;
527 if (!$self->{webkit}) {
528 $self->git_disable_webkit_submodule;
531 $self->git_set_submodule_config;
533 if ($self->{update}) {
534 $self->git_clone_all_submodules;
537 $self->git_add_staging_remote('qt5');
542 #==============================================================================
544 Qt::InitRepository->new(@ARGV)->run if (!caller);