Skip to content

Instantly share code, notes, and snippets.

@SteelPangolin
Last active August 29, 2015 13:56
Show Gist options
  • Save SteelPangolin/8840105 to your computer and use it in GitHub Desktop.
Save SteelPangolin/8840105 to your computer and use it in GitHub Desktop.
"""
Decorate SCons Environment constructor so that Homebrew paths are always included.
"""
from functools import wraps
import SCons.Environment
# Homebrew install directory
homebrew = '/opt/homebrew'
flag_prepends = [
('CFLAGS', '-I{}/include'.format(homebrew)),
('CXXFLAGS', '-I{}/include'.format(homebrew)),
('LDFLAGS', '-L{}/lib' .format(homebrew)),
]
def add_homebrew_vars(environment_init):
@wraps(environment_init)
def wrapper(self, *args, **kwargs):
for var, flag in flag_prepends:
flags_list = [flag]
if var in kwargs:
flags_list.append(kwargs[var])
kwargs[var] = ' '.join(flags_list)
environment_init(self, *args, **kwargs)
self.PrependENVPath('PATH', '{}/bin'.format(homebrew))
return wrapper
SCons.Environment.Environment.__init__ = add_homebrew_vars(SCons.Environment.Environment.__init__)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment