build: Add support to use a git tree as reference

This helps to test experimental trees.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
Mauro Carvalho Chehab
2011-08-02 16:21:08 -03:00
parent 92c851c430
commit 65153279b2

128
build
View File

@@ -11,11 +11,13 @@ my $level = 0;
my $help = 0;
my $man = 0;
my $check_only = 0;
my @git;
GetOptions('v|verbose' => \$level,
'help|?' => \$help,
man => \$man,
'check_only|check-only' => \$check_only,
'git=s{2}' => \@git,
) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
@@ -161,6 +163,37 @@ sub check_needs()
print "Needed package dependencies are met.\n";
}
######
# Git
######
sub get_remote_name()
{
if ($git[0] =~ m,^(http|git|git\+ssh|ssh):\/\/linuxtv.org\/(.*),) {
my $name = $2;
$name =~ s,^/git,,;
$name =~ s,\.git$,,g;
$name =~ s,/,_,g;
return $name;
}
die "Invalid URL. Need to use one from linuxtv.org site\n";
}
sub check_git($$)
{
my $cmd = shift;
my $remote = shift;
print "\$ git --git-dir media/.git $cmd\n" if ($level);
open IN, "git --git-dir media/.git $cmd|" or die "can't run git --git-dir media/.git $cmd";
while (<IN>) {
return 1 if (m/^[\*]*\s*($remote)\n$/);
}
close IN;
return 0;
}
######
# Main
######
@@ -169,26 +202,79 @@ check_needs;
exit (0) if ($check_only);
print "\n";
print "************************************************************\n";
print "* This script will download the latest tarball and build it*\n";
print "* Assuming that your kernel is compatible with the latest *\n";
print "* drivers. If not, you'll need to add some extra backports,*\n";
print "* ./backports/<kernel> directory. *\n";
print "* It will also update this tree to be sure that all compat *\n";
print "* bits are there, to avoid compilation failures *\n";
print "************************************************************\n";
print "\n";
if (@git == 2) {
my $rname = get_remote_name();
sleep 5;
print "\n";
print "************************************************************\n";
print "* This script will use a git tree as the reference for the *\n";
print "* media drivers. This build system takes into accont only *\n";
print "* the main repository, and the latest staging branch. *\n";
print "* Trying to compile an old experimental tree will likely *\n";
print "* fail, as the backport patches may not fit on the needs *\n";
print "************************************************************\n";
print "\n";
print "****************************\n";
print "Updating the building system\n";
print "****************************\n";
system("git pull git://linuxtv.org/media_build.git master");
sleep 3;
if (!stat "./media/.git/config") {
print "Getting the latest Kernel tree. This will take some time\n";
system("git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git media") == 0
or die "Can't clone from the upstream tree";
} else {
system("git --git-dir media/.git remote update origin") == 0
or die "Can't update from the upstream tree";
}
if (!check_git("remote", "r_$rname")) {
print "adding remote r_$rname to track $git[0], $git[1]\n";
printf "\$ git --git-dir media/.git remote add r_$rname $git[0] $git[1]\n" if ($level);
system ("git --git-dir media/.git remote add r_$rname $git[0] $git[1]") == 0
or die "Can't create remote r_$rname";
}
print "updating remote $rname\n";
system ("git --git-dir media/.git remote update r_$rname") == 0
or die "Can't update remote r_$rname";
print "creating a local branch $rname\n";
if (!check_git("branch", "$rname/$git[1]")) {
print "\$ (cd media; git checkout -b $rname/$git[1] remotes/r_$rname/$git[1])\n" if ($level);
system ("(cd media; git checkout -b $rname/$git[1] remotes/r_$rname/$git[1])") == 0
or die "Can't create local branch $rname";
} else {
system ("(cd media; git checkout $rname/$git[1])") == 0
or die "Can't checkout to branch $rname";
system ("(cd media; git pull . remotes/r_$rname/$git[1])") == 0
or die "Can't update local branch $rname";
}
system ("make -C linux dir DIR=../media/") == 0
or die "Can't link the building system to the media directory.";
} else {
print "\n";
print "************************************************************\n";
print "* This script will download the latest tarball and build it*\n";
print "* Assuming that your kernel is compatible with the latest *\n";
print "* drivers. If not, you'll need to add some extra backports,*\n";
print "* ./backports/<kernel> directory. *\n";
print "* It will also update this tree to be sure that all compat *\n";
print "* bits are there, to avoid compilation failures *\n";
print "************************************************************\n";
print "\n";
sleep 5;
print "****************************\n";
print "Updating the building system\n";
print "****************************\n";
system("git pull git://linuxtv.org/media_build.git master");
system ("make -C linux/ download") == 0 or die "Download failed";
system ("make -C linux/ untar") == 0 or die "Untar failed";
}
system ("make allyesconfig") == 0 or die "can't select all drivers";
system ("make -C linux/ download") == 0 or die "Download failed";
system ("make -C linux/ untar") == 0 or die "Untar failed";
system ("make") == 0 or die "build failed";
print "**********************************************************\n";
@@ -204,7 +290,7 @@ build - Builds the media drivers without needing to compile a new kernel
=head1 SYNOPSIS
build [options]
build [--help] [--man] [--verbose] [--check_only] [<--git> [URL] [BRANCH]]
=head1 OPTIONS
@@ -226,6 +312,12 @@ Be more verbose.
Don't do anything, except for checking if the needed dependencies are there.
=item B<--git> [URL] [BRANCH]
Allows specifying a URL and a git branch, instead of the default ones.
Currently, only linuxtv.org git URL's are supported, as the build needs to
warrant an unique namespace for git remotes.
=back
=head1 DESCRIPTION