Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade codegen and adapt (type alias) #1776

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name := "codepropertygraph"

// parsed by project/Versions.scala, updated by updateDependencies.sh
val overflowdbVersion = "1.192"
val overflowdbCodegenVersion = "2.110"
val overflowdbCodegenVersion = "2.112"

inThisBuild(
List(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package io.shiftleft.passes

import com.google.protobuf.GeneratedMessageV3
import io.shiftleft.SerializedCpg
import io.shiftleft.codepropertygraph.generated.Cpg
import io.shiftleft.codepropertygraph.generated.{Cpg, DiffGraphBuilder}
import org.slf4j.{Logger, LoggerFactory, MDC}
import overflowdb.BatchedUpdate

import java.util.function.{BiConsumer, Supplier}
import scala.annotation.nowarn
Expand All @@ -19,11 +18,11 @@ import scala.util.{Failure, Success, Try}
abstract class CpgPass(cpg: Cpg, outName: String = "", keyPool: Option[KeyPool] = None)
extends ForkJoinParallelCpgPass[AnyRef](cpg, outName, keyPool) {

def run(builder: overflowdb.BatchedUpdate.DiffGraphBuilder): Unit
def run(builder: DiffGraphBuilder): Unit

final override def generateParts(): Array[? <: AnyRef] = Array[AnyRef](null)

final override def runOnPart(builder: overflowdb.BatchedUpdate.DiffGraphBuilder, part: AnyRef): Unit =
final override def runOnPart(builder: DiffGraphBuilder, part: AnyRef): Unit =
run(builder)

override def isParallel: Boolean = false
Expand Down Expand Up @@ -109,7 +108,7 @@ abstract class ForkJoinParallelCpgPass[T <: AnyRef](
* hierarchy.
*/
abstract class NewStyleCpgPassBase[T <: AnyRef] extends CpgPassBase {
type DiffGraphBuilder = overflowdb.BatchedUpdate.DiffGraphBuilder
type DiffGraphBuilder = io.shiftleft.codepropertygraph.generated.DiffGraphBuilder
// generate Array of parts that can be processed in parallel
def generateParts(): Array[? <: AnyRef]
// setup large data structures, acquire external resources
Expand All @@ -123,7 +122,7 @@ abstract class NewStyleCpgPassBase[T <: AnyRef] extends CpgPassBase {

override def createAndApply(): Unit = createApplySerializeAndStore(null)

override def runWithBuilder(externalBuilder: BatchedUpdate.DiffGraphBuilder): Int = {
override def runWithBuilder(externalBuilder: DiffGraphBuilder): Int = {
try {
init()
val parts = generateParts()
Expand Down Expand Up @@ -185,12 +184,12 @@ trait CpgPassBase {
* 1), where nParts is either the number of parallel parts, or the number of iterarator elements in case of legacy
* passes. Includes init() and finish() logic.
*/
def runWithBuilder(builder: overflowdb.BatchedUpdate.DiffGraphBuilder): Int
def runWithBuilder(builder: DiffGraphBuilder): Int

/** Wraps runWithBuilder with logging, and swallows raised exceptions. Use with caution -- API is unstable. A return
* value of -1 indicates failure, otherwise the return value of runWithBuilder is passed through.
*/
def runWithBuilderLogged(builder: overflowdb.BatchedUpdate.DiffGraphBuilder): Int = {
def runWithBuilderLogged(builder: DiffGraphBuilder): Int = {
baseLogger.info(s"Start of pass: $name")
val nanoStart = System.nanoTime()
val size0 = builder.size()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.shiftleft.codepropertygraph

package object generated {
// some type aliases so that the domain-specific code can avoid referencing the `overflowdb` namespace

object help {
type Doc = _root_.overflowdb.traversal.help.Doc
type Traversal = _root_.overflowdb.traversal.help.Traversal
type TraversalSource = _root_.overflowdb.traversal.help.TraversalSource
}
}
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ addSbtPlugin("com.github.sbt" % "sbt-findbugs" % "2.0.0")
addSbtPlugin("io.shiftleft" % "sbt-ci-release-early" % "2.0.18")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.5")
addSbtPlugin("io.shiftleft" % "sbt-overflowdb" % "2.106")
addSbtPlugin("io.shiftleft" % "sbt-overflowdb" % "2.112")

3 changes: 1 addition & 2 deletions schema/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name := "codepropertygraph-schema"

// TODO change back to io.shiftleft after official releases are fixed, this is only temporary!
libraryDependencies += "com.michaelpollmeier" %% "overflowdb-codegen" % Versions.overflowdbCodegen
libraryDependencies += "io.shiftleft" %% "overflowdb-codegen" % Versions.overflowdbCodegen

lazy val generatedSrcDir = settingKey[File]("root for generated sources - we want to check those in")
enablePlugins(OdbCodegenSbtPlugin)
Expand Down
Loading