Skip to content

Commit

Permalink
Merge branch 'main' into glossary-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
reid-spencer committed Oct 21, 2023
2 parents a0a71fb + 8d68ff9 commit 089ab3a
Show file tree
Hide file tree
Showing 40 changed files with 534 additions and 338 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ object CommandOptions {
maxParallel <- optional(objCur, "max-parallel-parsing", Some(4)) { cc =>
cc.asInt.map(Option(_))
}
warnsAreFatal <- optional(objCur, "warnings-are-fatal", Option.empty[Boolean]) { cc =>
cc.asBoolean.map(Option(_))
}
yield {
val default = CommonOptions()
val shouldShowWarnings = suppressWarnings
Expand Down Expand Up @@ -196,7 +199,8 @@ object CommandOptions {
debug,
pluginsDir,
sortMessagesByLocation = sortMessages.getOrElse(false),
maxParallelParsing = maxParallel.getOrElse(4)
maxParallelParsing = maxParallel.getOrElse(4),
warningsAreFatal = warnsAreFatal.getOrElse(false)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ object CommandPlugin {
} else {
Messages.logMessages(passesResult.messages, log, commonOptions)
}
0
if commonOptions.warningsAreFatal && passesResult.messages.hasWarnings then 1
else 0
case Left(messages) =>
if commonOptions.quiet then { highestSeverity(messages) + 1 }
else { Messages.logMessages(messages, log, commonOptions) + 1 }
Expand All @@ -181,17 +182,18 @@ object CommandPlugin {
if commonOptions.quiet then StringLogger()
else SysLogger()

if remaining.isEmpty then {
if remaining.isEmpty then
log.error("No command argument was provided")
1
} else {
else
val name = remaining.head
if commonOptions.dryRun then log.info(s"Would have executed: ${remaining.mkString(" ")}")

val result = CommandPlugin
.runCommandWithArgs(name, remaining, log, commonOptions)
handleCommandResult(result, commonOptions, log)
}
if commonOptions.dryRun then
log.info(s"Would have executed: ${remaining.mkString(" ")}")
0
else
val result = CommandPlugin
.runCommandWithArgs(name, remaining, log, commonOptions)
handleCommandResult(result, commonOptions, log)
}

def runMain(args: Array[String], log: Logger = SysLogger()): Int = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ object CommonOptionsHelper {
.action((v,c) => c.copy(maxParallelParsing = v))
.text(
"Controls the maximum number of include files that will be parsed in parallel"
),
opt[Boolean]("warnings-are-fatal")
.optional()
.action((v,c) => c.copy(warningsAreFatal = true))
.text(
"Makes validation warnings fatal to encourage code perfection"
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,14 @@ abstract class PassCommand[OPT <: PassCommandOptions : ClassTag](name: String) e
case Right(root) =>
val input: PassInput = PassInput(root, commonOptions)
val passes = getPasses(log, commonOptions, options)
Pass(input, true, passes, log) match {
case Left(messages) => Left(messages)
case Right(result) =>
if commonOptions.debug then {
println("Errors after running validation:")
println(result.messages.format)
}
}
val output = PassesResult(input)
Right(output)
val result = Pass.runThesePasses(input, passes, log)
if result.messages.hasErrors then
Left(result.messages)
else
if commonOptions.debug then
println(s"Errors after running ${this.name}:")
println(result.messages.format)
Right(result)
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions hugo/src/main/scala/com/reactific/riddl/hugo/HugoCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ package com.reactific.riddl.hugo
import com.reactific.riddl.commands.CommandOptions.optional
import com.reactific.riddl.commands.{CommandOptions, PassCommand, TranslatingOptions}
import com.reactific.riddl.language.CommonOptions
import com.reactific.riddl.language.Messages
import com.reactific.riddl.language.Messages.Messages
import com.reactific.riddl.passes.Pass.{PassesCreator, standardPasses}
import com.reactific.riddl.passes.{PassInput, PassesResult}
import com.reactific.riddl.passes.{PassInput, PassesOutput, PassesResult}
import com.reactific.riddl.utils.Logger
import com.reactific.riddl.stats.StatsPass
import pureconfig.ConfigCursor
Expand Down Expand Up @@ -64,11 +65,11 @@ object HugoCommand {
options: Options
): PassesCreator = {
standardPasses ++ Seq(
{ (input: PassInput) => StatsPass(input) },
{ (input: PassInput) =>
val result = PassesResult(input)
{ (input: PassInput, outputs: PassesOutput) => StatsPass(input, outputs) },
{ (input: PassInput, outputs: PassesOutput) =>
val result = PassesResult(input, outputs, Messages.empty)
val state = HugoTranslatorState(result, options, commonOptions, log)
HugoPass(input, state)
HugoPass(input, outputs, state)
}
)
}
Expand Down
33 changes: 20 additions & 13 deletions hugo/src/main/scala/com/reactific/riddl/hugo/HugoPass.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package com.reactific.riddl.hugo
import com.reactific.riddl.language.*
import com.reactific.riddl.language.AST.{Include, *}
import com.reactific.riddl.language.Messages.Messages
import com.reactific.riddl.passes.{Pass, PassInfo, PassInput, PassOutput}
import com.reactific.riddl.passes.{Pass, PassInfo, PassInput, PassOutput, PassesOutput}
import com.reactific.riddl.passes.resolve.{ReferenceMap, ResolutionOutput, ResolutionPass}
import com.reactific.riddl.passes.symbols.SymbolsPass
import com.reactific.riddl.passes.validate.ValidationPass
Expand Down Expand Up @@ -37,31 +37,31 @@ case class HugoOutput(
state: HugoTranslatorState
) extends PassOutput

case class HugoPass(input: PassInput, state: HugoTranslatorState) extends Pass(input) {
@SuppressWarnings(Array("org.wartremover.warts.OptionPartial"))
case class HugoPass(input: PassInput, outputs: PassesOutput, state: HugoTranslatorState) extends Pass(input, outputs) {

requires(SymbolsPass)
requires(ResolutionPass)
requires(ValidationPass)
requires(StatsPass)

lazy val commonOptions: CommonOptions = state.commonOptions
lazy val options: HugoCommand.Options = state.options
lazy val refMap: ReferenceMap = input.outputOf[ResolutionOutput](ResolutionPass.name).refMap

require(options.outputRoot.getNameCount > 2, "Output path is too shallow")
require(
options.outputRoot.getFileName.toString.nonEmpty,
"Output path is empty"
)
if options.inputFile.nonEmpty then makeDirectoryStructure(options.inputFile, state.logger, options, commonOptions)

lazy val commonOptions: CommonOptions = state.commonOptions
lazy val options: HugoCommand.Options = state.options
lazy val refMap: ReferenceMap = outputs.outputOf[ResolutionOutput](ResolutionPass.name).get.refMap
val root: RootContainer = input.root
val name: String = HugoPass.name

if options.inputFile.nonEmpty then makeDirectoryStructure(options.inputFile, state.logger, options, commonOptions)

private val maybeAuthor = root.authors.headOption.orElse { root.domains.headOption.flatMap(_.authorDefs.headOption) }
writeConfigToml(options, maybeAuthor)

val name: String = HugoPass.name

override def process(definition: AST.Definition, parents: mutable.Stack[AST.Definition]): Unit = {
val stack = parents.toSeq
definition match {
Expand Down Expand Up @@ -143,10 +143,17 @@ case class HugoPass(input: PassInput, state: HugoTranslatorState) extends Pass(i
override def result: HugoOutput = HugoOutput(state = state)

private def deleteAll(directory: File): Boolean = {
for file <- directory.listFiles do {
deleteAll(file)
}
directory.delete
if !directory.isDirectory then false
else
Option(directory.listFiles) match {
case Some(files) =>
for file <- files do {
deleteAll(file)
}
directory.delete
case None =>
false
}
}

private def loadATheme(from: URL, destDir: Path): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.reactific.riddl.language.Messages.Accumulator
import com.reactific.riddl.language.{AST, CommonOptions}
import com.reactific.riddl.language.parsing.FileParserInput
import com.reactific.riddl.passes.PassesResult
import com.reactific.riddl.passes.resolve.ReferenceMap
import com.reactific.riddl.passes.resolve.{ReferenceMap, Usages}
import com.reactific.riddl.passes.symbols.SymbolsOutput
import com.reactific.riddl.passes.Finder
import com.reactific.riddl.utils.{Logger, SysLogger}
Expand All @@ -37,11 +37,11 @@ case class HugoTranslatorState(
commonOptions: CommonOptions = CommonOptions(),
logger: Logger = SysLogger()
) extends TranslatingState[MarkdownWriter] with SequenceDiagramSupport {
val result: PassesResult = passesResult
final val symbolTable: SymbolsOutput = result.symbols
final val refMap: ReferenceMap = result.refMap
final val root: RootContainer = result.root // base class compliance
final val messages: Accumulator = Accumulator(commonOptions)
final def symbolTable: SymbolsOutput = passesResult.symbols
final def refMap: ReferenceMap = passesResult.refMap
final def root: RootContainer = passesResult.root // base class compliance
final def usage: Usages = passesResult.usage
final def messages: Accumulator = Accumulator(commonOptions)

def addFile(parents: Seq[String], fileName: String): MarkdownWriter = {
val parDir = parents.foldLeft(options.contentRoot) { (next, par) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,12 @@ case class MarkdownWriter(filePath: Path, state: HugoTranslatorState) extends Te
}

private def emitUsage(definition: Definition): this.type = {
state.result.usage.getUsers(definition) match {
state.usage.getUsers(definition) match {
case users: Seq[Definition] if users.nonEmpty =>
listOf("Used By", users)
case _ => h2("Used By None")
}
state.result.usage.getUses(definition) match {
state.usage.getUses(definition) match {
case usages: Seq[Definition] if usages.nonEmpty => listOf("Uses", usages)
case _ => h2("Uses Nothing")
}
Expand Down Expand Up @@ -1009,7 +1009,7 @@ case class MarkdownWriter(filePath: Path, state: HugoTranslatorState) extends Te
Some("Statistical information about the RIDDL model documented")
)

val stats = state.result.outputOf[StatsOutput](StatsPass.name).getOrElse(StatsOutput())
val stats = state.passesResult.outputOf[StatsOutput](StatsPass.name).getOrElse(StatsOutput())
emitTableHead(
Seq(
"Category" -> 'L',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ class HugoPassTest

val passing_test_cases = Seq(
"ToDoodles",
"FooBar",
"ReactiveBBQ.conf",
"FooBarSuccess/FooBar",
// FIXME: re-enable when this case code is corrected
// FIXME: "ReactiveBBQ/ReactiveBBQ",
"dokn"
)
override def validate(name: String): Boolean = passing_test_cases.contains(name)
override def validateTestName(name: String): Boolean =
val result = passing_test_cases.exists(name.endsWith)
result

override def onSuccess(
commandName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class HugoTestBase extends ValidatingTest {
fail(errors.format)
case Right(root) =>
val passInput = PassInput(root, commonOptions)
Pass(passInput, shouldFailOnErrors = true, passes, logger).map { passesResult =>
(passesResult, root, rpi)
}
val result = Pass.runThesePasses(passInput, passes, logger)
if result.messages.hasErrors then Left(result.messages)
else Right((result, root, rpi))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ case class CommonOptions(
sortMessagesByLocation: Boolean = false,
groupMessagesByKind: Boolean = true,
noANSIMessages: Boolean = false,
maxParallelParsing: Int = 4
maxParallelParsing: Int = 4,
warningsAreFatal: Boolean = false
)

object CommonOptions {
Expand Down
Loading

0 comments on commit 089ab3a

Please sign in to comment.