| 1199 | return ret |
| 1200 | |
| 1201 | def get_library(self, name, generated_libs, configure=['sh', './configure'], # noqa |
| 1202 | configure_args=None, make=None, make_args=None, |
| 1203 | env_init=None, cache_name_extra='', native=False, |
| 1204 | force_rebuild=False): |
| 1205 | if make is None: |
| 1206 | make = ['make'] |
| 1207 | if env_init is None: |
| 1208 | env_init = {} |
| 1209 | if make_args is None: |
| 1210 | make_args = ['-j', str(utils.get_num_cores())] |
| 1211 | |
| 1212 | build_dir = self.get_build_dir() |
| 1213 | |
| 1214 | cflags = [] |
| 1215 | if not native: |
| 1216 | # get_library() is used to compile libraries, and not link executables, |
| 1217 | # so we don't want to pass linker flags here (emscripten warns if you |
| 1218 | # try to pass linker settings when compiling). |
| 1219 | cflags = self.get_cflags(compile_only=True) |
| 1220 | |
| 1221 | hash_input = (str(cflags) + ' $ ' + str(env_init)).encode('utf-8') |
| 1222 | cache_name = name + ','.join([opt for opt in cflags if len(opt) < 7]) + '_' + hashlib.md5(hash_input).hexdigest() + cache_name_extra |
| 1223 | |
| 1224 | valid_chars = "_%s%s" % (string.ascii_letters, string.digits) |
| 1225 | cache_name = ''.join([(c if c in valid_chars else '_') for c in cache_name]) |
| 1226 | |
| 1227 | if not force_rebuild and self.library_cache.get(cache_name): |
| 1228 | errlog('<load %s from cache> ' % cache_name) |
| 1229 | generated_libs = [] |
| 1230 | for basename, contents in self.library_cache[cache_name]: |
| 1231 | bc_file = os.path.join(build_dir, cache_name + '_' + basename) |
| 1232 | write_binary(bc_file, contents) |
| 1233 | generated_libs.append(bc_file) |
| 1234 | return generated_libs |
| 1235 | |
| 1236 | errlog(f'<building and saving {cache_name} into cache>') |
| 1237 | if configure and configure_args: |
| 1238 | # Make to copy to avoid mutating default param |
| 1239 | configure = list(configure) |
| 1240 | configure += configure_args |
| 1241 | |
| 1242 | cflags = ' '.join(cflags) |
| 1243 | env_init.setdefault('CFLAGS', cflags) |
| 1244 | env_init.setdefault('CXXFLAGS', cflags) |
| 1245 | return self.build_library(name, build_dir, generated_libs, configure, |
| 1246 | make, make_args, cache_name, env_init=env_init, native=native) |
| 1247 | |
| 1248 | def clear(self): |
| 1249 | force_delete_contents(self.get_dir()) |