Skip to content

Commit

Permalink
working wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Perklone committed Aug 6, 2024
1 parent 281d6b4 commit 7c54c0a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 32 deletions.
3 changes: 2 additions & 1 deletion modules/build/src/main/scala/scala/build/Project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ final case class Project(
Nil
)

println(s"This is script path ${command0}")
BloopConfig.SourceGenerator(
List(sourceGlobs0),
(config.outputPath / "source-generator-output").toNIO,
command0
List("/Users/kiki/Kerja/scala-cli/testing-a/scala-cli", "--power", "run", command0)
)
}.toList
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ object DirectiveSpecialSyntax {
val pattern = """(((?:\$)+)(\{\.\}))""".r
path match {
case Right(p) =>
println(p)
pattern.replaceAllIn(
directiveValue,
(m: Regex.Match) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,17 @@ final case class SourceGenerator(
inputDirectory: DirectiveValueParser.WithScopePath[Option[Positioned[String]]] =
DirectiveValueParser.WithScopePath.empty(None),
glob: Option[Positioned[String]] = None,
commandProcessor: DirectiveValueParser.WithScopePath[Option[Positioned[String]]] =
DirectiveValueParser.WithScopePath.empty(None),
) extends HasBuildOptions {
def buildOptions: Either[BuildException, BuildOptions] =
// println(s"ScopePath of Scripts: ${scripts.scopePath}")
// println(s"Values of Scripts: ${scripts.value(0).value}")
// println(s"Values of InputDir: ${inputDirectory.value}")
SourceGenerator.buildOptions(testy,scripts)
SourceGenerator.buildOptions(scripts)
}

object SourceGenerator {
val handler: DirectiveHandler[SourceGenerator] = DirectiveHandler.derive
def buildOptions(
sourceGenerator: DirectiveValueParser.WithScopePath[List[Positioned[String]]],
scripts: DirectiveValueParser.WithScopePath[List[Positioned[String]]]
): Either[BuildException, BuildOptions] = {
val proc = UsingDirectivesProcessor()
Expand Down Expand Up @@ -84,18 +81,25 @@ object SourceGenerator {
}
}

val strictDirectives = scriptConvert
.map(modify(_))
.map(_.take(3))
val componentKeyword = Seq("inputDirectory", "glob")
val strictDirectives = scriptConvert.map(modify(_))

// println(scripts.scopePath.subPath)
// strictDirectives.map(f => f.map(w => println(w)))
val generatorComponents = strictDirectives.map(directiveSeq =>
directiveSeq.filter(rawDirective =>
componentKeyword.exists(keyword => rawDirective.key.contains(keyword))
)
)

val directive = strictDirectives.collect {
case Seq(inputDir, glob, processor) =>
GeneratorConfig(inputDir.values.mkString, List(glob.values.mkString), processor.values.mkString.split(" ").toList,scripts.scopePath.subPath)
// generatorComponents.map(f => f.map(g => println(g.values)))
val directive = generatorComponents.collect {
case Seq(inputDir, glob) =>
GeneratorConfig(
inputDir.values.mkString,
List(glob.values.mkString),
scripts.value(0).value,
scripts.scopePath.subPath
)
}
println(directive.size)

// val sourceGenValue = sourceGenerator.value
// sourceGenValue
Expand All @@ -107,9 +111,10 @@ object SourceGenerator {
// SourceGeneratorOptions(generatorConfig = configs)
// )
// }

// directive.map { f => println(f)}

Right(BuildOptions(sourceGeneratorOptions = SourceGeneratorOptions(generatorConfig = directive)))
Right(BuildOptions(sourceGeneratorOptions =
SourceGeneratorOptions(generatorConfig = directive)
))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ import scala.build.errors.{BuildException, MalformedInputError}
final case class GeneratorConfig(
inputDir: String,
glob: List[String],
commandFilePath: List[String],
commandFilePath: String,
outputPath: os.SubPath
)

object GeneratorConfig {

def parse(input: Positioned[String], output: os.SubPath): Either[BuildException, GeneratorConfig] =
input.value.split("\\|", 3) match {
case Array(inputDir, glob, commandFilePath) =>
val commandFileList = commandFilePath.split(" ").toList
Right(GeneratorConfig(inputDir, List(glob), commandFileList, output))
case _ =>
Left(
new MalformedInputError(
"sourceGenerator",
input.value,
"inputDir|glob|commandFilePath",
input.positions
)
)
}
// def parse(input: Positioned[String], output: os.SubPath): Either[BuildException, GeneratorConfig] =
// input.value.split("\\|", 3) match {
// case Array(inputDir, glob, commandFilePath) =>
// val commandFileList = commandFilePath.split(" ").toList
// Right(GeneratorConfig(inputDir, List(glob), commandFileList, output))
// case _ =>
// Left(
// new MalformedInputError(
// "sourceGenerator",
// input.value,
// "inputDir|glob|commandFilePath",
// input.positions
// )
// )
// }
}

0 comments on commit 7c54c0a

Please sign in to comment.