|
66 | 66 | DEFAULT_BUILD_CMD = 'make' |
67 | 67 | DEFAULT_INSTALL_CMD = 'make install' |
68 | 68 |
|
| 69 | +def check_config_guess(config_guess, log=None): |
| 70 | + """Check timestamp & SHA256 checksum of config.guess script. |
| 71 | +
|
| 72 | + :param configu_gess: Path to config.guess script to check |
| 73 | + :param log: Instance of a logger to use or None to run in quiet mode |
| 74 | + :return: Whether the script is valid (matches the version and checksum) |
| 75 | + """ |
| 76 | + # config.guess includes a "timestamp='...'" indicating the version |
| 77 | + config_guess_version = None |
| 78 | + version_regex = re.compile("^timestamp='(.*)'", re.M) |
| 79 | + res = version_regex.search(read_file(config_guess)) |
| 80 | + if res: |
| 81 | + config_guess_version = res.group(1) |
| 82 | + |
| 83 | + config_guess_checksum = compute_checksum(config_guess, checksum_type=CHECKSUM_TYPE_SHA256) |
| 84 | + try: |
| 85 | + config_guess_timestamp = datetime.fromtimestamp(os.stat(config_guess).st_mtime).isoformat() |
| 86 | + except OSError as err: |
| 87 | + if log: |
| 88 | + log.warning("Failed to determine timestamp of %s: %s", config_guess, err) |
| 89 | + config_guess_timestamp = None |
| 90 | + |
| 91 | + # log version, timestamp & SHA256 checksum of config.guess |
| 92 | + if log: |
| 93 | + log.info("config.guess version: %s (last updated: %s, SHA256 checksum: %s)", |
| 94 | + config_guess_version, config_guess_timestamp, config_guess_checksum) |
| 95 | + |
| 96 | + result = True |
| 97 | + |
| 98 | + if config_guess_version != CONFIG_GUESS_VERSION: |
| 99 | + result = False |
| 100 | + tup = (config_guess, config_guess_version, CONFIG_GUESS_VERSION) |
| 101 | + if log: |
| 102 | + log.warning("config.guess version at %s does not match expected version: %s vs %s" % tup) |
| 103 | + if config_guess_checksum != CONFIG_GUESS_SHA256: |
| 104 | + result = False |
| 105 | + tup = (config_guess, config_guess_checksum, CONFIG_GUESS_SHA256) |
| 106 | + if log: |
| 107 | + log.warning("SHA256 checksum of config.guess at %s does not match expected checksum: %s vs %s" % tup) |
| 108 | + |
| 109 | + return result |
| 110 | + |
| 111 | +def obtain_config_guess(download_source_path=None, search_source_paths=None, log=None): |
| 112 | + """ |
| 113 | + Locate or download an up-to-date config.guess |
| 114 | +
|
| 115 | + :param download_source_path: Path to download config.guess to |
| 116 | + :param search_source_paths: Paths to search for config.guess |
| 117 | + :param log: Instance of a logger to use or None to run in quiet mode |
| 118 | + :return: Path to config.guess or None |
| 119 | + """ |
| 120 | + eb_source_paths = source_paths() |
| 121 | + if download_source_path is None: |
| 122 | + download_source_path = eb_source_paths[0] |
| 123 | + if search_source_paths is None: |
| 124 | + search_source_paths = eb_source_paths |
| 125 | + |
| 126 | + config_guess = 'config.guess' |
| 127 | + sourcepath_subdir = os.path.join('generic', 'eb_v%s' % EASYBLOCKS_VERSION, 'ConfigureMake') |
| 128 | + |
| 129 | + config_guess_path = None |
| 130 | + |
| 131 | + # check if config.guess has already been downloaded to source path |
| 132 | + for path in eb_source_paths: |
| 133 | + cand_config_guess_path = os.path.join(path, sourcepath_subdir, config_guess) |
| 134 | + if os.path.isfile(cand_config_guess_path): |
| 135 | + config_guess_path = cand_config_guess_path |
| 136 | + if log: |
| 137 | + log.info("Found recent %s at %s, using it if required", config_guess, config_guess_path) |
| 138 | + break |
| 139 | + |
| 140 | + # if not found, try to download it |
| 141 | + if config_guess_path is None: |
| 142 | + cand_config_guess_path = os.path.join(download_source_path, sourcepath_subdir, config_guess) |
| 143 | + config_guess_url = CONFIG_GUESS_URL_STUB + CONFIG_GUESS_COMMIT_ID |
| 144 | + downloaded_path = download_file(config_guess, config_guess_url, cand_config_guess_path) |
| 145 | + if downloaded_path is not None: |
| 146 | + # verify SHA256 checksum of download to avoid using a corrupted download |
| 147 | + if verify_checksum(downloaded_path, CONFIG_GUESS_SHA256): |
| 148 | + config_guess_path = downloaded_path |
| 149 | + # add execute permissions |
| 150 | + adjust_permissions(downloaded_path, stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH, add=True) |
| 151 | + if log: |
| 152 | + log.info("Downloaded recent %s to %s, using it if required", config_guess, config_guess_path) |
| 153 | + else: |
| 154 | + if log: |
| 155 | + log.warning("Checksum failed for downloaded file %s, not using it!", downloaded_path) |
| 156 | + remove_file(downloaded_path) |
| 157 | + elif log: |
| 158 | + log.warning("Failed to download recent %s to %s", config_guess, cand_config_guess_path) |
| 159 | + |
| 160 | + return config_guess_path |
| 161 | + |
69 | 162 |
|
70 | 163 | class ConfigureMake(EasyBlock): |
71 | 164 | """ |
@@ -106,74 +199,13 @@ def obtain_config_guess(self, download_source_path=None, search_source_paths=Non |
106 | 199 | :param search_source_paths: Paths to search for config.guess |
107 | 200 | :return: Path to config.guess or None |
108 | 201 | """ |
109 | | - eb_source_paths = source_paths() |
110 | | - if download_source_path is None: |
111 | | - download_source_path = eb_source_paths[0] |
112 | | - if search_source_paths is None: |
113 | | - search_source_paths = eb_source_paths |
114 | | - |
115 | | - config_guess = 'config.guess' |
116 | | - sourcepath_subdir = os.path.join('generic', 'eb_v%s' % EASYBLOCKS_VERSION, 'ConfigureMake') |
117 | | - |
118 | | - config_guess_path = None |
119 | | - |
120 | | - # check if config.guess has already been downloaded to source path |
121 | | - for path in eb_source_paths: |
122 | | - cand_config_guess_path = os.path.join(path, sourcepath_subdir, config_guess) |
123 | | - if os.path.isfile(cand_config_guess_path): |
124 | | - config_guess_path = cand_config_guess_path |
125 | | - self.log.info("Found recent %s at %s, using it if required", config_guess, config_guess_path) |
126 | | - break |
127 | | - |
128 | | - # if not found, try to download it |
129 | | - if config_guess_path is None: |
130 | | - cand_config_guess_path = os.path.join(download_source_path, sourcepath_subdir, config_guess) |
131 | | - config_guess_url = CONFIG_GUESS_URL_STUB + CONFIG_GUESS_COMMIT_ID |
132 | | - downloaded_path = download_file(config_guess, config_guess_url, cand_config_guess_path) |
133 | | - if downloaded_path is not None: |
134 | | - # verify SHA256 checksum of download to avoid using a corrupted download |
135 | | - if verify_checksum(downloaded_path, CONFIG_GUESS_SHA256): |
136 | | - config_guess_path = downloaded_path |
137 | | - # add execute permissions |
138 | | - adjust_permissions(downloaded_path, stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH, add=True) |
139 | | - self.log.info("Downloaded recent %s to %s, using it if required", config_guess, config_guess_path) |
140 | | - else: |
141 | | - self.log.warning("Checksum failed for downloaded file %s, not using it!", downloaded_path) |
142 | | - remove_file(downloaded_path) |
143 | | - else: |
144 | | - self.log.warning("Failed to download recent %s to %s for use with ConfigureMake easyblock (if needed)", |
145 | | - config_guess, cand_config_guess_path) |
146 | | - |
147 | | - return config_guess_path |
| 202 | + return obtain_config_guess(download_source_path, search_source_paths, log=self.log) |
148 | 203 |
|
149 | 204 | def check_config_guess(self): |
150 | 205 | """Check timestamp & SHA256 checksum of config.guess script.""" |
151 | 206 | # log version, timestamp & SHA256 checksum of config.guess that was found (if any) |
152 | 207 | if self.config_guess: |
153 | | - # config.guess includes a "timestamp='...'" indicating the version |
154 | | - config_guess_version = None |
155 | | - version_regex = re.compile("^timestamp='(.*)'", re.M) |
156 | | - res = version_regex.search(read_file(self.config_guess)) |
157 | | - if res: |
158 | | - config_guess_version = res.group(1) |
159 | | - |
160 | | - config_guess_checksum = compute_checksum(self.config_guess, checksum_type=CHECKSUM_TYPE_SHA256) |
161 | | - try: |
162 | | - config_guess_timestamp = datetime.fromtimestamp(os.stat(self.config_guess).st_mtime).isoformat() |
163 | | - except OSError as err: |
164 | | - self.log.warning("Failed to determine timestamp of %s: %s", self.config_guess, err) |
165 | | - config_guess_timestamp = None |
166 | | - |
167 | | - self.log.info("config.guess version: %s (last updated: %s, SHA256 checksum: %s)", |
168 | | - config_guess_version, config_guess_timestamp, config_guess_checksum) |
169 | | - |
170 | | - if config_guess_version != CONFIG_GUESS_VERSION: |
171 | | - tup = (self.config_guess, config_guess_version, CONFIG_GUESS_VERSION) |
172 | | - print_warning("config.guess version at %s does not match expected version: %s vs %s" % tup) |
173 | | - |
174 | | - if config_guess_checksum != CONFIG_GUESS_SHA256: |
175 | | - tup = (self.config_guess, config_guess_checksum, CONFIG_GUESS_SHA256) |
176 | | - print_warning("SHA256 checksum of config.guess at %s does not match expected checksum: %s vs %s" % tup) |
| 208 | + check_config_guess(self.config_guess, log=self.log) |
177 | 209 |
|
178 | 210 | def fetch_step(self, *args, **kwargs): |
179 | 211 | """Custom fetch step for ConfigureMake so we use an updated config.guess.""" |
|
0 commit comments