Skip to content

Commit

Permalink
Avoid permanent environment modification
Browse files Browse the repository at this point in the history
  • Loading branch information
db4 committed May 6, 2021
1 parent 3cf0095 commit 6752377
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions recipes/openssl/1.x.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import fnmatch
import textwrap
from contextlib import contextmanager
from functools import total_ordering
from conans.errors import ConanInvalidConfiguration
from conans import ConanFile, AutoToolsBuildEnvironment, tools
Expand Down Expand Up @@ -635,13 +636,6 @@ def _make(self):
if self._use_nmake and self._full_version >= "1.1.0":
self._replace_runtime_in_file(os.path.join("Configurations", "10-main.conf"))

if self._use_nmake:
# Windows: when cmake generates its cache, it populates some environment variables as well.
# If cmake also initiates openssl build, their values (containing spaces and forward slashes)
# break nmake (don't know about mingw make). So we fix them
for v in ['CC', 'CXX', 'RC']:
if v in os.environ and not '"' in os.environ[v]:
os.environ[v] = '"' + os.environ[v].replace('/', '\\') + '"'
self.run('{perl} ./Configure {args}'.format(perl=self._perl, args=args), win_bash=self._win_bash)

self._patch_install_name()
Expand Down Expand Up @@ -687,6 +681,20 @@ def _cc(self):
return "gcc"
return "cc"

@contextmanager
def _make_context(self):
if self._use_nmake:
# Windows: when cmake generates its cache, it populates some environment variables as well.
# If cmake also initiates openssl build, their values (containing spaces and forward slashes)
# break nmake (don't know about mingw make). So we fix them
def sanitize_env_var(var):
return '"{}"'.format(var).replace('/', '\\') if '"' not in var else var
env = {key: sanitize_env_var(tools.get_env(key)) for key in ("CC", "RC") if tools.get_env(key)}
with tools.environment_append(env):
yield
else:
yield

def build(self):
with tools.vcvars(self.settings) if self._use_nmake else tools.no_op():
env_vars = {"PERL": self._perl}
Expand All @@ -706,6 +714,7 @@ def build(self):
else:
self._patch_configure()
self._patch_makefile_org()
with self._make_context():
self._make()

@property
Expand Down

0 comments on commit 6752377

Please sign in to comment.