Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix compatibility with configuration cache (#304)
* Fix compatibility with configuration cache This commit reworks the agent task actions so that they are compatible with the configuration cache. The problem was that when the configuration cache is enabled, it will try to serialize the task actions that we add, so that if the task is not up-to-date and that the configuration didn't change, it can replay the action. The problem was that our task action used, as an input, a `Provider<List<String>>`, where those strings represented paths which do _not_ exist when the action is serialized yet. In practice, we don't care, because those are implementation details of the task action: the directories will not exist _before_ the task is executed, and not _after_, they only exist during task execution. The configuration cache, however, wants to know about all inputs. We could have changed the action so that it uses a _root directory_ instead of a list of directories as input, and make the computation of the `session-` directories _during_ the task action: this would have worked because the only input would be the "output directory" that we pass as root. However, the task action is also used in another task which uses completely different inputs, which are not derived from a single directory. At the same time, we _don't_ need the `Provider` semantics in the task action: all we care about is to have a supplier which will generate a list of directories. Therefore, we changed the `Provider` type to a `Supplier` one: the lambda will be serialized, but the only thing it will capture is the `outputDir` provider which is fine, configuration-cache wise. Now, let me take a pill. Fixes #302 * More configuration cache fixes Lambdas must be serializable in order to be configuration cache compatible. * More configuration cache fixes
- Loading branch information
Showing
9 changed files
with
176 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...lugin/src/main/java/org/graalvm/buildtools/gradle/internal/ConfigurationCacheSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* The Universal Permissive License (UPL), Version 1.0 | ||
* | ||
* Subject to the condition set forth below, permission is hereby granted to any | ||
* person obtaining a copy of this software, associated documentation and/or | ||
* data (collectively the "Software"), free of charge and under any and all | ||
* copyright rights in the Software, and any and all patent rights owned or | ||
* freely licensable by each licensor hereunder covering either (i) the | ||
* unmodified Software as contributed to or provided by such licensor, or (ii) | ||
* the Larger Works (as defined below), to deal in both | ||
* | ||
* (a) the Software, and | ||
* | ||
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if | ||
* one is included with the Software each a "Larger Work" to which the Software | ||
* is contributed by such licensors), | ||
* | ||
* without restriction, including without limitation the rights to copy, create | ||
* derivative works of, display, perform, and distribute the Software and make, | ||
* use, sell, offer for sale, import, export, have made, and have sold the | ||
* Software and the Larger Work(s), and to sublicense the foregoing rights on | ||
* either these or other terms. | ||
* | ||
* This license is subject to the following condition: | ||
* | ||
* The above copyright notice and either this complete permission notice or at a | ||
* minimum a reference to the UPL must be included in all copies or substantial | ||
* portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package org.graalvm.buildtools.gradle.internal; | ||
|
||
import org.gradle.api.Transformer; | ||
|
||
import java.io.Serializable; | ||
import java.util.function.Predicate; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Helper class to deal with Gradle configuration cache. | ||
*/ | ||
public class ConfigurationCacheSupport { | ||
/** | ||
* Generates a serializable supplier lambda. | ||
* @param supplier the supplier | ||
* @return a serializable supplier | ||
* @param <T> the type of the supplier | ||
*/ | ||
public static <T> Supplier<T> serializableSupplierOf(SerializableSupplier<T> supplier) { | ||
return supplier; | ||
} | ||
|
||
/** | ||
* Generates a serializable predicate lambda. | ||
* @param predicate the predicate | ||
* @return a serializable predicate | ||
* @param <T> the type of the predicate | ||
*/ | ||
public static <T> Predicate<T> serializablePredicateOf(SerializablePredicate<T> predicate) { | ||
return predicate; | ||
} | ||
|
||
/** | ||
* Generates a serializable transformer lambda. | ||
* @param transformer the transformer | ||
* @return a serializable transformer | ||
* @param <OUT> the output type of the transformer | ||
* @param <IN> the input type of the transformer | ||
*/ | ||
public static <OUT, IN> Transformer<OUT, IN> serializableTransformerOf(SerializableTransformer<OUT, IN> transformer) { | ||
return transformer; | ||
} | ||
|
||
public interface SerializableSupplier<T> extends Supplier<T>, Serializable { | ||
|
||
} | ||
|
||
public interface SerializablePredicate<T> extends Predicate<T>, Serializable { | ||
|
||
} | ||
|
||
public interface SerializableTransformer<OUT, IN> extends Transformer<OUT, IN>, Serializable { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.