use of org.jetbrains.jps.builders.storage.SourceToOutputMapping in project intellij-community by JetBrains.
the class JpsGroovycRunner method buildClassToSourceMap.
private Map<String, String> buildClassToSourceMap(ModuleChunk chunk, CompileContext context, Set<String> toCompilePaths, Map<T, String> finalOutputs) throws IOException {
final Map<String, String> class2Src = new HashMap<>();
JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(context.getProjectDescriptor().getProject());
for (T target : getTargets(chunk)) {
String moduleOutputPath = finalOutputs.get(target);
final SourceToOutputMapping srcToOut = context.getProjectDescriptor().dataManager.getSourceToOutputMap(target);
for (String src : srcToOut.getSources()) {
if (!toCompilePaths.contains(src) && GroovyBuilder.isGroovyFile(src) && !configuration.getCompilerExcludes().isExcluded(new File(src))) {
final Collection<String> outs = srcToOut.getOutputs(src);
if (outs != null) {
for (String out : outs) {
if (out.endsWith(".class") && out.startsWith(moduleOutputPath)) {
final String className = out.substring(moduleOutputPath.length(), out.length() - ".class".length()).replace('/', '.');
class2Src.put(className, src);
}
}
}
}
}
}
return class2Src;
}
use of org.jetbrains.jps.builders.storage.SourceToOutputMapping in project android by JetBrains.
the class AndroidSourceGeneratingBuilder method runRenderscriptCompiler.
private static boolean runRenderscriptCompiler(@NotNull final CompileContext context, @NotNull Map<File, ModuleBuildTarget> files, @NotNull Map<JpsModule, MyModuleData> moduleDataMap) {
if (files.size() > 0) {
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.renderscript")));
}
boolean success = true;
for (Map.Entry<File, ModuleBuildTarget> entry : files.entrySet()) {
final File file = entry.getKey();
final ModuleBuildTarget buildTarget = entry.getValue();
final MyModuleData moduleData = moduleDataMap.get(buildTarget.getModule());
if (!LOG.assertTrue(moduleData != null)) {
context.processMessage(new CompilerMessage(ANDROID_RENDERSCRIPT_COMPILER, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.internal.error")));
success = false;
continue;
}
final BuildDataManager dataManager = context.getProjectDescriptor().dataManager;
final File generatedSourcesDir = AndroidJpsUtil.getGeneratedSourcesStorage(buildTarget.getModule(), dataManager);
final File rsOutputDirectory = new File(generatedSourcesDir, AndroidJpsUtil.RENDERSCRIPT_GENERATED_SOURCE_ROOT_NAME);
if (!rsOutputDirectory.exists() && !rsOutputDirectory.mkdirs()) {
context.processMessage(new CompilerMessage(ANDROID_RENDERSCRIPT_COMPILER, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", rsOutputDirectory.getPath())));
success = false;
continue;
}
final File generatedResourcesDir = AndroidJpsUtil.getGeneratedResourcesStorage(buildTarget.getModule(), dataManager);
final File rawDir = new File(generatedResourcesDir, "raw");
if (!rawDir.exists() && !rawDir.mkdirs()) {
context.processMessage(new CompilerMessage(ANDROID_RENDERSCRIPT_COMPILER, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", rawDir.getPath())));
success = false;
continue;
}
final AndroidPlatform platform = moduleData.getPlatform();
final IAndroidTarget target = platform.getTarget();
final String sdkLocation = platform.getSdk().getHomePath();
final String filePath = file.getPath();
File tmpOutputDirectory = null;
try {
tmpOutputDirectory = FileUtil.createTempDirectory("generated-rs-temp", null);
final String depFolderPath = getDependencyFolder(context, file, tmpOutputDirectory);
final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidRenderscript.execute(sdkLocation, target, filePath, tmpOutputDirectory.getPath(), depFolderPath, rawDir.getPath());
addMessages(context, messages, filePath, ANDROID_RENDERSCRIPT_COMPILER);
if (messages.get(AndroidCompilerMessageKind.ERROR).size() > 0) {
success = false;
} else {
final List<File> newFiles = new ArrayList<File>();
AndroidCommonUtils.moveAllFiles(tmpOutputDirectory, rsOutputDirectory, newFiles);
final File bcFile = new File(rawDir, FileUtil.getNameWithoutExtension(file) + ".bc");
if (bcFile.exists()) {
newFiles.add(bcFile);
}
final List<String> newFilePaths = Arrays.asList(AndroidJpsUtil.toPaths(newFiles.toArray(new File[newFiles.size()])));
final SourceToOutputMapping sourceToOutputMap = dataManager.getSourceToOutputMap(buildTarget);
sourceToOutputMap.setOutputs(filePath, newFilePaths);
for (File newFile : newFiles) {
FSOperations.markDirty(context, CompilationRound.CURRENT, newFile);
}
}
} catch (IOException e) {
AndroidJpsUtil.reportExceptionError(context, filePath, e, ANDROID_RENDERSCRIPT_COMPILER);
success = false;
} finally {
if (tmpOutputDirectory != null) {
FileUtil.delete(tmpOutputDirectory);
}
}
}
return success;
}
Aggregations