diff --git a/.gitignore b/.gitignore index e762de7f9..03aec7c81 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ target/ __pycache__ +.idea diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 382acbfbe..09f0cc749 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -362,7 +362,8 @@ object Defaults extends BuildCommon { private[this] lazy val configGlobal = globalDefaults(Seq( initialCommands :== "", - cleanupCommands :== "" + cleanupCommands :== "", + asciiGraphWidth :== 40 )) lazy val projectTasks: Seq[Setting[_]] = Seq( diff --git a/main/src/main/scala/sbt/Keys.scala b/main/src/main/scala/sbt/Keys.scala index fcf980d93..6fa80a7f8 100644 --- a/main/src/main/scala/sbt/Keys.scala +++ b/main/src/main/scala/sbt/Keys.scala @@ -179,6 +179,7 @@ object Keys { val compileOrder = SettingKey[CompileOrder]("compile-order", "Configures the order in which Java and sources within a single compilation are compiled. Valid values are: JavaThenScala, ScalaThenJava, or Mixed.", BPlusSetting) val initialCommands = SettingKey[String]("initial-commands", "Initial commands to execute when starting up the Scala interpreter.", AMinusSetting) val cleanupCommands = SettingKey[String]("cleanup-commands", "Commands to execute before the Scala interpreter exits.", BMinusSetting) + val asciiGraphWidth = SettingKey[Int]("asciiGraphWidth", "Determines maximum width of the settings graph in ASCII mode", AMinusSetting) val compileOptions = TaskKey[CompileOptions]("compile-options", "Collects basic options to configure compilers", DTask) val compileInputs = TaskKey[Inputs]("compile-inputs", "Collects all inputs needed for compilation.", DTask) val scalaHome = SettingKey[Option[File]]("scala-home", "If Some, defines the local Scala installation to use for compilation, running, and testing.", ASetting) diff --git a/main/src/main/scala/sbt/Project.scala b/main/src/main/scala/sbt/Project.scala index d1f54a525..76323ae27 100755 --- a/main/src/main/scala/sbt/Project.scala +++ b/main/src/main/scala/sbt/Project.scala @@ -534,8 +534,8 @@ object Project extends ProjectExtra { printScopes("Delegates", delegates(structure, scope, key)) + printScopes("Related", related, 10) } - def settingGraph(structure: BuildStructure, basedir: File, scoped: ScopedKey[_])(implicit display: Show[ScopedKey[_]]): SettingGraph = - SettingGraph(structure, basedir, scoped, 0) + def settingGraph(structure: BuildStructure, basedir: File, scoped: ScopedKey[_], maxGraphWidth: Int)(implicit display: Show[ScopedKey[_]]): SettingGraph = + SettingGraph(structure, basedir, scoped, 0, maxGraphWidth) def graphSettings(structure: BuildStructure, basedir: File)(implicit display: Show[ScopedKey[_]]): Unit = { def graph(actual: Boolean, name: String) = graphSettings(structure, actual, name, new File(basedir, name + ".dot")) graph(true, "actual_dependencies") diff --git a/main/src/main/scala/sbt/internal/Inspect.scala b/main/src/main/scala/sbt/internal/Inspect.scala index 0d1e9ff6a..98d3759b3 100644 --- a/main/src/main/scala/sbt/internal/Inspect.scala +++ b/main/src/main/scala/sbt/internal/Inspect.scala @@ -47,7 +47,7 @@ object Inspect { Project.details(structure, actual, sk.scope, sk.key) case DependencyTreeMode => val basedir = new File(Project.session(s).current.build) - Project.settingGraph(structure, basedir, sk).dependsAscii + Project.settingGraph(structure, basedir, sk, get(sbt.Keys.asciiGraphWidth)).dependsAscii case UsesMode => Project.showUses(Project.usedBy(structure, true, sk.key)) case DefinitionsMode => diff --git a/main/src/main/scala/sbt/internal/SettingGraph.scala b/main/src/main/scala/sbt/internal/SettingGraph.scala index ec2b62df6..de12baea6 100644 --- a/main/src/main/scala/sbt/internal/SettingGraph.scala +++ b/main/src/main/scala/sbt/internal/SettingGraph.scala @@ -13,7 +13,7 @@ import Predef.{ any2stringadd => _, _ } import sbt.io.IO object SettingGraph { - def apply(structure: BuildStructure, basedir: File, scoped: ScopedKey[_], generation: Int)(implicit display: Show[ScopedKey[_]]): SettingGraph = + def apply(structure: BuildStructure, basedir: File, scoped: ScopedKey[_], generation: Int, graphMaxWidth: Int)(implicit display: Show[ScopedKey[_]]): SettingGraph = { val cMap = flattenLocals(compiled(structure.settings, false)(structure.delegates, structure.scopeLocal, display)) def loop(scoped: ScopedKey[_], generation: Int): SettingGraph = @@ -28,7 +28,8 @@ object SettingGraph { SettingGraph(display(scoped), definedIn, Project.scopedKeyData(structure, scope, key), key.description, basedir, - depends map { (x: ScopedKey[_]) => loop(x, generation + 1) }) + depends map { (x: ScopedKey[_]) => loop(x, generation + 1) }, + graphMaxWidth) } loop(scoped, generation) } @@ -40,7 +41,8 @@ case class SettingGraph( data: Option[ScopedKeyData[_]], description: Option[String], basedir: File, - depends: Set[SettingGraph] + depends: Set[SettingGraph], + graphMaxWidth: Int ) { def dataString: String = data map { d => @@ -53,7 +55,8 @@ case class SettingGraph( def dependsAscii: String = Graph.toAscii( this, (x: SettingGraph) => x.depends.toSeq.sortBy(_.name), - (x: SettingGraph) => "%s = %s" format (x.definedIn getOrElse { "" }, x.dataString) + (x: SettingGraph) => "%s = %s" format (x.definedIn getOrElse { "" }, x.dataString), + graphMaxWidth ) } @@ -63,8 +66,7 @@ object Graph { // [info] | +-baz // [info] | // [info] +-quux - def toAscii[A](top: A, children: A => Seq[A], display: A => String): String = { - val defaultWidth = 40 + def toAscii[A](top: A, children: A => Seq[A], display: A => String, defaultWidth: Int): String = { // TODO: Fix JLine val maxColumn = math.max( /*JLine.usingTerminal(_.getWidth)*/ 0, defaultWidth) - 8 val twoSpaces = " " + " " // prevent accidentally being converted into a tab diff --git a/notes/1.0.0/ascii-graph-width.markdown b/notes/1.0.0/ascii-graph-width.markdown new file mode 100644 index 000000000..341577b3e --- /dev/null +++ b/notes/1.0.0/ascii-graph-width.markdown @@ -0,0 +1,9 @@ +[@RomanIakovlev]: https://github.com/RomanIakovlev + +### Fixes with compatibility implications + +### Improvements + +Add new global setting `asciiGraphWidth` that controls the maximum width of the ASCII graphs printed by commands like `inspect tree`. Default value corresponds to the previously hardcoded value of 40 characters. By [@RomanIakovlev][@RomanIakovlev]. + +### Bug fixes