Merge pull request #7165 from mdedetrich/make-skip-work-on-publish-local

Make skip work on publishLocal
This commit is contained in:
eugene yokota 2023-03-03 22:01:28 -05:00 committed by GitHub
commit 51da437f22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 5 deletions

View File

@ -2614,6 +2614,7 @@ object Defaults extends BuildCommon {
if (turbo.value) ClassLoaderLayeringStrategy.AllLibraryJars if (turbo.value) ClassLoaderLayeringStrategy.AllLibraryJars
else ClassLoaderLayeringStrategy.ScalaLibrary else ClassLoaderLayeringStrategy.ScalaLibrary
}, },
publishLocal / skip := (publish / skip).value, // So we don't break previous behaviour
) )
// build.sbt is treated a Scala source of metabuild, so to enable deprecation flag on build.sbt we set the option here. // build.sbt is treated a Scala source of metabuild, so to enable deprecation flag on build.sbt we set the option here.
lazy val deprecationSettings: Seq[Setting[_]] = lazy val deprecationSettings: Seq[Setting[_]] =
@ -3585,15 +3586,57 @@ object Classpaths {
): Initialize[Task[Unit]] = ): Initialize[Task[Unit]] =
publishTask(config) publishTask(config)
private def logSkipPublish(log: Logger, ref: ProjectRef): Unit =
log.debug(s"Skipping publish* for ${ref.project}")
private def checkAndPublishLocal(
currentCon: PublishConfiguration,
publishLocalConf: PublishConfiguration,
publishSkipLocal: Boolean,
module: IvySbt#Module,
log: Logger,
ref: ProjectRef
)(notPublishLocal: () => Unit): Unit = {
if (currentCon == publishLocalConf) {
if (publishSkipLocal) {
logSkipPublish(log, ref)
} else {
IvyActions.publish(module, currentCon, log)
}
} else {
notPublishLocal()
}
}
def publishTask(config: TaskKey[PublishConfiguration]): Initialize[Task[Unit]] = def publishTask(config: TaskKey[PublishConfiguration]): Initialize[Task[Unit]] =
Def.taskIf { Def.taskIf {
if ((publish / skip).value) { if ((publish / skip).value) {
val s = streams.value val log = streams.value.log
val ref = thisProjectRef.value val ref = thisProjectRef.value
s.log.debug(s"Skipping publish* for ${ref.project}") checkAndPublishLocal(
config.value,
publishLocalConfiguration.value,
(publishLocal / skip).value,
ivyModule.value,
log,
ref
) { () =>
logSkipPublish(log, ref)
}
} else { } else {
val s = streams.value val conf = config.value
IvyActions.publish(ivyModule.value, config.value, s.log) val log = streams.value.log
val module = ivyModule.value
checkAndPublishLocal(
conf,
publishLocalConfiguration.value,
(publishLocal / skip).value,
module,
log,
thisProjectRef.value
) { () =>
IvyActions.publish(module, conf, log)
}
} }
} tag (Tags.Publish, Tags.Network) } tag (Tags.Publish, Tags.Network)

View File

@ -566,7 +566,7 @@ object Keys {
val sbtDependency = settingKey[ModuleID]("Provides a definition for declaring the current version of sbt.").withRank(BMinusSetting) val sbtDependency = settingKey[ModuleID]("Provides a definition for declaring the current version of sbt.").withRank(BMinusSetting)
val sbtVersion = settingKey[String]("Provides the version of sbt. This setting should not be modified.").withRank(AMinusSetting) val sbtVersion = settingKey[String]("Provides the version of sbt. This setting should not be modified.").withRank(AMinusSetting)
val sbtBinaryVersion = settingKey[String]("Defines the binary compatibility version substring.").withRank(BPlusSetting) val sbtBinaryVersion = settingKey[String]("Defines the binary compatibility version substring.").withRank(BPlusSetting)
val skip = taskKey[Boolean]("For tasks that support it (currently only 'compile', 'update', and 'publish'), setting skip to true will force the task to not to do its work. This exact semantics may vary by task.").withRank(BSetting) val skip = taskKey[Boolean]("For tasks that support it (currently only 'compile', 'update', 'publish' and 'publishLocal'), setting skip to true will force the task to not to do its work. This exact semantics may vary by task.").withRank(BSetting)
val templateResolverInfos = settingKey[Seq[TemplateResolverInfo]]("Template resolvers used for 'new'.").withRank(BSetting) val templateResolverInfos = settingKey[Seq[TemplateResolverInfo]]("Template resolvers used for 'new'.").withRank(BSetting)
val interactionService = taskKey[InteractionService]("Service used to ask for user input through the current user interface(s).").withRank(CTask) val interactionService = taskKey[InteractionService]("Service used to ask for user input through the current user interface(s).").withRank(CTask)
val insideCI = SettingKey[Boolean]("insideCI", "Determines if the sbt is running in a Continuous Integration environment", AMinusSetting) val insideCI = SettingKey[Boolean]("insideCI", "Determines if the sbt is running in a Continuous Integration environment", AMinusSetting)

View File

@ -0,0 +1,20 @@
publish / skip := true
lazy val check = taskKey[Unit]("check")
lazy val a = project
.in(file("a"))
.settings(
publishLocal / skip := true
)
lazy val b = project
.in(file("b"))
check := {
assert((publishLocal / skip).value, "Expected true, got false")
assert((a / publishLocal / skip).value, "Expected true, got false")
assert(!(a / publish / skip).value, "Expected false, got true")
assert(!(b / publish / skip).value, "Expected false, got true")
assert(!(b / publishLocal / skip).value, "Expected false, got true")
}

View File

@ -0,0 +1 @@
> check