Skip to content

Commit a1ed5c8

Browse files
On FreeBSD, prefer the ports version of krb5 to base
Base has heimdal-1.1.0 at the time of writing, while ports have krb5-1.18.2 and heimdal-7.7.0. Related: #228 Signed-off-by: Robbie Harwood <[email protected]>
1 parent 1524cad commit a1ed5c8

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

setup.py

+24-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def get_output(*args, **kwargs):
3737

3838

3939
# get the compile and link args
40+
kc = "krb5-config"
4041
posix = os.name != 'nt'
4142
link_args, compile_args = [
4243
shlex.split(os.environ[e], posix=posix) if e in os.environ else None
@@ -71,6 +72,26 @@ def get_output(*args, **kwargs):
7172
except ValueError:
7273
cygwinccompiler.get_msvcr = lambda *a, **kw: []
7374

75+
if sys.platform.startswith("freebsd"):
76+
# FreeBSD does $PATH backward, for our purposes. That is, the package
77+
# manager's version of the software is in /usr/local, which is in PATH
78+
# *after* the version in /usr. We prefer the package manager's version
79+
# because the Heimdal in base is truly ancient, but this can be overridden
80+
# - either in the "normal" fashion by putting something in PATH in front
81+
# of it, or by removing /usr/local from PATH.
82+
83+
bins = []
84+
for b in os.environ["PATH"].split(":"):
85+
p = f"{b}/krb5-config"
86+
if not os.path.exists(p):
87+
continue
88+
bins.append(p)
89+
90+
if len(bins) > 1 and bins[0] == "/usr/bin/krb5-config" and \
91+
"/usr/local/bin/krb5-config" in bins:
92+
kc = "/usr/local/bin/krb5-config"
93+
print(f"Detected: {kc}")
94+
7495
if link_args is None:
7596
if osx_has_gss_framework:
7697
link_args = ['-framework', 'GSS']
@@ -85,7 +106,7 @@ def get_output(*args, **kwargs):
85106
elif os.environ.get('MINGW_PREFIX'):
86107
link_args = ['-lgss']
87108
else:
88-
link_args = shlex.split(get_output('krb5-config --libs gssapi'))
109+
link_args = shlex.split(get_output(f"{kc} --libs gssapi"))
89110

90111
if compile_args is None:
91112
if osx_has_gss_framework:
@@ -98,14 +119,14 @@ def get_output(*args, **kwargs):
98119
elif os.environ.get('MINGW_PREFIX'):
99120
compile_args = ['-fPIC']
100121
else:
101-
compile_args = shlex.split(get_output('krb5-config --cflags gssapi'))
122+
compile_args = shlex.split(get_output(f"{kc} --cflags gssapi"))
102123

103124
# add in the extra workarounds for different include structures
104125
if winkrb_path:
105126
prefix = winkrb_path
106127
else:
107128
try:
108-
prefix = get_output('krb5-config gssapi --prefix')
129+
prefix = get_output(f"{kc} gssapi --prefix")
109130
except Exception:
110131
print("WARNING: couldn't find krb5-config; assuming prefix of %s"
111132
% str(sys.prefix))

0 commit comments

Comments
 (0)