Skip to content

Commit d530837

Browse files
committed
add excludescript
1 parent 7c54c0a commit d530837

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

modules/build/src/main/scala/scala/build/Project.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ final case class Project(
6363
Nil
6464
)
6565

66-
println(s"This is script path ${command0}")
6766
BloopConfig.SourceGenerator(
6867
List(sourceGlobs0),
6968
(config.outputPath / "source-generator-output").toNIO,
70-
List("/Users/kiki/Kerja/scala-cli/testing-a/scala-cli", "--power", "run", command0)
69+
List("/Users/kiki/Kerja/scala-cli/testing-a/scala-cli", "run", command0, "--power", "--")
7170
)
7271
}.toList
7372
)

modules/directives/src/main/scala/scala/build/directives/DirectiveSpecialSyntax.scala

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ object DirectiveSpecialSyntax {
2121
val pattern = """(((?:\$)+)(\{\.\}))""".r
2222
path match {
2323
case Right(p) =>
24-
println(p)
2524
pattern.replaceAllIn(
2625
directiveValue,
2726
(m: Regex.Match) => {

modules/directives/src/main/scala/scala/build/preprocessing/directives/SourceGenerator.scala

+36-23
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import scala.build.options.{BuildOptions, SourceGeneratorOptions, GeneratorConfi
2121
import scala.build.options.GeneratorConfig
2222
import scala.build.{Positioned, options}
2323
import scala.build.directives.DirectiveValueParser.WithScopePath
24+
import scala.util.matching.Regex
25+
import java.nio.file.Paths
26+
import scala.build.options.InternalOptions
2427

2528
@DirectiveGroupName("SourceGenerator")
2629
@DirectivePrefix("sourceGenerator.")
@@ -35,19 +38,17 @@ final case class SourceGenerator(
3538
excludeScripts: Option[Boolean] = None,
3639
inputDirectory: DirectiveValueParser.WithScopePath[Option[Positioned[String]]] =
3740
DirectiveValueParser.WithScopePath.empty(None),
38-
glob: Option[Positioned[String]] = None,
41+
glob: Option[Positioned[String]] = None
3942
) extends HasBuildOptions {
4043
def buildOptions: Either[BuildException, BuildOptions] =
41-
// println(s"ScopePath of Scripts: ${scripts.scopePath}")
42-
// println(s"Values of Scripts: ${scripts.value(0).value}")
43-
// println(s"Values of InputDir: ${inputDirectory.value}")
44-
SourceGenerator.buildOptions(scripts)
44+
SourceGenerator.buildOptions(scripts, excludeScripts)
4545
}
4646

4747
object SourceGenerator {
4848
val handler: DirectiveHandler[SourceGenerator] = DirectiveHandler.derive
4949
def buildOptions(
50-
scripts: DirectiveValueParser.WithScopePath[List[Positioned[String]]]
50+
scripts: DirectiveValueParser.WithScopePath[List[Positioned[String]]],
51+
excludeScripts: Option[Boolean]
5152
): Either[BuildException, BuildOptions] = {
5253
val proc = UsingDirectivesProcessor()
5354
val scriptConvert = scripts.value
@@ -57,9 +58,12 @@ object SourceGenerator {
5758
.map(proc.extract(_).asScala)
5859
.map(_.headOption)
5960

60-
// println(scriptConvert.size)
61+
val scriptsValue = scripts.value
62+
.map(script =>
63+
os.Path(script.value)
64+
)
6165

62-
def modify(script: Option[UsingDirectives]) = {
66+
def modify(script: Option[UsingDirectives]) =
6367
script.toSeq.flatMap { directives =>
6468
def toStrictValue(value: UsingValue): Seq[Value[_]] = value match {
6569
case uvs: UsingValues => uvs.values.asScala.toSeq.flatMap(toStrictValue)
@@ -79,6 +83,20 @@ object SourceGenerator {
7983
case uds: UsingDefs => uds.getUsingDefs.asScala.toSeq.map(toStrictDirective)
8084
case _ => Nil // There should be nothing else here other than UsingDefs
8185
}
86+
87+
def replaceSpecialSyntax(directiveValue: String, path: os.Path): String = {
88+
val pattern = """(((?:\$)+)(\{\.\}))""".r
89+
pattern.replaceAllIn(
90+
directiveValue,
91+
(m: Regex.Match) => {
92+
val dollarSigns = m.group(2)
93+
val dollars = "\\$" * (dollarSigns.length / 2)
94+
if (dollarSigns.length % 2 == 0)
95+
s"$dollars${m.group(3)}"
96+
else
97+
s"$dollars${path / os.up}"
98+
}
99+
)
82100
}
83101

84102
val componentKeyword = Seq("inputDirectory", "glob")
@@ -90,31 +108,26 @@ object SourceGenerator {
90108
)
91109
)
92110

93-
// generatorComponents.map(f => f.map(g => println(g.values)))
111+
val pathModifier = scriptsValue.iterator
94112
val directive = generatorComponents.collect {
95113
case Seq(inputDir, glob) =>
114+
val relPath = pathModifier.next()
96115
GeneratorConfig(
97-
inputDir.values.mkString,
116+
replaceSpecialSyntax(inputDir.values.mkString, relPath),
98117
List(glob.values.mkString),
99118
scripts.value(0).value,
100119
scripts.scopePath.subPath
101120
)
102121
}
103122

104-
// val sourceGenValue = sourceGenerator.value
105-
// sourceGenValue
106-
// .map(config => GeneratorConfig.parse(config, sourceGenerator.scopePath.subPath))
107-
// .sequence
108-
// .left.map(CompositeBuildException(_))
109-
// .map { configs =>
110-
// BuildOptions(sourceGeneratorOptions =
111-
// SourceGeneratorOptions(generatorConfig = configs)
112-
// )
113-
// }
114-
// directive.map { f => println(f)}
123+
val excludedGeneratorPath = excludeScripts.match {
124+
case Some(true) => scripts.value
125+
case _ => List.empty[Positioned[String]]
126+
}
115127

116-
Right(BuildOptions(sourceGeneratorOptions =
117-
SourceGeneratorOptions(generatorConfig = directive)
128+
Right(BuildOptions(
129+
sourceGeneratorOptions = SourceGeneratorOptions(generatorConfig = directive),
130+
internal = InternalOptions(exclude = excludedGeneratorPath)
118131
))
119132
}
120133
}

0 commit comments

Comments
 (0)