private static ToolChainCandidate findClang() { File compilerExe = OperatingSystem.current().findInPath("clang"); if (compilerExe != null) { return new InstalledClangToolChain(); } return new UnavailableToolChain("clang"); }
public WorkResult execute(CommandLineToolInvocation invocation) { ExecAction compiler = execActionFactory.newExecAction(); compiler.executable(executable); if (invocation.getWorkDirectory() != null) { GFileUtils.mkdirs(invocation.getWorkDirectory()); compiler.workingDir(invocation.getWorkDirectory()); } compiler.args(invocation.getArgs()); if (!invocation.getPath().isEmpty()) { String pathVar = OperatingSystem.current().getPathVar(); String compilerPath = Joiner.on(File.pathSeparator).join(invocation.getPath()); compilerPath = compilerPath + File.pathSeparator + System.getenv(pathVar); compiler.environment(pathVar, compilerPath); } compiler.environment(invocation.getEnvironment()); try { compiler.execute(); } catch (ExecException e) { throw new GradleException( String.format("%s failed; see the error output for details.", action), e); } return new SimpleWorkResult(true); }
private static ToolChainCandidate findGcc(String versionPrefix, String hardcodedFallback) { String name = String.format("gcc %s", versionPrefix); GccVersionDeterminer versionDeterminer = new GccVersionDeterminer( new ExecActionFactory() { public ExecAction newExecAction() { return new DefaultExecAction(new IdentityFileResolver()); } }); List<File> gppCandidates = OperatingSystem.current().findAllInPath("g++"); for (int i = 0; i < gppCandidates.size(); i++) { File candidate = gppCandidates.get(i); if (versionDeterminer.transform(candidate).startsWith(versionPrefix)) { InstalledGcc gcc = new InstalledGcc(name); if (i > 0) { // Not the first g++ in the path, needs the path variable updated gcc.inPath(candidate.getParentFile()); } return gcc; } } if (hardcodedFallback != null) { File fallback = new File(hardcodedFallback); if (fallback.isFile()) { return new InstalledGcc(name).inPath(fallback.getParentFile()); } } return new UnavailableToolChain(name); }
public void setenv(String name, String value) { Map<String, String> map = getEnv(); map.put(name, value); if (OperatingSystem.current().isWindows()) { Map<String, String> env2 = getWindowsEnv(); env2.put(name, value); } }
public void unsetenv(String name) { Map<String, String> map = getEnv(); map.remove(name); if (OperatingSystem.current().isWindows()) { Map<String, String> env2 = getWindowsEnv(); env2.remove(name); } }
private String getTestReportUrl() { // File.toURI().toString() leads to an URL like this on Mac: file:/reports/index.html // This URL is not recognized by the Mac terminal (too few leading slashes). We solve // this be creating an URI with an empty authority. File indexFile = new File(getTestReportDir(), "index.html"); try { if (OperatingSystem.current().isWindows()) { return indexFile.toURI().toString(); } return new URI("file", "", indexFile.toString(), null, null).toString(); } catch (URISyntaxException e) { throw UncheckedException.throwAsUncheckedException(e); } }
private static ToolChainCandidate findVisualCpp() { // Search in the standard installation locations VisualStudioLocator vsLocator = new DefaultVisualStudioLocator( OperatingSystem.current(), NativeServices.getInstance().get(WindowsRegistry.class), NativeServices.getInstance().get(SystemInfo.class)); VisualStudioLocator.SearchResult searchResult = vsLocator.locateVisualStudioInstalls(null); if (searchResult.isAvailable()) { VisualStudioInstall install = searchResult.getVisualStudio(); return new InstalledVisualCpp("visual c++").withInstall(install); } return new UnavailableToolChain("visual c++"); }
public WorkResult execute(WindowsResourceCompileSpec spec) { boolean didWork = false; boolean windowsPathLimitation = OperatingSystem.current().isWindows(); MutableCommandLineToolInvocation invocation = baseInvocation.copy(); spec = specTransformer.transform(spec); for (File sourceFile : spec.getSourceFiles()) { RcCompilerArgsTransformer argsTransformer = new RcCompilerArgsTransformer(sourceFile, windowsPathLimitation); invocation.setArgs(argsTransformer.transform(spec)); invocation.setWorkDirectory(spec.getObjectFileDir()); WorkResult result = commandLineTool.execute(invocation); didWork |= result.getDidWork(); } return new SimpleWorkResult(didWork); }
@Override public void evaluate() throws Throwable { base.evaluate(); // Don't delete on failure try { testDirectory.deleteDir(); } catch (Exception e) { boolean suppressException = leaksHandles && OperatingSystem.current().isWindows(); if (suppressException) { e.printStackTrace(); } else { throw e; } } }
private static ToolChainCandidate findVisualCpp() { // Search first in path, then in the standard installation locations File compilerExe = OperatingSystem.current().findInPath("cl.exe"); if (compilerExe != null) { return new InstalledVisualCpp("visual c++"); } VisualStudioLocator vsLocator = new DefaultVisualStudioLocator(); File visualStudioDir = vsLocator.locateDefaultVisualStudio().getResult(); if (visualStudioDir != null) { VisualStudioInstall install = new VisualStudioInstall(visualStudioDir); return new InstalledVisualCpp("visual c++").withInstall(install); } return new UnavailableToolChain("visual c++"); }
public List<JvmInstallation> findJvms() { List<JvmInstallation> jvms = new ArrayList<JvmInstallation>(); if (OperatingSystem.current().isLinux()) { jvms.add( new JvmInstallation( JavaVersion.VERSION_1_5, "1.5.0", new File("/opt/jdk/sun-jdk-5"), true, JvmInstallation.Arch.i386)); jvms.add( new JvmInstallation( JavaVersion.VERSION_1_6, "1.6.0", new File("/opt/jdk/sun-jdk-6"), true, JvmInstallation.Arch.x86_64)); jvms.add( new JvmInstallation( JavaVersion.VERSION_1_6, "1.6.0", new File("/opt/jdk/ibm-jdk-6"), true, JvmInstallation.Arch.x86_64)); jvms.add( new JvmInstallation( JavaVersion.VERSION_1_7, "1.7.0", new File("/opt/jdk/oracle-jdk-7"), true, JvmInstallation.Arch.x86_64)); jvms.add( new JvmInstallation( JavaVersion.VERSION_1_8, "1.8.0", new File("/opt/jdk/oracle-jdk-8"), true, JvmInstallation.Arch.x86_64)); } return CollectionUtils.filter( jvms, new Spec<JvmInstallation>() { public boolean isSatisfiedBy(JvmInstallation element) { return element.getJavaHome().isDirectory(); } }); }
private ExecHandleBuilder createExecHandleBuilder() { TestFile gradleHomeDir = getDistribution().getGradleHomeDir(); if (!gradleHomeDir.isDirectory()) { fail( gradleHomeDir + " is not a directory.\n" + "If you are running tests from IDE make sure that gradle tasks that prepare the test image were executed. Last time it was 'intTestImage' task."); } NativeServicesTestFixture.initialize(); ExecHandleBuilder builder = new ExecHandleBuilder(TestFiles.resolver()) { @Override public File getWorkingDir() { // Override this, so that the working directory is not canonicalised. Some int tests // require that // the working directory is not canonicalised return ForkingGradleExecuter.this.getWorkingDir(); } }; // Clear the user's environment builder.environment("GRADLE_HOME", ""); builder.environment("JAVA_HOME", ""); builder.environment("GRADLE_OPTS", ""); builder.environment("JAVA_OPTS", ""); GradleInvocation invocation = buildInvocation(); builder.environment(invocation.environmentVars); builder.workingDir(getWorkingDir()); builder.setStandardInput(connectStdIn()); builder.args(invocation.args); ExecHandlerConfigurer configurer = OperatingSystem.current().isWindows() ? new WindowsConfigurer() : new UnixConfigurer(); configurer.configure(builder); getLogger() .debug( String.format( "Execute in %s with: %s %s", builder.getWorkingDir(), builder.getExecutable(), builder.getArgs())); return builder; }
/** * @return A list of all tool chains for this platform, with the default tool chain listed first. */ public static List<ToolChainCandidate> getToolChains() { List<ToolChainCandidate> compilers = new ArrayList<ToolChainCandidate>(); if (OperatingSystem.current().isWindows()) { compilers.add(findVisualCpp()); compilers.add(findMinGW()); compilers.add(findCygwin()); } else { // GCC4.x must be on the path compilers.add(findGcc("4", null)); // Clang must be on the path // TODO:ADAM Also check on windows compilers.add(findClang()); // TODO:DAZ Make a GCC3 install available for testing } return compilers; }
private void locateSdkInPath() { File resourceCompiler = os.findInPath(RESOURCE_FILENAME); if (resourceCompiler == null) { LOGGER.debug("Could not find Windows resource compiler in system path."); return; } File sdkDir = GFileUtils.canonicalise(resourceCompiler.getParentFile().getParentFile()); if (!isWindowsSdk(sdkDir)) { sdkDir = sdkDir.getParentFile(); if (!isWindowsSdk(sdkDir)) { LOGGER.debug( "Ignoring candidate Windows SDK for {} as it does not look like a Windows SDK installation.", resourceCompiler); } } LOGGER.debug("Found Windows SDK {} using system path", sdkDir); if (!foundSdks.containsKey(sdkDir)) { addSdk(sdkDir, "path", "Path-resolved Windows SDK"); } pathSdk = foundSdks.get(sdkDir); }
public String getOutputType() { return String.format("%s-%s", getName(), operatingSystem.getName()); }
public String getStaticLibraryName(String libraryName) { return operatingSystem.getStaticLibraryName(libraryName); }
public NativeBinaryFixture staticLibrary(Object path) { return new NativeBinaryFixture( new TestFile(OperatingSystem.current().getStaticLibraryName(path.toString())), this); }
public SharedLibraryFixture sharedLibrary(Object path) { return new SharedLibraryFixture( new TestFile(OperatingSystem.current().getSharedLibraryName(path.toString())), this); }
public ExecutableFixture executable(Object path) { return new ExecutableFixture( new TestFile(OperatingSystem.current().getExecutableName(path.toString())), this); }
public InstalledToolChain(String displayName) { this.displayName = displayName; this.pathVarName = OperatingSystem.current().getPathVar(); }
public String getExecutableName(String executablePath) { return operatingSystem.getExecutableName(executablePath); }