Alter prefix for pkg-config to get correct values #620

Merged
merged 7 commits into from Jul 1, 2016

Conversation

Projects
None yet
3 participants
Collaborator

sergiusens commented Jun 30, 2016

LP: #1595243

Signed-off-by: Sergio Schvezov sergio.schvezov@ubuntu.com

Alter prefix for pkg-config to get correct values
LP: #1595243

Signed-off-by: Sergio Schvezov <sergio.schvezov@ubuntu.com>
snapcraft/internal/repo.py
+def fix_pkg_config(root, pkg_config_file):
+ """Opens a pkg_config_file and prefixes the prefix with root."""
+ pattern = re.compile('^prefix=(?P<prefix>.*)')
+ for line in fileinput.input(pkg_config_file, inplace=True):
@kyrofa

kyrofa Jul 1, 2016

Member

Ah, I've not seen this before. We've got some other file replacement functions that might be able to use this.

snapcraft/internal/pluginhandler.py
@@ -644,7 +651,7 @@ def _migratable_filesets(fileset, srcdir):
def _migrate_files(snap_files, snap_dirs, srcdir, dstdir, missing_ok=False,
- follow_symlinks=False):
+ follow_symlinks=False, fixup_func=None):
@kyrofa

kyrofa Jul 1, 2016

Member

This doesn't make for a particularly intuitive function from its signature, but I guess there's little reason to walk dstdir again.

@kyrofa

kyrofa Jul 1, 2016

Member

Nah, I take that back-- could see this being useful. I wonder if it's worth supporting multiple fixup_funcs.

@didrocks

didrocks Jul 1, 2016

Contributor

Don't you want to make it a lambda function taking one parameter? That way, it's clear from the signature that the function is of form:

def fun(dst):
  pass

As you don't have docstrings to specify it.

Member

kyrofa commented Jul 1, 2016

Yeah this is looking good. Missing a rewrite for the installdir (as you mentioned)-- also could use some tests 😉 . How do you intend to support installdir and stagedir at the same time?

Collaborator

sergiusens commented Jul 1, 2016

El 01/07/16 a las 09:23, Kyle Fazzari escribió:

Yeah this is looking good. How do you plan on supporting |installdir|
for the root? Also, could use some tests 😉 .

Test will come when I figure out the installdir story :-)

snapcraft/internal/pluginhandler.py
@@ -664,6 +671,8 @@ def _migrate_files(snap_files, snap_dirs, srcdir, dstdir, missing_ok=False,
os.remove(dst)
common.link_or_copy(src, dst, follow_symlinks=follow_symlinks)
+ if fixup_func:
@didrocks

didrocks Jul 1, 2016

Contributor

and so, with a lambda, you can just call the function and not caring :)

snapcraft/internal/repo.py
+ pattern_trim = re.compile(
+ '^prefix={}(?P<prefix>.*)'.format(prefix_trim))
+ pattern = re.compile('^prefix=(?P<prefix>.*)')
+ for line in fileinput.input(pkg_config_file, inplace=True):
@didrocks

didrocks Jul 1, 2016

Contributor

I personnally tend to use fileinput as a contextmanager (easier to read, cleaner on opening/close files) as it's a more pythonish way of doing files handling in python3: https://docs.python.org/3/library/fileinput.html

elif os.path.exists(path):
_fix_filemode(path)
+ if path.endswith('.pc') and not os.path.islink(path):
+ fix_pkg_config(debdir, path)
@didrocks

didrocks Jul 1, 2016

Contributor

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?

@sergiusens

sergiusens Jul 1, 2016

Collaborator

This is the only comment I have not addressed as I really want to get rid of common

snapcraft/internal/repo.py
+ logger.debug('Skipping {}'.format(target))
+ return
+ if not os.path.exists(target):
+ if not _try_copy_local(path, target):
@didrocks

didrocks Jul 1, 2016

Contributor

and isn't of 2 nested if? ;)

sergiusens added some commits Jul 1, 2016

Collaborator

sergiusens commented Jul 1, 2016

the java example failed to build in examples tests. Unrelated IMO and it passed in adt.

Member

kyrofa commented Jul 1, 2016

Yeah, this looks very good 👍

Collaborator

sergiusens commented Jul 1, 2016

tested on @mhall119 's pantheon and works fine

@sergiusens sergiusens merged commit f25abf9 into snapcore:master Jul 1, 2016

3 of 4 checks passed

Examples tests
Details
autopkgtest Success
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.01%) to 96.253%
Details

@sergiusens sergiusens deleted the sergiusens:bugfix/1595243/pkg-config-prefix-what branch Jul 1, 2016

kalikiana pushed a commit to kalikiana/snapcraft that referenced this pull request Apr 6, 2017

Alter prefix for pkg-config to get correct values (#620)
LP: #1595243

Signed-off-by: Sergio Schvezov <sergio.schvezov@ubuntu.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment