in tc-sbt-runner-agent/src/main/java/jetbrains/buildServer/sbt/SbtRunnerBuildService.java [375:408]
private void fixSbtSocketLengthIssueIfNeeded(Map<String, String> envVars) throws RunBuildException {
if ("false".equalsIgnoreCase(getConfigParameters().get("teamcity.internal.sbt.setXdgRuntimeDir.enabled"))) {
return;
}
final String xdgRuntimeDir = "XDG_RUNTIME_DIR";
if (getEnvironmentVariables().containsKey(xdgRuntimeDir)) { // allow to override the value
return;
}
final int maxAllowedTmpDirLength = 54;
if (SystemInfo.isWindows || getBuildTempDirectory().getAbsolutePath().length() <= maxAllowedTmpDirLength) {
return;
}
final String ourSubDir = RandomStringUtils.randomAlphanumeric(4).toLowerCase();
final String tmpDirEnv = firstNonEmptyEnvVariableOrNull("TMPDIR", "TEMP", "TMP");
final String tmpDirRoot;
if (tmpDirEnv != null && tmpDirEnv.length() <= maxAllowedTmpDirLength - ourSubDir.length()) {
if (tmpDirEnv.endsWith("/")) {
tmpDirRoot = tmpDirEnv.substring(0, tmpDirEnv.length() - 1);
} else {
tmpDirRoot = tmpDirEnv;
}
} else {
tmpDirRoot = "/tmp";
}
final File tmpDir = new File(tmpDirRoot, ourSubDir);
try {
FileUtil.createDir(tmpDir);
} catch (IOException e) {
throw new RunBuildException("Failed to create temp directory for SBT at " + tmpDir.getAbsolutePath(), e);
}
myFilesToDelete.add(tmpDir);
getLogger().message(xdgRuntimeDir + " set to: " + tmpDir.getAbsolutePath());
envVars.put(xdgRuntimeDir, tmpDir.getAbsolutePath());
}