Skip to content

Commit

Permalink
Use InternalFlag for the internal flag to disable script compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
lptr committed Apr 19, 2024
1 parent 8bf667c commit 4c1bbd7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
Expand Up @@ -26,6 +26,7 @@ import org.gradle.api.internal.initialization.loadercache.DefaultClasspathHasher
import org.gradle.groovy.scripts.internal.ScriptSourceHasher
import org.gradle.initialization.ClassLoaderScopeRegistry
import org.gradle.initialization.GradlePropertiesController
import org.gradle.internal.buildoption.InternalOptions
import org.gradle.internal.classloader.ClasspathHasher
import org.gradle.internal.classpath.CachedClasspathTransformer
import org.gradle.internal.classpath.transforms.ClasspathElementTransformFactoryForLegacy
Expand Down Expand Up @@ -101,6 +102,7 @@ object BuildServices {
@Suppress("UNUSED_PARAMETER") kotlinCompilerContextDisposer: KotlinCompilerContextDisposer,
fileCollectionFactory: FileCollectionFactory,
inputFingerprinter: InputFingerprinter,
internalOptions: InternalOptions,
gradlePropertiesController: GradlePropertiesController,
transformFactoryForLegacy: ClasspathElementTransformFactoryForLegacy
): KotlinScriptEvaluator =
Expand All @@ -124,6 +126,7 @@ object BuildServices {
workspaceProvider,
fileCollectionFactory,
inputFingerprinter,
internalOptions,
gradlePropertiesController,
transformFactoryForLegacy
)
Expand Down
Expand Up @@ -29,6 +29,7 @@ import org.gradle.groovy.scripts.ScriptSource
import org.gradle.groovy.scripts.internal.ScriptSourceHasher
import org.gradle.initialization.ClassLoaderScopeOrigin
import org.gradle.initialization.GradlePropertiesController
import org.gradle.internal.buildoption.InternalOptions
import org.gradle.internal.classloader.ClasspathHasher
import org.gradle.internal.classpath.CachedClasspathTransformer
import org.gradle.internal.classpath.ClassPath
Expand Down Expand Up @@ -100,6 +101,7 @@ class StandardKotlinScriptEvaluator(
private val workspaceProvider: KotlinDslWorkspaceProvider,
private val fileCollectionFactory: FileCollectionFactory,
private val inputFingerprinter: InputFingerprinter,
private val internalOptions: InternalOptions,
private val gradlePropertiesController: GradlePropertiesController,
private val transformFactoryForLegacy: ClasspathElementTransformFactoryForLegacy
) : KotlinScriptEvaluator {
Expand Down Expand Up @@ -264,6 +266,7 @@ class StandardKotlinScriptEvaluator(
workspaceProvider,
fileCollectionFactory,
inputFingerprinter,
internalOptions,
transformFactoryForLegacy
)
)
Expand Down Expand Up @@ -354,8 +357,9 @@ class StandardKotlinScriptEvaluator(
workspaceProvider: KotlinDslWorkspaceProvider,
fileCollectionFactory: FileCollectionFactory,
inputFingerprinter: InputFingerprinter,
internalOptions: InternalOptions,
transformFactory: ClasspathElementTransformFactoryForLegacy
) : BuildScriptCompilationAndInstrumentation(workspaceProvider.scripts, fileCollectionFactory, inputFingerprinter, transformFactory) {
) : BuildScriptCompilationAndInstrumentation(workspaceProvider.scripts, fileCollectionFactory, inputFingerprinter, internalOptions, transformFactory) {

companion object {
const val JVM_TARGET = "jvmTarget"
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.gradle.groovy.scripts.ScriptSource;
import org.gradle.groovy.scripts.internal.GroovyScriptClassCompiler.GroovyScriptCompilationAndInstrumentation.GroovyScriptCompilationOutput;
import org.gradle.internal.Pair;
import org.gradle.internal.buildoption.InternalOptions;
import org.gradle.internal.classanalysis.AsmConstants;
import org.gradle.internal.classpath.CachedClasspathTransformer;
import org.gradle.internal.classpath.ClassData;
Expand Down Expand Up @@ -79,6 +80,7 @@ public class GroovyScriptClassCompiler implements ScriptClassCompiler, Closeable
private final ExecutionEngine earlyExecutionEngine;
private final FileCollectionFactory fileCollectionFactory;
private final InputFingerprinter inputFingerprinter;
private final InternalOptions internalOptions;
private final ImmutableWorkspaceProvider workspaceProvider;
private final ClasspathElementTransformFactoryForLegacy transformFactoryForLegacy;

Expand All @@ -89,6 +91,7 @@ public GroovyScriptClassCompiler(
ExecutionEngine earlyExecutionEngine,
FileCollectionFactory fileCollectionFactory,
InputFingerprinter inputFingerprinter,
InternalOptions internalOptions,
ImmutableWorkspaceProvider workspaceProvider,
ClasspathElementTransformFactoryForLegacy transformFactoryForLegacy
) {
Expand All @@ -98,6 +101,7 @@ public GroovyScriptClassCompiler(
this.earlyExecutionEngine = earlyExecutionEngine;
this.fileCollectionFactory = fileCollectionFactory;
this.inputFingerprinter = inputFingerprinter;
this.internalOptions = internalOptions;
this.workspaceProvider = workspaceProvider;
this.transformFactoryForLegacy = transformFactoryForLegacy;
}
Expand Down Expand Up @@ -150,6 +154,7 @@ private <T extends Script> GroovyScriptCompilationOutput doCompile(
workspaceProvider,
fileCollectionFactory,
inputFingerprinter,
internalOptions,
transformFactoryForLegacy,
scriptCompilationHandler
);
Expand Down Expand Up @@ -233,10 +238,11 @@ public GroovyScriptCompilationAndInstrumentation(
ImmutableWorkspaceProvider workspaceProvider,
FileCollectionFactory fileCollectionFactory,
InputFingerprinter inputFingerprinter,
InternalOptions internalOptions,
ClasspathElementTransformFactoryForLegacy transformFactoryForLegacy,
ScriptCompilationHandler scriptCompilationHandler
) {
super(workspaceProvider, fileCollectionFactory, inputFingerprinter, transformFactoryForLegacy);
super(workspaceProvider, fileCollectionFactory, inputFingerprinter, internalOptions, transformFactoryForLegacy);
this.templateId = templateId;
this.sourceHashCode = sourceHashCode;
this.classLoader = classLoader;
Expand Down
Expand Up @@ -17,6 +17,8 @@
package org.gradle.internal.scripts;

import org.gradle.api.internal.file.FileCollectionFactory;
import org.gradle.internal.buildoption.InternalFlag;
import org.gradle.internal.buildoption.InternalOptions;
import org.gradle.internal.classpath.transforms.ClasspathElementTransform;
import org.gradle.internal.classpath.transforms.ClasspathElementTransformFactoryForLegacy;
import org.gradle.internal.classpath.transforms.InstrumentingClassTransform;
Expand Down Expand Up @@ -47,29 +49,32 @@
* This work unit first compiles the build script to a directory, and then instruments the directory for configuration cache and returns instrumented output.
*/
public abstract class BuildScriptCompilationAndInstrumentation implements ImmutableUnitOfWork {
private static final String CACHING_DISABLED_PROPERTY = "org.gradle.internal.script-caching-disabled";
private static final InternalFlag CACHING_DISABLED_PROPERTY = new InternalFlag("org.gradle.internal.script-caching-disabled");
private static final CachingDisabledReason CACHING_DISABLED_REASON = new CachingDisabledReason(CachingDisabledReasonCategory.NOT_CACHEABLE, "Caching of script compilation disabled by property (experimental)");

private final ImmutableWorkspaceProvider workspaceProvider;
private final InputFingerprinter inputFingerprinter;
private final ClasspathElementTransformFactoryForLegacy transformFactory;
private final boolean cachingDisabledByProperty;
protected final FileCollectionFactory fileCollectionFactory;

public BuildScriptCompilationAndInstrumentation(
ImmutableWorkspaceProvider workspaceProvider,
FileCollectionFactory fileCollectionFactory,
InputFingerprinter inputFingerprinter,
InternalOptions internalOptions,
ClasspathElementTransformFactoryForLegacy transformFactory
) {
this.workspaceProvider = workspaceProvider;
this.fileCollectionFactory = fileCollectionFactory;
this.inputFingerprinter = inputFingerprinter;
this.transformFactory = transformFactory;
this.cachingDisabledByProperty = internalOptions.getOption(CACHING_DISABLED_PROPERTY).get();
}

@Override
public Optional<CachingDisabledReason> shouldDisableCaching(@Nullable OverlappingOutputs detectedOverlappingOutputs) {
if (System.getProperty(CACHING_DISABLED_PROPERTY) != null) {
if (cachingDisabledByProperty) {
return Optional.of(CACHING_DISABLED_REASON);
}

Expand Down
Expand Up @@ -178,6 +178,7 @@
import org.gradle.internal.build.PublicBuildPath;
import org.gradle.internal.buildevents.BuildStartedTime;
import org.gradle.internal.buildoption.FeatureFlags;
import org.gradle.internal.buildoption.InternalOptions;
import org.gradle.internal.buildtree.BuildInclusionCoordinator;
import org.gradle.internal.buildtree.BuildModelParameters;
import org.gradle.internal.classloader.ClassLoaderFactory;
Expand Down Expand Up @@ -474,6 +475,7 @@ protected GroovyScriptClassCompiler createFileCacheBackedScriptClassCompiler(
ExecutionEngine executionEngine,
FileCollectionFactory fileCollectionFactory,
InputFingerprinter inputFingerprinter,
InternalOptions internalOptions,
GroovyDslWorkspaceProvider groovyDslWorkspaceProvider,
ClasspathElementTransformFactoryForLegacy transformFactoryForLegacy
) {
Expand All @@ -484,6 +486,7 @@ protected GroovyScriptClassCompiler createFileCacheBackedScriptClassCompiler(
executionEngine,
fileCollectionFactory,
inputFingerprinter,
internalOptions,
groovyDslWorkspaceProvider.getWorkspace(),
transformFactoryForLegacy
);
Expand Down

0 comments on commit 4c1bbd7

Please sign in to comment.