2020-10-09 17:19:58 +03:00
|
|
|
import sbt.Keys._
|
|
|
|
import sbt._
|
2021-07-20 14:32:19 +03:00
|
|
|
import sbt.internal.util.ManagedLogger
|
2020-10-09 17:19:58 +03:00
|
|
|
import sbt.io.IO
|
|
|
|
import sbt.librarymanagement.{ConfigurationFilter, DependencyFilter}
|
2020-10-02 19:17:21 +03:00
|
|
|
|
2022-05-11 13:12:18 +03:00
|
|
|
import java.io.File
|
2021-07-20 14:32:19 +03:00
|
|
|
|
2020-10-02 19:17:21 +03:00
|
|
|
object StdBits {
|
2020-10-09 17:19:58 +03:00
|
|
|
|
2020-10-22 17:12:28 +03:00
|
|
|
/** Discovers dependencies of a project and copies them into the destination
|
2020-10-09 17:19:58 +03:00
|
|
|
* directory.
|
|
|
|
*
|
|
|
|
* @param destination location where to put the dependencies
|
2023-03-11 12:27:26 +03:00
|
|
|
* @param providedJarNames name of JARs generated by the local projects;
|
|
|
|
* unexpected (old) files are removed, so this task
|
|
|
|
* needs to know these files' names to avoid removing
|
|
|
|
* them
|
2020-10-09 17:19:58 +03:00
|
|
|
* @param ignoreScalaLibrary whether to ignore Scala dependencies that are
|
|
|
|
* added by default be SBT and are not relevant in
|
|
|
|
* pure-Java projects
|
|
|
|
*/
|
|
|
|
def copyDependencies(
|
|
|
|
destination: File,
|
2023-03-11 12:27:26 +03:00
|
|
|
providedJarNames: Seq[String],
|
2022-10-14 21:08:08 +03:00
|
|
|
ignoreScalaLibrary: Boolean
|
2020-10-09 17:19:58 +03:00
|
|
|
): Def.Initialize[Task[Unit]] =
|
2020-10-02 19:17:21 +03:00
|
|
|
Def.task {
|
2020-10-09 17:19:58 +03:00
|
|
|
val libraryUpdates = (Compile / update).value
|
|
|
|
val log = streams.value.log
|
|
|
|
|
2022-05-12 13:44:46 +03:00
|
|
|
val baseFilter: NameFilter = new ExactFilter(Configurations.Runtime.name)
|
|
|
|
val validConfig =
|
2023-03-11 03:15:58 +03:00
|
|
|
if (ignoreScalaLibrary)
|
|
|
|
baseFilter - new ExactFilter(Configurations.ScalaTool.name)
|
2022-05-12 13:44:46 +03:00
|
|
|
else baseFilter
|
2021-07-20 14:32:19 +03:00
|
|
|
val configFilter: ConfigurationFilter =
|
2022-05-12 13:44:46 +03:00
|
|
|
DependencyFilter.configurationFilter(name = validConfig)
|
2021-07-20 14:32:19 +03:00
|
|
|
|
|
|
|
val graalOrg = new ExactFilter("org.graalvm.sdk")
|
|
|
|
val relevantFiles =
|
|
|
|
libraryUpdates
|
|
|
|
.select(
|
|
|
|
configuration = configFilter,
|
|
|
|
module = DependencyFilter.moduleFilter(organization = -graalOrg),
|
|
|
|
artifact = DependencyFilter.artifactFilter()
|
|
|
|
)
|
2020-10-09 17:19:58 +03:00
|
|
|
|
|
|
|
val dependencyStore =
|
|
|
|
streams.value.cacheStoreFactory.make("std-bits-dependencies")
|
|
|
|
Tracked.diffInputs(dependencyStore, FileInfo.hash)(relevantFiles.toSet) {
|
|
|
|
report =>
|
2021-02-25 16:48:18 +03:00
|
|
|
val expectedFileNames =
|
2023-03-11 12:27:26 +03:00
|
|
|
report.checked.map(file => file.getName) ++ providedJarNames
|
2020-10-09 17:19:58 +03:00
|
|
|
for (existing <- IO.listFiles(destination)) {
|
|
|
|
if (!expectedFileNames.contains(existing.getName)) {
|
|
|
|
log.info(
|
|
|
|
s"Removing outdated std-bits dependency ${existing.getName}."
|
|
|
|
)
|
|
|
|
IO.delete(existing)
|
|
|
|
}
|
2020-10-02 19:17:21 +03:00
|
|
|
}
|
2020-10-09 17:19:58 +03:00
|
|
|
for (changed <- report.modified -- report.removed) {
|
|
|
|
log.info(
|
|
|
|
s"Updating changed std-bits dependency ${changed.getName}."
|
2020-10-02 19:17:21 +03:00
|
|
|
)
|
2022-10-14 21:08:08 +03:00
|
|
|
updateDependency(changed, destination, log)
|
2020-10-09 17:19:58 +03:00
|
|
|
}
|
2020-12-09 16:58:11 +03:00
|
|
|
for (file <- report.unmodified) {
|
2022-10-14 21:08:08 +03:00
|
|
|
val dest = destination / file.getName
|
2020-10-09 17:19:58 +03:00
|
|
|
if (!dest.exists()) {
|
|
|
|
log.info(s"Adding missing std-bits dependency ${file.getName}.")
|
2022-10-14 21:08:08 +03:00
|
|
|
updateDependency(file, destination, log)
|
2020-10-09 17:19:58 +03:00
|
|
|
}
|
|
|
|
}
|
2020-10-02 19:17:21 +03:00
|
|
|
}
|
|
|
|
}
|
2021-07-20 14:32:19 +03:00
|
|
|
|
|
|
|
private def updateDependency(
|
|
|
|
jar: File,
|
|
|
|
destinationDir: File,
|
|
|
|
logger: ManagedLogger
|
|
|
|
): Unit = {
|
2022-10-14 21:08:08 +03:00
|
|
|
val destination = destinationDir / jar.getName
|
|
|
|
IO.copyFile(jar, destination)
|
2021-07-20 14:32:19 +03:00
|
|
|
}
|
2022-05-11 13:12:18 +03:00
|
|
|
|
2023-03-11 03:15:58 +03:00
|
|
|
/** Builds a single standard library package `name`. Should only be used
|
|
|
|
* in tasks used in local development.
|
|
|
|
*
|
|
|
|
* @param name name of the package, see `stdBitsProjects` in build.sbt
|
|
|
|
* @param root top directory where distribution is being built
|
|
|
|
* @param cache used for persisting the cached information
|
|
|
|
* @param log logger used in the task
|
|
|
|
* @param defaultDevEnsoVersion default `dev` version
|
|
|
|
*/
|
2022-05-11 13:12:18 +03:00
|
|
|
def buildStdLibPackage(
|
|
|
|
name: String,
|
|
|
|
root: File,
|
|
|
|
cacheFactory: sbt.util.CacheStoreFactory,
|
|
|
|
log: sbt.Logger,
|
|
|
|
defaultDevEnsoVersion: String
|
2022-10-11 02:11:04 +03:00
|
|
|
) = {
|
2022-05-11 13:12:18 +03:00
|
|
|
log.info(s"Building standard library package for '$name'")
|
2023-03-11 03:15:58 +03:00
|
|
|
val prefix = "Standard"
|
2022-05-11 13:12:18 +03:00
|
|
|
val targetPkgRoot = root / "lib" / prefix / name / defaultDevEnsoVersion
|
2023-03-11 03:15:58 +03:00
|
|
|
val sourceDir = file(
|
|
|
|
s"distribution/lib/$prefix/$name/$defaultDevEnsoVersion"
|
|
|
|
)
|
2022-05-11 13:12:18 +03:00
|
|
|
if (!sourceDir.exists) {
|
|
|
|
throw new RuntimeException("Invalid standard library package " + name)
|
|
|
|
}
|
|
|
|
val result = DistributionPackage.copyDirectoryIncremental(
|
|
|
|
source = file(s"distribution/lib/$prefix/$name/$defaultDevEnsoVersion"),
|
|
|
|
destination = targetPkgRoot,
|
2023-03-11 03:15:58 +03:00
|
|
|
cache = cacheFactory.sub("engine-libraries").make(s"$prefix.$name")
|
2022-05-11 13:12:18 +03:00
|
|
|
)
|
|
|
|
if (result) {
|
|
|
|
log.info(s"Package '$name' has been updated")
|
|
|
|
} else {
|
|
|
|
log.info(s"No changes detected for '$name' package")
|
|
|
|
}
|
|
|
|
}
|
2020-10-02 19:17:21 +03:00
|
|
|
}
|