aboutsummaryrefslogtreecommitdiff
path: root/stage2
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-03-20 22:09:38 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2017-03-27 19:56:13 -0400
commitbba2abe7ee38b8903822a07578c46466923d13ed (patch)
treea357fb8def6f58a9ea9a37411f3f5640dcb525fe /stage2
parentd2f8cade709b7d55a93e18592b6e38247d648ca9 (diff)
downloadcbt-bba2abe7ee38b8903822a07578c46466923d13ed.tar.gz
cbt-bba2abe7ee38b8903822a07578c46466923d13ed.tar.bz2
cbt-bba2abe7ee38b8903822a07578c46466923d13ed.zip
start modularizing cbt into libraries
this extracts certain parts of cbt into stand-alone libraries, which can be published to maven and used outside of cbt. This also adds scalariform for these parts of the code. This slows down cbt’s own build a lot because of the number of projects involved! So we’ll follow this by a bunch of performance tweak commits.
Diffstat (limited to 'stage2')
-rw-r--r--stage2/BasicBuild.scala11
-rw-r--r--stage2/BuildBuild.scala18
-rw-r--r--stage2/DirectoryDependency.scala2
-rw-r--r--stage2/Lib.scala58
-rw-r--r--stage2/libraries.scala12
-rw-r--r--stage2/plugins.scala17
-rw-r--r--stage2/plugins/Dotty.scala6
7 files changed, 39 insertions, 85 deletions
diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala
index 4158040..ebb6a40 100644
--- a/stage2/BasicBuild.scala
+++ b/stage2/BasicBuild.scala
@@ -13,12 +13,7 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with SbtDep
def moduleKey: String = "BaseBuild("+target.string+")"
implicit def transientCache: java.util.Map[AnyRef,AnyRef] = context.transientCache
- object libraries{
- private def dep(name: String) = DirectoryDependency( context.cbtHome / "libraries" / name )
- def captureArgs = dep( "capture_args" )
- def eval = dep( "eval" )
- def proguard = dep( "proguard" )
- }
+ implicit def libraries(implicit context: Context): libraries = new libraries(context)
// library available to builds
implicit protected final val logger: Logger = context.logger
@@ -211,7 +206,8 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with SbtDep
)
}
- def run: ExitCode = run( context.args: _* )
+ def run: ExitCode = runMain( context.args )
+
def test: Dependency = {
val testDirectory = projectDirectory / "test"
if( (testDirectory / lib.buildDirectoryName / lib.buildFileName).exists ){
@@ -225,6 +221,7 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with SbtDep
}
}
}
+
def t: Any = lib.callReflective( test, Some("run"), context )
def rt = recursiveUnsafe(Some("test.run"))
diff --git a/stage2/BuildBuild.scala b/stage2/BuildBuild.scala
index 17ccb36..cc69905 100644
--- a/stage2/BuildBuild.scala
+++ b/stage2/BuildBuild.scala
@@ -3,22 +3,6 @@ import java.nio.file._
import java.io.File
class ConcreteBuildBuild(val context: Context) extends BuildBuild
-class plugins(implicit context: Context){
- // TODO: move this out of the OO
- private def plugin(dir: String) = cbt.DirectoryDependency(context.cbtHome / "plugins" / dir)
- final lazy val googleJavaFormat = plugin( "google-java-format" )
- final lazy val proguard = plugin( "proguard" )
- final lazy val sbtLayout = plugin( "sbt_layout" )
- final lazy val scalafmt = plugin( "scalafmt" )
- final lazy val scalaJs = plugin( "scalajs" )
- final lazy val scalapb = plugin( "scalapb" )
- final lazy val scalariform = plugin( "scalariform" )
- final lazy val scalaTest = plugin( "scalatest" )
- final lazy val sonatypeRelease = plugin( "sonatype-release" )
- final lazy val uberJar = plugin( "uber-jar" )
- final lazy val wartremover = plugin( "wartremover" )
- final lazy val scalafix = plugin( "scalafix" )
-}
trait BuildBuild extends BaseBuild{
override def dependencies = super.dependencies :+ context.cbtDependency
@@ -31,7 +15,7 @@ trait BuildBuild extends BaseBuild{
)
}
-trait CbtInternal extends BuildBuild{
+trait CbtInternal extends BaseBuild{
protected object cbtInternal{
def shared = DirectoryDependency(context.cbtHome / "/internal/plugins/shared")
def library = DirectoryDependency(context.cbtHome / "/internal/plugins/library")
diff --git a/stage2/DirectoryDependency.scala b/stage2/DirectoryDependency.scala
index cfc0bfd..9b07702 100644
--- a/stage2/DirectoryDependency.scala
+++ b/stage2/DirectoryDependency.scala
@@ -96,7 +96,7 @@ object DirectoryDependency {
)
} else {
val buildClass = buildClasses.head
- buildClass.getConstructors.find( _.getParameterTypes.toList === List( classOf[Context] ) ).map {
+ buildClass.constructors.find( _.parameterTypes.toList === List( classOf[Context] ) ).map {
_.newInstance( managedContext ).asInstanceOf[AnyRef]
}.getOrElse {
throw new Exception(
diff --git a/stage2/Lib.scala b/stage2/Lib.scala
index fd3346e..6488c1a 100644
--- a/stage2/Lib.scala
+++ b/stage2/Lib.scala
@@ -64,10 +64,8 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){
c =>
c
.getMethods
- .filter{ m =>
- java.lang.reflect.Modifier.isPublic(m.getModifiers)
- }
- .filter( _.getParameterTypes.length == 0 )
+ .filter( _.isPublic )
+ .filter( _.parameterTypes.length == 0 )
.map(m => NameTransformer.decode(m.getName) -> m)
.filterNot(_._1 contains "$")
).toMap
@@ -262,34 +260,6 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){
m
}
- def autoRelative( files: Seq[File], collector: PartialFunction[(File,String), String] = { case (_,r) => r }): Seq[(File, String)] = {
- val map = files.sorted.flatMap{ base =>
- val b = base.getCanonicalFile.string
- if( base.isDirectory ){
- base.listRecursive.map{ f =>
- f -> f.getCanonicalFile.string.stripPrefix(b).stripPrefix(File.separator)
- }
- } else {
- Seq( base -> base.getName )
- }
- }.collect{
- case v@(file, _) if collector.isDefinedAt(v) => file -> collector(v)
- }
- val relatives = map.unzip._2
- val duplicateFiles = (relatives diff relatives.distinct).distinct
- assert(
- duplicateFiles.isEmpty,
- {
- val rs = relatives.toSet
- "Conflicting:\n\n" +
- map.filter(rs contains _._2).groupBy(_._2).mapValues(_.map(_._1).sorted).toSeq.sortBy(_._1).map{
- case (name, files) => s"$name:\n" ++ files.mkString("\n")
- }.mkString("\n\n")
- }
- )
- map
- }
-
def createJar( jarFile: File, files: Seq[File], mainClass: Option[String] = None ): Option[File] = {
deleteIfExists(jarFile.toPath)
if( files.isEmpty ){
@@ -474,29 +444,5 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){
) findOuterMostModuleDirectory(directory.getParentFile) else directory
}
- def transformFiles( files: Seq[File], transform: String => String ): Seq[File] = {
- transformFilesOrError( files, s => Right(transform(s)) )._1
- }
-
- def transformFilesOrError[T]( files: Seq[File], transform: String => Either[T,String] ): ( Seq[File], Seq[(File, T)] ) = {
- val results = files.map{ file =>
- val string = file.readAsString
- transform( string ).left.map(
- file -> _
- ).right.map(
- replaced =>
- if( string != replaced ) {
- val tmpFile = file ++ ".cbt-tmp"
- assert( !tmpFile.exists )
- write( tmpFile, replaced )
- move( tmpFile.toPath, file.toPath, StandardCopyOption.REPLACE_EXISTING )
- Some( file )
- } else None
- )
- }
-
- ( results.map(_.right.toOption).flatten.flatten, results.map(_.left.toOption).flatten )
- }
-
def clearScreen = System.err.println( (27.toChar +: "[2J").mkString )
}
diff --git a/stage2/libraries.scala b/stage2/libraries.scala
new file mode 100644
index 0000000..3d2951c
--- /dev/null
+++ b/stage2/libraries.scala
@@ -0,0 +1,12 @@
+package cbt
+class libraries( context: Context ) {
+ private def dep( name: String ) = DirectoryDependency( context.cbtHome / "libraries" / name )( context )
+ def captureArgs = dep( "capture_args" )
+ def eval = dep( "eval" )
+ def file = dep( "file" )
+ def proguard = dep( "proguard" )
+ def reflect = dep( "reflect" )
+ def common_0 = dep( "common-0" )
+ def common_1 = dep( "common-1" )
+ def interfaces = dep( "interfaces" )
+}
diff --git a/stage2/plugins.scala b/stage2/plugins.scala
new file mode 100644
index 0000000..eca28f0
--- /dev/null
+++ b/stage2/plugins.scala
@@ -0,0 +1,17 @@
+package cbt
+class plugins( implicit context: Context ) {
+ // TODO: move this out of the OO
+ private def plugin( dir: String ) = DirectoryDependency( context.cbtHome / "plugins" / dir )
+ final lazy val googleJavaFormat = plugin( "google-java-format" )
+ final lazy val proguard = plugin( "proguard" )
+ final lazy val sbtLayout = plugin( "sbt_layout" )
+ final lazy val scalafix = plugin( "scalafix" )
+ final lazy val scalafmt = plugin( "scalafmt" )
+ final lazy val scalaJs = plugin( "scalajs" )
+ final lazy val scalapb = plugin( "scalapb" )
+ final lazy val scalariform = plugin( "scalariform" )
+ final lazy val scalaTest = plugin( "scalatest" )
+ final lazy val sonatypeRelease = plugin( "sonatype-release" )
+ final lazy val uberJar = plugin( "uber-jar" )
+ final lazy val wartremover = plugin( "wartremover" )
+}
diff --git a/stage2/plugins/Dotty.scala b/stage2/plugins/Dotty.scala
index 0bbaf44..766e9d1 100644
--- a/stage2/plugins/Dotty.scala
+++ b/stage2/plugins/Dotty.scala
@@ -107,11 +107,9 @@ class DottyLib(
) ++ compileArgs ++ sourceFiles.map(_.toString)
logger.lib("creating docs for source files "+args.mkString(", "))
val exitCode = redirectOutToErr{
- runMain(
+ dottyCompiler.runMain(
"dotty.tools.dottydoc.DocDriver",
- args,
- dottyCompiler.classLoader,
- fakeInstance = true // this is a hack as Dottydoc's main method is not static
+ args
)
}
System.err.println("done")