Skip to content

Commit

Permalink
add notion of uses_vcs in meta and in build; fix win calling
Browse files Browse the repository at this point in the history
  • Loading branch information
msarahan committed Jun 24, 2016
1 parent 2d889ab commit aeda5b8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
23 changes: 17 additions & 6 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 18 additions & 1 deletion conda_build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
"""
Expand All @@ -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
2 changes: 1 addition & 1 deletion conda_build/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions conda_build/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit aeda5b8

Please sign in to comment.