1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-09 17:39:31 +00:00

scripts/create-recipe: Python improvements for create-recipe.

1. Added ability to parse .zip files.
2. Added optional automatic dependency resolving for python
   recipes(easy_install wrapper).
3. Fixed a few name/version bugs.

Give it a whirl by:
create-recipe -r https://launchpad.net/nova/folsom/2012.2.3/+download/nova-2012.2.3.tar.gz

Saves me some time unwinding python dependencies, and creating template recipes.

(From OE-Core rev: 1a491a4dde0d3618f8815182d12c21f76b64de5a)

Signed-off-by: David Nyström <david.nystrom@enea.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
David Nyström
2013-02-04 13:32:51 +01:00
committed by Richard Purdie
parent 5b7c822609
commit bc8150d9d4
+124 -32
View File
@@ -37,11 +37,14 @@ use File::Basename qw(basename dirname);
my $name = ""; my $name = "";
my $predef_version = "TO BE FILLED IN"; my $predef_version = "TO BE FILLED IN";
my $version = $predef_version; my $version = $predef_version;
my $pversion = $predef_version;
my $description = ""; my $description = "";
my $summary = ""; my $summary = "";
my $url = ""; my $url = "";
my $homepage; my $homepage = "";
my @depends;
my @rdepends; my @rdepends;
my @rawpythondeps;
my $configure = ""; my $configure = "";
my $localename = ""; my $localename = "";
my @sources; my @sources;
@@ -59,6 +62,7 @@ my $builder = "";
my $oscmode = 0; my $oscmode = 0;
my $python = 0;
my @banned_pkgconfig; my @banned_pkgconfig;
my %failed_commands; my %failed_commands;
@@ -74,7 +78,7 @@ my %failed_headers;
# We store the sha1sum of common COPYING files in an associative array # We store the sha1sum of common COPYING files in an associative array
# %licenses. # %licenses.
# #
# For all matching sha1's in the tarbal, we then push the result # For all matching sha1's in the tarball, we then push the result
# in the @license array (which we'll dedupe at the time of printing). # in the @license array (which we'll dedupe at the time of printing).
# #
@@ -134,6 +138,18 @@ sub guess_license_from_file {
$lic_files{$copying} = $md5 $lic_files{$copying} = $md5
} }
#
# if file is found, and licence of python
# package is already aquired, add file.
#
if ($python == 1 && @license != 0) {
my $md5output = `md5sum $copying`;
$md5output =~ /^([a-zA-Z0-9]*) /;
my $md5 = $1;
chomp($md5);
$lic_files{$copying} = $md5
}
# #
# We also must make sure that the COPYING/etc files # We also must make sure that the COPYING/etc files
# end up in the main package as %doc.. # end up in the main package as %doc..
@@ -1539,10 +1555,14 @@ sub guess_name_from_url {
} }
my $tarfile = $spliturl[0]; my $tarfile = $spliturl[0];
# Ensure correct name resolution from .zip&tgz archives
$tarfile =~ s/\.zip/\.tar/;
$tarfile =~ s/\.tgz/\.tar/;
$tarfile =~ s/\_/\-/g;
if ($tarfile =~ /(.*?)\-([0-9\.\-\~]+.*?)\.tar/) { if ($tarfile =~ /(.*?)\-([0-9\.\-\~]+.*?)\.tar/) {
$name = $1; $name = $1;
$version = $2; $version = $2;
$version =~ s/\-/\_/g; $version =~ s/\-/\_/g;
} }
} }
@@ -1678,11 +1698,29 @@ sub write_yaml
sub write_bbfile sub write_bbfile
{ {
my $curdir = `pwd`;
chomp($curdir);
if ($python == 1) {
$name =~ s/python-//;
$name = lc("python-" . $name);
}
if (-e "$curdir/${name}_$version.bb") {
print "Wont overwrite file:";
print "$curdir/${name}_$version.bb, exiting\n";
return;
}
open(BBFILE, ">${name}_$version.bb"); open(BBFILE, ">${name}_$version.bb");
print BBFILE "SUMMARY = \"$summary\"\n"; print BBFILE "SUMMARY = \"$summary\"\n";
print BBFILE "DESCRIPTION = \"$description\"\n"; print BBFILE "DESCRIPTION = \"$description\"\n";
print BBFILE "HOMEPAGE = \"$homepage\"\n"; print BBFILE "HOMEPAGE = \"$homepage\"\n";
if ($python == 1) {
print BBFILE "SRCNAME = \"$summary\"\n";
}
print BBFILE "LICENSE = \"@license\"\n"; print BBFILE "LICENSE = \"@license\"\n";
print BBFILE "LIC_FILES_CHKSUM = \""; print BBFILE "LIC_FILES_CHKSUM = \"";
foreach (keys %lic_files) { foreach (keys %lic_files) {
@@ -1702,10 +1740,18 @@ sub write_bbfile
}; };
if (@rdepends > 0) { if (@rdepends > 0) {
print BBFILE "RDEPENDS_\$\{PN\} += \"@rdepends\"\n"; print BBFILE "RDEPENDS_\$\{PN\} += \"";
foreach (@rdepends) {
print BBFILE "$_ \\\n\t";
}
print BBFILE "\"\n";
}
print BBFILE 'PR = "r0"' . "\n";
if ($python == 1) {
print BBFILE "PV = \"$pversion\"\n\n";
} }
print BBFILE 'PR = "r0"' . "\n\n";
print BBFILE "SRC_URI = \""; print BBFILE "SRC_URI = \"";
foreach (@sources) { foreach (@sources) {
print BBFILE "$_ \\\n"; print BBFILE "$_ \\\n";
@@ -1713,18 +1759,19 @@ sub write_bbfile
print BBFILE "\"\n\n"; print BBFILE "\"\n\n";
print BBFILE "SRC_URI[md5sum] = \"$md5sum\"\n"; print BBFILE "SRC_URI[md5sum] = \"$md5sum\"\n";
print BBFILE "SRC_URI[sha256sum] = \"$sha256sum\"\n\n"; print BBFILE "SRC_URI[sha256sum] = \"$sha256sum\"\n\n";
if ($python == 1) {
print BBFILE "S = \"\${WORKDIR}/\${SRCNAME}-\${PV}\"\n";
}
if (@inherits) { if (@inherits) {
print BBFILE "inherit "; print BBFILE "inherit ";
foreach (@inherits) { foreach (@inherits) {
print BBFILE "$_ "; print BBFILE "$_ ";
} }
print BBFILE "\n";
} }
close(BBFILE); close(BBFILE);
my $curdir = `pwd`;
chomp($curdir);
print "Create bb file: $curdir/${name}_$version.bb\n"; print "Create bb file: $curdir/${name}_$version.bb\n";
} }
@@ -1748,10 +1795,18 @@ sub calculate_sums
# #
if ( @ARGV < 1 ) { if ( @ARGV < 1 ) {
print "Usage: $0 <url-of-source-tarballs>\n"; print "Usage: $0 [-r] <url-of-source-tarballs>\n";
exit(1); exit(1);
} }
# Recusive parsing of python dependencies using
# easy_install
my $recurse_python = 0;
if ($ARGV[0] eq "-r") {
$recurse_python = 1;
shift @ARGV;
}
if (@ARGV > 1) { if (@ARGV > 1) {
my $i = 1; my $i = 1;
while ($i < @ARGV) { while ($i < @ARGV) {
@@ -1809,7 +1864,7 @@ foreach (@tgzfiles) {
# this is a step backwards in time that is just silly. # this is a step backwards in time that is just silly.
# #
my @sourcetars = <$orgdir/$outputdir/*\.tar\.bz2 $orgdir/$outputdir/*\.tar\.gz>; my @sourcetars = <$orgdir/$outputdir/*\.tar\.bz2 $orgdir/$outputdir/*\.tar\.gz $orgdir/$outputdir/*\.zip>;
if ( length @sourcetars == 0) { if ( length @sourcetars == 0) {
print "Can NOT find source tarball. Exiting...\n"; print "Can NOT find source tarball. Exiting...\n";
exit (1); exit (1);
@@ -1818,6 +1873,8 @@ if (defined($sourcetars[0]) and $sourcetars[0] =~ ".*\.tar\.bz2") {
system("cd $tmpdir; tar -jxf $sourcetars[0] &>/dev/null"); system("cd $tmpdir; tar -jxf $sourcetars[0] &>/dev/null");
} elsif (defined($sourcetars[0]) and $sourcetars[0] =~ ".*\.tar\.gz") { } elsif (defined($sourcetars[0]) and $sourcetars[0] =~ ".*\.tar\.gz") {
system("cd $tmpdir; tar -zxf $sourcetars[0] &>/dev/null"); system("cd $tmpdir; tar -zxf $sourcetars[0] &>/dev/null");
} elsif (defined($sourcetars[0]) and $sourcetars[0] =~ ".*\.zip") {
system("cd $tmpdir; unzip $sourcetars[0] &>/dev/null");
} }
print "Parsing content ....\n"; print "Parsing content ....\n";
@@ -1830,34 +1887,64 @@ $fulldir = $dir;
if ( -e "$dir/setup.py" ) { if ( -e "$dir/setup.py" ) {
$python = 1; $python = 1;
push(@inherits, "distutils"); $tmp_stools = `grep -r setuptools $dir/setup.py`;
if (length($tmp_stools) > 2) {
system("cd $dir ; python setup.py build sdist &> /dev/null"); push(@inherits, "setuptools");
} else {
push(@inherits, "distutils");
}
$templic = `sed '/^License: */!d; s///;q' $dir/*.egg-info/PKG-INFO`; $templic = `cd $dir; python setup.py --license;`;
chomp($templic); $templic =~ s/[\r\n]+//g;
push(@license, $templic); push(@license, $templic);
$summary = `sed '/^Name: */!d; s///;q' $dir/*.egg-info/PKG-INFO`; $summary = `cd $dir; python setup.py --name`;
chomp($summary); $summary =~ s/[\r\n]+//g;
$description = `sed '/^Summary: */!d; s///;q' $dir/*.egg-info/PKG-INFO`; $description = `cd $dir; python setup.py --description`;
chomp($description); $description =~ s/[\r\n]+//g;
$homepage = `sed '/^Home-page: */!d; s///;q' $dir/*.egg-info/PKG-INFO`; $homepage = `cd $dir; python setup.py --url`;
chomp($homepage); $homepage =~ s/[\r\n]+//g;
$pversion = `cd $dir; python setup.py -V`;
$pversion =~ s/[\r\n]+//g;
# $findoutput = `cd $dir; python setup.py --requires`;
# if (length($findoutput) < 3) {
$findoutput = `find $dir/*.egg-info/ -name "requires.txt" 2>/dev/null`; $findoutput = `find $dir/*.egg-info/ -name "requires.txt" 2>/dev/null`;
# }
@findlist = split(/\n/, $findoutput); @findlist = split(/\n/, $findoutput);
foreach (@findlist) { foreach (@findlist) {
# Adding dependency do buildreqs should be removed when push(@rawpythondeps, `sed -e '/^\$/d' "$_" | sed '/^\\[/d'`);
# distutils is unbroken, i.e. blocks setup.py install from chomp(@rawpythondeps);
# downloading and installing dependencies. push(@rdepends, `sed -e 's/python-//g' "$_" | sed '/^\\[/d'`);
push(@buildreqs, `sed 's/[^a-zA-Z]//g' $dir/*.egg-info/requires.txt`);
chomp(@buildreqs);
foreach $item (@buildreqs) {
$item = "python-" . $item
}
push(@rdepends, `sed 's/[^a-zA-Z]//g' $dir/*.egg-info/requires.txt`);
chomp(@rdepends); chomp(@rdepends);
if ($recurse_python == 1) {
foreach (@rawpythondeps) {
my $ptempdir = tempdir();
$purl = `easy_install -eb $ptempdir "$_" 2>/dev/null`;
$purl =~ s/#.*//;
@purllist = $purl =~ m/Downloading (http:\/\/.*\n)/g;
chomp(@purllist);
# Remove empty lines
@purllist = grep(/\S/, @purllist);
# Recursively create recipes for dependencies
if (@purllist != 0) {
if (fork) {
# Parent, do nothing
} else {
# child, execute
print "Recursively creating recipe for: $purllist[0]\n";
exec("cd .. ; create-recipe -r $purllist[0]");
}
}
}
wait;
}
foreach $item (@rdepends) { foreach $item (@rdepends) {
$item = "python-" . $item @pyclean = split(/(\=|\<|\>).*/, $item);
if (defined($pyclean[0])) {
$item = lc("python-" . $pyclean[0]);
}
} }
} }
} }
@@ -1920,6 +2007,11 @@ if ($uses_configure == 0) {
$configure = "none"; $configure = "none";
} }
@files = <$dir/docs/license.txt>;
foreach (@files) {
guess_license_from_file("$_");
}
@files = <$dir/COPY*>; @files = <$dir/COPY*>;
foreach (@files) { foreach (@files) {
guess_license_from_file("$_"); guess_license_from_file("$_");