Skip to content

Commit acabb33

Browse files
committed
analyzing everything before writing
1 parent 2472321 commit acabb33

File tree

4 files changed

+35
-28
lines changed

4 files changed

+35
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ j2eo.jar
1111
sarif/**
1212
polystat-x86_64-pc-linux
1313
out/
14+
**.json

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ buildInfoPackage := "org.polystat.cli"
3131

3232
Global / excludeLintKeys += nativeImageVersion
3333

34-
Compile / mainClass := Some("org.polystat.Main")
34+
Compile / mainClass := Some("org.polystat.cli.Main")
3535

3636
enablePlugins(NativeImagePlugin)
3737
nativeImageVersion := "22.1.0"

src/main/scala/org/polystat/cli/EO.scala

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import org.polystat.odin.analysis.EOOdinAnalyzer
99
import org.polystat.odin.parser.EoParser.sourceCodeEoParser
1010
import org.polystat.sarif.AggregatedSarifOutput
1111
import org.polystat.sarif.SarifOutput
12+
import fs2.io.file.Path
1213

1314
import PolystatConfig.*
1415
import InputUtils.*
16+
import org.polystat.odin.analysis.EOOdinAnalyzer.OdinAnalysisResult
1517

1618
object EO:
1719

@@ -27,60 +29,60 @@ object EO:
2729
val inputFiles = readCodeFromInput(".eo", cfg.input)
2830
val analyzed = inputFiles
2931
.evalMap { case (codePath, code) =>
30-
for analyzed <- runAnalyzers(cfg.filteredAnalyzers)(code)
32+
for
33+
_ <- IO.println(s"Analyzing $codePath...")
34+
analyzed <- runAnalyzers(cfg.filteredAnalyzers)(code)
3135
yield (codePath, analyzed)
3236
}
3337
.compile
3438
.toVector
35-
.map(_.toMap)
36-
val analyzeToDirs = inputFiles
37-
.evalMap { case (codePath, code) =>
39+
40+
def writeToDirs(analyzed: Vector[(Path, List[OdinAnalysisResult])]) =
41+
analyzed.traverse_ { case (codePath, results) =>
3842
for
39-
_ <- IO.println(s"Analyzing $codePath...")
40-
analyzed <- runAnalyzers(cfg.filteredAnalyzers)(code)
4143
_ <- if cfg.output.console then IO.println(analyzed) else IO.unit
4244
_ <- cfg.fmts.traverse_ { case OutputFormat.Sarif =>
4345
val sarifJson = SarifOutput(
4446
codePath,
45-
analyzed,
47+
results,
4648
).json.toString
4749
cfg.output.dirs.traverse_(out =>
4850
val outPath =
4951
out / "sarif" / codePath.replaceExt(".sarif.json")
5052
for
51-
_ <- IO.println(s"Writing results to $outPath")
53+
_ <- IO.println(s"Writing results to $outPath...")
5254
_ <- writeOutputTo(outPath)(sarifJson)
5355
yield ()
5456
)
5557
}
5658
yield ()
5759
}
58-
.compile
59-
.drain
60-
val analyzeAggregate = cfg.output.files.traverse_ { outputPath =>
61-
cfg.fmts.traverse_ { case OutputFormat.Sarif =>
62-
for
63-
_ <- IO.println(s"Writing aggregated output to $outputPath...")
64-
analyzed <- analyzed
65-
sariOutput = AggregatedSarifOutput
66-
.fromAnalyzed(analyzed)
67-
.asJson
68-
.deepDropNullValues
69-
.toString
70-
_ <- writeOutputTo(outputPath)(sariOutput)
71-
yield ()
60+
61+
def writeAggregate(analyzed: Vector[(Path, List[OdinAnalysisResult])]) =
62+
cfg.output.files.traverse_ { outputPath =>
63+
cfg.fmts.traverse_ { case OutputFormat.Sarif =>
64+
for
65+
_ <- IO.println(s"Writing aggregated output to $outputPath...")
66+
sariOutput = AggregatedSarifOutput
67+
.fromAnalyzed(analyzed)
68+
.asJson
69+
.deepDropNullValues
70+
.toString
71+
_ <- writeOutputTo(outputPath)(sariOutput)
72+
yield ()
73+
}
7274
}
73-
}
7475

7576
for
77+
analyzed <- analyzed
7678
_ <- cfg.output.dirs.traverse_ { outDir =>
7779
for
7880
_ <- IO.println(s"Cleaning $outDir before writing...")
7981
_ <- outDir.clean
8082
yield ()
8183
}
82-
_ <- analyzeToDirs
83-
_ <- analyzeAggregate
84+
_ <- writeToDirs(analyzed)
85+
_ <- writeAggregate(analyzed)
8486
yield ()
8587
end for
8688
end analyze

src/main/scala/org/polystat/sarif/AggregatedSarifOutput.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ import org.polystat.odin.analysis.EOOdinAnalyzer.OdinAnalysisResult
55

66
import Sarif.*
77

8+
case class AggregatedSarifOutput(
9+
analyzed: Seq[(Path, List[OdinAnalysisResult])]
10+
)
11+
812
object AggregatedSarifOutput:
913
def fromAnalyzed(
10-
analyzed: Map[Path, List[OdinAnalysisResult]]
14+
analyzed: Seq[(Path, List[OdinAnalysisResult])]
1115
): Seq[SarifLog] =
12-
analyzed.toSeq.map { case (path, results) =>
16+
analyzed.map { case (path, results) =>
1317
SarifOutput(path, results).sarif
1418
}
1519
end AggregatedSarifOutput

0 commit comments

Comments
 (0)