@@ -23,7 +23,8 @@ class FuzzyC2Cpg() {
2323 includePaths : Set [String ],
2424 defines : Set [String ],
2525 undefines : Set [String ],
26- preprocessorExecutable : String ): Unit = {
26+ preprocessorExecutable : String ,
27+ optionalOutputPath : Option [String ] = None ): Unit = {
2728 // Create temp dir to store preprocessed source.
2829 val preprocessedPath = Files .createTempDirectory(" fuzzyc2cpg_preprocessed_" )
2930 logger.info(s " Writing preprocessed files to [ $preprocessedPath] " )
@@ -54,7 +55,7 @@ class FuzzyC2Cpg() {
5455
5556 if (exitCode == 0 ) {
5657 logger.info(s " Preprocessing complete, files written to [ $preprocessedPath], starting CPG generation... " )
57- val cpg = runAndOutput(Set (preprocessedPath.toString), sourceFileExtensions)
58+ val cpg = runAndOutput(Set (preprocessedPath.toString), sourceFileExtensions, optionalOutputPath )
5859 cpg.close()
5960 } else {
6061 logger.error(
@@ -81,6 +82,10 @@ class FuzzyC2Cpg() {
8182 cpg
8283 }
8384
85+ /**
86+ * Create an empty CPG, backed by the file at `optionalOutputPath` or
87+ * in-memory if `optionalOutputPath` is empty.
88+ * */
8489 private def initCpg (optionalOutputPath : Option [String ]): Cpg = {
8590 val odbConfig = optionalOutputPath
8691 .map { outputPath =>
@@ -113,13 +118,16 @@ object FuzzyC2Cpg {
113118 val fuzzyc = new FuzzyC2Cpg ()
114119
115120 if (config.usePreprocessor) {
116- fuzzyc.runWithPreprocessorAndOutput(config.inputPaths,
117- config.sourceFileExtensions,
118- config.includeFiles,
119- config.includePaths,
120- config.defines,
121- config.undefines,
122- config.preprocessorExecutable)
121+ fuzzyc.runWithPreprocessorAndOutput(
122+ config.inputPaths,
123+ config.sourceFileExtensions,
124+ config.includeFiles,
125+ config.includePaths,
126+ config.defines,
127+ config.undefines,
128+ config.preprocessorExecutable,
129+ Some (config.outputPath)
130+ )
123131 } else {
124132 val cpg = fuzzyc.runAndOutput(config.inputPaths, config.sourceFileExtensions, Some (config.outputPath))
125133 cpg.close()
0 commit comments