Skip to content

Commit e39a6ef

Browse files
authored
Remove preprocessor for fuzzyc (#1506)
* Remove all scala code related to failed preproc experiment * Remove CPP code related to failed preproc experiment * Remove preprocessor from build
1 parent 483c053 commit e39a6ef

25 files changed

+4
-1686
lines changed

.github/workflows/pr.yml

-48
Original file line numberDiff line numberDiff line change
@@ -27,51 +27,3 @@ jobs:
2727
run: sbt scalafmtCheck test:scalafmtCheck "scalafixAll --check OrganizeImports"
2828
- run: echo "Previous step failed because code is not formatted. Run 'sbt format'"
2929
if: ${{ failure() }}
30-
31-
test-fuzzypp-linux:
32-
runs-on: ubuntu-18.04
33-
34-
steps:
35-
- uses: actions/checkout@v2
36-
with:
37-
lfs: true
38-
- name: Clone submodules
39-
run: git submodule update --init --recursive
40-
- name: Install g++-8
41-
run: sudo apt-get install gcc-8 g++-8
42-
- name: Run cmake on fuzzypp
43-
run: cmake -DCMAKE_CXX_COMPILER=/usr/bin/g++-8 ./fuzzypp
44-
- name: Run cmake build
45-
run: cmake --build . -- -j4
46-
- name: Run fuzzyppcli-tests
47-
run: "./fuzzypp/bin/fuzzyppcli-tests"
48-
- name: Zip artifact
49-
run: zip -j ./fuzzyppcli.zip ./fuzzypp/bin/fuzzyppcli
50-
- name: Upload zip artifact
51-
uses: actions/upload-artifact@v2
52-
with:
53-
name: unix-zip
54-
path: ./fuzzyppcli.zip
55-
56-
test-fuzzypp-windows:
57-
runs-on: windows-2019
58-
59-
steps:
60-
- uses: actions/checkout@v2
61-
with:
62-
lfs: true
63-
- name: Clone submodules
64-
run: git submodule update --init --recursive
65-
- name: Run cmake on fuzzypp
66-
run: cmake -G "Visual Studio 16 2019" -A "x64" ./fuzzypp
67-
- name: Run cmake build
68-
run: cmake --build . --config Release
69-
- name: Run fuzzyppcli-tests
70-
run: "./fuzzypp/bin/Release/fuzzyppcli-tests.exe"
71-
- name: Zip artifact
72-
run: 7z a -r -tzip ./fuzzyppcli-win.zip ./fuzzypp/bin/Release/fuzzyppcli.exe
73-
- name: Upload zip artifact
74-
uses: actions/upload-artifact@v2
75-
with:
76-
name: windows-zip
77-
path: ./fuzzyppcli-win.zip

.github/workflows/push.yml

+1-77
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77
jobs:
88
test-codepropertygraph:
99
runs-on: ubuntu-18.04
10-
1110
steps:
1211
- uses: actions/checkout@v2
1312
with:
@@ -29,58 +28,9 @@ jobs:
2928
- run: echo "Previous step failed because code is not formatted. Run 'sbt format'"
3029
if: ${{ failure() }}
3130

32-
test-fuzzypp-linux:
33-
runs-on: ubuntu-18.04
34-
35-
steps:
36-
- uses: actions/checkout@v2
37-
with:
38-
lfs: true
39-
- name: Clone submodules
40-
run: git submodule update --init --recursive
41-
- name: Install g++-8
42-
run: sudo apt-get install gcc-8 g++-8
43-
- name: Run cmake on fuzzypp
44-
run: cmake -DCMAKE_CXX_COMPILER=/usr/bin/g++-8 ./fuzzypp
45-
- name: Run cmake build
46-
run: cmake --build . -- -j4
47-
- name: Run fuzzyppcli-tests
48-
run: "./fuzzypp/bin/fuzzyppcli-tests"
49-
- name: Zip artifact
50-
run: zip -j ./fuzzyppcli.zip ./fuzzypp/bin/fuzzyppcli
51-
- name: Upload zip artifact
52-
uses: actions/upload-artifact@v2
53-
with:
54-
name: unix-zip
55-
path: ./fuzzyppcli.zip
56-
57-
test-fuzzypp-windows:
58-
runs-on: windows-2019
59-
60-
steps:
61-
- uses: actions/checkout@v2
62-
with:
63-
lfs: true
64-
- name: Clone submodules
65-
run: git submodule update --init --recursive
66-
- name: Run cmake on fuzzypp
67-
run: cmake -G "Visual Studio 16 2019" -A "x64" ./fuzzypp
68-
- name: Run cmake build
69-
run: cmake --build . --config Release
70-
- name: Run fuzzyppcli-tests
71-
run: "./fuzzypp/bin/Release/fuzzyppcli-tests.exe"
72-
- name: Zip artifact
73-
run: 7z a -r -tzip ./fuzzyppcli-win.zip ./fuzzypp/bin/Release/fuzzyppcli.exe
74-
- name: Upload zip artifact
75-
uses: actions/upload-artifact@v2
76-
with:
77-
name: windows-zip
78-
path: ./fuzzyppcli-win.zip
79-
8031
release:
81-
needs: [test-codepropertygraph, test-fuzzypp-linux, test-fuzzypp-windows]
32+
needs: [test-codepropertygraph]
8233
runs-on: ubuntu-18.04
83-
8434
steps:
8535
- uses: actions/checkout@v2
8636
with:
@@ -119,32 +69,6 @@ jobs:
11969
release_name: ${{ env.LATEST_TAG }}
12070
draft: false
12171
prerelease: false
122-
- name: Download unix zip
123-
uses: actions/download-artifact@v2
124-
with:
125-
name: unix-zip
126-
- name: Upload fuzzypp zip
127-
uses: actions/upload-release-asset@v1
128-
env:
129-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
130-
with:
131-
upload_url: ${{ steps.create_release.outputs.upload_url }}
132-
asset_path: ./fuzzyppcli.zip
133-
asset_name: fuzzyppcli.zip
134-
asset_content_type: application/zip
135-
- name: Download windows zip
136-
uses: actions/download-artifact@v2
137-
with:
138-
name: windows-zip
139-
- name: Upload fuzzypp Windows zip
140-
uses: actions/upload-release-asset@v1
141-
env:
142-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
143-
with:
144-
upload_url: ${{ steps.create_release.outputs.upload_url }}
145-
asset_path: ./fuzzyppcli-win.zip
146-
asset_name: fuzzyppcli-win.zip
147-
asset_content_type: application/zip
14872
- name: Package frontends for release
14973
run: sbt clean fuzzyc2cpg/Universal/packageBin
15074
- name: Upload fuzzyc2cpg to release

.gitmodules

-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
[submodule "fuzzypp/external/cxxopts"]
2-
path = fuzzypp/external/cxxopts
3-
url = https://github.com/jarro2783/cxxopts.git
4-
[submodule "fuzzypp/external/catch2"]
5-
path = fuzzypp/external/catch2
6-
url = https://github.com/catchorg/Catch2.git
7-
[submodule "fuzzypp/external/simplecpp"]
8-
path = fuzzypp/external/simplecpp
9-
url = https://github.com/ShiftLeftSecurity/simplecpp.git

fuzzyc2cpg/src/main/scala/io/shiftleft/fuzzyc2cpg/FuzzyC2Cpg.scala

+3-91
Original file line numberDiff line numberDiff line change
@@ -10,62 +10,13 @@ import io.shiftleft.x2cpg.{SourceFiles, X2Cpg, X2CpgConfig}
1010
import org.slf4j.LoggerFactory
1111
import scopt.OParser
1212

13-
import java.nio.file.Files
1413
import java.util.concurrent.ConcurrentHashMap
15-
import scala.collection.mutable.ListBuffer
1614
import scala.jdk.CollectionConverters._
1715
import scala.util.control.NonFatal
1816

1917
case class Global(usedTypes: ConcurrentHashMap[String, Boolean] = new ConcurrentHashMap[String, Boolean]())
2018

2119
class FuzzyC2Cpg() {
22-
import FuzzyC2Cpg.logger
23-
24-
def runWithPreprocessorAndOutput(sourcePaths: Set[String],
25-
sourceFileExtensions: Set[String],
26-
includeFiles: Set[String],
27-
includePaths: Set[String],
28-
defines: Set[String],
29-
undefines: Set[String],
30-
preprocessorExecutable: String,
31-
optionalOutputPath: Option[String] = None): Unit = {
32-
// Create temp dir to store preprocessed source.
33-
val preprocessedPath = Files.createTempDirectory("fuzzyc2cpg_preprocessed_")
34-
logger.info(s"Writing preprocessed files to [$preprocessedPath]")
35-
36-
val preprocessorLogFile = Files.createTempFile("fuzzyc2cpg_preprocessor_log", ".txt").toFile
37-
logger.info(s"Writing preprocessor logs to [$preprocessorLogFile]")
38-
39-
val sourceFileNames = SourceFiles.determine(sourcePaths, sourceFileExtensions)
40-
41-
val commandBuffer = new ListBuffer[String]()
42-
commandBuffer.appendAll(List(preprocessorExecutable, "--verbose", "-o", preprocessedPath.toString))
43-
if (sourceFileNames.nonEmpty) commandBuffer.appendAll(List("-f", sourceFileNames.mkString(",")))
44-
if (includeFiles.nonEmpty) commandBuffer.appendAll(List("--include", includeFiles.mkString(",")))
45-
if (includePaths.nonEmpty) commandBuffer.appendAll(List("-I", includePaths.mkString(",")))
46-
if (defines.nonEmpty) commandBuffer.appendAll(List("-D", defines.mkString(",")))
47-
if (undefines.nonEmpty) commandBuffer.appendAll(List("-U", defines.mkString(",")))
48-
49-
val cmd = commandBuffer.toList
50-
51-
// Run preprocessor
52-
logger.info("Running preprocessor...")
53-
val process = new ProcessBuilder()
54-
.redirectOutput(preprocessorLogFile)
55-
.redirectError(preprocessorLogFile)
56-
.command(cmd: _*)
57-
.start()
58-
val exitCode = process.waitFor()
59-
60-
if (exitCode == 0) {
61-
logger.info(s"Preprocessing complete, files written to [$preprocessedPath], starting CPG generation...")
62-
val cpg = runAndOutput(Set(preprocessedPath.toString), sourceFileExtensions, optionalOutputPath)
63-
cpg.close()
64-
} else {
65-
logger.error(
66-
s"Error occurred whilst running preprocessor. Log written to [$preprocessorLogFile]. Exit code [$exitCode].")
67-
}
68-
}
6920

7021
def runAndOutput(sourcePaths: Set[String],
7122
sourceFileExtensions: Set[String],
@@ -93,15 +44,8 @@ object FuzzyC2Cpg {
9344

9445
final case class Config(inputPaths: Set[String] = Set.empty,
9546
outputPath: String = X2CpgConfig.defaultOutputPath,
96-
sourceFileExtensions: Set[String] = Set(".c", ".cc", ".cpp", ".h", ".hpp"),
97-
includeFiles: Set[String] = Set.empty,
98-
includePaths: Set[String] = Set.empty,
99-
defines: Set[String] = Set.empty,
100-
undefines: Set[String] = Set.empty,
101-
preprocessorExecutable: String = "./fuzzypp/bin/fuzzyppcli")
47+
sourceFileExtensions: Set[String] = Set(".c", ".cc", ".cpp", ".h", ".hpp"))
10248
extends X2CpgConfig[Config] {
103-
lazy val usePreprocessor: Boolean =
104-
includeFiles.nonEmpty || includePaths.nonEmpty || defines.nonEmpty || undefines.nonEmpty
10549

10650
override def withAdditionalInputPath(inputPath: String): Config = copy(inputPaths = inputPaths + inputPath)
10751
override def withOutputPath(x: String): Config = copy(outputPath = x)
@@ -125,47 +69,15 @@ object FuzzyC2Cpg {
12569
.text(
12670
"source file extensions to include when gathering source files. Defaults are .c, .cc, .cpp, .h and .hpp")
12771
.action((pat, cfg) => cfg.copy(sourceFileExtensions = cfg.sourceFileExtensions + pat)),
128-
opt[String]("include")
129-
.unbounded()
130-
.text("header include files")
131-
.action((incl, cfg) => cfg.copy(includeFiles = cfg.includeFiles + incl)),
132-
opt[String]('I', "")
133-
.unbounded()
134-
.text("header include paths")
135-
.action((incl, cfg) => cfg.copy(includePaths = cfg.includePaths + incl)),
136-
opt[String]('D', "define")
137-
.unbounded()
138-
.text("define a name")
139-
.action((d, cfg) => cfg.copy(defines = cfg.defines + d)),
140-
opt[String]('U', "undefine")
141-
.unbounded()
142-
.text("undefine a name")
143-
.action((u, cfg) => cfg.copy(undefines = cfg.undefines + u)),
144-
opt[String]("preprocessor-executable")
145-
.text("path to the preprocessor executable")
146-
.action((s, cfg) => cfg.copy(preprocessorExecutable = s)),
14772
)
14873
}
14974

15075
X2Cpg.parseCommandLine(args, frontendSpecificOptions, Config()) match {
15176
case Some(config) =>
15277
try {
15378
val fuzzyc = new FuzzyC2Cpg()
154-
if (config.usePreprocessor) {
155-
fuzzyc.runWithPreprocessorAndOutput(
156-
config.inputPaths,
157-
config.sourceFileExtensions,
158-
config.includeFiles,
159-
config.includePaths,
160-
config.defines,
161-
config.undefines,
162-
config.preprocessorExecutable,
163-
Some(config.outputPath)
164-
)
165-
} else {
166-
val cpg = fuzzyc.runAndOutput(config.inputPaths, config.sourceFileExtensions, Some(config.outputPath))
167-
cpg.close()
168-
}
79+
val cpg = fuzzyc.runAndOutput(config.inputPaths, config.sourceFileExtensions, Some(config.outputPath))
80+
cpg.close()
16981
} catch {
17082
case NonFatal(ex) =>
17183
logger.error("Failed to generate CPG.", ex)

fuzzypp/.vscode/c_cpp_properties.json

-22
This file was deleted.

fuzzypp/.vscode/launch.json

-27
This file was deleted.

0 commit comments

Comments
 (0)