Latest __FREEBSD__ value for each release

Anton Berezin tobez at FreeBSD.org
Tue Nov 15 22:14:00 PST 2005


On Tue, Nov 15, 2005 at 11:52:07PM -0500, Dan Langille wrote:

> For an upcoming FreshPorts project, I want to extract the latest 
> value for __FREEBSD__ for each branch.  I'm hoping someone can save 
> me some time and write a small perl script for me.  Thanks.
> 
> Given the release tags for the 4, 5, 6, and 7 branches[1], grab 
> src/sys/sys/param.h from cvsweb[2], and grep for __FreeBSD_version.
> 
> What I need printed out on a single line is something like this.
> 
> 4 492100
> 5 504104
> 6 600100
> 7 700006
> 
> Try starting with something like this:
> 
> my %Branches = ('HEAD' => 7, 'RELENG_6' => 6, 'RELENG_5' => 5, 
> 'RELENG_4' => 4);
> 
> Thank you.
> 
> [1] - http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/cvs-
> tags.html
> 
> [2] - http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/sys/param.h

I took a liberty to revert the branches hash in your specs, since it is
more natural to do it this way.


#! /usr/bin/perl
use 5.006;
use warnings;
use strict;
use WWW::Mechanize;

my %branches = (
	4 => 'RELENG_4',
	5 => 'RELENG_5',
	6 => 'RELENG_6',
	7 => 'HEAD',
);

for my $b (sort { $a <=> $b } keys %branches) {
	my $ver = retrieve_branch($branches{$b});
	print "$b\t$ver\n" if $ver;
}

sub retrieve_branch
{
	my ($branch) = @_;
	my $mech = WWW::Mechanize->new();
	my $url = "http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/sys/param.h";
	$mech->get("$url?only_with_tag=$branch");
	my $x = $mech->follow_link(text_regex => qr/[\d.]+/);
	return $1 if $mech->content() =~ /^#define\s+__FreeBSD_version\s+(\d+)\s*/m;
	return "";
}

Cheers,
\Anton.
-- 
An undefined problem has an infinite number of solutions.
-- Robert A. Humphrey


More information about the freebsd-ports mailing list