Search in sources :

Example 11 with SourceToOutputMapping

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;
}
Also used : JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) File(java.io.File)

Example 12 with SourceToOutputMapping

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;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) IAndroidTarget(com.android.sdklib.IAndroidTarget) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager) HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap)

Aggregations

SourceToOutputMapping (org.jetbrains.jps.builders.storage.SourceToOutputMapping)12 File (java.io.File)8 THashSet (gnu.trove.THashSet)5 IOException (java.io.IOException)4 MultiMap (com.intellij.util.containers.MultiMap)3 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)3 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)3 IAndroidTarget (com.android.sdklib.IAndroidTarget)2 HashMap (com.intellij.util.containers.HashMap)2 THashMap (gnu.trove.THashMap)2 TIntObjectHashMap (gnu.trove.TIntObjectHashMap)2 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)2 ProjectBuilderLogger (org.jetbrains.jps.builders.logging.ProjectBuilderLogger)2 ProjectDescriptor (org.jetbrains.jps.cmdline.ProjectDescriptor)2 BuildDataManager (org.jetbrains.jps.incremental.storage.BuildDataManager)2 OutputToTargetRegistry (org.jetbrains.jps.incremental.storage.OutputToTargetRegistry)2 SmartList (com.intellij.util.SmartList)1 MappingFailedException (com.intellij.util.io.MappingFailedException)1 TIntHashSet (gnu.trove.TIntHashSet)1 TObjectIntHashMap (gnu.trove.TObjectIntHashMap)1