export function findLocalTool()

in tool.ts [122:157]


export function findLocalTool(toolName: string, versionSpec: string, arch?: string): string {
    if (!toolName) {
        throw new Error('toolName parameter is required');
    }

    if (!versionSpec) {
        throw new Error('versionSpec parameter is required');
    }

    arch = arch || os.arch();

    // attempt to resolve an explicit version
    if (!isExplicitVersion(versionSpec)) {
        let localVersions: string[] = findLocalToolVersions(toolName, arch);
        let match = evaluateVersions(localVersions, versionSpec);
        versionSpec = match;
    }

    // check for the explicit version in the cache
    let toolPath: string;
    if (versionSpec) {
        versionSpec = semver.clean(versionSpec);
        let cacheRoot = _getCacheRoot();
        let cachePath = path.join(cacheRoot, toolName, versionSpec, arch);
        tl.debug('checking cache: ' + cachePath);
        if (tl.exist(cachePath) && tl.exist(`${cachePath}.complete`)) {
            console.log(tl.loc('TOOL_LIB_FoundInCache', toolName, versionSpec, arch));
            toolPath = cachePath;
        }
        else {
            tl.debug('not found');
        }
    }

    return toolPath;
}