From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [OSSTEST PATCH 04/13] BuildSupport: Provide some support for git submodules Date: Fri, 16 May 2014 19:01:31 +0100 Message-ID: <1400263300-22903-5-git-send-email-ian.jackson@eu.citrix.com> References: <1400263300-22903-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WlMSe-0002E1-Va for xen-devel@lists.xenproject.org; Fri, 16 May 2014 18:02:25 +0000 In-Reply-To: <1400263300-22903-1-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org * Provide a new "submodulefixup" function which, given a cloned tree which has submodules: - massages the .gitmodules file according to the tree_* runvars and massage_url - arranges for the submodules to be fetched and checked out - stores the revisions of the submodules, as necessary - honours any revision_ tags for the submodules - allows the caller to give the submodules names which are suitable for use in runvars etc. (and might differ from the names or paths used in the supermodule) * In a submodule, .git is actually a file containing a reference to a subdirectory of the main git tree. Cope with that. Signed-off-by: Ian Jackson --- Osstest/BuildSupport.pm | 60 +++++++++++++++++++++++++++++++++++++++++++++++ Osstest/TestSupport.pm | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Osstest/BuildSupport.pm b/Osstest/BuildSupport.pm index 1b15557..9a43f00 100644 --- a/Osstest/BuildSupport.pm +++ b/Osstest/BuildSupport.pm @@ -43,6 +43,8 @@ BEGIN { xendist $xendist + submodulefixup + ); %EXPORT_TAGS = ( ); @@ -90,4 +92,62 @@ sub xendist () { target_cmd($ho, "tar -C $xendist -hzxf $distcopy", 300); } +#----- submodules ----- + +sub submodulefixup ($$$$) { + my ($ho, $subdir, $basewhich, $submodmap) = @_; + + my @submodules; + target_editfile($ho, "$builddir/$subdir/.gitmodules", + "$subdir-gitmodules", sub { + my $submod; + my $log1 = sub { logm("submodule $submod->{OurName} @_"); }; + while (<::EI>) { + if (m/^\[submodule \"(.*)\"\]$/) { + $submod = { TheirName => $1 }, + push @submodules, $submod; + my $mapped = $submodmap->{$1}; + die "unknown submodule $1" unless defined $mapped; + $submod->{OurName} = $mapped; + $log1->("($submod->{TheirName}):"); + } elsif (m/^\s*path\s*=\s*(\S+)/) { + die unless $submod; + $submod->{Path} = $1; + $log1->(" subpath=$submod->{Path}"); + } elsif (m/^(\s*url\s*\=\s*)(\S+)/) { + die unless $submod; + my $l = $1; + my $u = $submod->{OrgUrl} = $2; + my $urv = "tree_${basewhich}_$submod->{OurName}"; + if (length $r{$urv}) { + $log1->(" overriding url=$u with runvar $urv=$r{$urv}"); + $u = $r{$urv}; + } else { + $log1->(" recording url=$u"); + store_runvar($urv, $u); + } + my $nu = $submod->{Url} = git_massage_url($u); + $_ = "${l}${nu}\n"; + } + print ::EO or die $!; + } + }); + + target_cmd_build($ho, 60,"$builddir/$subdir","git submodule init"); + target_cmd_build($ho,3600,"$builddir/$subdir","git submodule update"); + + foreach my $submod (@submodules) { + my $wantrev = $r{"revision_${basewhich}_$submod->{OurName}"}; + if (length $wantrev) { + target_cmd_build($ho,200,"$builddir/$subdir/$submod->{Path}", + "git reset --hard $wantrev"); + } else { + store_revision($ho, "${basewhich}_$submod->{OurName}", + "$builddir/$subdir/$submod->{Path}"); + } + } + + return \@submodules; +} + 1; diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm index 1492d9f..49bb175 100644 --- a/Osstest/TestSupport.pm +++ b/Osstest/TestSupport.pm @@ -1087,7 +1087,7 @@ sub dir_identify_vcs ($$) { set -e if ! test -e $dir; then echo none; exit 0; fi cd $dir - (test -d .git && echo git) || + (test -e .git && echo git) || (test -d .hg && echo hg) || (echo >&2 'unable to determine vcs'; fail) END -- 1.7.10.4