Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Alter prefix for pkg-config to get correct values #620
Merged
sergiusens
merged 7 commits into
snapcore:master
from
sergiusens:bugfix/1595243/pkg-config-prefix-what
Jul 1, 2016
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bef80c6
Alter prefix for pkg-config to get correct values
sergiusens 2e5a8d9
take installdir into account
sergiusens 30ee05c
units
sergiusens 5da113a
use a noop lambda func as the default fixup_func
sergiusens 770e178
use a context manager for the fileinput
sergiusens 2263f0b
reduce ifs, if only
sergiusens 79fbcdf
static
sergiusens
Jump to file or symbol
Failed to load files and symbols.
| @@ -14,15 +14,16 @@ | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| +import fileinput | ||
| import glob | ||
| import itertools | ||
| import logging | ||
| import os | ||
| import platform | ||
| import re | ||
| -import string | ||
| import shutil | ||
| import stat | ||
| +import string | ||
| import subprocess | ||
| import urllib | ||
| import urllib.request | ||
| @@ -180,7 +181,7 @@ def unpack(self, rootdir): | ||
| except subprocess.CalledProcessError: | ||
| raise UnpackError(pkg) | ||
| - _fix_symlinks(rootdir) | ||
| + _fix_artifacts(rootdir) | ||
| _fix_xml_tools(rootdir) | ||
| _fix_shebangs(rootdir) | ||
| @@ -284,7 +285,28 @@ def _setup_apt_cache(rootdir, sources, project_options): | ||
| return apt_cache, progress | ||
| -def _fix_symlinks(debdir): | ||
| +def fix_pkg_config(root, pkg_config_file, prefix_trim=None): | ||
| + """Opens a pkg_config_file and prefixes the prefix with root.""" | ||
| + pattern_trim = None | ||
| + if prefix_trim: | ||
| + pattern_trim = re.compile( | ||
| + '^prefix={}(?P<prefix>.*)'.format(prefix_trim)) | ||
| + pattern = re.compile('^prefix=(?P<prefix>.*)') | ||
| + | ||
| + with fileinput.input(pkg_config_file, inplace=True) as input_file: | ||
| + for line in input_file: | ||
| + match = pattern.search(line) | ||
| + if prefix_trim: | ||
| + match_trim = pattern_trim.search(line) | ||
| + if prefix_trim and match_trim: | ||
| + print('prefix={}{}'.format(root, match_trim.group('prefix'))) | ||
| + elif match: | ||
| + print('prefix={}{}'.format(root, match.group('prefix'))) | ||
| + else: | ||
| + print(line, end='') | ||
| + | ||
| + | ||
| +def _fix_artifacts(debdir): | ||
| ''' | ||
| Sometimes debs will contain absolute symlinks (e.g. if the relative | ||
| path would go all the way to root, they just do absolute). We can't | ||
| @@ -299,18 +321,13 @@ def _fix_symlinks(debdir): | ||
| for entry in itertools.chain(files, dirs): | ||
| path = os.path.join(root, entry) | ||
| if os.path.islink(path) and os.path.isabs(os.readlink(path)): | ||
| - target = os.path.join(debdir, os.readlink(path)[1:]) | ||
| - if _skip_link(os.readlink(path)): | ||
| - logger.debug('Skipping {}'.format(target)) | ||
| - continue | ||
| - if not os.path.exists(target): | ||
| - if not _try_copy_local(path, target): | ||
| - continue | ||
| - os.remove(path) | ||
| - os.symlink(os.path.relpath(target, root), path) | ||
| + _fix_symlink(path, debdir, root) | ||
| elif os.path.exists(path): | ||
| _fix_filemode(path) | ||
| + if path.endswith('.pc') and not os.path.islink(path): | ||
| + fix_pkg_config(debdir, path) | ||
sergiusens
Collaborator
|
||
| + | ||
| def _fix_xml_tools(root): | ||
| xml2_config_path = os.path.join(root, 'usr', 'bin', 'xml2-config') | ||
| @@ -326,6 +343,17 @@ def _fix_xml_tools(root): | ||
| format(root), xslt_config_path]) | ||
| +def _fix_symlink(path, debdir, root): | ||
| + target = os.path.join(debdir, os.readlink(path)[1:]) | ||
| + if _skip_link(os.readlink(path)): | ||
| + logger.debug('Skipping {}'.format(target)) | ||
| + return | ||
| + if not os.path.exists(target) and not _try_copy_local(path, target): | ||
| + return | ||
| + os.remove(path) | ||
| + os.symlink(os.path.relpath(target, root), path) | ||
| + | ||
| + | ||
| def _fix_filemode(path): | ||
| mode = stat.S_IMODE(os.stat(path, follow_symlinks=False).st_mode) | ||
| if mode & 0o4000 or mode & 0o2000: | ||
Oops, something went wrong.
Shouldn't you call fixup_func() rather here? (need to match the number of parameters) and move it to common as you are duplicating the checks for pc files + symlinks?