Skip to content

Commit

Permalink
use vendored php-parser as default
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxology committed Feb 29, 2024
1 parent 068765d commit a883357
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ phpParseDlTask := {
phpBinDir.mkdirs()

val downloadedFile = SimpleCache.downloadMaybe(phpParserDlUrl)
IO.copyFile(downloadedFile, phpBinDir / upstreamParserBinName)
IO.copyFile(downloadedFile, phpBinDir / versionedParserBinName)

File((phpBinDir / "php-parser.php").getPath)
.createFileIfNotExists()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.slf4j.{Logger, LoggerFactory}

import java.nio.file.Paths
import java.util.Calendar
import java.io.File

class PhpProcessor(
ruleCache: RuleCache,
Expand Down Expand Up @@ -68,11 +69,30 @@ class PhpProcessor(
println(s"${Calendar.getInstance().getTime} - Processing source code using $lang engine")

createCpgFolder(sourceRepoLocation)

// get vendored php parser path
val parserBinPath: String = {
val dir = getClass.getProtectionDomain.getCodeSource.getLocation.toString
val indexOfLib = dir.lastIndexOf("lib")
val fixedDir = if (indexOfLib != -1) {
new File(dir.substring("file:".length, indexOfLib)).toString
} else {
val indexOfTarget = dir.lastIndexOf("target")
if (indexOfTarget != -1) {
new File(dir.substring("file:".length, indexOfTarget)).toString
} else {
"."
}
}
Paths.get(fixedDir, "/bin/php-parser/php-parser.php").toAbsolutePath.toString
}

val cpgOutput = Paths.get(sourceRepoLocation, outputDirectoryName, cpgOutputFileName)
val cpgConfig = Config()
.withInputPath(sourceRepoLocation)
.withOutputPath(cpgOutput.toString)
.withIgnoredFilesRegex(ruleCache.getExclusionRegex)
.withPhpParserBin(parserBinPath)

val xtocpg = new Php2Cpg().createCpg(cpgConfig).map { cpg =>
println(
Expand Down

0 comments on commit a883357

Please sign in to comment.