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

Enable cross-repository navigation between Gradle/Maven codebases #616

Merged
merged 4 commits into from
Jul 20, 2023

Conversation

olafurpg
Copy link
Member

@olafurpg olafurpg commented Jul 20, 2023

Previously, scip-java only allowed cross-index (or cross-repo) navigation between symbols that are compiled to classfiles inside jar files. The practical implication of this was that cross-repo navigation never worked between Gradle/Maven projects even if one of the projects defined symbols that the other project used.

This behavior mixed an intentional design decision with an accidental implementation detail. The intentional design decision was that the ideal cross-repo navigation experience is from repositories to packages. To achieve this behavior, scip-java didn't assign a package name and package version to symbols that are compiled to directory entries on the classpath. The accidental implementation detail was that Gradle, Maven, and sbt compile to directories while packages only have jar files.

This commit changes the behavior to treat symbols the same regardless if they are compiled to jar files or directories. The accidental implemenation detail was a hack, and this behavior has come up as a surprise in at least twice cases of trying to integrate scip-java with big propriatery codebases. To get the default old behavior, the flag --allow-exporting-global-symbols-from-directory-entries can be set to false.

Test plan

See updated Gradle and Maven tests.

Previously, scip-java only allowed cross-index (or cross-repo)
navigation between symbols that are compiled to classfiles inside jar
files. This behavior mixed an intentional design decision with an
accidental implementation detail. The intentional design decision was
that the ideal cross-repo navigation experience is from repositories to
packages. To achieve this behavior, scip-java didn't assign a package
name and package version to symbols that are compiled to directory
entries on the classpath.  The accidental implementation detail was that
Gradle, Maven, and sbt compile to directories while packages only have
jar files.

This commit changes the behavior to treat symbols the same regardless if
they are compiled to jar files or directories. The accidental
implemenation detail was a hack, and this behavior has come up as a
surprise in at least twice cases of trying to integrate scip-java with
big propriatery codebases. To get the default old behavior, the flag
`--allow-exporting-global-symbols-from-directory-entries` can be set to
false.
@olafurpg olafurpg requested a review from keynmol July 20, 2023 12:01
@olafurpg olafurpg changed the title Add option --allow-exporting-global-symbols-from-directory-entries Enable cross-repository navigation between Gradle/Maven codebases Jul 20, 2023
Comment on lines 67 to +69
/* emitInverseRelationships */ true,
/* allowEmptyIndex */ true);
/* allowEmptyIndex */ true,
/* indexDirectoryEntries */ false // because Bazel only compiles to jar files.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit (for future refactor): this many boolean params in a row is a bit annoying, and we can't use named parameters with java class

At some point I think we should generate a builder for this options class to make things clearer.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. Builders are great when using Java.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't used named arguments from Scala if the definition is in Java.

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem with builders is that we can't make the fields final, but it's not a problem here. We could simplify a lot by just providing sensible default values

@olafurpg olafurpg force-pushed the olafurpg/classes-directory branch from 3b76e7a to e313c2e Compare July 20, 2023 14:19
@olafurpg olafurpg requested a review from keynmol July 20, 2023 14:22
classesDirectory <- project
.getExtensions()
.getByType(classOf[SourceSetContainer])
.getByName("main")
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess to handle test sources here we'd need to modify the artifact id or something, given that the descriptor doesn't have a notion of classifier like maven dependencies have

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it common to publish test sources? We can support the test scope as long as there is a reliable way to know the artifact ID of the test config

Copy link
Contributor

Choose a reason for hiding this comment

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

I've seen set ups where a library publishes a testkit from its tests, but now that I think about it - it's frequently discouraged and doesn't work with the rest of tooling: https://github.com/scalacenter/bloop/pulls?q=is%3Apr+author%3Akeynmol+is%3Aclosed+test-jar

So let's ignore this for now until there's a clear need.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can probably support it if there's demand and there's support to extract the right information

@tailrec
def loop(dir: Path): Option[ClasspathEntry] = {
if (dir == null || !dir.startsWith(sourceroot))
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this could easily be if (...) None else ... match

Copy link
Contributor

@keynmol keynmol left a comment

Choose a reason for hiding this comment

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

CI green = PR gud

Nice!

@olafurpg olafurpg merged commit a1d4ff2 into main Jul 20, 2023
@olafurpg olafurpg deleted the olafurpg/classes-directory branch July 20, 2023 15:20
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.

None yet

2 participants