diff options
author | Ola x Nilsson <ola.x.nilsson@axis.com> | 2019-10-21 12:30:32 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-10-23 16:30:36 +0100 |
commit | 95dca0ec5a89a6b4277abb7100dbeacede1cc4e3 (patch) | |
tree | 0b156ec8740d5bde3279d6e339c697482c211b25 | |
parent | a92ef13e3dc417c0dbb0543eccb3ed2223d02b92 (diff) | |
download | poky-95dca0ec5a89a6b4277abb7100dbeacede1cc4e3.tar.gz |
package.bbclass: Use with to manage file handle lifetimes
(From OE-Core rev: e90978056c4b49e138b3d422939bf995829ec3b0)
Signed-off-by: Ola x Nilsson <olani@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/classes/package.bbclass | 76 |
1 files changed, 34 insertions, 42 deletions
diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass index d8bef3afb0..f955df1111 100644 --- a/meta/classes/package.bbclass +++ b/meta/classes/package.bbclass | |||
@@ -826,8 +826,9 @@ python fixup_perms () { | |||
826 | 826 | ||
827 | # Now we actually load from the configuration files | 827 | # Now we actually load from the configuration files |
828 | for conf in get_fs_perms_list(d).split(): | 828 | for conf in get_fs_perms_list(d).split(): |
829 | if os.path.exists(conf): | 829 | if not os.path.exists(conf): |
830 | f = open(conf) | 830 | continue |
831 | with open(conf) as f: | ||
831 | for line in f: | 832 | for line in f: |
832 | if line.startswith('#'): | 833 | if line.startswith('#'): |
833 | continue | 834 | continue |
@@ -848,7 +849,6 @@ python fixup_perms () { | |||
848 | fs_perms_table[entry.path] = entry | 849 | fs_perms_table[entry.path] = entry |
849 | if entry.path in fs_link_table: | 850 | if entry.path in fs_link_table: |
850 | fs_link_table.pop(entry.path) | 851 | fs_link_table.pop(entry.path) |
851 | f.close() | ||
852 | 852 | ||
853 | # Debug -- list out in-memory table | 853 | # Debug -- list out in-memory table |
854 | #for dir in fs_perms_table: | 854 | #for dir in fs_perms_table: |
@@ -1424,10 +1424,9 @@ fi | |||
1424 | pkgdest = d.getVar('PKGDEST') | 1424 | pkgdest = d.getVar('PKGDEST') |
1425 | pkgdatadir = d.getVar('PKGDESTWORK') | 1425 | pkgdatadir = d.getVar('PKGDESTWORK') |
1426 | 1426 | ||
1427 | data_file = pkgdatadir + d.expand("/${PN}" ) | 1427 | data_file = pkgdatadir + d.expand("/${PN}") |
1428 | f = open(data_file, 'w') | 1428 | with open(data_file, 'w') as fd: |
1429 | f.write("PACKAGES: %s\n" % packages) | 1429 | fd.write("PACKAGES: %s\n" % packages) |
1430 | f.close() | ||
1431 | 1430 | ||
1432 | pn = d.getVar('PN') | 1431 | pn = d.getVar('PN') |
1433 | global_variants = (d.getVar('MULTILIB_GLOBAL_VARIANTS') or "").split() | 1432 | global_variants = (d.getVar('MULTILIB_GLOBAL_VARIANTS') or "").split() |
@@ -1778,21 +1777,20 @@ python package_do_shlibs() { | |||
1778 | bb.note("Renaming %s to %s" % (old, new)) | 1777 | bb.note("Renaming %s to %s" % (old, new)) |
1779 | os.rename(old, new) | 1778 | os.rename(old, new) |
1780 | pkgfiles[pkg].remove(old) | 1779 | pkgfiles[pkg].remove(old) |
1781 | 1780 | ||
1782 | shlibs_file = os.path.join(shlibswork_dir, pkg + ".list") | 1781 | shlibs_file = os.path.join(shlibswork_dir, pkg + ".list") |
1783 | if len(sonames): | 1782 | if len(sonames): |
1784 | fd = open(shlibs_file, 'w') | 1783 | with open(shlibs_file, 'w') as fd: |
1785 | for s in sonames: | 1784 | for s in sonames: |
1786 | if s[0] in shlib_provider and s[1] in shlib_provider[s[0]]: | 1785 | if s[0] in shlib_provider and s[1] in shlib_provider[s[0]]: |
1787 | (old_pkg, old_pkgver) = shlib_provider[s[0]][s[1]] | 1786 | (old_pkg, old_pkgver) = shlib_provider[s[0]][s[1]] |
1788 | if old_pkg != pkg: | 1787 | if old_pkg != pkg: |
1789 | bb.warn('%s-%s was registered as shlib provider for %s, changing it to %s-%s because it was built later' % (old_pkg, old_pkgver, s[0], pkg, pkgver)) | 1788 | bb.warn('%s-%s was registered as shlib provider for %s, changing it to %s-%s because it was built later' % (old_pkg, old_pkgver, s[0], pkg, pkgver)) |
1790 | bb.debug(1, 'registering %s-%s as shlib provider for %s' % (pkg, pkgver, s[0])) | 1789 | bb.debug(1, 'registering %s-%s as shlib provider for %s' % (pkg, pkgver, s[0])) |
1791 | fd.write(s[0] + ':' + s[1] + ':' + s[2] + '\n') | 1790 | fd.write(s[0] + ':' + s[1] + ':' + s[2] + '\n') |
1792 | if s[0] not in shlib_provider: | 1791 | if s[0] not in shlib_provider: |
1793 | shlib_provider[s[0]] = {} | 1792 | shlib_provider[s[0]] = {} |
1794 | shlib_provider[s[0]][s[1]] = (pkg, pkgver) | 1793 | shlib_provider[s[0]][s[1]] = (pkg, pkgver) |
1795 | fd.close() | ||
1796 | if needs_ldconfig and use_ldconfig: | 1794 | if needs_ldconfig and use_ldconfig: |
1797 | bb.debug(1, 'adding ldconfig call to postinst for %s' % pkg) | 1795 | bb.debug(1, 'adding ldconfig call to postinst for %s' % pkg) |
1798 | postinst = d.getVar('pkg_postinst_%s' % pkg) | 1796 | postinst = d.getVar('pkg_postinst_%s' % pkg) |
@@ -1864,11 +1862,10 @@ python package_do_shlibs() { | |||
1864 | deps_file = os.path.join(pkgdest, pkg + ".shlibdeps") | 1862 | deps_file = os.path.join(pkgdest, pkg + ".shlibdeps") |
1865 | if os.path.exists(deps_file): | 1863 | if os.path.exists(deps_file): |
1866 | os.remove(deps_file) | 1864 | os.remove(deps_file) |
1867 | if len(deps): | 1865 | if deps: |
1868 | fd = open(deps_file, 'w') | 1866 | with open(deps_file, 'w') as fd: |
1869 | for dep in sorted(deps): | 1867 | for dep in sorted(deps): |
1870 | fd.write(dep + '\n') | 1868 | fd.write(dep + '\n') |
1871 | fd.close() | ||
1872 | } | 1869 | } |
1873 | 1870 | ||
1874 | python package_do_pkgconfig () { | 1871 | python package_do_pkgconfig () { |
@@ -1898,9 +1895,8 @@ python package_do_pkgconfig () { | |||
1898 | pkgconfig_provided[pkg].append(name) | 1895 | pkgconfig_provided[pkg].append(name) |
1899 | if not os.access(file, os.R_OK): | 1896 | if not os.access(file, os.R_OK): |
1900 | continue | 1897 | continue |
1901 | f = open(file, 'r') | 1898 | with open(file, 'r') as f: |
1902 | lines = f.readlines() | 1899 | lines = f.readlines() |
1903 | f.close() | ||
1904 | for l in lines: | 1900 | for l in lines: |
1905 | m = var_re.match(l) | 1901 | m = var_re.match(l) |
1906 | if m: | 1902 | if m: |
@@ -1918,10 +1914,9 @@ python package_do_pkgconfig () { | |||
1918 | for pkg in packages.split(): | 1914 | for pkg in packages.split(): |
1919 | pkgs_file = os.path.join(shlibswork_dir, pkg + ".pclist") | 1915 | pkgs_file = os.path.join(shlibswork_dir, pkg + ".pclist") |
1920 | if pkgconfig_provided[pkg] != []: | 1916 | if pkgconfig_provided[pkg] != []: |
1921 | f = open(pkgs_file, 'w') | 1917 | with open(pkgs_file, 'w') as f: |
1922 | for p in pkgconfig_provided[pkg]: | 1918 | for p in pkgconfig_provided[pkg]: |
1923 | f.write('%s\n' % p) | 1919 | f.write('%s\n' % p) |
1924 | f.close() | ||
1925 | 1920 | ||
1926 | # Go from least to most specific since the last one found wins | 1921 | # Go from least to most specific since the last one found wins |
1927 | for dir in reversed(shlibs_dirs): | 1922 | for dir in reversed(shlibs_dirs): |
@@ -1931,9 +1926,8 @@ python package_do_pkgconfig () { | |||
1931 | m = re.match(r'^(.*)\.pclist$', file) | 1926 | m = re.match(r'^(.*)\.pclist$', file) |
1932 | if m: | 1927 | if m: |
1933 | pkg = m.group(1) | 1928 | pkg = m.group(1) |
1934 | fd = open(os.path.join(dir, file)) | 1929 | with open(os.path.join(dir, file)) as fd: |
1935 | lines = fd.readlines() | 1930 | lines = fd.readlines() |
1936 | fd.close() | ||
1937 | pkgconfig_provided[pkg] = [] | 1931 | pkgconfig_provided[pkg] = [] |
1938 | for l in lines: | 1932 | for l in lines: |
1939 | pkgconfig_provided[pkg].append(l.rstrip()) | 1933 | pkgconfig_provided[pkg].append(l.rstrip()) |
@@ -1951,10 +1945,9 @@ python package_do_pkgconfig () { | |||
1951 | bb.note("couldn't find pkgconfig module '%s' in any package" % n) | 1945 | bb.note("couldn't find pkgconfig module '%s' in any package" % n) |
1952 | deps_file = os.path.join(pkgdest, pkg + ".pcdeps") | 1946 | deps_file = os.path.join(pkgdest, pkg + ".pcdeps") |
1953 | if len(deps): | 1947 | if len(deps): |
1954 | fd = open(deps_file, 'w') | 1948 | with open(deps_file, 'w') as fd: |
1955 | for dep in deps: | 1949 | for dep in deps: |
1956 | fd.write(dep + '\n') | 1950 | fd.write(dep + '\n') |
1957 | fd.close() | ||
1958 | } | 1951 | } |
1959 | 1952 | ||
1960 | def read_libdep_files(d): | 1953 | def read_libdep_files(d): |
@@ -1965,9 +1958,8 @@ def read_libdep_files(d): | |||
1965 | for extension in ".shlibdeps", ".pcdeps", ".clilibdeps": | 1958 | for extension in ".shlibdeps", ".pcdeps", ".clilibdeps": |
1966 | depsfile = d.expand("${PKGDEST}/" + pkg + extension) | 1959 | depsfile = d.expand("${PKGDEST}/" + pkg + extension) |
1967 | if os.access(depsfile, os.R_OK): | 1960 | if os.access(depsfile, os.R_OK): |
1968 | fd = open(depsfile) | 1961 | with open(depsfile) as fd: |
1969 | lines = fd.readlines() | 1962 | lines = fd.readlines() |
1970 | fd.close() | ||
1971 | for l in lines: | 1963 | for l in lines: |
1972 | l.rstrip() | 1964 | l.rstrip() |
1973 | deps = bb.utils.explode_dep_versions2(l) | 1965 | deps = bb.utils.explode_dep_versions2(l) |