Search in sources :

Example 1 with BuildDataManager

use of org.jetbrains.jps.incremental.storage.BuildDataManager in project intellij-community by JetBrains.

the class BuildOperations method cleanOutputsCorrespondingToChangedFiles.

public static <R extends BuildRootDescriptor, T extends BuildTarget<R>> Map<T, Set<File>> cleanOutputsCorrespondingToChangedFiles(final CompileContext context, DirtyFilesHolder<R, T> dirtyFilesHolder) throws ProjectBuildException {
    final BuildDataManager dataManager = context.getProjectDescriptor().dataManager;
    try {
        final Map<T, Set<File>> cleanedSources = new HashMap<>();
        final THashSet<File> dirsToDelete = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
        final Collection<String> deletedPaths = new ArrayList<>();
        dirtyFilesHolder.processDirtyFiles(new FileProcessor<R, T>() {

            // cache the mapping locally
            private final Map<T, SourceToOutputMapping> mappingsCache = new HashMap<>();

            private final TObjectIntHashMap<T> idsCache = new TObjectIntHashMap<>();

            @Override
            public boolean apply(T target, File file, R sourceRoot) throws IOException {
                SourceToOutputMapping srcToOut = mappingsCache.get(target);
                if (srcToOut == null) {
                    srcToOut = dataManager.getSourceToOutputMap(target);
                    mappingsCache.put(target, srcToOut);
                }
                final int targetId;
                if (!idsCache.containsKey(target)) {
                    targetId = dataManager.getTargetsState().getBuildTargetId(target);
                    idsCache.put(target, targetId);
                } else {
                    targetId = idsCache.get(target);
                }
                final String srcPath = file.getPath();
                final Collection<String> outputs = srcToOut.getOutputs(srcPath);
                if (outputs != null) {
                    final boolean shouldPruneOutputDirs = target instanceof ModuleBasedTarget;
                    final List<String> deletedForThisSource = new ArrayList<>(outputs.size());
                    for (String output : outputs) {
                        deleteRecursively(output, deletedForThisSource, shouldPruneOutputDirs ? dirsToDelete : null);
                    }
                    deletedPaths.addAll(deletedForThisSource);
                    dataManager.getOutputToTargetRegistry().removeMapping(deletedForThisSource, targetId);
                    Set<File> cleaned = cleanedSources.get(target);
                    if (cleaned == null) {
                        cleaned = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
                        cleanedSources.put(target, cleaned);
                    }
                    cleaned.add(file);
                }
                return true;
            }
        });
        if (JavaBuilderUtil.isCompileJavaIncrementally(context)) {
            final ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
            if (logger.isEnabled()) {
                logger.logDeletedFiles(deletedPaths);
            }
        }
        if (!deletedPaths.isEmpty()) {
            context.processMessage(new FileDeletedEvent(deletedPaths));
        }
        // attempting to delete potentially empty directories
        FSOperations.pruneEmptyDirs(context, dirsToDelete);
        return cleanedSources;
    } catch (Exception e) {
        throw new ProjectBuildException(e);
    }
}
Also used : SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) THashSet(gnu.trove.THashSet) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) IOException(java.io.IOException) FileDeletedEvent(org.jetbrains.jps.incremental.messages.FileDeletedEvent) File(java.io.File)

Example 2 with BuildDataManager

use of org.jetbrains.jps.incremental.storage.BuildDataManager in project intellij-community by JetBrains.

the class JpsBuildTestCase method createProjectDescriptor.

protected ProjectDescriptor createProjectDescriptor(final BuildLoggingManager buildLoggingManager) {
    try {
        BuildTargetRegistryImpl targetRegistry = new BuildTargetRegistryImpl(myModel);
        ModuleExcludeIndex index = new ModuleExcludeIndexImpl(myModel);
        IgnoredFileIndexImpl ignoredFileIndex = new IgnoredFileIndexImpl(myModel);
        BuildDataPaths dataPaths = new BuildDataPathsImpl(myDataStorageRoot);
        BuildRootIndexImpl buildRootIndex = new BuildRootIndexImpl(targetRegistry, myModel, index, dataPaths, ignoredFileIndex);
        BuildTargetIndexImpl targetIndex = new BuildTargetIndexImpl(targetRegistry, buildRootIndex);
        BuildTargetsState targetsState = new BuildTargetsState(dataPaths, myModel, buildRootIndex);
        ProjectTimestamps timestamps = new ProjectTimestamps(myDataStorageRoot, targetsState);
        BuildDataManager dataManager = new BuildDataManager(dataPaths, targetsState, true);
        return new ProjectDescriptor(myModel, new BuildFSState(true), timestamps, dataManager, buildLoggingManager, index, targetsState, targetIndex, buildRootIndex, ignoredFileIndex);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ProjectTimestamps(org.jetbrains.jps.incremental.storage.ProjectTimestamps) BuildTargetRegistryImpl(org.jetbrains.jps.builders.impl.BuildTargetRegistryImpl) BuildRootIndexImpl(org.jetbrains.jps.builders.impl.BuildRootIndexImpl) IgnoredFileIndexImpl(org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl) BuildTargetIndexImpl(org.jetbrains.jps.builders.impl.BuildTargetIndexImpl) IOException(java.io.IOException) BuildTargetsState(org.jetbrains.jps.incremental.storage.BuildTargetsState) BuildFSState(org.jetbrains.jps.incremental.fs.BuildFSState) BuildDataPaths(org.jetbrains.jps.builders.storage.BuildDataPaths) ModuleExcludeIndex(org.jetbrains.jps.indices.ModuleExcludeIndex) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) ModuleExcludeIndexImpl(org.jetbrains.jps.indices.impl.ModuleExcludeIndexImpl) BuildDataPathsImpl(org.jetbrains.jps.builders.impl.BuildDataPathsImpl) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager)

Example 3 with BuildDataManager

use of org.jetbrains.jps.incremental.storage.BuildDataManager in project android by JetBrains.

the class AndroidPackagingBuilder method doPackaging.

private static boolean doPackaging(@NotNull BuildTarget<?> target, @NotNull CompileContext context, @NotNull JpsModule module, boolean hasDirtyFiles, @NotNull BuildOutputConsumer outputConsumer) throws IOException {
    final boolean release = AndroidJpsUtil.isReleaseBuild(context);
    final BuildDataManager dataManager = context.getProjectDescriptor().dataManager;
    boolean success = true;
    final AndroidApkBuilderConfigStateStorage.Provider builderStateStoragetProvider = new AndroidApkBuilderConfigStateStorage.Provider("apk_builder_config");
    final AndroidApkBuilderConfigStateStorage apkBuilderConfigStateStorage = dataManager.getStorage(target, builderStateStoragetProvider);
    final AndroidPackagingStateStorage packagingStateStorage = dataManager.getStorage(target, AndroidPackagingStateStorage.Provider.INSTANCE);
    try {
        if (!doPackagingForModule(context, module, apkBuilderConfigStateStorage, packagingStateStorage, release, hasDirtyFiles, outputConsumer)) {
            success = false;
        }
    } catch (IOException e) {
        AndroidJpsUtil.reportExceptionError(context, null, e, BUILDER_NAME);
        success = false;
    }
    return success;
}
Also used : BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager) IOException(java.io.IOException)

Example 4 with BuildDataManager

use of org.jetbrains.jps.incremental.storage.BuildDataManager in project android by JetBrains.

the class AndroidSourceGeneratingBuilder method doBuild.

private static ModuleLevelBuilder.ExitCode doBuild(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder) throws IOException {
    final Map<JpsModule, MyModuleData> moduleDataMap = computeModuleDatas(chunk.getModules(), context);
    if (moduleDataMap == null || moduleDataMap.size() == 0) {
        return ExitCode.ABORT;
    }
    if (!checkVersions(moduleDataMap, context)) {
        return ExitCode.ABORT;
    }
    checkAndroidDependencies(moduleDataMap, context);
    if (!checkArtifacts(context)) {
        return ExitCode.ABORT;
    }
    if (JavaBuilderUtil.isForcedRecompilationAllJavaModules(context)) {
        if (!clearAndroidStorages(context, chunk.getModules())) {
            return ExitCode.ABORT;
        }
    }
    final Map<File, ModuleBuildTarget> idlFilesToCompile = new HashMap<File, ModuleBuildTarget>();
    final Map<File, ModuleBuildTarget> rsFilesToCompile = new HashMap<File, ModuleBuildTarget>();
    dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {

        @Override
        public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor sourceRoot) throws IOException {
            final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(target.getModule());
            if (extension == null) {
                return true;
            }
            String fileName = file.getName();
            if (FileUtilRt.extensionEquals(fileName, AIDL_EXTENSION)) {
                idlFilesToCompile.put(file, target);
            } else if (FileUtilRt.extensionEquals(fileName, RENDERSCRIPT_EXTENSION)) {
                rsFilesToCompile.put(file, target);
            }
            return true;
        }
    });
    boolean success = true;
    final BuildDataManager dataManager = context.getProjectDescriptor().dataManager;
    if (JavaBuilderUtil.isForcedRecompilationAllJavaModules(context)) {
        for (JpsModule module : moduleDataMap.keySet()) {
            final File generatedSourcesStorage = AndroidJpsUtil.getGeneratedSourcesStorage(module, dataManager);
            if (generatedSourcesStorage.exists() && !deleteAndMarkRecursively(generatedSourcesStorage, context, BUILDER_NAME)) {
                success = false;
            }
            final File generatedResourcesStorage = AndroidJpsUtil.getGeneratedResourcesStorage(module, dataManager);
            if (generatedResourcesStorage.exists() && !deleteAndMarkRecursively(generatedResourcesStorage, context, BUILDER_NAME)) {
                success = false;
            }
        }
    }
    if (!success) {
        return ExitCode.ABORT;
    }
    boolean didSomething = false;
    if (idlFilesToCompile.size() > 0) {
        if (!runAidlCompiler(context, idlFilesToCompile, moduleDataMap)) {
            success = false;
        }
        didSomething = true;
    }
    if (rsFilesToCompile.size() > 0) {
        if (!runRenderscriptCompiler(context, rsFilesToCompile, moduleDataMap)) {
            success = false;
        }
        didSomething = true;
    }
    MyExitStatus status = runAaptCompiler(context, moduleDataMap);
    if (status == MyExitStatus.FAIL) {
        success = false;
    } else if (status == MyExitStatus.OK) {
        didSomething = true;
    }
    status = runBuildConfigGeneration(context, moduleDataMap);
    if (status == MyExitStatus.FAIL) {
        success = false;
    } else if (status == MyExitStatus.OK) {
        didSomething = true;
    }
    if (!success) {
        return ExitCode.ABORT;
    }
    status = copyGeneratedSources(moduleDataMap, dataManager, context);
    if (status == MyExitStatus.FAIL) {
        return ExitCode.ABORT;
    } else if (status == MyExitStatus.OK) {
        didSomething = true;
    }
    if (didSomething) {
        return ExitCode.OK;
    }
    return ExitCode.NOTHING_DONE;
}
Also used : HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager)

Example 5 with BuildDataManager

use of org.jetbrains.jps.incremental.storage.BuildDataManager 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

BuildDataManager (org.jetbrains.jps.incremental.storage.BuildDataManager)8 IOException (java.io.IOException)5 BuildDataPathsImpl (org.jetbrains.jps.builders.impl.BuildDataPathsImpl)3 BuildRootIndexImpl (org.jetbrains.jps.builders.impl.BuildRootIndexImpl)3 BuildTargetIndexImpl (org.jetbrains.jps.builders.impl.BuildTargetIndexImpl)3 BuildTargetRegistryImpl (org.jetbrains.jps.builders.impl.BuildTargetRegistryImpl)3 BuildDataPaths (org.jetbrains.jps.builders.storage.BuildDataPaths)3 BuildTargetsState (org.jetbrains.jps.incremental.storage.BuildTargetsState)3 ModuleExcludeIndex (org.jetbrains.jps.indices.ModuleExcludeIndex)3 IgnoredFileIndexImpl (org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl)3 ModuleExcludeIndexImpl (org.jetbrains.jps.indices.impl.ModuleExcludeIndexImpl)3 HashMap (com.intellij.util.containers.HashMap)2 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)2 File (java.io.File)2 SourceToOutputMapping (org.jetbrains.jps.builders.storage.SourceToOutputMapping)2 ProjectDescriptor (org.jetbrains.jps.cmdline.ProjectDescriptor)2 BuildFSState (org.jetbrains.jps.incremental.fs.BuildFSState)2 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)2 ProjectTimestamps (org.jetbrains.jps.incremental.storage.ProjectTimestamps)2 IAndroidTarget (com.android.sdklib.IAndroidTarget)1