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

Add compilation database options from CPG as CLI option #902

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import de.fraunhofer.aisec.cpg.TranslationConfiguration
import de.fraunhofer.aisec.cpg.TranslationManager
import de.fraunhofer.aisec.cpg.TranslationResult
import de.fraunhofer.aisec.cpg.frontends.CompilationDatabase
import io.github.detekt.sarif4k.Artifact
import io.github.detekt.sarif4k.ArtifactLocation
import io.github.detekt.sarif4k.ToolComponent
Expand Down Expand Up @@ -72,6 +73,12 @@
.useUnityBuild(useUnityBuild)
.processAnnotations(processAnnotations)

compilationDatabase?.let {
translationConfiguration.useCompilationDatabase(
CompilationDatabase.fromFile(it.toFile(), filterCompilationDatabase)

Check warning on line 78 in codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/CPGBackend.kt

View check run for this annotation

Codecov / codecov/patch

codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/CPGBackend.kt#L77-L78

Added lines #L77 - L78 were not covered by tests
)
}

// TODO: very hacky, but needed for the Go frontend
source.firstOrNull()?.parent?.toFile().let { translationConfiguration.topLevel(it) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ data class CPGConfiguration(
val includePaths: List<Path>,
val includeAllowlist: List<Path>,
val includeBlocklist: List<Path>,
val compilationDatabase: Path? = null,
val filterCompilationDatabase: List<String> = emptyList<String>(),
) : BackendConfiguration {
init {
logger.info { "Analyzing following sources $source" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ import kotlin.reflect.full.isSuperclassOf
*/
@Suppress("UNUSED")
class CPGOptionGroup : BackendOptions(helpName = "CPG Backend Options") {

val compilationDatabase: Path? by option(
"--compilationDatabase",
help = "Use compilation database to load project specific files and includes",
)
.path(mustExist = true, mustBeReadable = true)

val filterCompilationDatabase: List<String> by option(
"--filterCompilationDatabase",
help = "Filters compilation database for specific components",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe extend the comment that if the filter is empty, all components are used.

)
.multiple()

private val rawSource: List<Path> by option(
"-s",
"--source",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
includePaths = includePaths,
includeAllowlist = includeAllowlist,
includeBlocklist = includeBlocklist,
compilationDatabase = compilationDatabase,
filterCompilationDatabase = filterCompilationDatabase,

Check warning on line 52 in codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/cli/BaseCpgBackendCommand.kt

View check run for this annotation

Codecov / codecov/patch

codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/cli/BaseCpgBackendCommand.kt#L51-L52

Added lines #L51 - L52 were not covered by tests
).normalize()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
includePaths = includePaths,
includeAllowlist = includeAllowlist,
includeBlocklist = includeBlocklist,
compilationDatabase = compilationDatabase,
filterCompilationDatabase = filterCompilationDatabase,

Check warning on line 53 in codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/cli/CokoCpgBackendCommand.kt

View check run for this annotation

Codecov / codecov/patch

codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/cli/CokoCpgBackendCommand.kt#L52-L53

Added lines #L52 - L53 were not covered by tests
).normalize()
)
}
Expand Down