diff options
author | David Nyström <david.c.nystrom@gmail.com> | 2013-02-04 13:32:51 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-02-06 13:13:01 +0000 |
commit | bc8150d9d4db81006d1f778dedc4e167f5b89a8d (patch) | |
tree | f66b566c8c950844c184409b28fe8c33bda9f45e /scripts/create-recipe | |
parent | 5b7c822609a42e58e96a004071978c9ff196e955 (diff) | |
download | poky-bc8150d9d4db81006d1f778dedc4e167f5b89a8d.tar.gz |
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>
Diffstat (limited to 'scripts/create-recipe')
-rwxr-xr-x | scripts/create-recipe | 156 |
1 files changed, 124 insertions, 32 deletions
diff --git a/scripts/create-recipe b/scripts/create-recipe index a556e39dd1..1b10e1b591 100755 --- a/scripts/create-recipe +++ b/scripts/create-recipe | |||
@@ -37,11 +37,14 @@ use File::Basename qw(basename dirname); | |||
37 | my $name = ""; | 37 | my $name = ""; |
38 | my $predef_version = "TO BE FILLED IN"; | 38 | my $predef_version = "TO BE FILLED IN"; |
39 | my $version = $predef_version; | 39 | my $version = $predef_version; |
40 | my $pversion = $predef_version; | ||
40 | my $description = ""; | 41 | my $description = ""; |
41 | my $summary = ""; | 42 | my $summary = ""; |
42 | my $url = ""; | 43 | my $url = ""; |
43 | my $homepage; | 44 | my $homepage = ""; |
45 | my @depends; | ||
44 | my @rdepends; | 46 | my @rdepends; |
47 | my @rawpythondeps; | ||
45 | my $configure = ""; | 48 | my $configure = ""; |
46 | my $localename = ""; | 49 | my $localename = ""; |
47 | my @sources; | 50 | my @sources; |
@@ -59,6 +62,7 @@ my $builder = ""; | |||
59 | 62 | ||
60 | 63 | ||
61 | my $oscmode = 0; | 64 | my $oscmode = 0; |
65 | my $python = 0; | ||
62 | 66 | ||
63 | my @banned_pkgconfig; | 67 | my @banned_pkgconfig; |
64 | my %failed_commands; | 68 | my %failed_commands; |
@@ -74,7 +78,7 @@ my %failed_headers; | |||
74 | # We store the sha1sum of common COPYING files in an associative array | 78 | # We store the sha1sum of common COPYING files in an associative array |
75 | # %licenses. | 79 | # %licenses. |
76 | # | 80 | # |
77 | # For all matching sha1's in the tarbal, we then push the result | 81 | # For all matching sha1's in the tarball, we then push the result |
78 | # in the @license array (which we'll dedupe at the time of printing). | 82 | # in the @license array (which we'll dedupe at the time of printing). |
79 | # | 83 | # |
80 | 84 | ||
@@ -135,6 +139,18 @@ sub guess_license_from_file { | |||
135 | } | 139 | } |
136 | 140 | ||
137 | # | 141 | # |
142 | # if file is found, and licence of python | ||
143 | # package is already aquired, add file. | ||
144 | # | ||
145 | if ($python == 1 && @license != 0) { | ||
146 | my $md5output = `md5sum $copying`; | ||
147 | $md5output =~ /^([a-zA-Z0-9]*) /; | ||
148 | my $md5 = $1; | ||
149 | chomp($md5); | ||
150 | $lic_files{$copying} = $md5 | ||
151 | } | ||
152 | |||
153 | # | ||
138 | # We also must make sure that the COPYING/etc files | 154 | # We also must make sure that the COPYING/etc files |
139 | # end up in the main package as %doc.. | 155 | # end up in the main package as %doc.. |
140 | # | 156 | # |
@@ -1539,10 +1555,14 @@ sub guess_name_from_url { | |||
1539 | } | 1555 | } |
1540 | my $tarfile = $spliturl[0]; | 1556 | my $tarfile = $spliturl[0]; |
1541 | 1557 | ||
1558 | # Ensure correct name resolution from .zip&tgz archives | ||
1559 | $tarfile =~ s/\.zip/\.tar/; | ||
1560 | $tarfile =~ s/\.tgz/\.tar/; | ||
1561 | $tarfile =~ s/\_/\-/g; | ||
1542 | if ($tarfile =~ /(.*?)\-([0-9\.\-\~]+.*?)\.tar/) { | 1562 | if ($tarfile =~ /(.*?)\-([0-9\.\-\~]+.*?)\.tar/) { |
1543 | $name = $1; | 1563 | $name = $1; |
1544 | $version = $2; | 1564 | $version = $2; |
1545 | $version =~ s/\-/\_/g; | 1565 | $version =~ s/\-/\_/g; |
1546 | } | 1566 | } |
1547 | } | 1567 | } |
1548 | 1568 | ||
@@ -1678,11 +1698,29 @@ sub write_yaml | |||
1678 | 1698 | ||
1679 | sub write_bbfile | 1699 | sub write_bbfile |
1680 | { | 1700 | { |
1701 | my $curdir = `pwd`; | ||
1702 | chomp($curdir); | ||
1703 | |||
1704 | if ($python == 1) { | ||
1705 | $name =~ s/python-//; | ||
1706 | $name = lc("python-" . $name); | ||
1707 | } | ||
1708 | |||
1709 | if (-e "$curdir/${name}_$version.bb") { | ||
1710 | print "Wont overwrite file:"; | ||
1711 | print "$curdir/${name}_$version.bb, exiting\n"; | ||
1712 | return; | ||
1713 | } | ||
1681 | open(BBFILE, ">${name}_$version.bb"); | 1714 | open(BBFILE, ">${name}_$version.bb"); |
1715 | |||
1682 | print BBFILE "SUMMARY = \"$summary\"\n"; | 1716 | print BBFILE "SUMMARY = \"$summary\"\n"; |
1683 | print BBFILE "DESCRIPTION = \"$description\"\n"; | 1717 | print BBFILE "DESCRIPTION = \"$description\"\n"; |
1684 | print BBFILE "HOMEPAGE = \"$homepage\"\n"; | 1718 | print BBFILE "HOMEPAGE = \"$homepage\"\n"; |
1685 | 1719 | ||
1720 | if ($python == 1) { | ||
1721 | print BBFILE "SRCNAME = \"$summary\"\n"; | ||
1722 | } | ||
1723 | |||
1686 | print BBFILE "LICENSE = \"@license\"\n"; | 1724 | print BBFILE "LICENSE = \"@license\"\n"; |
1687 | print BBFILE "LIC_FILES_CHKSUM = \""; | 1725 | print BBFILE "LIC_FILES_CHKSUM = \""; |
1688 | foreach (keys %lic_files) { | 1726 | foreach (keys %lic_files) { |
@@ -1702,10 +1740,18 @@ sub write_bbfile | |||
1702 | }; | 1740 | }; |
1703 | 1741 | ||
1704 | if (@rdepends > 0) { | 1742 | if (@rdepends > 0) { |
1705 | print BBFILE "RDEPENDS_\$\{PN\} += \"@rdepends\"\n"; | 1743 | print BBFILE "RDEPENDS_\$\{PN\} += \""; |
1744 | foreach (@rdepends) { | ||
1745 | print BBFILE "$_ \\\n\t"; | ||
1746 | } | ||
1747 | print BBFILE "\"\n"; | ||
1748 | } | ||
1749 | |||
1750 | print BBFILE 'PR = "r0"' . "\n"; | ||
1751 | if ($python == 1) { | ||
1752 | print BBFILE "PV = \"$pversion\"\n\n"; | ||
1706 | } | 1753 | } |
1707 | 1754 | ||
1708 | print BBFILE 'PR = "r0"' . "\n\n"; | ||
1709 | print BBFILE "SRC_URI = \""; | 1755 | print BBFILE "SRC_URI = \""; |
1710 | foreach (@sources) { | 1756 | foreach (@sources) { |
1711 | print BBFILE "$_ \\\n"; | 1757 | print BBFILE "$_ \\\n"; |
@@ -1713,18 +1759,19 @@ sub write_bbfile | |||
1713 | print BBFILE "\"\n\n"; | 1759 | print BBFILE "\"\n\n"; |
1714 | print BBFILE "SRC_URI[md5sum] = \"$md5sum\"\n"; | 1760 | print BBFILE "SRC_URI[md5sum] = \"$md5sum\"\n"; |
1715 | print BBFILE "SRC_URI[sha256sum] = \"$sha256sum\"\n\n"; | 1761 | print BBFILE "SRC_URI[sha256sum] = \"$sha256sum\"\n\n"; |
1762 | if ($python == 1) { | ||
1763 | print BBFILE "S = \"\${WORKDIR}/\${SRCNAME}-\${PV}\"\n"; | ||
1764 | } | ||
1716 | 1765 | ||
1717 | if (@inherits) { | 1766 | if (@inherits) { |
1718 | print BBFILE "inherit "; | 1767 | print BBFILE "inherit "; |
1719 | foreach (@inherits) { | 1768 | foreach (@inherits) { |
1720 | print BBFILE "$_ "; | 1769 | print BBFILE "$_ "; |
1721 | } | 1770 | } |
1771 | print BBFILE "\n"; | ||
1722 | } | 1772 | } |
1723 | 1773 | ||
1724 | close(BBFILE); | 1774 | close(BBFILE); |
1725 | |||
1726 | my $curdir = `pwd`; | ||
1727 | chomp($curdir); | ||
1728 | print "Create bb file: $curdir/${name}_$version.bb\n"; | 1775 | print "Create bb file: $curdir/${name}_$version.bb\n"; |
1729 | } | 1776 | } |
1730 | 1777 | ||
@@ -1748,10 +1795,18 @@ sub calculate_sums | |||
1748 | # | 1795 | # |
1749 | 1796 | ||
1750 | if ( @ARGV < 1 ) { | 1797 | if ( @ARGV < 1 ) { |
1751 | print "Usage: $0 <url-of-source-tarballs>\n"; | 1798 | print "Usage: $0 [-r] <url-of-source-tarballs>\n"; |
1752 | exit(1); | 1799 | exit(1); |
1753 | } | 1800 | } |
1754 | 1801 | ||
1802 | # Recusive parsing of python dependencies using | ||
1803 | # easy_install | ||
1804 | my $recurse_python = 0; | ||
1805 | if ($ARGV[0] eq "-r") { | ||
1806 | $recurse_python = 1; | ||
1807 | shift @ARGV; | ||
1808 | } | ||
1809 | |||
1755 | if (@ARGV > 1) { | 1810 | if (@ARGV > 1) { |
1756 | my $i = 1; | 1811 | my $i = 1; |
1757 | while ($i < @ARGV) { | 1812 | while ($i < @ARGV) { |
@@ -1809,7 +1864,7 @@ foreach (@tgzfiles) { | |||
1809 | # this is a step backwards in time that is just silly. | 1864 | # this is a step backwards in time that is just silly. |
1810 | # | 1865 | # |
1811 | 1866 | ||
1812 | my @sourcetars = <$orgdir/$outputdir/*\.tar\.bz2 $orgdir/$outputdir/*\.tar\.gz>; | 1867 | my @sourcetars = <$orgdir/$outputdir/*\.tar\.bz2 $orgdir/$outputdir/*\.tar\.gz $orgdir/$outputdir/*\.zip>; |
1813 | if ( length @sourcetars == 0) { | 1868 | if ( length @sourcetars == 0) { |
1814 | print "Can NOT find source tarball. Exiting...\n"; | 1869 | print "Can NOT find source tarball. Exiting...\n"; |
1815 | exit (1); | 1870 | exit (1); |
@@ -1818,6 +1873,8 @@ if (defined($sourcetars[0]) and $sourcetars[0] =~ ".*\.tar\.bz2") { | |||
1818 | system("cd $tmpdir; tar -jxf $sourcetars[0] &>/dev/null"); | 1873 | system("cd $tmpdir; tar -jxf $sourcetars[0] &>/dev/null"); |
1819 | } elsif (defined($sourcetars[0]) and $sourcetars[0] =~ ".*\.tar\.gz") { | 1874 | } elsif (defined($sourcetars[0]) and $sourcetars[0] =~ ".*\.tar\.gz") { |
1820 | system("cd $tmpdir; tar -zxf $sourcetars[0] &>/dev/null"); | 1875 | system("cd $tmpdir; tar -zxf $sourcetars[0] &>/dev/null"); |
1876 | } elsif (defined($sourcetars[0]) and $sourcetars[0] =~ ".*\.zip") { | ||
1877 | system("cd $tmpdir; unzip $sourcetars[0] &>/dev/null"); | ||
1821 | } | 1878 | } |
1822 | 1879 | ||
1823 | print "Parsing content ....\n"; | 1880 | print "Parsing content ....\n"; |
@@ -1830,34 +1887,64 @@ $fulldir = $dir; | |||
1830 | 1887 | ||
1831 | if ( -e "$dir/setup.py" ) { | 1888 | if ( -e "$dir/setup.py" ) { |
1832 | $python = 1; | 1889 | $python = 1; |
1833 | push(@inherits, "distutils"); | 1890 | $tmp_stools = `grep -r setuptools $dir/setup.py`; |
1834 | 1891 | if (length($tmp_stools) > 2) { | |
1835 | system("cd $dir ; python setup.py build sdist &> /dev/null"); | 1892 | push(@inherits, "setuptools"); |
1893 | } else { | ||
1894 | push(@inherits, "distutils"); | ||
1895 | } | ||
1836 | 1896 | ||
1837 | $templic = `sed '/^License: */!d; s///;q' $dir/*.egg-info/PKG-INFO`; | 1897 | $templic = `cd $dir; python setup.py --license;`; |
1838 | chomp($templic); | 1898 | $templic =~ s/[\r\n]+//g; |
1839 | push(@license, $templic); | 1899 | push(@license, $templic); |
1840 | $summary = `sed '/^Name: */!d; s///;q' $dir/*.egg-info/PKG-INFO`; | 1900 | $summary = `cd $dir; python setup.py --name`; |
1841 | chomp($summary); | 1901 | $summary =~ s/[\r\n]+//g; |
1842 | $description = `sed '/^Summary: */!d; s///;q' $dir/*.egg-info/PKG-INFO`; | 1902 | $description = `cd $dir; python setup.py --description`; |
1843 | chomp($description); | 1903 | $description =~ s/[\r\n]+//g; |
1844 | $homepage = `sed '/^Home-page: */!d; s///;q' $dir/*.egg-info/PKG-INFO`; | 1904 | $homepage = `cd $dir; python setup.py --url`; |
1845 | chomp($homepage); | 1905 | $homepage =~ s/[\r\n]+//g; |
1906 | $pversion = `cd $dir; python setup.py -V`; | ||
1907 | $pversion =~ s/[\r\n]+//g; | ||
1908 | # $findoutput = `cd $dir; python setup.py --requires`; | ||
1909 | # if (length($findoutput) < 3) { | ||
1846 | $findoutput = `find $dir/*.egg-info/ -name "requires.txt" 2>/dev/null`; | 1910 | $findoutput = `find $dir/*.egg-info/ -name "requires.txt" 2>/dev/null`; |
1911 | # } | ||
1847 | @findlist = split(/\n/, $findoutput); | 1912 | @findlist = split(/\n/, $findoutput); |
1848 | foreach (@findlist) { | 1913 | foreach (@findlist) { |
1849 | # Adding dependency do buildreqs should be removed when | 1914 | push(@rawpythondeps, `sed -e '/^\$/d' "$_" | sed '/^\\[/d'`); |
1850 | # distutils is unbroken, i.e. blocks setup.py install from | 1915 | chomp(@rawpythondeps); |
1851 | # downloading and installing dependencies. | 1916 | push(@rdepends, `sed -e 's/python-//g' "$_" | sed '/^\\[/d'`); |
1852 | push(@buildreqs, `sed 's/[^a-zA-Z]//g' $dir/*.egg-info/requires.txt`); | ||
1853 | chomp(@buildreqs); | ||
1854 | foreach $item (@buildreqs) { | ||
1855 | $item = "python-" . $item | ||
1856 | } | ||
1857 | push(@rdepends, `sed 's/[^a-zA-Z]//g' $dir/*.egg-info/requires.txt`); | ||
1858 | chomp(@rdepends); | 1917 | chomp(@rdepends); |
1918 | if ($recurse_python == 1) { | ||
1919 | foreach (@rawpythondeps) { | ||
1920 | my $ptempdir = tempdir(); | ||
1921 | $purl = `easy_install -eb $ptempdir "$_" 2>/dev/null`; | ||
1922 | $purl =~ s/#.*//; | ||
1923 | @purllist = $purl =~ m/Downloading (http:\/\/.*\n)/g; | ||
1924 | chomp(@purllist); | ||
1925 | |||
1926 | # Remove empty lines | ||
1927 | @purllist = grep(/\S/, @purllist); | ||
1928 | |||
1929 | # Recursively create recipes for dependencies | ||
1930 | if (@purllist != 0) { | ||
1931 | if (fork) { | ||
1932 | # Parent, do nothing | ||
1933 | } else { | ||
1934 | # child, execute | ||
1935 | print "Recursively creating recipe for: $purllist[0]\n"; | ||
1936 | exec("cd .. ; create-recipe -r $purllist[0]"); | ||
1937 | } | ||
1938 | } | ||
1939 | } | ||
1940 | wait; | ||
1941 | } | ||
1942 | |||
1859 | foreach $item (@rdepends) { | 1943 | foreach $item (@rdepends) { |
1860 | $item = "python-" . $item | 1944 | @pyclean = split(/(\=|\<|\>).*/, $item); |
1945 | if (defined($pyclean[0])) { | ||
1946 | $item = lc("python-" . $pyclean[0]); | ||
1947 | } | ||
1861 | } | 1948 | } |
1862 | } | 1949 | } |
1863 | } | 1950 | } |
@@ -1920,6 +2007,11 @@ if ($uses_configure == 0) { | |||
1920 | $configure = "none"; | 2007 | $configure = "none"; |
1921 | } | 2008 | } |
1922 | 2009 | ||
2010 | @files = <$dir/docs/license.txt>; | ||
2011 | foreach (@files) { | ||
2012 | guess_license_from_file("$_"); | ||
2013 | } | ||
2014 | |||
1923 | @files = <$dir/COPY*>; | 2015 | @files = <$dir/COPY*>; |
1924 | foreach (@files) { | 2016 | foreach (@files) { |
1925 | guess_license_from_file("$_"); | 2017 | guess_license_from_file("$_"); |