(shortname, creator, what=None, force=False, quiet=False)
| 154 | # Request a cached file. If it isn't in the cache, it will be created with |
| 155 | # the given creator function |
| 156 | def get(shortname, creator, what=None, force=False, quiet=False): |
| 157 | ensure_setup() |
| 158 | cachename = Path(cachedir, shortname) |
| 159 | # Check for existence before taking the lock in case we can avoid the |
| 160 | # lock completely. |
| 161 | if cachename.exists() and not force: |
| 162 | return str(cachename) |
| 163 | |
| 164 | if config.FROZEN_CACHE: |
| 165 | # Raise an exception here rather than exit_with_error since in practice this |
| 166 | # should never happen |
| 167 | raise Exception(f'FROZEN_CACHE is set, but cache file is missing: "{shortname}" (in cache root path "{cachedir}")') |
| 168 | |
| 169 | with lock(shortname): |
| 170 | if cachename.exists() and not force: |
| 171 | return str(cachename) |
| 172 | if what is None: |
| 173 | if shortname.endswith(('.bc', '.so', '.a')): |
| 174 | what = 'system library' |
| 175 | else: |
| 176 | what = 'system asset' |
| 177 | message = f'generating {what}: {shortname}... (this will be cached in "{cachename}" for subsequent builds)' |
| 178 | logger.info(message) |
| 179 | utils.safe_ensure_dirs(cachename.parent) |
| 180 | creator(str(cachename)) |
| 181 | # In embuilder/deferred building mode, the library is not actually compiled at |
| 182 | # "creation" time; instead, the ninja files are built up incrementally, and |
| 183 | # compiled all at once with a single ninja invocation. So in that case we |
| 184 | # can't assert that the library was correctly built here. |
| 185 | if not os.getenv('EMBUILDER_PORT_BUILD_DEFERRED'): |
| 186 | assert cachename.is_file() |
| 187 | if not quiet: |
| 188 | logger.info(' - ok') |
| 189 | |
| 190 | return str(cachename) |
| 191 | |
| 192 | |
| 193 | def setup(): |
no test coverage detected