Merge pull request #2169 from Duhemm/scripted-local-repo

Publish compiler interface to an alternate local repository for Scripted tests
This commit is contained in:
eugene yokota 2016-04-05 13:16:34 -04:00
commit bc70ec0492
2 changed files with 56 additions and 5 deletions

View File

@ -41,6 +41,31 @@ def baseSettings: Seq[Setting[_]] =
def testedBaseSettings: Seq[Setting[_]] = def testedBaseSettings: Seq[Setting[_]] =
baseSettings ++ testDependencies baseSettings ++ testDependencies
val altLocalRepoName = "alternative-local"
val altLocalRepoPath = sys.props("user.home") + "/.ivy2/sbt-alternative"
lazy val altLocalResolver = Resolver.file(altLocalRepoName, file(sys.props("user.home") + "/.ivy2/sbt-alternative"))(Resolver.ivyStylePatterns)
lazy val altLocalPublish = TaskKey[Unit]("alt-local-publish", "Publishes an artifact locally to an alternative location.")
def altPublishSettings: Seq[Setting[_]] = Seq(
resolvers += altLocalResolver,
altLocalPublish := {
val config = (Keys.publishLocalConfiguration).value
val moduleSettings = (Keys.moduleSettings).value
val ivy = new IvySbt((ivyConfiguration.value))
val module =
new ivy.Module(moduleSettings)
val newConfig =
new PublishConfiguration(
config.ivyFile,
altLocalRepoName,
config.artifacts,
config.checksums,
config.logging)
streams.value.log.info("Publishing " + module + " to local repo: " + altLocalRepoName)
IvyActions.publish(module, newConfig, streams.value.log)
})
lazy val sbtRoot: Project = (project in file(".")). lazy val sbtRoot: Project = (project in file(".")).
configs(Sxr.sxrConf). configs(Sxr.sxrConf).
aggregate(nonRoots: _*). aggregate(nonRoots: _*).
@ -93,7 +118,8 @@ lazy val interfaceProj = (project in file("interface")).
sourceManaged in Compile, sourceManaged in Compile,
mainClass in datatypeProj in Compile, mainClass in datatypeProj in Compile,
runner, runner,
streams) map generateAPICached streams) map generateAPICached,
altPublishSettings
) )
// defines operations on the API of a source, including determining whether it has changed and converting it to a string // defines operations on the API of a source, including determining whether it has changed and converting it to a string
@ -307,7 +333,8 @@ lazy val compileInterfaceProj = (project in compilePath / "interface").
// needed because we fork tests and tests are ran in parallel so we have multiple Scala // needed because we fork tests and tests are ran in parallel so we have multiple Scala
// compiler instances that are memory hungry // compiler instances that are memory hungry
javaOptions in Test += "-Xmx1G", javaOptions in Test += "-Xmx1G",
publishArtifact in (Compile, packageSrc) := true publishArtifact in (Compile, packageSrc) := true,
altPublishSettings
) )
// Implements the core functionality of detecting and propagating changes incrementally. // Implements the core functionality of detecting and propagating changes incrementally.
@ -437,6 +464,11 @@ lazy val mavenResolverPluginProj = (project in file("sbt-maven-resolver")).
def scriptedTask: Def.Initialize[InputTask[Unit]] = Def.inputTask { def scriptedTask: Def.Initialize[InputTask[Unit]] = Def.inputTask {
val result = scriptedSource(dir => (s: State) => scriptedParser(dir)).parsed val result = scriptedSource(dir => (s: State) => scriptedParser(dir)).parsed
publishAll.value publishAll.value
// These two projects need to be visible in a repo even if the default
// local repository is hidden, so we publish them to an alternate location and add
// that alternate repo to the running scripted test (in Scripted.scriptedpreScripted).
(altLocalPublish in interfaceProj).value
(altLocalPublish in compileInterfaceProj).value
doScripted((sbtLaunchJar in bundledLauncherProj).value, (fullClasspath in scriptedSbtProj in Test).value, doScripted((sbtLaunchJar in bundledLauncherProj).value, (fullClasspath in scriptedSbtProj in Test).value,
(scalaInstance in scriptedSbtProj).value, scriptedSource.value, result, scriptedPrescripted.value) (scalaInstance in scriptedSbtProj).value, scriptedSource.value, result, scriptedPrescripted.value)
} }
@ -468,7 +500,7 @@ def rootSettings = fullDocSettings ++
Util.publishPomSettings ++ otherRootSettings ++ Formatting.sbtFilesSettings ++ Util.publishPomSettings ++ otherRootSettings ++ Formatting.sbtFilesSettings ++
Transform.conscriptSettings(bundledLauncherProj) Transform.conscriptSettings(bundledLauncherProj)
def otherRootSettings = Seq( def otherRootSettings = Seq(
Scripted.scriptedPrescripted := { _ => }, Scripted.scriptedPrescripted := { addSbtAlternateResolver _ },
Scripted.scripted <<= scriptedTask, Scripted.scripted <<= scriptedTask,
Scripted.scriptedUnpublished <<= scriptedUnpublishedTask, Scripted.scriptedUnpublished <<= scriptedUnpublishedTask,
Scripted.scriptedSource := (sourceDirectory in sbtProj).value / "sbt-test", Scripted.scriptedSource := (sourceDirectory in sbtProj).value / "sbt-test",
@ -485,8 +517,28 @@ def otherRootSettings = Seq(
IO.write(inj, "addMavenResolverPlugin") IO.write(inj, "addMavenResolverPlugin")
// sLog.value.info(s"""Injected project/maven.sbt to $f""") // sLog.value.info(s"""Injected project/maven.sbt to $f""")
} }
addSbtAlternateResolver(f)
} }
)) ))
def addSbtAlternateResolver(scriptedRoot: File) = {
val resolver = scriptedRoot / "project" / "AddResolverPlugin.scala"
if (!resolver.exists) {
IO.write(resolver, s"""import sbt._
|import Keys._
|
|object AddResolverPlugin extends AutoPlugin {
| override def requires = sbt.plugins.JvmPlugin
| override def trigger = allRequirements
|
| override lazy val projectSettings = Seq(resolvers += alternativeLocalResolver)
| lazy val alternativeLocalResolver = Resolver.file("$altLocalRepoName", file("$altLocalRepoPath"))(Resolver.ivyStylePatterns)
|}
|""".stripMargin)
}
}
lazy val docProjects: ScopeFilter = ScopeFilter( lazy val docProjects: ScopeFilter = ScopeFilter(
inAnyProject -- inProjects(sbtRoot, sbtProj, scriptedBaseProj, scriptedSbtProj, scriptedPluginProj, mavenResolverPluginProj), inAnyProject -- inProjects(sbtRoot, sbtProj, scriptedBaseProj, scriptedSbtProj, scriptedPluginProj, mavenResolverPluginProj),
inConfigurations(Compile) inConfigurations(Compile)

View File

@ -4,8 +4,7 @@ def commonSettings: Seq[Def.Setting[_]] =
dependencyCacheDirectory := (baseDirectory in LocalRootProject).value / "dependency", dependencyCacheDirectory := (baseDirectory in LocalRootProject).value / "dependency",
scalaVersion := "2.10.4", scalaVersion := "2.10.4",
organization in ThisBuild := "org.example", organization in ThisBuild := "org.example",
version in ThisBuild := "1.0-SNAPSHOT", version in ThisBuild := "1.0-SNAPSHOT"
resolvers += Resolver.file("old-local", file(sys.props("user.home") + "/.ivy2/local"))(Resolver.ivyStylePatterns)
) )
lazy val main = project. lazy val main = project.