8000 Reduce redundancy while checking *FLAGS for LTO. · matplotlib/matplotlib@3fd316d · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3fd316d

Browse files
committed
Reduce redundancy while checking *FLAGS for LTO.
1 parent b121942 commit 3fd316d

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

setup.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -110,31 +110,27 @@ def add_optimization_flags(self):
110110
enable_lto = setupext.config.getboolean('libs', 'enable_lto',
111111
fallback=None)
112112

113-
if 'CFLAGS' in os.environ:
114-
if '-fno-lto' in os.environ['CFLAGS']:
115-
if enable_lto is True:
116-
raise ValueError('Configuration enable_lto=True, but '
117-
'CFLAGS contains -fno-lto')
118-
enable_lto = False
119-
cppflags = []
120-
if 'CPPFLAGS' in os.environ:
121-
cppflags.append(os.environ['CPPFLAGS'])
122-
if '-fno-lto' in os.environ['CPPFLAGS']:
123-
if enable_lto is True:
124-
raise ValueError('Configuration enable_lto=True, but '
125-
'CPPFLAGS contains -fno-lto')
126-
enable_lto = False
127-
cxxflags = []
128-
if 'CXXFLAGS' in os.environ:
129-
cxxflags.append(os.environ['CXXFLAGS'])
130-
if '-fno-lto' in os.environ['CXXFLAGS']:
131-
if enable_lto is True:
132-
raise ValueError('Configuration enable_lto=True, but '
133-
'CXXFLAGS contains -fno-lto')
134-
enable_lto = False
135-
ldflags = []
136-
if 'LDFLAGS' in os.environ:
137-
ldflags.append(os.environ['LDFLAGS'])
113+
def prepare_flags(name, enable_lto):
114+
"""
115+
Prepare *FLAGS from the environment.
116+
117+
If set, return them, and also check whether LTO is disabled in each
118+
one, raising an error if Matplotlib config explicitly enabled LTO.
119+
"""
120+
flags = []
121+
if name in os.environ:
122+
flags.append(os.environ[name])
123+
if '-fno-lto' in os.environ[name]:
124+
if enable_lto is True:
125+
raise ValueError('Configuration enable_lto=True, but '
126+
'{0} contains -fno-lto'.format(name))
127+
enable_lto = False
128+
return flags, enable_lto
129+
130+
_, enable_lto = prepare_flags('CFLAGS', enable_lto) # Only check lto.
131+
cppflags, enable_lto = prepare_flags('CPPFLAGS', enable_lto)
132+
cxxflags, enable_lto = prepare_flags('CXXFLAGS', enable_lto)
133+
ldflags, enable_lto = prepare_flags('LDFLAGS', enable_lto)
138134

139135
if enable_lto is False:
140136
return env

0 commit comments

Comments
 (0)
0