mirror of https://github.com/sbt/sbt.git
Refactor Def.declareOutputDirectory to return vf
This commit is contained in:
parent
987ab5f214
commit
eb9a507419
|
|
@ -353,18 +353,6 @@ trait Cont:
|
|||
})($cacheConfigExpr)
|
||||
}
|
||||
|
||||
def toVirtualFileExpr(
|
||||
cacheConfigExpr: Expr[BuildWideCacheConfiguration]
|
||||
)(out: Output): Expr[VirtualFile] =
|
||||
if out.isFile then out.toRef.asExprOf[VirtualFile]
|
||||
else
|
||||
'{
|
||||
ActionCache.packageDirectory(
|
||||
dir = ${ out.toRef.asExprOf[VirtualFileRef] },
|
||||
conv = $cacheConfigExpr.fileConverter,
|
||||
)
|
||||
}
|
||||
|
||||
// This will generate following code for Def.declareOutput(...):
|
||||
// var $o1: VirtualFile = null
|
||||
// ActionCache.ActionResult({
|
||||
|
|
@ -382,7 +370,8 @@ trait Cont:
|
|||
ActionCache.InternalActionResult(
|
||||
value = $body,
|
||||
outputs = List(${
|
||||
Varargs[VirtualFile](outputs.map(toVirtualFileExpr(cacheConfigExpr)))
|
||||
Varargs[VirtualFile](outputs.map: out =>
|
||||
out.toRef.asExprOf[VirtualFile])
|
||||
}: _*),
|
||||
)
|
||||
}.asTerm
|
||||
|
|
@ -397,19 +386,38 @@ trait Cont:
|
|||
given t: Type[a] = tpe
|
||||
convert[a](name, qual) transform { (replacement: Term) =>
|
||||
name match
|
||||
case WrapOutputName | WrapOutputDirectoryName =>
|
||||
case WrapOutputName =>
|
||||
val output = Output(
|
||||
tpe = TypeRepr.of[a],
|
||||
term = qual,
|
||||
name = freshName("o"),
|
||||
parent = Symbol.spliceOwner,
|
||||
outputType = name match
|
||||
case WrapOutputName => OutputType.File
|
||||
case WrapOutputDirectoryName => OutputType.Directory,
|
||||
outputType = OutputType.File
|
||||
)
|
||||
outputBuf += output
|
||||
if cacheConfigExprOpt.isDefined then output.toAssign
|
||||
if cacheConfigExprOpt.isDefined then output.toAssign(output.term)
|
||||
else oldTree
|
||||
case WrapOutputDirectoryName =>
|
||||
val output = Output(
|
||||
// even though the term is VirtualFileRef, we want the output to make VirtualFile,
|
||||
// which contains hash.
|
||||
tpe = TypeRepr.of[VirtualFile],
|
||||
term = qual,
|
||||
name = freshName("o"),
|
||||
parent = Symbol.spliceOwner,
|
||||
outputType = OutputType.Directory,
|
||||
)
|
||||
outputBuf += output
|
||||
cacheConfigExprOpt match
|
||||
case Some(cacheConfigExpr) =>
|
||||
output.toAssign('{
|
||||
ActionCache.packageDirectory(
|
||||
dir = ${ output.term.asExprOf[VirtualFileRef] },
|
||||
conv = $cacheConfigExpr.fileConverter,
|
||||
outputDirectory = $cacheConfigExpr.outputDirectory,
|
||||
)
|
||||
}.asTerm)
|
||||
case None => oldTree
|
||||
case _ =>
|
||||
// todo cache opt-out attribute
|
||||
inputBuf += Input(TypeRepr.of[a], qual, replacement, freshName("q"))
|
||||
|
|
|
|||
|
|
@ -106,7 +106,9 @@ trait ContextUtil[C <: Quotes & scala.Singleton](val valStart: Int):
|
|||
case Directory
|
||||
|
||||
/**
|
||||
* Represents an output expression via Def.declareOutput
|
||||
* Represents an output expression via:
|
||||
* 1. Def.declareOutput(VirtualFile)
|
||||
* 2. Def.declareOutputDirectory(VirtualFileRef)
|
||||
*/
|
||||
final class Output(
|
||||
val tpe: TypeRepr,
|
||||
|
|
@ -129,7 +131,11 @@ trait ContextUtil[C <: Quotes & scala.Singleton](val valStart: Int):
|
|||
)
|
||||
def toVarDef: ValDef =
|
||||
ValDef(placeholder, rhs = Some('{ null }.asTerm))
|
||||
def toAssign: Term = Assign(toRef, term)
|
||||
def toAssign(value: Term): Term =
|
||||
Block(
|
||||
Assign(toRef, value) :: Nil,
|
||||
toRef
|
||||
)
|
||||
def toRef: Ref = Ref(placeholder)
|
||||
def isFile: Boolean = outputType == OutputType.File
|
||||
end Output
|
||||
|
|
|
|||
|
|
@ -326,11 +326,11 @@ object Def extends Init[Scope] with TaskMacroExtra with InitializeImplicits:
|
|||
*/
|
||||
def promise[A]: PromiseWrap[A] = new PromiseWrap[A]()
|
||||
|
||||
inline def declareOutput(inline vf: VirtualFile): Unit =
|
||||
inline def declareOutput(inline vf: VirtualFile): VirtualFile =
|
||||
InputWrapper.`wrapOutput_\u2603\u2603`[VirtualFile](vf)
|
||||
|
||||
inline def declareOutputDirectory(inline vf: VirtualFileRef): Unit =
|
||||
InputWrapper.`wrapOutputDirectory_\u2603\u2603`[VirtualFileRef](vf)
|
||||
inline def declareOutputDirectory(inline vf: VirtualFileRef): VirtualFile =
|
||||
InputWrapper.`wrapOutputDirectory_\u2603\u2603`[VirtualFile](vf)
|
||||
|
||||
// The following conversions enable the types Initialize[T], Initialize[Task[T]], and Task[T] to
|
||||
// be used in task and setting macros as inputs with an ultimate result of type T
|
||||
|
|
|
|||
Loading…
Reference in New Issue