Skip to content

Commit 0b13bd2

Browse files
authored
Merge pull request #8185 from sfayer/fix_platformdet
[8.0] Platform detection on recent EL9 broken
2 parents 1467f2f + 4db2487 commit 0b13bd2

File tree

2 files changed

+2
-199
lines changed

2 files changed

+2
-199
lines changed

src/DIRAC/Core/Utilities/Platform.py

Lines changed: 1 addition & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -2,119 +2,13 @@
22
Compile the externals
33
"""
44
import platform
5-
import sys
6-
import os
7-
import re
8-
9-
# We need to patch python platform module. It does a string comparison for the libc versions.
10-
# it fails when going from 2.9 to 2.10,
11-
# the fix converts the version to a tuple and attempts a numeric comparison
12-
13-
_libc_search = re.compile(b"(__libc_init)" b"|" b"(GLIBC_([0-9.]+))" b"|" b"(libc(_\\w+)?\\.so(?:\\.(\\d[0-9.]*))?)")
14-
15-
16-
def libc_ver(executable=sys.executable, lib="", version="", chunksize=2048):
17-
"""Tries to determine the libc version that the file executable
18-
(which defaults to the Python interpreter) is linked against.
19-
20-
Returns a tuple of strings (lib,version) which default to the
21-
given parameters in case the lookup fails.
22-
23-
Note that the function has intimate knowledge of how different
24-
libc versions add symbols to the executable and thus is probably
25-
only useable for executables compiled using gcc.
26-
27-
The file is read and scanned in chunks of chunksize bytes.
28-
29-
"""
30-
with open(executable, "rb") as f:
31-
binary = f.read(chunksize)
32-
pos = 0
33-
version = [0, 0, 0]
34-
while True:
35-
m = _libc_search.search(binary, pos)
36-
if not m:
37-
binary = f.read(chunksize)
38-
if not binary:
39-
break
40-
pos = 0
41-
continue
42-
libcinit, glibc, glibcversion, so, threads, soversion = m.groups()
43-
if libcinit and not lib:
44-
lib = b"libc"
45-
elif glibc:
46-
glibcversion_parts = glibcversion.split(b".")
47-
for i in range(len(glibcversion_parts)):
48-
try:
49-
glibcversion_parts[i] = int(glibcversion_parts[i])
50-
except ValueError:
51-
glibcversion_parts[i] = 0
52-
if libcinit and not lib:
53-
lib = b"libc"
54-
elif glibc:
55-
if lib != b"glibc":
56-
lib = b"glibc"
57-
version = glibcversion_parts
58-
elif glibcversion_parts > version:
59-
version = glibcversion_parts
60-
elif so:
61-
if lib != b"glibc":
62-
lib = b"libc"
63-
version = max(version, [int(soversion)]).pop()
64-
if threads and version[-len(threads) :] != threads:
65-
version = version + threads
66-
pos = m.end()
67-
return lib.decode(), ".".join(map(str, version))
68-
69-
70-
# ## Command line interface
715

726

737
def getPlatformString():
748
# Modified to return our desired platform string, R. Graciani
759
platformTuple = (platform.system(), platform.machine())
7610
if platformTuple[0] == "Linux":
77-
try:
78-
import subprocess
79-
80-
sp = subprocess.Popen(["/sbin/ldconfig", "--print-cache"], stdout=subprocess.PIPE, universal_newlines=True)
81-
spStdout = sp.stdout
82-
except Exception:
83-
sp = None
84-
spStdout = os.popen("/sbin/ldconfig --print-cache", "r")
85-
ldre = re.compile(r".*=> (.*/libc\.so\..*$)")
86-
libs = []
87-
for line in spStdout.readlines():
88-
reM = ldre.match(line)
89-
if reM:
90-
libs.append(reM.groups()[0])
91-
if sp:
92-
if "terminate" in dir(sp):
93-
sp.terminate()
94-
sp.wait()
95-
96-
if not libs:
97-
# get version of higher libc installed
98-
if platform.machine().find("64") != -1:
99-
lib = "/lib64"
100-
else:
101-
lib = "/lib"
102-
for libFile in os.listdir(lib):
103-
if libFile.find("libc-") == 0 or libFile.find("libc.so") == 0:
104-
libs.append(os.path.join(lib, libFile))
105-
newest_lib = [0, 0, 0]
106-
for lib in libs:
107-
lib_parts = libc_ver(lib)[1].split(".")
108-
for i in range(len(lib_parts)):
109-
try:
110-
lib_parts[i] = int(lib_parts[i])
111-
except ValueError:
112-
lib_parts[i] = 0
113-
# print "non integer version numbers"
114-
if lib_parts > newest_lib:
115-
newest_lib = lib_parts
116-
117-
platformTuple += ("glibc-" + ".".join(map(str, newest_lib)),)
11+
platformTuple += ("-".join(platform.libc_ver()),)
11812
elif platformTuple[0] == "Darwin":
11913
platformTuple += (".".join(platform.mac_ver()[0].split(".")[:2]),)
12014
elif platformTuple[0] == "Windows":

src/DIRAC/Core/scripts/dirac_platform.py

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -23,107 +23,16 @@
2323
except Exception:
2424
import argparse
2525
import platform
26-
import os
27-
import sys
28-
import re
29-
import subprocess
3026

3127
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
3228
parser.parse_known_args()
3329

34-
# We need to patch python platform module. It does a string comparison for the libc versions.
35-
# it fails when going from 2.9 to 2.10,
36-
# the fix converts the version to a tuple and attempts a numeric comparison
37-
38-
_libc_search = re.compile(r"(__libc_init)" "|" "(GLIBC_([0-9.]+))" "|" r"(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)")
39-
40-
def libc_ver(executable=sys.executable, lib="", version="", chunksize=2048):
41-
"""Tries to determine the libc version that the file executable
42-
(which defaults to the Python interpreter) is linked against.
43-
44-
Returns a tuple of strings (lib,version) which default to the
45-
given parameters in case the lookup fails.
46-
47-
Note that the function has intimate knowledge of how different
48-
libc versions add symbols to the executable and thus is probably
49-
only useable for executables compiled using gcc.
50-
51-
The file is read and scanned in chunks of chunksize bytes.
52-
53-
"""
54-
with open(executable, "rb") as f:
55-
binary = f.read(chunksize)
56-
pos = 0
57-
version = [0, 0, 0]
58-
while True:
59-
m = _libc_search.search(binary, pos)
60-
if not m:
61-
binary = f.read(chunksize)
62-
if not binary:
63-
break
64-
pos = 0
65-
continue
66-
libcinit, glibc, glibcversion, so, threads, soversion = m.groups()
67-
if libcinit and not lib:
68-
lib = "libc"
69-
elif glibc:
70-
glibcversion_parts = glibcversion.split(".")
71-
for i in range(len(glibcversion_parts)):
72-
try:
73-
glibcversion_parts[i] = int(glibcversion_parts[i])
74-
except ValueError:
75-
glibcversion_parts[i] = 0
76-
if libcinit and not lib:
77-
lib = "libc"
78-
elif glibc:
79-
if lib != "glibc":
80-
lib = "glibc"
81-
version = glibcversion_parts
82-
elif glibcversion_parts > version:
83-
version = glibcversion_parts
84-
elif so:
85-
if lib != "glibc":
86-
lib = "libc"
87-
version = max(version, soversion)
88-
if threads and version[-len(threads) :] != threads:
89-
version = version + threads
90-
pos = m.end()
91-
return lib, ".".join(map(str, version))
92-
9330
# Command line interface
9431
def getPlatformString():
9532
# Modified to return our desired platform string, R. Graciani
9633
platformTuple = (platform.system(), platform.machine())
9734
if platformTuple[0] == "Linux":
98-
sp = subprocess.Popen(["/sbin/ldconfig", "--print-cache"], stdout=subprocess.PIPE)
99-
ldre = re.compile(r".*=> (.*/libc\.so\..*$)")
100-
libs = []
101-
for line in sp.stdout.readlines():
102-
reM = ldre.match(line)
103-
if reM:
104-
libs.append(reM.groups()[0])
105-
if not libs:
106-
# get version of higher libc installed
107-
if platform.machine().find("64") != -1:
108-
lib = "/lib64"
109-
else:
110-
lib = "/lib"
111-
for libFile in os.listdir(lib):
112-
if libFile.find("libc-") == 0 or libFile.find("libc.so") == 0:
113-
libs.append(os.path.join(lib, libFile))
114-
newest_lib = [0, 0, 0]
115-
for lib in libs:
116-
lib_parts = libc_ver(lib)[1].split(".")
117-
for i in range(len(lib_parts)):
118-
try:
119-
lib_parts[i] = int(lib_parts[i])
120-
except ValueError:
121-
lib_parts[i] = 0
122-
# print "non integer version numbers"
123-
if lib_parts > newest_lib:
124-
newest_lib = lib_parts
125-
126-
platformTuple += ("glibc-" + ".".join(map(str, newest_lib)),)
35+
platformTuple += ("-".join(platform.libc_ver()),)
12736
elif platformTuple[0] == "Darwin":
12837
platformTuple += (".".join(platform.mac_ver()[0].split(".")[:2]),)
12938
elif platformTuple[0] == "Windows":

0 commit comments

Comments
 (0)