Skip to content

Commit

Permalink
Replace OutputSetting by OutputGroup
Browse files Browse the repository at this point in the history
`OutputSetting` is like `OutputGroup` by just returns strings instead of
files. I see no reason why `OutputGroup` should not be used instead,
therefore simplifying the Zinc API and allowing users to have access to
files and not mere strings. If they want strings, they always can do
`getAbsolutePath`.

N.B. This is good for machine independence.
  • Loading branch information
jvican committed May 21, 2017
1 parent df4d222 commit 1f2d12c
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ sealed abstract class CallbackGlobal(settings: Settings,

lazy val outputDirs: Iterable[File] = {
output match {
case single: SingleOutput => List(single.outputDirectory)
case single: SingleOutput => List(single.outputDirectory)
// Use Stream instead of List because Analyzer maps intensively over the directories
case multi: MultipleOutput => multi.outputGroups.toStream map (_.outputDirectory)
}
}
Expand Down
12 changes: 1 addition & 11 deletions internal/compiler-interface/src/main/contraband/other.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,14 @@
{ "name": "hash", "type": "int" }
]
},
{
"name": "OutputSetting",
"namespace": "xsbti.api",
"target": "Java",
"type": "record",
"fields": [
{ "name": "sourceDirectory", "type": "String" },
{ "name": "outputDirectory", "type": "String" }
]
},
{
"name": "Compilation",
"namespace": "xsbti.api",
"target": "Java",
"type": "record",
"fields": [
{ "name": "startTime", "type": "long" },
{ "name": "outputs", "type": "OutputSetting*" }
{ "name": "outputs", "type": "xsbti.compile.OutputGroup*" }
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,6 @@

/** Define the interface for several kind of output directories. */
public interface MultipleOutput extends Output {

/** Define the interface of a group of outputs. */
interface OutputGroup {
/**
* Return the directory where source files are stored for this group.
*
* Note that source directories should uniquely identify the group
* for a certain source file.
*/
File sourceDirectory();

/**
* Return the directory where class files should be generated.
*
* Incremental compilation manages the class files in this directory, so
* don't play with this directory out of the Zinc API. Zinc already takes
* care of deleting classes before every compilation run.
*
* This directory must be exclusively used for one set of sources.
*/
File outputDirectory();
}

/** Return an array of the existent output groups. */
OutputGroup[] outputGroups();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package xsbti.compile;

import java.io.File;

/** Define the interface of a group of outputs. */
public interface OutputGroup {
/**
* Return the directory where source files are stored for this group.
*
* Note that source directories should uniquely identify the group
* for a certain source file.
*/
public File sourceDirectory();

/**
* Return the directory where class files should be generated.
*
* Incremental compilation manages the class files in this directory, so
* don't play with this directory out of the Zinc API. Zinc already takes
* care of deleting classes before every compilation run.
*
* This directory must be exclusively used for one set of sources.
*/
public File outputDirectory();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package sbt
package internal
package inc

import xsbti.compile.{ Output, SingleOutput, MultipleOutput }
import xsbti.compile.{ MultipleOutput, Output, OutputGroup, SingleOutput }
import java.io.File

/**
Expand Down Expand Up @@ -39,7 +39,7 @@ object CompileOutput {
def apply(groups: (File, File)*): Output = new MultipleOutput {
def outputGroups = groups.toArray map {
case (src, out) =>
new MultipleOutput.OutputGroup {
new OutputGroup {
def sourceDirectory = src
def outputDirectory = out
override def toString = s"OutputGroup($src -> $out)"
Expand Down
15 changes: 8 additions & 7 deletions internal/zinc-core/src/main/scala/sbt/internal/inc/Compile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import sbt.internal.inc.Analysis.{ LocalProduct, NonLocalProduct }
import xsbt.api.{ APIUtil, HashAPI, NameHashing }
import xsbti.api._
import xsbti.compile.{
ClassFileManager,
CompileAnalysis,
DependencyChanges,
IncOptions,
MultipleOutput,
Output,
OutputGroup,
SingleOutput
}
import xsbti.{ Position, Problem, Severity, UseScope }
Expand All @@ -27,7 +29,6 @@ import java.io.File
import java.util

import xsbti.api.DependencyContext
import xsbti.compile.ClassFileManager
import xsbti.compile.analysis.ReadStamps

/**
Expand Down Expand Up @@ -133,14 +134,14 @@ private final class AnalysisCallback(
private[this] val compilation: Compilation = {
val outputSettings = output match {
case single: SingleOutput =>
Array(new OutputSetting("/", single.outputDirectory.getAbsolutePath))
// TODO: Why are we using the root as the file with all the sources? Smell.
val rootFile = new java.io.File("/")
List(new SimpleOutputGroup(rootFile, single.outputDirectory))
case multi: MultipleOutput =>
multi.outputGroups.map(
out =>
new OutputSetting(out.sourceDirectory.getAbsolutePath,
out.outputDirectory.getAbsolutePath))
multi.outputGroups.toList.map(out =>
new SimpleOutputGroup(out.sourceDirectory, out.outputDirectory))
}
new Compilation(System.currentTimeMillis, outputSettings)
new Compilation(System.currentTimeMillis, outputSettings.toArray)
}

override def toString =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import java.io.File

import xsbti.T2
import xsbti.compile.{
MiniSetup,
CompileOrder,
Output => APIOutput,
SingleOutput,
MiniOptions,
MiniSetup,
MultipleOutput,
MiniOptions
OutputGroup,
SingleOutput,
Output => APIOutput
}

/**
Expand Down Expand Up @@ -87,7 +88,7 @@ object MiniSetupUtil {
implicit val equivOutput: Equiv[APIOutput] = {
new Equiv[APIOutput] {
implicit val outputGroupsOrdering =
Ordering.by((og: MultipleOutput.OutputGroup) => og.sourceDirectory)
Ordering.by((og: OutputGroup) => og.sourceDirectory)

def equiv(out1: APIOutput, out2: APIOutput) = (out1, out2) match {
case (m1: MultipleOutput, m2: MultipleOutput) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package sbt.internal.inc

import java.io.File

import xsbti.compile.OutputGroup

case class SimpleOutputGroup(sourceDirectory: File, outputDirectory: File) extends OutputGroup
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ class TextAnalysisFormat(override val mappers: AnalysisMappers)
}
case `multipleOutputMode` =>
new MultipleOutput {
val outputGroups: Array[MultipleOutput.OutputGroup] = outputAsMap.toArray.map {
val outputGroups: Array[OutputGroup] = outputAsMap.toArray.map {
case (src: File, out: File) =>
new MultipleOutput.OutputGroup {
new OutputGroup {
val sourceDirectory = src
val outputDirectory = out
override def toString = s"OutputGroup($src -> $out)"
Expand Down

0 comments on commit 1f2d12c

Please sign in to comment.