Search in sources :

Example 1 with BuildTargetChunk

use of org.jetbrains.jps.builders.impl.BuildTargetChunk in project intellij-community by JetBrains.

the class IncProjectBuilder method runBuildersForChunk.

private boolean runBuildersForChunk(final CompileContext context, final BuildTargetChunk chunk) throws ProjectBuildException, IOException {
    Set<? extends BuildTarget<?>> targets = chunk.getTargets();
    if (targets.size() > 1) {
        Set<ModuleBuildTarget> moduleTargets = new LinkedHashSet<>();
        for (BuildTarget<?> target : targets) {
            if (target instanceof ModuleBuildTarget) {
                moduleTargets.add((ModuleBuildTarget) target);
            } else {
                String targetsString = StringUtil.join(targets, (Function<BuildTarget<?>, String>) target1 -> StringUtil.decapitalize(target1.getPresentableName()), ", ");
                context.processMessage(new CompilerMessage("", BuildMessage.Kind.ERROR, "Cannot build " + StringUtil.decapitalize(target.getPresentableName()) + " because it is included into a circular dependency (" + targetsString + ")"));
                return false;
            }
        }
        return runModuleLevelBuilders(context, new ModuleChunk(moduleTargets));
    }
    final BuildTarget<?> target = targets.iterator().next();
    if (target instanceof ModuleBuildTarget) {
        return runModuleLevelBuilders(context, new ModuleChunk(Collections.singleton((ModuleBuildTarget) target)));
    }
    // In general the set of files corresponding to changed source file may be different
    // Need this for example, to keep up with case changes in file names  for case-insensitive OSes: 
    // deleting the output before copying is the only way to ensure the case of the output file's name is exactly the same as source file's case
    cleanOldOutputs(context, target);
    final List<TargetBuilder<?, ?>> builders = BuilderRegistry.getInstance().getTargetBuilders();
    final float builderProgressDelta = 1.0f / builders.size();
    for (TargetBuilder<?, ?> builder : builders) {
        buildTarget(target, context, builder);
        updateDoneFraction(context, builderProgressDelta);
    }
    return true;
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) BuildTargetConfiguration(org.jetbrains.jps.incremental.storage.BuildTargetConfiguration) ExternalJavacManager(org.jetbrains.jps.javac.ExternalJavacManager) THashSet(gnu.trove.THashSet) CanceledStatus(org.jetbrains.jps.api.CanceledStatus) CompilationRound(org.jetbrains.jps.incremental.fs.CompilationRound) THashMap(gnu.trove.THashMap) FilesDelta(org.jetbrains.jps.incremental.fs.FilesDelta) org.jetbrains.jps.incremental.messages(org.jetbrains.jps.incremental.messages) Predicate(com.intellij.util.containers.Predicate) TimingLog(org.jetbrains.jps.TimingLog) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) SmartList(com.intellij.util.SmartList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) BuildRunner(org.jetbrains.jps.cmdline.BuildRunner) MultiMap(com.intellij.util.containers.MultiMap) Method(java.lang.reflect.Method) BuildFSState(org.jetbrains.jps.incremental.fs.BuildFSState) ModuleChunk(org.jetbrains.jps.ModuleChunk) java.util.concurrent(java.util.concurrent) PersistentEnumerator(com.intellij.util.io.PersistentEnumerator) JpsModule(org.jetbrains.jps.model.module.JpsModule) DirtyFilesHolderBase(org.jetbrains.jps.builders.impl.DirtyFilesHolderBase) InvocationTargetException(java.lang.reflect.InvocationTargetException) Nullable(org.jetbrains.annotations.Nullable) Function(com.intellij.util.Function) NotNull(org.jetbrains.annotations.NotNull) ModuleExcludeIndex(org.jetbrains.jps.indices.ModuleExcludeIndex) OutputToTargetRegistry(org.jetbrains.jps.incremental.storage.OutputToTargetRegistry) java.util(java.util) Proxy(java.lang.reflect.Proxy) SharedThreadPool(org.jetbrains.jps.service.SharedThreadPool) SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) ContainerUtil(com.intellij.util.containers.ContainerUtil) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) AtomicReference(java.util.concurrent.atomic.AtomicReference) GlobalOptions(org.jetbrains.jps.api.GlobalOptions) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService) BuildTargetChunk(org.jetbrains.jps.builders.impl.BuildTargetChunk) BoundedTaskExecutor(com.intellij.util.concurrency.BoundedTaskExecutor) OneToManyPathsMapping(org.jetbrains.jps.incremental.storage.OneToManyPathsMapping) StringUtil(com.intellij.openapi.util.text.StringUtil) IOException(java.io.IOException) File(java.io.File) JavaBuilderUtil(org.jetbrains.jps.builders.java.JavaBuilderUtil) org.jetbrains.jps.builders(org.jetbrains.jps.builders) AtomicLong(java.util.concurrent.atomic.AtomicLong) JavacMain(org.jetbrains.jps.javac.JavacMain) Callbacks(org.jetbrains.jps.builders.java.dependencyView.Callbacks) InvocationHandler(java.lang.reflect.InvocationHandler) MappingFailedException(com.intellij.util.io.MappingFailedException) BuildOutputConsumerImpl(org.jetbrains.jps.builders.impl.BuildOutputConsumerImpl) JpsPathUtil(org.jetbrains.jps.util.JpsPathUtil) ModuleChunk(org.jetbrains.jps.ModuleChunk)

Example 2 with BuildTargetChunk

use of org.jetbrains.jps.builders.impl.BuildTargetChunk in project intellij-community by JetBrains.

the class FSOperations method markDirtyRecursively.

public static void markDirtyRecursively(CompileContext context, final CompilationRound round, ModuleChunk chunk, @Nullable FileFilter filter) throws IOException {
    Set<JpsModule> modules = chunk.getModules();
    Set<ModuleBuildTarget> targets = chunk.getTargets();
    final Set<ModuleBuildTarget> dirtyTargets = new HashSet<>(targets);
    // now mark all modules that depend on dirty modules
    final JpsJavaClasspathKind classpathKind = JpsJavaClasspathKind.compile(chunk.containsTests());
    boolean found = false;
    for (BuildTargetChunk targetChunk : context.getProjectDescriptor().getBuildTargetIndex().getSortedTargetChunks(context)) {
        if (!found) {
            if (targetChunk.getTargets().equals(chunk.getTargets())) {
                found = true;
            }
        } else {
            for (final BuildTarget<?> target : targetChunk.getTargets()) {
                if (target instanceof ModuleBuildTarget) {
                    final Set<JpsModule> deps = getDependentModulesRecursively(((ModuleBuildTarget) target).getModule(), classpathKind);
                    if (ContainerUtil.intersects(deps, modules)) {
                        for (BuildTarget<?> buildTarget : targetChunk.getTargets()) {
                            if (buildTarget instanceof ModuleBuildTarget) {
                                dirtyTargets.add((ModuleBuildTarget) buildTarget);
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
    if (JavaBuilderUtil.isCompileJavaIncrementally(context)) {
        // mark as non-incremental only the module that triggered non-incremental change
        for (ModuleBuildTarget target : targets) {
            if (!isMarkedDirty(context, target)) {
                // if the target was marked dirty already, all its files were compiled, so
                // it makes no sense to mark it non-incremental
                context.markNonIncremental(target);
            }
        }
    }
    removeTargetsAlreadyMarkedDirty(context, dirtyTargets);
    final Timestamps timestamps = context.getProjectDescriptor().timestamps.getStorage();
    for (ModuleBuildTarget target : dirtyTargets) {
        markDirtyFiles(context, target, round, timestamps, true, null, filter);
    }
}
Also used : Timestamps(org.jetbrains.jps.incremental.storage.Timestamps) JpsModule(org.jetbrains.jps.model.module.JpsModule) BuildTargetChunk(org.jetbrains.jps.builders.impl.BuildTargetChunk) JpsJavaClasspathKind(org.jetbrains.jps.model.java.JpsJavaClasspathKind) THashSet(gnu.trove.THashSet) HashSet(java.util.HashSet)

Example 3 with BuildTargetChunk

use of org.jetbrains.jps.builders.impl.BuildTargetChunk in project intellij-community by JetBrains.

the class IncProjectBuilder method buildChunks.

private void buildChunks(final CompileContextImpl context) throws ProjectBuildException {
    try {
        final CompileScope scope = context.getScope();
        final ProjectDescriptor pd = context.getProjectDescriptor();
        final BuildTargetIndex targetIndex = pd.getBuildTargetIndex();
        // for better progress dynamics consider only actually affected chunks
        int totalAffected = 0;
        for (BuildTargetChunk chunk : targetIndex.getSortedTargetChunks(context)) {
            if (isAffected(context.getScope(), chunk)) {
                totalAffected += chunk.getTargets().size();
            }
        }
        myTotalTargetsWork = totalAffected;
        boolean compileInParallel = BuildRunner.PARALLEL_BUILD_ENABLED;
        if (compileInParallel && MAX_BUILDER_THREADS <= 1) {
            LOG.info("Switched off parallel compilation because maximum number of builder threads is less than 2. Set '" + GlobalOptions.COMPILE_PARALLEL_MAX_THREADS_OPTION + "' system property to a value greater than 1 to really enable parallel compilation.");
            compileInParallel = false;
        }
        if (compileInParallel) {
            new BuildParallelizer(context).buildInParallel();
        } else {
            // non-parallel build
            for (BuildTargetChunk chunk : targetIndex.getSortedTargetChunks(context)) {
                try {
                    buildChunkIfAffected(context, scope, chunk);
                } finally {
                    pd.dataManager.closeSourceToOutputStorages(Collections.singleton(chunk));
                    pd.dataManager.flush(true);
                }
            }
        }
    } catch (IOException e) {
        throw new ProjectBuildException(e);
    }
}
Also used : BuildTargetChunk(org.jetbrains.jps.builders.impl.BuildTargetChunk) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) IOException(java.io.IOException)

Aggregations

BuildTargetChunk (org.jetbrains.jps.builders.impl.BuildTargetChunk)3 THashSet (gnu.trove.THashSet)2 IOException (java.io.IOException)2 JpsModule (org.jetbrains.jps.model.module.JpsModule)2 Logger (com.intellij.openapi.diagnostic.Logger)1 com.intellij.openapi.util (com.intellij.openapi.util)1 FileUtil (com.intellij.openapi.util.io.FileUtil)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 Function (com.intellij.util.Function)1 SmartList (com.intellij.util.SmartList)1 BoundedTaskExecutor (com.intellij.util.concurrency.BoundedTaskExecutor)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 MultiMap (com.intellij.util.containers.MultiMap)1 Predicate (com.intellij.util.containers.Predicate)1 MappingFailedException (com.intellij.util.io.MappingFailedException)1 PersistentEnumerator (com.intellij.util.io.PersistentEnumerator)1 THashMap (gnu.trove.THashMap)1 File (java.io.File)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1