function downloadPlatform (projectRoot, platform, version, opts) {
    var target = version ? (platform + '@' + version) : platform;
    return Promise.resolve().then(function () {
        // append cordova to platform
        if (platform in platforms) {
            target = 'cordova-' + target;
        }

        // gitURLs don't supply a platform, it equals null
        if (!platform) {
            target = version;
        }
        events.emit('log', 'Using cordova-fetch for ' + target);
        return fetch(target, projectRoot, opts);
    }).catch(function (error) {
        var message = 'Failed to fetch platform ' + target +
            '\nProbably this is either a connection problem, or platform spec is incorrect.' +
            '\nCheck your connection and platform name/version/URL.' +
            '\n' + error;
        return Promise.reject(new CordovaError(message));
    }).then(function (libDir) {
        return require('./index').getPlatformDetailsFromDir(libDir, platform);
    });
}