Skip to content
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

Fixed compile failure for missing 'CC' key #226

Merged
merged 6 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Enhancements
Bug fixes
----------
- Fixing docs build failure on Travis [#215]
- Fixing compile failure on missing 'CC' in environment [#226]


2.3.3 (2019-02-03)
Expand Down
79 changes: 49 additions & 30 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,23 +234,21 @@ def requirements_check():
common = replace_first_key_in_makefile(common, key, replacement,
common_mk_file)

# check if the environ is set
if os.environ['CC']:
value = os.environ['CC']

# Check if CC is in argv:
CC = "CC"
for iarg, arg in enumerate(sys.argv):
if CC not in arg:
continue

if '=' in arg:
# user passed `CC=/path/to/compiler`
# therefore, split on '=' to get the
# compiler (i.e, 'CC') and the value
# (i.e, the name/path of compiler)
key, value = arg.strip().split('=')
else:
# Space-separated or no spaces and equal
# Space-separated or spaces and an '=' sign
key = arg.strip()
check_arg = iarg+1

if key != CC:
msg = "Something strange has happened. Expected to find "\
"a custom compiler from the command-line but \n"\
Expand All @@ -259,21 +257,39 @@ def requirements_check():
"produced CC={1}".format(arg, key)
raise ValueError(msg)

# Is there an "=" sign or did the user
# simply pass `CC /path/to/compiler`
if check_arg < len(sys.argv):
if sys.argv[check_arg] == '=':
# skip '=' sign
del sys.argv[check_arg]

# should be parsing the compiler value now
if not check_arg < len(sys.argv):
msg = "Found compiler key = CC but could not locate "\
"compiler value (either as `CC=/path/to/CC` "\
"or as `CC /path/to/CC`"
check_arg = iarg+1
# Is there an "=" sign (i.e., `CC = /path/to/compiler`)
# or did the user simply pass `CC /path/to/compiler`
if check_arg >= len(sys.argv):
msg = "Found compiler key = {} but could not locate "\
"compiler value - no further command-line "\
"parameters were passed.\nPlease pass the "\
"custom compiler name either `CC=compiler`"\
"or as `CC=/path/to/compiler`".format(key)
raise ValueError(msg)

value = sys.argv[check_arg].strip()
# The user could have specified `CC =compiler` or
# `CC = compiler`. The following 'if' condition checks
# for the first case, the 'else' checks for the second
# case (`CC = compiler`)
if '=' in sys.argv[check_arg] and \
sys.argv[check_arg].strip() != '=':
_, value = sys.argv[check_arg].strip().split('=')
else:
# Otherwise, there was white-space separated '='
# we can delete that command-line argument containing
# just the '=' sign.
del sys.argv[check_arg]
# should be parsing the compiler value now
if check_arg >= len(sys.argv):
msg = "Found compiler key = CC but could not locate "\
"compiler value (either as `CC=/path/to/CC` "\
"or as `CC /path/to/CC`"
raise ValueError(msg)

value = sys.argv[check_arg].strip()

# this deletes the argument containing the compiler name
del sys.argv[check_arg]

if key != CC or value == '':
Expand All @@ -289,19 +305,22 @@ def requirements_check():
full_compiler = which(value)
if full_compiler is None:
msg = "Found compiler = '{0}' on the command-line but '{0}' "\
"can not be resolved from the shell.\n"\
"Please specify CC=/path/to/compiler in the "\
"python -m pip setup.py call.".format(value)
"can not be resolved from the shell.\n"\
"Please specify CC=/path/to/compiler in the "\
"python -m pip setup.py call.".format(value)
raise ValueError(msg)
del sys.argv[iarg]
break

replacement = '\n{0}:={1}'.format(CC, value)
replace_first_key_in_makefile(common, CC,
replacement, common_mk_file)
replacement = '\n{0}:={1}'.format(CC, value)
replace_first_key_in_makefile(common, CC,
replacement, common_mk_file)

global compiler
compiler = value

global compiler
compiler = value
# Delete the 'CC' key, the compiler name and the '='
# have already been deleted
del sys.argv[iarg]
break

return common_dict

Expand Down