Search in sources :

Example 11 with BuildFSState

use of org.jetbrains.jps.incremental.fs.BuildFSState in project intellij-community by JetBrains.

the class BuildSession method runBuild.

private void runBuild(final MessageHandler msgHandler, CanceledStatus cs) throws Throwable {
    final File dataStorageRoot = Utils.getDataStorageRoot(myProjectPath);
    if (dataStorageRoot == null) {
        msgHandler.processMessage(new CompilerMessage("build", BuildMessage.Kind.ERROR, "Cannot determine build data storage root for project " + myProjectPath));
        return;
    }
    final boolean storageFilesAbsent = !dataStorageRoot.exists() || !new File(dataStorageRoot, FS_STATE_FILE).exists();
    if (storageFilesAbsent) {
        // invoked the very first time for this project
        myBuildRunner.setForceCleanCaches(true);
    }
    final ProjectDescriptor preloadedProject = myPreloadedData != null ? myPreloadedData.getProjectDescriptor() : null;
    final DataInputStream fsStateStream = storageFilesAbsent || preloadedProject != null || myInitialFSDelta == null ? /*this will force FS rescan*/
    null : createFSDataStream(dataStorageRoot, myInitialFSDelta.getOrdinal());
    if (fsStateStream != null || myPreloadedData != null) {
        // optimization: check whether we can skip the build
        final boolean hasWorkFlag = fsStateStream != null ? fsStateStream.readBoolean() : myPreloadedData.hasWorkToDo();
        final boolean hasWorkToDoWithModules = hasWorkFlag || myInitialFSDelta == null;
        if (!myForceModelLoading && (myBuildType == BuildType.BUILD || myBuildType == BuildType.UP_TO_DATE_CHECK) && !hasWorkToDoWithModules && scopeContainsModulesOnlyForIncrementalMake(myScopes) && !containsChanges(myInitialFSDelta)) {
            final DataInputStream storedFsData;
            if (myPreloadedData != null) {
                storedFsData = createFSDataStream(dataStorageRoot, myInitialFSDelta.getOrdinal());
                if (storedFsData != null) {
                    // skip hasWorkToDo flag
                    storedFsData.readBoolean();
                }
            } else {
                storedFsData = fsStateStream;
            }
            if (storedFsData != null) {
                updateFsStateOnDisk(dataStorageRoot, storedFsData, myInitialFSDelta.getOrdinal());
                LOG.info("No changes found since last build. Exiting.");
                if (preloadedProject != null) {
                    preloadedProject.release();
                }
                return;
            }
        }
    }
    final BuildFSState fsState = preloadedProject != null ? preloadedProject.fsState : new BuildFSState(false);
    try {
        final ProjectDescriptor pd;
        if (preloadedProject != null) {
            pd = preloadedProject;
            final List<BuildMessage> preloadMessages = myPreloadedData.getLoadMessages();
            if (!preloadMessages.isEmpty()) {
                // replay preload-time messages, so that they are delivered to the IDE
                for (BuildMessage message : preloadMessages) {
                    msgHandler.processMessage(message);
                }
            }
            if (myInitialFSDelta == null || myPreloadedData.getFsEventOrdinal() + 1L != myInitialFSDelta.getOrdinal()) {
                // FS rescan was forced
                fsState.clearAll();
            } else {
                // apply events to already loaded state
                try {
                    applyFSEvent(pd, myInitialFSDelta, false);
                } catch (Throwable e) {
                    LOG.error(e);
                    fsState.clearAll();
                }
            }
        } else {
            // standard case
            pd = myBuildRunner.load(msgHandler, dataStorageRoot, fsState);
            TimingLog.LOG.debug("Project descriptor loaded");
            if (fsStateStream != null) {
                try {
                    try {
                        fsState.load(fsStateStream, pd.getModel(), pd.getBuildRootIndex());
                        applyFSEvent(pd, myInitialFSDelta, false);
                        TimingLog.LOG.debug("FS Delta loaded");
                    } finally {
                        fsStateStream.close();
                    }
                } catch (Throwable e) {
                    LOG.error(e);
                    fsState.clearAll();
                }
            }
        }
        myProjectDescriptor = pd;
        myLastEventOrdinal = myInitialFSDelta != null ? myInitialFSDelta.getOrdinal() : 0L;
        // free memory
        myInitialFSDelta = null;
        // ensure events from controller are processed after FSState initialization
        myEventsProcessor.startProcessing();
        myBuildRunner.runBuild(pd, cs, myConstantSearch, msgHandler, myBuildType, myScopes, false);
        TimingLog.LOG.debug("Build finished");
    } finally {
        saveData(fsState, dataStorageRoot);
    }
}
Also used : BuildFSState(org.jetbrains.jps.incremental.fs.BuildFSState)

Example 12 with BuildFSState

use of org.jetbrains.jps.incremental.fs.BuildFSState in project intellij-community by JetBrains.

the class ChainedTargetsBuildListener method filesGenerated.

@Override
public void filesGenerated(FileGeneratedEvent event) {
    final ProjectDescriptor pd = myContext.getProjectDescriptor();
    final BuildFSState fsState = pd.fsState;
    for (Pair<String, String> pair : event.getPaths()) {
        final String relativePath = pair.getSecond();
        final File file = relativePath.equals(".") ? new File(pair.getFirst()) : new File(pair.getFirst(), relativePath);
        for (BuildRootDescriptor desc : pd.getBuildRootIndex().findAllParentDescriptors(file, myContext)) {
            if (!event.getSourceTarget().equals(desc.getTarget())) {
                // It is assumed that those files will be explicitly marked dirty by particular builder, if needed.
                try {
                    fsState.markDirty(myContext, file, desc, pd.timestamps.getStorage(), false);
                } catch (IOException ignored) {
                }
            }
        }
    }
}
Also used : BuildFSState(org.jetbrains.jps.incremental.fs.BuildFSState) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) IOException(java.io.IOException) File(java.io.File)

Aggregations

BuildFSState (org.jetbrains.jps.incremental.fs.BuildFSState)12 ProjectDescriptor (org.jetbrains.jps.cmdline.ProjectDescriptor)6 File (java.io.File)5 IOException (java.io.IOException)5 BuildTargetsState (org.jetbrains.jps.incremental.storage.BuildTargetsState)3 BuildRootDescriptor (org.jetbrains.jps.builders.BuildRootDescriptor)2 BuildDataPathsImpl (org.jetbrains.jps.builders.impl.BuildDataPathsImpl)2 BuildRootIndexImpl (org.jetbrains.jps.builders.impl.BuildRootIndexImpl)2 BuildTargetIndexImpl (org.jetbrains.jps.builders.impl.BuildTargetIndexImpl)2 BuildTargetRegistryImpl (org.jetbrains.jps.builders.impl.BuildTargetRegistryImpl)2 BuildDataCorruptedException (org.jetbrains.jps.builders.storage.BuildDataCorruptedException)2 BuildDataPaths (org.jetbrains.jps.builders.storage.BuildDataPaths)2 BuildDataManager (org.jetbrains.jps.incremental.storage.BuildDataManager)2 ProjectTimestamps (org.jetbrains.jps.incremental.storage.ProjectTimestamps)2 Timestamps (org.jetbrains.jps.incremental.storage.Timestamps)2 ModuleExcludeIndex (org.jetbrains.jps.indices.ModuleExcludeIndex)2 IgnoredFileIndexImpl (org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl)2 ModuleExcludeIndexImpl (org.jetbrains.jps.indices.impl.ModuleExcludeIndexImpl)2 MultiMap (com.intellij.util.containers.MultiMap)1 MappingFailedException (com.intellij.util.io.MappingFailedException)1