From 6654e8a1ba0077217c5b3c9d17ec2d154d199dc3 Mon Sep 17 00:00:00 2001 From: Don Slutz Date: Wed, 30 Oct 2013 13:33:07 -0400 Subject: [PATCH 1/5] Adjust to use rpmbuild Signed-off-by: Don Slutz --- gen_version.pl | 391 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ update_config.pl | 109 ++++++++++++++++ xen-4.4.spec | 131 +++++++++++++++++++ 3 files changed, 631 insertions(+) create mode 100755 gen_version.pl create mode 100755 update_config.pl create mode 100644 xen-4.4.spec diff --git a/gen_version.pl b/gen_version.pl new file mode 100755 index 0000000..08ab7e6 --- /dev/null +++ b/gen_version.pl @@ -0,0 +1,391 @@ +#! /usr/bin/perl -w +# -*- Mode: cperl; coding: utf-8; cperl-indent-level: 2 -*- + +use strict; + +my $debug = 0; +my $cygwin = $^O eq 'cygwin'; +my $brief = 0; +my $major = 0; +my $minor = 0; +my $patch = 0; +my $clean = 0; +my $update = 0; +my $tags = ' --tags'; +my $xen_conf = 0; + +while ((defined $ARGV[0]) && + (substr($ARGV[0],0,1) eq '-')) { + my $opts = shift @ARGV; + if ($opts =~ /^-d(\d+)$/) { + $debug = $1; + } elsif ($opts eq '-d') { + $debug = shift @ARGV; + } elsif ($opts eq '-u') { + $cygwin = 0; + } elsif ($opts eq '-b') { + $brief = 1; + } elsif ($opts eq '-nt') { + $tags = ''; + } elsif ($opts eq '-c') { + $xen_conf = 1; + } elsif ($opts eq '-major') { + $major = 1; + } elsif ($opts eq '-minor') { + $minor = 1; + } elsif ($opts eq '-patch') { + $patch = 1; + } elsif ($opts eq '-clean') { + $clean = 1; + } elsif ($opts eq '-update') { + $update = 1; + } else { + print "Unknown options \"$opts\" ignored\n"; + } +} + +die "Only one of -major -minor -patch" if ($major + $minor + $patch) > 1; + +$/ = "\cJ" if $cygwin; + +my $jenkins_build_number = $ENV{'BUILD_NUMBER'}; +$jenkins_build_number = '0000' + if ! defined $jenkins_build_number; + +sub clean_line { + my $line = shift @_; + + chomp $line; + chop($line) if substr($line,-1,1) eq "\cM"; + return $line; +} + +sub three_parts { + my $ver = shift @_; + my @parts = split /-/, $ver; + + while ($#parts > 2) { + my $old = shift @parts; + $parts[0] = $old.'-'. $parts[0]; + } + return @parts; +} + +my $branch = `basename \$(git rev-parse --abbrev-ref HEAD)`; +chomp $branch; +if ($debug =~ /br/) { + print STDERR "branch=$branch\n"; +} + +my %conf = + ( + 'QEMU_UPSTREAM_URL' => 'git@xxxxxxxxxxxxxxxxxxxxx:qemu.git', + 'QEMU_UPSTREAM_REVISION' => 'origin/'.$branch, + 'QEMU_UPSTREAM_EXTRA_CONFIG', => '--with-pkgversion=dirty', + 'SEABIOS_UPSTREAM_URL' => 'git@xxxxxxxxxxxxxxxxxxxxx:seabios-george.git', + 'SEABIOS_UPSTREAM_TAG' => 'origin/'.$branch, + ); + +if ($xen_conf) { + open CONFIG, "Config.mk" + || die "Failed to open Config.mk: $!"; + while() { + my $line = clean_line($_); + if ($line =~ /^QEMU_UPSTREAM_REVISION\s*\?=\s*(.*)$/) { + $conf{'QEMU_UPSTREAM_REVISION'} = $1; + } elsif ($line =~ /^SEABIOS_UPSTREAM_TAG\s*\?=\s*(.*)$/) { + $conf{'SEABIOS_UPSTREAM_TAG'} = $1; + } + } + close CONFIG; +} + +my $base_xen_ver; +my $xen_ver; +my $qemu_ver; +my $seabios_ver; +my $uname_ver = "Unknown"; + +open (UNAME, "uname -a|") + || die "Failed to open uname -a|: $!"; +$uname_ver = clean_line(); +close UNAME; + + +if (-f ".config") { + open (CONFIG, ".config") + || die "Failed to open .config: $!"; + while() { + my $line = clean_line($_); + if ($line =~ /^(.*?)\s*=\s*(.*)$/) { + $conf{$1} = $2; + } + } + close CONFIG; +} + +if ($debug =~ /cf/) { + for my $key (sort keys %conf) { + print STDERR $key,' = ',$conf{$key},$/; + } +} + +if ($clean) { + my $cmd = "git clean -fdxq"; + open (GIT, "$cmd|") + || die "Failed to git clean($cmd): $!"; + print STDERR "$cmd\n"; + while () { + print STDERR; + } + close GIT; + for my $git_dir ('firmware/seabios-dir-remote', 'qemu-xen-dir-remote', 'qemu-xen-traditional-dir-remote') { + if (-d "tools/$git_dir") { + $cmd = "rm -rf tools/$git_dir"; + open (GIT, "$cmd|") + || die "Failed to clean dir($cmd): $!"; + print STDERR "$cmd\n"; + while () { + print STDERR; + } + close GIT; + } + } + open (CONFIG, ">.config") + || die "Failed to open for write .config: $!"; + for my $key (sort keys %conf) { + print CONFIG $key,' = ',$conf{$key},$/; + } + close CONFIG; + $cmd = "mkdir -p rpmbuild_dir/BUILD rpmbuild_dir/BUILDROOT rpmbuild_dir/RPMS/x86_64"; + open (GIT, "$cmd|") + || die "Failed to create jenkins rpm dirs dir($cmd): $!"; + print STDERR "$cmd\n"; + while () { + print STDERR; + } + close GIT; +} + +if ($update) { + for my $git_dir ('firmware/seabios-dir-remote', 'qemu-xen-dir-remote', 'qemu-xen-traditional-dir-remote') { + if (-d "tools/$git_dir") { + my $cmd = "cd tools/$git_dir;git pull"; + open (GIT, "$cmd|") + || die "Failed to update dir($cmd): $!"; + print STDERR "$cmd\n"; + while () { + print STDERR; + } + close GIT; + } + } +} + +if (!-d 'tools/qemu-xen-dir') { + my $cmd = "export GIT=git;cd tools;../scripts/git-checkout.sh $conf{'QEMU_UPSTREAM_URL'} $conf{'QEMU_UPSTREAM_REVISION'} qemu-xen-dir"; + open (GIT, "$cmd|") + || die "Failed to get qemu($cmd): $!"; + print STDERR "$cmd\n"; + while () { + print STDERR; + } + close GIT; +} + +if (!-d 'tools/firmware/seabios-dir') { + my $cmd = "export GIT=git;cd tools/firmware;../../scripts/git-checkout.sh $conf{'SEABIOS_UPSTREAM_URL'} $conf{'SEABIOS_UPSTREAM_TAG'} seabios-dir"; + open (GIT, "$cmd|") + || die "Failed to get seabios($cmd): $!"; + print STDERR "$cmd\n"; + while () { + print STDERR; + } + close GIT; +} + +open (GIT, "git fetch --tags|") + || die "Failed to fetch tags via git: $!"; +binmode (GIT) if $cygwin; +while() { + print STDERR; +} +close GIT; + +my @xen_ver_tags = (); +open (GIT, "git log --oneline --decorate=full -20|") + || die "Failed to get xen version via git: $!"; +binmode (GIT) if $cygwin; +while() { + push @xen_ver_tags, clean_line($_); +} +close GIT; + +my @qemu_ver_tags = (); +open (GIT, "cd tools/qemu-xen-dir;git log --oneline --decorate=full -20|") + || die "Failed to get qemu version via git: $!"; +binmode (GIT) if $cygwin; +while() { + push @qemu_ver_tags, clean_line($_); +} +close GIT; + +my @seabios_ver_tags = (); +open (GIT, "cd tools/firmware/seabios-dir;git log --oneline --decorate=full -20|") + || die "Failed to get seabios version via git: $!"; +binmode (GIT) if $cygwin; +while() { + push @seabios_ver_tags, clean_line($_); +} +close GIT; + +open (GIT, "git describe $tags --long --dirty|") + || die "Failed to get xen version via git: $!"; +binmode (GIT) if $cygwin; +$xen_ver = clean_line(); +close GIT; +$base_xen_ver = $xen_ver; +if ($xen_ver =~ /^jenkins/) { + my $ghash; + for my $i (0 .. $#xen_ver_tags) { + my $line = $xen_ver_tags[$i]; + if (($i == 0) && ($line =~ /^(\S+)/)) { + $ghash = 'g'.$1; + } + if ($line =~ m-\((.*)\)-) { + my @tags = split(/, /, $1); + my $cur = 0; + my $pre; + for my $part (@tags) { + if ($part =~ m-^tag: refs/tags/(ver_\d+\.\d+\.)(\d+)-) { + if ($2 >= $cur) { + $pre = $1; + $cur = $2; + } + } + } + if (defined $pre) { + $xen_ver = $pre.$cur.'-'.$i.'-'.$ghash; + $xen_ver .= '-dirty' + if $base_xen_ver =~ /dirty$/; + last; + } + } + } +} + +open (GIT, "cd tools/qemu-xen-dir;git describe $tags --long --dirty|") + || die "Failed to get qemu version via git: $!"; +binmode (GIT) if $cygwin; +$qemu_ver = clean_line(); +close GIT; + +open (GIT, "cd tools/firmware/seabios-dir;git describe $tags --long --dirty|") + || die "Failed to get seabios version via git: $!"; +binmode (GIT) if $cygwin; +$seabios_ver = clean_line(); +close GIT; + +if ($debug =~ /sv/) { + print STDERR "xen_ver=$xen_ver qemu_ver=$qemu_ver seabios_ver=$seabios_ver\n"; +} + +my @xen_vers = three_parts($xen_ver); +my @qemu_vers = three_parts($qemu_ver); +my @seabios_vers = three_parts($seabios_ver); + +if ($debug =~ /pv/) { + for my $i (0..$#xen_vers) { + print STDERR "xen_vers[$i] = $xen_vers[$i]\n"; + } + for my $i (0..$#qemu_vers) { + print STDERR "qemu_vers[$i] = $qemu_vers[$i]\n"; + } + for my $i (0..$#seabios_vers) { + print STDERR "seabios_vers[$i] = $seabios_vers[$i]\n"; + } +} + +my $out = $xen_vers[0]; +if (($out ne $qemu_vers[0]) || ($out ne $seabios_vers[0])) { + die "Complex version: xen_ver=$xen_ver qemu_ver=$qemu_ver seabios_ver=$seabios_ver" + if $major || $minor || $patch || $clean; + if ($xen_vers[0] ne $qemu_vers[0]) { + $out .= '_'.$qemu_vers[0]; + } else { + $out .= '_'; + } + if ($xen_vers[0] ne $seabios_vers[0]) { + $out .= '_'.$seabios_vers[0]; + } else { + $out .= '_'; + } +} +if (($xen_vers[1] ne '0') || ($qemu_vers[1] ne '0') || ($seabios_vers[1] ne '0')) { + $out .= '_'.$xen_vers[1]; + $out .= '_'.$qemu_vers[1]; + $out .= '_'.$seabios_vers[1]; +} +my $short_out = $out; +$short_out .= '-dirty' + if $base_xen_ver =~ /dirty$/; +$short_out =~ s/-/_/g; +$out .= '_'.$xen_vers[2]; +$out .= '_'.$qemu_vers[2]; +$out .= '_'.$seabios_vers[2]; +$out =~ s/-/_/g; +if (!-d 'dist/install/etc/xen') { + my $rc = system 'mkdir', '-p', 'dist/install/etc/xen'; + die "Failed to create dist/install/etc/xen: $!" + if $rc != 0; +} +open(VERFILE, ">dist/install/etc/xen/gen_version") + || die "Failed to create dist/install/etc/xen/gen_version: $!"; +print VERFILE $out,$/; +print VERFILE 'all=',$out,$/; +print VERFILE 'brief=',$short_out,$/; +print VERFILE 'jenkins_build_number=',$jenkins_build_number,$/; +print VERFILE 'base_xen_ver=',$base_xen_ver,$/; +print VERFILE 'xen_ver=',$xen_ver,$/; +print VERFILE 'qemu_ver=',$qemu_ver,$/; +print VERFILE 'seabios_ver=',$seabios_ver,$/; +print VERFILE 'uname_ver=',$uname_ver,$/; +print VERFILE 'HOSTNAME=',$ENV{'HOSTNAME'},$/; +for my $key (sort keys %conf) { + print VERFILE $key,'=',$conf{$key},$/; +} +for my $i (0 .. $#xen_ver_tags) { + print VERFILE 'xen_ver_tags['.$i.']=',$xen_ver_tags[$i],$/; +} +for my $i (0 .. $#qemu_ver_tags) { + print VERFILE 'qemu_ver_tags['.$i.']=',$qemu_ver_tags[$i],$/; +} +for my $i (0 .. $#seabios_ver_tags) { + print VERFILE 'seabios_ver_tags['.$i.']=',$seabios_ver_tags[$i],$/; +} +close VERFILE; +if ($major) { + if ($short_out =~ /ver_(\d+)\.\d+\.\d+/) { + print $1,$/; + } else { + die "Failed to parse:$short_out"; + } +} elsif ($minor) { + if ($short_out =~ /ver_\d+\.(\d+)\.\d+/) { + print $1,$/; + } else { + die "Failed to parse:$short_out"; + } +} elsif ($patch) { + if ($short_out =~ /ver_\d+\.\d+\.(\d+)/) { + print $1,$/; + } else { + die "Failed to parse:$short_out"; + } +} elsif ($brief) { + print $short_out,$/; +} else { + print $out,$/; +} + +1; diff --git a/update_config.pl b/update_config.pl new file mode 100755 index 0000000..097f1da --- /dev/null +++ b/update_config.pl @@ -0,0 +1,109 @@ +#! /usr/bin/perl -w +# -*- Mode: cperl; coding: utf-8; cperl-indent-level: 2 -*- + +use strict; + +my $debug = 0; +my $cygwin = $^O eq 'cygwin'; + +while ((defined $ARGV[0]) && + (substr($ARGV[0],0,1) eq '-')) { + my $opts = shift @ARGV; + if ($opts =~ /^-d(\d+)$/) { + $debug = $1; + } elsif ($opts eq '-d') { + $debug = shift @ARGV; + } elsif ($opts eq '-u') { + $cygwin = 0; + } else { + print "Unknown options \"$opts\" ignored\n"; + } +} + +$/ = "\cJ" if $cygwin; + +sub clean_line { + my $line = shift @_; + + chomp $line; + chop($line) if substr($line,-1,1) eq "\cM"; + return $line; +} + +my %conf = + ( + 'QEMU_UPSTREAM_URL' => 'git@xxxxxxxxxxxxxxxxxxxxx:qemu.git', + 'QEMU_UPSTREAM_REVISION' => 'origin/dev-integration', + 'QEMU_UPSTREAM_EXTRA_CONFIG', => '--with-pkgversion=dirty', + 'SEABIOS_UPSTREAM_URL' => 'git@xxxxxxxxxxxxxxxxxxxxx:seabios-george.git', + 'SEABIOS_UPSTREAM_TAG' => 'origin/dev-integration', + ); +my %conf_seen = (); +my @configs = (); + +if (-f ".config") { + open (CONFIG, ".config") + || die "Failed to open .config: $!"; + while() { + my $line = clean_line($_); + if ($line =~ /^(.*?)\s*=\s*(.*)$/) { + $conf{$1} = $2; + $conf_seen{$1} = 1; + } + push @configs, $line; + } +} +close CONFIG; + +for my $key (keys %conf) { + if (!defined $conf_seen{$key}) { + push @configs, "$key = $conf{$key}"; + } +} + +if (!-d 'tools/qemu-xen-dir') { + my $cmd = "export GIT=git;cd tools;../scripts/git-checkout.sh $conf{'QEMU_UPSTREAM_URL'} $conf{'QEMU_UPSTREAM_REVISION'} qemu-xen-dir"; + open (GIT, "$cmd|") + || die "Failed to get qemu($cmd): $!"; + print "$cmd\n"; + while () { + print; + } + close GIT; +} + +open (GIT, "cd tools/qemu-xen-dir;git describe --tags --long --dirty|") + || die "Failed to get qemu version via git: $!"; +binmode (GIT) if $cygwin; +my $qemu_ver = clean_line(); +close GIT; + +print STDERR "qemu_ver=$qemu_ver\n" + if $debug =~ /qv/; + +for my $i (0..$#configs) { + my $line = $configs[$i]; + if ($line =~ /^QEMU_UPSTREAM_EXTRA_CONFIG/) { + print STDERR "line=$line\n" + if $debug =~ /qc/; + my @parts = split / +/, $line; + my $found_pkgversion = 0; + for my $i (0..$#parts) { + if ($parts[$i] =~ /^--with-pkgversion=/) { + $parts[$i] = "--with-pkgversion=$qemu_ver"; + $found_pkgversion = 1; + } + } + push @parts, "--with-pkgversion=$qemu_ver" + if !$found_pkgversion; + $configs[$i] = join ' ', @parts; + } +} + +open (CONFIG, ">.config") + || die "Failed to open for write .config: $!"; +for my $line (@configs) { + print CONFIG $line,$/; +} +close CONFIG; +1; diff --git a/xen-4.4.spec b/xen-4.4.spec new file mode 100644 index 0000000..38ff5ba --- /dev/null +++ b/xen-4.4.spec @@ -0,0 +1,131 @@ +Summary: The Xen Hypervisor, modified by CloudSwitch, Inc. +Name: xen +Version: 4.4.unstable +Release: %(./gen_version.pl -b -update) +License: GPLv2 +Group: System Environment/Kernel +URL: http://www.xen.org +#Source0: %{name}-%{version}.tar.gz +BuildRoot: rpmbuild/BUILDROOT/%{name}-%{version}-%{release} + +# $ cd +# $ rpmbuild -bb xen-4.3.spec + +%debug_package + +%description +Xen Hypervisor + +%prep +#%setup -q + +%build +AT_DIR=%(pwd) +rm -rf $RPM_BUILD_ROOT +cd $AT_DIR +./update_config.pl +./configure --prefix=/usr --disable-stubdom +./gen_version.pl +make dist +make -C xen MAP + +%install +AT_DIR=%(pwd) +mkdir -p $RPM_BUILD_ROOT +cp -a $AT_DIR/dist/install/boot $RPM_BUILD_ROOT +cp -a $AT_DIR/xen/System.map $RPM_BUILD_ROOT/boot/System.map-%{name}-%{version}-%{release} +cp -a $AT_DIR/dist/install/etc $RPM_BUILD_ROOT +cp -a $AT_DIR/dist/install/usr $RPM_BUILD_ROOT +cp -a $AT_DIR/dist/install/var $RPM_BUILD_ROOT +mkdir -p $RPM_BUILD_ROOT/var/log/xen/console +mkdir -p $RPM_BUILD_ROOT/boot/flask +# mv $RPM_BUILD_ROOT/boot/xenpolicy.24 $RPM_BUILD_ROOT/boot/flask/ + +%post +if [ $1 = 1 -a -f /sbin/grub2-mkconfig -a -f /boot/grub2/grub.cfg ]; then + /sbin/grub2-mkconfig -o /boot/grub2/grub.cfg +fi +ldconfig +chkconfig --add xencommons + +%preun +chkconfig --del xencommons + +%postun +if [ -f /sbin/grub2-mkconfig -a -f /boot/grub2/grub.cfg ]; then + /sbin/grub2-mkconfig -o /boot/grub2/grub.cfg +fi +ldconfig + +%clean +rm -rf $RPM_BUILD_ROOT + + +%files +%defattr(-,root,root,-) +%config /etc/rc.d/init.d/xencommons +%doc +/boot +/etc +/var +/usr/bin +/usr/etc/qemu/target-x86_64.conf +/usr/include +/usr/sbin +/usr/share +/usr/lib64 +/usr/libexec +/usr/lib/fs/ext2fs/fsimage.so +/usr/lib/fs/fat/fsimage.so +/usr/lib/fs/iso9660/fsimage.so +/usr/lib/fs/reiserfs/fsimage.so +/usr/lib/fs/ufs/fsimage.so +/usr/lib/fs/xfs/fsimage.so +/usr/lib/fs/zfs/fsimage.so +/usr/lib/libblktapctl.a +/usr/lib/libblktapctl.so +/usr/lib/libblktapctl.so.1.0 +/usr/lib/libblktapctl.so.1.0.0 +/usr/lib/libfsimage.so +/usr/lib/libfsimage.so.1.0 +/usr/lib/libfsimage.so.1.0.0 +/usr/lib/libvhd.a +/usr/lib/libvhd.so +/usr/lib/libvhd.so.1.0 +/usr/lib/libvhd.so.1.0.0 +/usr/lib/libxenctrl.a +/usr/lib/libxenctrl.so +/usr/lib/libxenctrl.so.4.3 +/usr/lib/libxenctrl.so.4.3.0 +/usr/lib/libxenguest.a +/usr/lib/libxenguest.so +/usr/lib/libxenguest.so.4.3 +/usr/lib/libxenguest.so.4.3.0 +/usr/lib/libxenlight.a +/usr/lib/libxenlight.so +/usr/lib/libxenlight.so.4.3 +/usr/lib/libxenlight.so.4.3.0 +/usr/lib/libxenstat.a +/usr/lib/libxenstat.so +/usr/lib/libxenstat.so.0 +/usr/lib/libxenstat.so.0.0 +/usr/lib/libxenstore.a +/usr/lib/libxenstore.so +/usr/lib/libxenstore.so.3.0 +/usr/lib/libxenstore.so.3.0.3 +/usr/lib/libxenvchan.a +/usr/lib/libxenvchan.so +/usr/lib/libxenvchan.so.1.0 +/usr/lib/libxenvchan.so.1.0.0 +/usr/lib/libxlutil.a +/usr/lib/libxlutil.so +/usr/lib/libxlutil.so.4.3 +/usr/lib/libxlutil.so.4.3.0 +/usr/lib/xen + +%changelog +* Thu Oct 3 2013 Don Slutz - 4.3.0-%(./gen_version.pl -b -update) +- Move xenpolicy.24 out of /boot + +* Wed Oct 3 2012 Harry Hart - 4.2-1 +- Initial build. -- 1.7.11.7