reads SWIFT_HOME from environment variables.
This commit is contained in:
parent
10a3ee3f49
commit
e8962dad7e
|
@ -4,16 +4,18 @@ set -euo pipefail
|
|||
mkdir swift
|
||||
curl https://swift.org/builds/$SWIFT_VERSION-release/ubuntu1404/$SWIFT_VERSION-RELEASE/$SWIFT_VERSION-RELEASE-ubuntu14.04.tar.gz -s | tar xz -C swift &> /dev/null
|
||||
|
||||
# install dependencies
|
||||
sudo apt-get install clang libicu52
|
||||
# make sure we use trusty repositories (travis by default uses precise)
|
||||
curl https://repogen.simplylinux.ch/txt/trusty/sources_c4aa56bd26c0f54f391d8fae3e687ef5f6e97c26.txt | sudo tee /etc/apt/sources.list
|
||||
|
||||
# update libstdc++6, travis uses some old version
|
||||
echo "\n" | sudo add-apt-repository ppa:ubuntu-toolchain-r/test
|
||||
# install dependencies
|
||||
# some packages below will be update, swift assumes newer versions
|
||||
# of, for example, sqlite3 and libicu, without the update some
|
||||
# tools will not work
|
||||
sudo apt-get update
|
||||
sudo apt-get install gcc-4.9
|
||||
sudo apt-get install libstdc++6
|
||||
sudo apt-get install clang libicu-dev libxml2 sqlite3
|
||||
|
||||
# check swift
|
||||
export PATH=$(pwd)/swift/$SWIFT_VERSION-RELEASE-ubuntu14.04/usr/bin:$PATH
|
||||
export SWIFT_HOME=$(pwd)/swift/$SWIFT_VERSION-RELEASE-ubuntu14.04/usr/bin/
|
||||
export PATH=${SWIFT_HOME):$PATH
|
||||
swift --version
|
||||
swift build --version
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
|
@ -34,30 +35,34 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
|||
*/
|
||||
private static String ANTLR_RUNTIME_PATH;
|
||||
|
||||
/**
|
||||
* Absolute path to swift command.
|
||||
*/
|
||||
private static String SWIFT_CMD;
|
||||
|
||||
/**
|
||||
* Environment variable name for swift home.
|
||||
*/
|
||||
private static final String SWIFT_HOME_ENV_KEY = "SWIFT_HOME";
|
||||
|
||||
static {
|
||||
String baseTestDir = System.getProperty("antlr-swift-test-dir");
|
||||
if (baseTestDir == null || baseTestDir.isEmpty()) {
|
||||
baseTestDir = System.getProperty("java.io.tmpdir");
|
||||
}
|
||||
|
||||
if (!new File(baseTestDir).isDirectory()) {
|
||||
throw new UnsupportedOperationException("The specified base test directory does not exist: " + baseTestDir);
|
||||
}
|
||||
|
||||
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
Map<String, String> env = System.getenv();
|
||||
String swiftHome = env.containsKey(SWIFT_HOME_ENV_KEY) ? env.get(SWIFT_HOME_ENV_KEY) : "";
|
||||
SWIFT_CMD = swiftHome + "swift";
|
||||
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
// build swift runtime
|
||||
final URL swiftRuntime = loader.getResource("Swift");
|
||||
URL swiftRuntime = loader.getResource("Swift");
|
||||
if (swiftRuntime == null) {
|
||||
throw new RuntimeException("Swift runtime file not found at:" + swiftRuntime.getPath());
|
||||
}
|
||||
ANTLR_RUNTIME_PATH = swiftRuntime.getPath();
|
||||
fastFailRunProcess(ANTLR_RUNTIME_PATH, "swift", "build");
|
||||
fastFailRunProcess(ANTLR_RUNTIME_PATH, SWIFT_CMD, "build");
|
||||
|
||||
// shutdown logic
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
public void run() {
|
||||
fastFailRunProcess(ANTLR_RUNTIME_PATH, "swift", "package", "clean");
|
||||
fastFailRunProcess(ANTLR_RUNTIME_PATH, SWIFT_CMD, "package", "clean");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -180,7 +185,7 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
|||
|
||||
private void buildProject(String projectDir) {
|
||||
mkdir(projectDir);
|
||||
fastFailRunProcess(projectDir, "swift", "package", "init", "--type", "executable");
|
||||
fastFailRunProcess(projectDir, SWIFT_CMD, "package", "init", "--type", "executable");
|
||||
for (String sourceFile: sourceFiles) {
|
||||
String absPath = getTmpDir() + "/" + sourceFile;
|
||||
fastFailRunProcess(getTmpDir(), "mv", "-f", absPath, projectDir + "/Sources/");
|
||||
|
@ -189,7 +194,7 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
|||
|
||||
try {
|
||||
String dylibPath = ANTLR_RUNTIME_PATH + "/.build/debug/";
|
||||
runProcess(projectDir, "swift", "build",
|
||||
runProcess(projectDir, SWIFT_CMD, "build",
|
||||
"-Xswiftc", "-I"+dylibPath,
|
||||
"-Xlinker", "-L"+dylibPath,
|
||||
"-Xlinker", "-lAntlr4");
|
||||
|
|
Loading…
Reference in New Issue