From aeda5b8bba57df9ad3111ce8619adc9cf59d3ec4 Mon Sep 17 00:00:00 2001 From: Michael Sarahan Date: Fri, 24 Jun 2016 13:06:16 -0500 Subject: [PATCH] add notion of uses_vcs in meta and in build; fix win calling --- conda_build/build.py | 23 ++++++++++++++----- conda_build/metadata.py | 19 ++++++++++++++- conda_build/render.py | 2 +- conda_build/windows.py | 3 +-- .../bld.bat | 3 +++ 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/conda_build/build.py b/conda_build/build.py index dbf1bda9dd..2f13770b8f 100644 --- a/conda_build/build.py +++ b/conda_build/build.py @@ -29,7 +29,7 @@ from conda.resolve import Resolve, MatchSpec, NoPackagesFound from conda_build import __version__ -from conda_build import environ, source, tarcheck +from conda_build import environ, source, tarcheck, external from conda_build.config import config from conda_build.render import parse_or_try_download, output_yaml, bldpkg_path from conda_build.scripts import create_entry_points, prepend_bin_path @@ -472,12 +472,23 @@ def build(m, post=None, include_recipe=True, keep_old_work=False, # have the appropriate VCS available in the environment. People # are not used to explicitly listing it in recipes, though. # We add it for them here, but warn them about it. - vcs_source = m.uses_vcs() + vcs_source = m.uses_vcs_in_build() if vcs_source and vcs_source not in specs: - specs.append(vcs_source) - log.warn("Your recipe depends on {} at build time (for templates), " - "but you have not listed it as a build dependency. Doing so for" - " this build.") + vcs_executable = "hg" if vcs_source == "mercurial" else vcs_source + has_vcs_available = os.path.isfile(external.find_executable(vcs_executable)) + if not has_vcs_available: + if (vcs_source != "mercurial" or + not any(spec.startswith('python') and "3." in spec + for spec in specs)): + specs.append(vcs_source) + + log.warn("Your recipe depends on {} at build time (for templates), " + "but you have not listed it as a build dependency. Doing " + "so for this build.") + else: + raise ValueError("Your recipe uses mercurial in build, but mercurial" + " does not yet support Python 3. Please handle all of " + "your mercurial actions outside of your build script.") # Display the name only # Version number could be missing due to dependency on source info. create_env(config.build_prefix, specs) diff --git a/conda_build/metadata.py b/conda_build/metadata.py index b302624e03..56eb7f011a 100644 --- a/conda_build/metadata.py +++ b/conda_build/metadata.py @@ -29,6 +29,8 @@ from conda_build.config import config from conda_build.utils import comma_join +on_win = (sys.platform == 'win32') + def ns_cfg(): # Remember to update the docs of any of this changes @@ -695,7 +697,7 @@ def __repr__(self): ''' return self.__str__() - def uses_vcs(self): + def uses_vcs_in_meta(self): """returns true if recipe contains metadata associated with version control systems. If this metadata is present, a download/copy will be forced in parse_or_try_download. """ @@ -719,3 +721,18 @@ def uses_vcs(self): vcs = "mercurial" return vcs return None + + def uses_vcs_in_build(self): + build_script = "bld.bat" if on_win else "build.sh" + build_script = os.path.join(os.path.dirname(self.meta_path), build_script) + if os.path.isfile(build_script): + vcs_types = ["git", "svn", "hg"] + with open(self.meta_path) as f: + build_script = f.read() + for vcs in vcs_types: + matches = re.findall(r"{}(?:\.exe)?".format(vcs), build_script) + if len(matches) > 0: + if vcs == "hg": + vcs = "mercurial" + return vcs + return None diff --git a/conda_build/render.py b/conda_build/render.py index 1354a57c82..04afaa9b4b 100644 --- a/conda_build/render.py +++ b/conda_build/render.py @@ -77,7 +77,7 @@ def bldpkg_path(m): def parse_or_try_download(metadata, no_download_source, verbose, force_download=False, dirty=False): - if (force_download or (not no_download_source and metadata.uses_vcs())): + if (force_download or (not no_download_source and metadata.uses_vcs_in_meta())): # this try/catch is for when the tool to download source is actually in # meta.yaml, and not previously installed in builder env. try: diff --git a/conda_build/windows.py b/conda_build/windows.py index 6370f67a1a..d224999dc9 100644 --- a/conda_build/windows.py +++ b/conda_build/windows.py @@ -218,11 +218,10 @@ def build(m, bld_bat, dirty=False, activate=True): fo.write(msvc_env_cmd(bits=cc.bits, override=m.get_value('build/msvc_compiler', None))) if activate: fo.write("call activate _build\n") - fo.write('\n') fo.write("REM ===== end generated header =====\n") fo.write(data) - cmd = [os.environ['COMSPEC'], '/c', 'call', 'bld.bat'] + cmd = [os.environ['COMSPEC'], '/c', 'bld.bat'] _check_call(cmd, cwd=src_dir) kill_processes() fix_staged_scripts() diff --git a/tests/test-recipes/metadata/_conda-build-test-environment-vars-in-build-env/bld.bat b/tests/test-recipes/metadata/_conda-build-test-environment-vars-in-build-env/bld.bat index 1a2f8ad626..cc6eed0c09 100644 --- a/tests/test-recipes/metadata/_conda-build-test-environment-vars-in-build-env/bld.bat +++ b/tests/test-recipes/metadata/_conda-build-test-environment-vars-in-build-env/bld.bat @@ -1,5 +1,8 @@ mkdir %PREFIX%\etc\conda\activate.d +:: output something so it's more obvious when scripts are running +echo "echo setting TEST_VAR" > %PREFIX%\etc\conda\activate.d\test.bat echo set TEST_VAR=1 > %PREFIX%\etc\conda\activate.d\test.bat mkdir %PREFIX%\etc\conda\deactivate.d +echo "echo setting TEST_VAR" > %PREFIX%\etc\conda\deactivate.d\test.bat echo set TEST_VAR= > %PREFIX%\etc\conda\deactivate.d\test.bat