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

Support not bundling SemanticDB files in the output JAR #50

Merged

Conversation

jadenPete
Copy link

This is an attempt to recreate these changes in this repository. Unlike bazelbuild/rules_scala's SemanticDB support, these changes don't check that the SemanticDB compiler plugin is loaded if we're working with Scala 2. Instead, it's assumed that if the user sets the semanticdb_bundle ScalaConfiguration parameter to False, they'll add the plugin. If they don't, the build will fail.

@jadenPete jadenPete force-pushed the support-generating-semanticdb-files-separately branch from d5315ac to a698dd2 Compare August 26, 2024 18:22
@jadenPete
Copy link
Author

Formatted code.

@@ -30,24 +35,22 @@ phase_coverage_jacoco = _phase_coverage_jacoco

phase_ijinfo = _phase_ijinfo

phase_noop = _phase_noop
phase_javainfo = _phase_javainfo
Copy link

Choose a reason for hiding this comment

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

Looks like these were sorted alphabetically. Is that what is going on here?

Copy link
Author

Choose a reason for hiding this comment

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

That's right.

return struct(outputs = [], scalacopts = [])

outputs = []
semanticdb_directory = paths.join("_semanticdb/", ctx.label.name)
Copy link

Choose a reason for hiding this comment

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

Is it possible for the name to contain characters that are illegal to use as file names?

Copy link
Author

@jadenPete jadenPete Aug 27, 2024

Choose a reason for hiding this comment

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

From Bazel's documentation on labels:

Allowed characters in package names are the lowercase letters a through z, the uppercase letters A through Z, the digits 0 through 9, the characters ! \"#$%&'()*+,-.;<=>?@[]^_`{|} (yes, there's a space character in there!), and of course forward slash / (since it's the directory separator).

I assume legal target names can't include slashes because that'd make the package and name indistinguishable.

I think the only illegal characters in Unix filenames are / and the null character, both of which Bazel doesn't allow, so no, it shouldn't be possible. Windows is a different story, but I think it's highly unlikely that special characters other than - and _ will be used anyways, and even if they are, an error should be reported.

@@ -55,7 +55,7 @@ def phase_bootstrap_compile(ctx, g):
jar_creator = ctx.executable._jar_creator.path,
main_class = main_class,
output_jar = g.classpaths.jar.path,
scalacopts = " ".join(ctx.attr.scalacopts),
scalacopts = " ".join(ctx.attr.scalacopts + g.semanticdb.scalacopts),
Copy link

Choose a reason for hiding this comment

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

Do we need semanticdb for the bootstrap compiler? It's only used for a small number of internal targets.

Copy link
Author

Choose a reason for hiding this comment

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

We don't. I didn't understand the full purpose of the bootstrap compiler when I wrote this. I'll fix it.


outputs.append(ctx.actions.declare_file(output_filename))

if scala_configuration.version.startswith("2"):
Copy link

Choose a reason for hiding this comment

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

I'm not sure how much we care about this, but how does this work for things like Scalajs or Scala Native?

Copy link
Author

Choose a reason for hiding this comment

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

Hmm, it depends on what version is set to. The only other place in which we use it is phase_bootstrap_compile, where we also check if we're dealing with Scala 2 or 3.

Now that I think about it, is SemanticDB even a concept in Scala.js and Scala Native? I think both Scala.js and Scala Native use the same compiler, so it should be. For now, I'll leave this as is and dig into it further if folks want Scala.js and/or Scala Native support (assuming that's ok with you).

@@ -37,6 +37,7 @@ def phase_zinc_compile(ctx, g):
]

zincs = [dep[_ZincInfo] for dep in ctx.attr.deps if _ZincInfo in dep]
scalacopts = ctx.attr.scalacopts + g.semanticdb.scalacopts
Copy link

Choose a reason for hiding this comment

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

Nit: should we name this something other than scalacopts, so it's obvious that it's the combination of the regular scalacopts + the semanticdb opts? Perhaps combined_scalacopts?

Copy link
Author

Choose a reason for hiding this comment

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

Good idea.

),
"semanticdb_bundle": attr.bool(
default = True,
doc = "Whether to bundle SemanticDB files in the resulting JAR. Note that in Scala 2, this requires the SemanticDB compiler plugin.",
Copy link

Choose a reason for hiding this comment

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

Should we provide some default for Scala 2? Is that even possible?

Copy link

Choose a reason for hiding this comment

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

Would we even want to do that if we could?

Copy link
Author

Choose a reason for hiding this comment

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

What do you mean by this? The default is set to true, which matches the default for the compiler plugin (bundling SemanticDB files in the JAR).

bazel build :semanticdb-2_13
check_for_semanticdb_files 2_13
bazel build :semanticdb-3
check_for_semanticdb_files '3'
Copy link

Choose a reason for hiding this comment

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

Nit: This has single quotes around it and the 2_13 version does not.

Copy link
Author

Choose a reason for hiding this comment

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

Oh, I did that for syntax highlighting. It has no effect on the script. Bash differentiates numbers and strings, so it was being highlighted differently from 2_13.

@jadenPete jadenPete self-assigned this Aug 27, 2024
@jadenPete jadenPete merged commit ebb9ec4 into lucid-master Aug 27, 2024
1 check passed
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