static parseCache()

in src/cache.ts [150:229]


    static parseCache(content: string): Map<string, Entry> {
        log.debug(localize('parsing.cmake.cache.string', 'Parsing CMake cache string'));
        const lines = content.split(/\r\n|\n|\r/).filter(line => !!line.length).filter(line => !/^\s*#/.test(line));

        const entries = new Map<string, Entry>();
        let docs_acc = '';
        const advancedNames: string[] = [];
        const choices: Map<string, string[]> = new Map();
        for (const line of lines) {
            if (line.startsWith('//')) {
                docs_acc += /^\/\/(.*)/.exec(line)![1] + ' ';
            } else {
                const match = /^("(.*?)"|(.*?)):([^:]*?)=(.*)/.exec(line);
                if (!match) {
                    rollbar.error(localize('failed.to.read.line.from.cmake.cache.file', 'Failed to read a line from a CMake cache file {0}', line));
                    continue;
                }
                const [, serializedName, quoted_name, unquoted_name, typename, valuestr] = match;
                const name = quoted_name || unquoted_name;
                if (!name || !typename) {
                    continue;
                }
                log.trace(localize('read.line.in.cache', 'Read line in cache with {0}={1}, {2}={3}, {4}={5}', 'name', name, 'typename', typename, 'valuestr', valuestr));
                if (name.endsWith('-ADVANCED')) {
                    if (valuestr === '1') {
                        const entryName = name.substr(0, name.lastIndexOf('-'));
                        advancedNames.push(entryName);
                    }
                } else if (name.endsWith('-MODIFIED')) {
                    // ignore irrelevant entry property
                } else if (name.endsWith('-STRINGS')) {
                    choices.set(name.substr(0, name.lastIndexOf('-')), valuestr.split(';'));
                } else {
                    const key = name;
                    const typemap = {
                        BOOL: api.CacheEntryType.Bool,
                        STRING: api.CacheEntryType.String,
                        PATH: api.CacheEntryType.Path,
                        FILEPATH: api.CacheEntryType.FilePath,
                        INTERNAL: api.CacheEntryType.Internal,
                        UNINITIALIZED: api.CacheEntryType.Uninitialized,
                        STATIC: api.CacheEntryType.Static
                    } as { [type: string]: api.CacheEntryType | undefined };
                    const type = typemap[typename];
                    const docs = docs_acc.trim();
                    docs_acc = '';
                    if (type === undefined) {
                        rollbar.error(localize('cache.entry.unknown', 'Cache entry {0} has unknown type: {1}', `"${name}"`, `"${typename}"`));
                    } else {
                        log.trace(localize('constructing.new.cache.entry', 'Constructing a new cache entry from the given line'));
                        const entry = new Entry(key, valuestr, type, docs, false);
                        entry.serializedKey = serializedName;
                        entries.set(name, entry);
                    }
                }
            }
        }

        // Update `advanced` attribute
        advancedNames.forEach(name => {
            const entry = entries.get(name);
            if (entry) {
                entry.advanced = true;
            } else {
                log.warning(localize('nonexisting.advanced.entry', 'Nonexisting cache entry {0} marked as advanced', `"${name}"`));
            }
        });
        // update `choices`
        choices.forEach((list, name) => {
            const entry = entries.get(name);
            if (entry) {
                entry.choices = list;
            } else {
                log.warning(localize('ignore.strings.for.nonexisting.entry', 'Ignoring {1} property for nonexisting cache entry {0}', `"${name}"`, '"STRINGS"'));
            }
        });

        log.trace(localize('parsed.cache.entries', 'Parsed {0} cache entries', entries.size));
        return entries;
    }