-
-
Notifications
You must be signed in to change notification settings - Fork 553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'sage-location' shouldn't "initialize" .pc (pkg-config) files more than once #11760
Comments
This comment has been minimized.
This comment has been minimized.
Changed keywords from pkgconfig libpng to pkgconfig libpng Duplicate definition SAGE_ROOT |
comment:3
leif, this ticket is listed as blocker. Any ideas for a quick fix? |
SCRIPTS repo. Based on Sage 4.7.2.alpha3. |
This comment has been minimized.
This comment has been minimized.
Author: Leif Leonhardy |
comment:4
Attachment: trac_11760-avoid_multiple_defs_of_SAGE_ROOT.scripts.patch.gz Couldn't resist to also do some clean-up. Actual (trivial) fix starting on line 178. |
comment:5
P.S.: The fix doesn't cure already broken installations (i.e., To test the patch, you can change the contents of or remove the file |
comment:6
Replying to @nexttime:
I could more or less easily also add that, but it wouldn't help much (on e.g. upgrades) since neither |
comment:7
In lines 178-181:
what if the path to SAGE_ROOT has changed? Would it be better to delete this first line (containing |
comment:8
Replying to @jhpalmieri:
This is
As mentioned in the description, I was aiming at a quick fix which solves the issue we have, not at curing arbitrary corrupted Also, Nevertheless, any wrong definition of Since |
comment:9
Replying to @nexttime:
Ah, I see. So we could in principle add diff --git a/sage-location b/sage-location
--- a/sage-location
+++ b/sage-location
@@ -68,6 +68,7 @@
write_location_file()
update_library_files()
initialize_pkgconfig_files()
+ update_pkgconfig_files()
return False
elif path != SAGE_ROOT:
# location moved but that's IMHO really a minor issue since that situation doesn't occur unless the user damages his |
comment:10
John, would the following make you happy? diff --git a/sage-location b/sage-location
--- a/sage-location
+++ b/sage-location
@@ -167,6 +167,7 @@
the Sage installation has moved, i.e., paths have changed.
"""
import re
+ pat = re.compile(r"^SAGE_ROOT=.*\n", re.MULTILINE)
LIB = os.path.join(os.path.abspath(SAGE_ROOT), 'local', 'lib')
PKG = os.path.join(LIB, 'pkgconfig')
for name in os.listdir(PKG):
@@ -175,10 +176,23 @@
with open(filename) as file:
config = file.read()
- if re.search("^SAGE_ROOT=", config, re.MULTILINE):
- # There's already a definition of SAGE_ROOT,
- # so skip this file. (Cf. #11760).
- continue
+ first_match = pat.search(config)
+ if first_match:
+ # There are already one or more definitions of SAGE_ROOT,
+ # which also happens if we previously processed the same
+ # file (here) because of [symbolic or hard] links, so this
+ # isn't necessarily an error. (Cf. #11760).
+ # For simplicity, we just remove any definition, and only
+ # issue a warning if there was more than one, and don't
+ # check whether a previous definition was already current:
+ config, n = pat.subn("", config)
+ if n>1:
+ sys.stderr.write(
+ "Warning: sage_location: initialize_pkgconfig_files():\n" +
+ " File \"%s\" already contained %d definitions of SAGE_ROOT.\n" %
+ (name, n) +
+ " These will get replaced by a single, current definition.\n")
+ sys.stderr.flush()
new_config = config.replace(os.path.abspath(SAGE_ROOT), "${SAGE_ROOT}")
new_config = 'SAGE_ROOT=%s\n' % os.path.abspath(SAGE_ROOT) + new_config If so, I'll just attach that patch, to be applied on top of the other one. |
comment:11
I could of course remove the temporary variable I.e., if pat.search(config):
... would be sufficient. |
comment:12
P.S.: We could do similar in |
comment:13
Replying to @nexttime:
Like this, which IMHO is also somehow a bit cleaner: diff --git a/sage-location b/sage-location
--- a/sage-location
+++ b/sage-location
@@ -194,16 +207,17 @@
``initialize_pkgconfig_files()``, in particular, each of them contains a
definition of the variable ``SAGE_ROOT``, since only that is updated here.
"""
+ import re
+ pat = re.compile(r"^SAGE_ROOT=.*\n", re.MULTILINE)
LIB = os.path.join(os.path.abspath(SAGE_ROOT), 'local', 'lib')
PKG = os.path.join(LIB, 'pkgconfig')
for name in os.listdir(PKG):
- filename = os.path.join(PKG,name)
+ filename = os.path.join(PKG, name)
if os.path.splitext(filename)[1]==".pc":
with open(filename) as file:
config = file.read()
- prefix_start = config.find('SAGE_ROOT=')
- if prefix_start==-1:
+ if not pat.search(config):
# This should never happen, unless the user modified the file.
sys.stderr.write(
"Error: sage_location: update_pkgconfig_files():\n" +
@@ -211,12 +225,16 @@
name + " Skipping it...\n")
sys.stderr.flush()
continue
+ # We could of course call initialize_pkgconfig_file(filename)
+ # here instead to fix this issue, but unfortunately there's no
+ # such function (for a single file) [yet].
- prefix_end = config.find('\n', prefix_start)
- new_prefix = 'SAGE_ROOT=%s' % os.path.abspath(SAGE_ROOT)
- new_config = config[:prefix_start] + new_prefix + config[prefix_end:]
+ # Delete all previous definitions of SAGE_ROOT:
+ config = pat.sub("", config)
+
+ definition = "SAGE_ROOT=%s\n" % os.path.abspath(SAGE_ROOT)
with open(filename, 'w') as file:
- file.write(new_config)
+ file.write(definition + config)
def remove_files(path, remove_extensions): |
comment:14
Ok, I've further improved and normalized both functions... Just wonder whether using (I've factored out |
Attachment: trac_11760-additional_improvements_to_pkgconfig_funs.optional.scripts.patch.gz SCRIPTS repo. Optional improvements to |
comment:15
Ok, I've attached another, optional patch, to be applied on top of the other one. |
This comment has been minimized.
This comment has been minimized.
Attachment: trac_11760-cumulative_diff_of_both_patches.diff.gz Cumulative diff of both patches against Sage 4.7.2.alpha3. For review only. |
comment:16
Note that (as I already mentioned elsewhere), on a follow-up or one of the other tickets, we have to (re-)initialize This ticket just fixes the worst cases, and especially the one that currently always occurs (since more than a year by the way), namely duplicate definitions of If sh*t happens during reinstallation of one or more packages, with the patches here, the user will now be able to repair all |
comment:17
Regarding the comment
You could use re.escape to deal with this issue. In
The Otherwise, the combined patch looks pretty good to me. I still have to actually test it... |
comment:18
Replying to @jhpalmieri:
Yep, but I haven't tested [yet] whether using
Nope. The optional |
comment:19
Replying to @nexttime:
There seems to be no (measurable) difference (10.9--11 vs. 11 ns with |
comment:20
Btw., with |
comment:21
Looks like IPython's |
comment:22
Replying to @nexttime:
Oh, my bad, I quoted the statement... 8/ Btw., interestingly the timing framework somehow makes the braces special characters, so I have to escape them for the timing tests, but the backslashs also end up in the result... Weird. |
comment:23
Replying to @nexttime:
Sorry, I misread the documentation (thought it said "leftmost non-overlapping occurrence" instead of "leftmost non-overlapping occurrences").
Yes, but you don't have to ever look at them, do you? Just pass them on to Anyway, things look good to me. In testing, the old version acts badly if, for example, you delete "sage-location.txt", whereas the new version does a good job of cleaning up the resulting mess. I've tried to break the new version in other ways, but not successfully. There may still be holes, but I'm not sure where. In any case, it's an improvement over the previous version. (If you feel like adding a comment about re.escape, in case someone else works on this, go ahead. No need for further review in that case.) |
Reviewer: John Palmieri |
This comment has been minimized.
This comment has been minimized.
comment:25
Replying to @jhpalmieri:
Of course, but longer strings take longer to compile... ;-)
It seems |
comment:26
P.S.: Thanks for reviewing this; triple X when it's finally merged and we get rid of this long-lasting issue. |
comment:27
Replying to @nexttime:
So where is the party? |
Merged: sage-4.7.2.alpha4 |
comment:28
See #12331 for a follow-up. |
The logic of "initializing"
.pc
files exactly once is currently broken, which at the moment "only" causes trouble with libpng ifpkg-config
is installed.The main reason is that
sage-location
doesn't really check whether a.pc
file already contains a definition ofSAGE_ROOT
, and unconditionally replaces any occurrences of$SAGE_ROOT
(i.e., its current value) by${SAGE_ROOT}
, then adding a (in the case ofupdate_pkgconfig_files()
, replacing the first) line definingSAGE_ROOT
to have the current value.The specific problem with libpng (see e.g. #11686, which was originally intended to just again fix a completely unrelated issue with the matplotlib spkg) arises since it installs both a
libpng12.pc
file and a symbolic linklibpng.pc
, the latter pointing to the former.sage-location
now "initializes" all of Sage's.pc
files, not checking whether a.pc
file is just a symbolic link to another one, nor checking whether a file already got modified as mentioned above.Note that the "initialization" doesn't take place during a build, but when Sage is started for the first time, also when e.g. running tests, such that problems with modified
.pc
files occur later, when one tries to (re)install some package(s), which includes upgrading Sage.In the long run,
sage-location
shouldn't (have to) deal with.pc
files at all, but we IMHO need a quick fix until we have a better, more general solution to all issues withpkg-config
. (There are a couple of other issues; cf. for example #10202, #9668, #11687, #11681.) Therefore this ticket isn't intended to fix any of the other issues.Apply
to the Sage scripts repository.
Component: scripts
Keywords: pkgconfig libpng Duplicate definition SAGE_ROOT
Author: Leif Leonhardy
Reviewer: John Palmieri
Merged: sage-4.7.2.alpha4
Issue created by migration from https://trac.sagemath.org/ticket/11760
The text was updated successfully, but these errors were encountered: