diff --git a/.gitignore b/.gitignore index f80f5ac3195..022fcd35a1d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .DS_Store .idea/shelf -dependencies +/dependencies/all dist translator/src/test/kotlin/tests/*/linked out diff --git a/build.gradle b/build.gradle index 1a8ef7e6587..d44a0f53fc1 100644 --- a/build.gradle +++ b/build.gradle @@ -4,4 +4,10 @@ if (new File("$project.rootDir/local.properties").exists()) { Properties props = new Properties() props.load(new FileInputStream("$project.rootDir/local.properties")) props.each {prop -> project.ext.set(prop.key, prop.value)} +} + +allprojects { + if (path != ":dependencies") { + evaluationDependsOn(":dependencies") + } } \ No newline at end of file diff --git a/dependencies/build.gradle b/dependencies/build.gradle new file mode 100644 index 00000000000..ccbba79c389 --- /dev/null +++ b/dependencies/build.gradle @@ -0,0 +1,84 @@ +abstract class NativeDep extends DefaultTask { + + private static String getCurrentHostTarget() { + String osName = System.properties['os.name'] + String osArch = System.properties['os.arch'] + + // TODO: implement more generally + if (osArch in ['x86_64', 'amd64']) { + if (osName == 'Mac OS X') { + return 'darwin-macos' + } else if (osName == 'Linux') { + return 'linux-x86-64' + } else { + throw new Error("Unsupported OS: $osName") + } + } else { + throw new Error("Unsupported arch: $osArch") + } + } + + protected final String target = getCurrentHostTarget(); + + @Input + abstract String getFileName() + + protected String getUrl() { + return "http://repo.labs.intellij.net/kotlin-native/$fileName" + } + + protected File getBaseOutDir() { + final File res = project.file("all") + res.mkdirs() + return res + } + + protected File download() { + File result = new File(baseOutDir, fileName) + ant.get(src: url, dest: result, usetimestamp: true) + return result + } +} + +class TgzNativeDep extends NativeDep { + String baseName + + @Override + String getFileName() { + return "${baseName}.tar.gz" + } + + @OutputDirectory + File getOutputDir() { + return new File(baseOutDir, baseName) + } + + @TaskAction + public void downloadAndExtract() { + File archived = this.download() + + try { + // Builtin Gradle unpacking tools seem to unable to handle symlinks; + // Use external "tar" executable as workaround: + project.exec { + executable "tar" + workingDir baseOutDir + args "xf", archived + } + } catch (Throwable e) { + project.delete(outputDir) + throw e + } + + // TODO: do not extract if already extracted + } +} + + +task update { + dependsOn tasks.withType(NativeDep) +} + +tasks.withType(TgzNativeDep) { + rootProject.ext.set("${name}Dir", outputDir.path) +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 04fc18c90ee..eb5e9b8a330 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,4 @@ +include ':dependencies' include ':Interop:Indexer' include ':Interop:StubGenerator' include ':Interop:Runtime'