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

[php] fix php-parser path lookup #4951

Closed
wants to merge 1 commit into from

Conversation

mpollmeier
Copy link
Contributor

On buildbot the installation path for php2cpg is
/worker/sptestV2-php2cpg/build/x2cpg-internal/php2cpg/target/universal/stage
which (prior to this PR) leads to an invalid derived php-parser name
and the following error:

2024-09-25 09:30:08.623 ERROR Invalid path for PhpParserBin: /worker/sptestV2-/php2cpg/bin/php-parser/php-parser.php

On buildbot the installation path for php2cpg is
`/worker/sptestV2-php2cpg/build/x2cpg-internal/php2cpg/target/universal/stage`
which (prior to this PR) leads to an invalid derived php-parser name
and the following error:
```
2024-09-25 09:30:08.623 ERROR Invalid path for PhpParserBin: /worker/sptestV2-/php2cpg/bin/php-parser/php-parser.php
```
@mpollmeier
Copy link
Contributor Author

Hmm, this hotfix doesn't really work either:

2024-09-25 12:45:04.996 ERROR PhpParser$: Invalid path for PhpParserBin: /home/runner/work/joern/joern/joern-cli/target/universal/stage/frontends/php2cpg/lib/io.joern./php2cpg/bin/php-parser/php-parser.php

Any ideas for a less-flakey way to handle this? If we use the second-to-last "php2cpg" then it works for the staged artifact, but other setups would fail again, e.g. a fat jar, or running it from within sbt or so...
Also note that we want to be able to execute php2cpg independent of the current working directory.

Or we leave it as is and configure the path override when we run it in buildbot. Still not ideal, because downstream users may run into the same issue and have a hard time debugging this...

@johannescoetzee
Copy link
Contributor

johannescoetzee commented Sep 25, 2024

I'd guess whatever we do for astgen would be best. It looks like a generic AstGenRunner exists in x2cpg. That might be different since we don't execute php-parser directly. I'm not sure how to fix that in a windows friendly way

@mpollmeier
Copy link
Contributor Author

Here's the part you mean. I guess that'll be the way forward then - a bit fiddly, but can't come up with a better way either...

def executableDir(implicit metaData: AstGenProgramMetaData): String = {
val dir = metaData.packagePath.toString
val indexOfLib = dir.lastIndexOf("lib")
val fixedDir = if (indexOfLib != -1) {
new java.io.File(dir.substring("file:".length, indexOfLib)).toString
} else {
val indexOfTarget = dir.lastIndexOf("target")
if (indexOfTarget != -1) {
new java.io.File(dir.substring("file:".length, indexOfTarget)).toString
} else {
"."
}
}
Paths.get(fixedDir, "/bin/astgen").toAbsolutePath.toString
}

@johannescoetzee
Copy link
Contributor

a bit fiddly, but can't come up with a better way either...

Yeah, it's not ideal, but it would be consistent, at least...

@mpollmeier
Copy link
Contributor Author

superseded by #4956

@mpollmeier mpollmeier closed this Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants