Navigation Menu

Skip to content

Commit

Permalink
Download config.guess on the fly (if possible)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan O'Cais committed Sep 21, 2018
1 parent aa4d649 commit adfc4fc
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 3,214 deletions.
95 changes: 78 additions & 17 deletions easybuild/easyblocks/generic/configuremake.py
Expand Up @@ -36,13 +36,20 @@
"""

import os
import stat

from easybuild.framework.easyblock import EasyBlock
from easybuild.framework.easyconfig import CUSTOM
from easybuild.tools.build_log import print_warning
from easybuild.tools.filetools import read_file, which
from easybuild.tools.config import source_paths
from easybuild.tools.version import EASYBLOCKS_VERSION
from easybuild.tools.filetools import adjust_permissions, download_file, read_file, remove_file, verify_checksum
from easybuild.tools.run import run_cmd

CONFIG_DOT_GUESS_URL_STUB = "https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb="
CONFIG_DOT_GUESS_COMMIT_ID = "59e2ce0e6b46bb47ef81b68b600ed087e14fdaad"
CONFIG_DOT_GUESS_SHA256 = "c02eb9cc55c86cfd1e9a794e548d25db5c9539e7b2154beb649bc6e2cbffc74c"


class ConfigureMake(EasyBlock):
"""
Expand All @@ -62,6 +69,61 @@ def extra_options(extra_vars=None):
})
return extra_vars

def obtain_config_dot_guess(self, download_source_path=None, search_source_paths=None):
"""
Locate or download an up-to-date config.guess for use with ConfigureMake
:param download_source_path: Path to download config.guess to
:param search_source_paths: Paths to search for config.guess
:return: Path to config.guess or None
"""
eb_source_paths = source_paths()
if download_source_path is None:
download_source_path = eb_source_paths[0]
if search_source_paths is None:
search_source_paths = eb_source_paths

download_name = 'config.guess'
download_relpath = os.path.join('generic', 'eb_v' + EASYBLOCKS_VERSION.vstring, 'ConfigureMake', download_name)
download_url = CONFIG_DOT_GUESS_URL_STUB + CONFIG_DOT_GUESS_COMMIT_ID

config_dot_guess_path = None

# Check file exists
for path in eb_source_paths:
tmp_config_dot_guess_path = os.path.join(path, download_relpath)
if os.path.isfile(tmp_config_dot_guess_path):
config_dot_guess_path = tmp_config_dot_guess_path
self.log.info("Found recent %s at %s, using it if required.", download_name, config_dot_guess_path)
break
# If not try to grab it
if config_dot_guess_path is None:
tmp_config_dot_guess_path = os.path.join(download_source_path, download_relpath)
downloaded_path = download_file(download_name, download_url, tmp_config_dot_guess_path)
if downloaded_path is not None:
# Check the SHA256
if verify_checksum(downloaded_path, CONFIG_DOT_GUESS_SHA256):
config_dot_guess_path = downloaded_path
# Add execute permissions
adjust_permissions(downloaded_path, stat.S_IXUSR|stat.S_IXGRP|stat.S_IXOTH, add=True)
self.log.info("Downloaded recent %s to %s, using it if required.", download_name,
config_dot_guess_path)
else:
self.log.info("Checksum failed for downloaded file %s, not using!", downloaded_path)
remove_file(downloaded_path)
else:
self.log.info("Failed to download recent %s to %s for use with ConfigureMake easyblock (if needed).",
download_name, tmp_config_dot_guess_path)

return config_dot_guess_path

def fetch_step(self, *args, **kwargs):
"""Custom fetch step for ConfigureMake so we use an updated config.guess."""
super(ConfigureMake, self).fetch_step(*args, **kwargs)

# Use an updated config.guess from a global location (if possible)
self.config_dot_guess = self.obtain_config_dot_guess()

def configure_step(self, cmd_prefix=''):
"""
Configure step
Expand Down Expand Up @@ -96,22 +158,21 @@ def configure_step(self, cmd_prefix=''):
# use the version shipped with EB instead and provide the result to the configure command
build_type_option = ''
# possible that the configure_command is generated using preconfigopts...we're at the mercy of the gods then
if os.path.isfile(configure_command):
if 'Generated by GNU Autoconf' in read_file(configure_command):
build_type = self.cfg.get('build_type')

if build_type is None:
config_guess_path = which('config.guess')
if config_guess_path is None:
print_warning("No config.guess in $PATH, not setting '--build' option for configure step\n"
"EasyBuild ships with a recent config.guess, please verify your installation!")
else:
build_type, _ = run_cmd('config.guess', log_all=True)
build_type = build_type.strip()
self.log.info("%s returned a build type %s", config_guess_path, build_type)

if build_type is not None:
build_type_option = '--build=' + build_type
if 'Generated by GNU Autoconf' in read_file(configure_command):
build_type = self.cfg.get('build_type')

if build_type is None:
config_guess_path = self.config_dot_guess
if config_guess_path is None:
print_warning("No config.guess available, not setting '--build' option for configure step\n"
"EasyBuild attempts to download a recent config.guess but seems to have failed!")
else:
build_type, _ = run_cmd(config_guess_path, log_all=True)
build_type = build_type.strip()
self.log.info("%s returned a build type %s", config_guess_path, build_type)

if build_type is not None:
build_type_option = '--build=' + build_type

cmd = ' '.join([
self.cfg['preconfigopts'],
Expand Down
30 changes: 0 additions & 30 deletions easybuild/scripts/configuremake/README.md

This file was deleted.

0 comments on commit adfc4fc

Please sign in to comment.