Skip to content

Commit

Permalink
Trying ZINC.
Browse files Browse the repository at this point in the history
Doesn't work
Issues:
Biggest one is mess with classpath:
    Source compiling compiler_bridge
        NoSuchMethodError: 'scala.tools.nsc.settings.AbsSettings$AbsSetting scala.tools.nsc.Settings.nowarn()'
        davidB/scala-maven-plugin#363
        sbt/zinc#698
    Need uber jars in various forms (not hacked all the way through and where I gave up)
        Caused by: java.lang.ClassNotFoundException: jline.TerminalFactory
    Required adding ~40 dependencies of Zinc
    Conflicts with IJ scala plugin classes
        com.intellij.diagnostic.PluginException: Cannot load class scala.Option (
          error: loader constraint violation: loader com.intellij.ide.plugins.cl.PluginClassLoader @29446114 wants to load abstract class scala.Option. A different abstract class with the same name was previously loaded by com.intellij.ide.plugins.cl.PluginClassLoader @61ed07dc. (scala.Option is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @61ed07dc, parent loader 'bootstrap'),
          classLoader=PluginClassLoader(plugin=PluginDescriptor(name=Bazel, id=com.google.idea.bazel.ijwb, descriptorPath=plugin.xml, path=~/Library/Caches/JetBrains/IntelliJIdea2022.2/plugins-sandbox/plugins/ijwb, version=9999-api-version-222, package=null, isBundled=false), packagePrefix=null, instanceId=282, state=active)
        )
            at com.intellij.ide.plugins.cl.PluginClassLoader.loadClassInsideSelf(PluginClassLoader.java:411)

Smaller:
    Hack in how to find the jar of the fast scalac
    Hardcoding the scala version and the SDK
    No access for now to scalaCompilerPlugins, scalaCompilerOptions, javaCompilerOptions

Tech debt in the PR:
    Two compiler impls (fast_build_scalac2, ScalaCompilerImpl2)
    Especially in the BUILD files
  • Loading branch information
ittaiz committed Nov 10, 2022
1 parent 07ae689 commit 5efcf69
Show file tree
Hide file tree
Showing 10 changed files with 799 additions and 90 deletions.
20 changes: 19 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ http_archive(
_SCALA_BUILD_FILE = """
java_import(
name = "scala",
jars = glob(["Scala/lib/*.jar"]),
jars = glob(["Scala/lib/*.jar"], exclude = ["Scala/lib/compiler-interface-1.6.1.jar"]),
visibility = ["//visibility:public"],
)
"""
Expand Down Expand Up @@ -621,3 +621,21 @@ buildbuddy_deps()
load("@io_buildbuddy_buildbuddy_toolchain//:rules.bzl", "buildbuddy")

buildbuddy(name = "buildbuddy_toolchain")

load("//:zinc.bzl", zinc_deps = "dependencies")

zinc_deps()

_SRC_FILEGROUP_BUILD_FILE_CONTENT = """
filegroup(
name = "src",
srcs = glob(["**/*.scala", "**/*.java"]),
visibility = ["//visibility:public"]
)"""

http_archive(
name = "compiler_bridge_2_12",
build_file_content = _SRC_FILEGROUP_BUILD_FILE_CONTENT,
sha256 = "24cd30dcb37c2b24f962118f49489c98a66b49600cfd7fbb9eab68475ddd56a2",
url = "https://repo.maven.apache.org/maven2/org/scala-sbt/compiler-bridge_2.12/1.3.4/compiler-bridge_2.12-1.3.4-sources.jar",
)
28 changes: 26 additions & 2 deletions ijwb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,33 @@ repackaged_files(
prefix = "ijwb/lib",
)

repackaged_files(
name = "fast_build_scalac2",
srcs = ["//scala:fast_build_scalac2_deploy.jar"],
prefix = "ijwb/lib",
)

repackaged_files(
name = "fast_build_scalac2_deps",
srcs = ["//scala:fast_build_scalac2_deps_deploy.jar"],
prefix = "ijwb/lib",
)

repackaged_files(
name = "compiler_bridge_2_12",
srcs = ["//scala:compiler_bridge_2_12"],
prefix = "ijwb/lib",
)

intellij_plugin_debug_target(
name = "ijwb_bazel_dev",
deps = [
":aspect_directory",
":fast_build_javac",
":fast_build_scalac",
# ":fast_build_scalac",
":fast_build_scalac2",
":fast_build_scalac2_deps",
":compiler_bridge_2_12",
":plugin_jar",
],
)
Expand All @@ -136,7 +157,10 @@ plugin_deploy_zip(
srcs = [
":aspect_directory",
":fast_build_javac",
":fast_build_scalac",
# ":fast_build_scalac",
":fast_build_scalac2",
":fast_build_scalac2_deps",
":compiler_bridge_2_12",
":plugin_jar",
],
zip_filename = "ijwb_bazel.zip",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.google.idea.blaze.java.fastbuild;

import com.google.idea.blaze.base.command.info.BlazeInfo;
import com.intellij.openapi.extensions.ExtensionPointName;

import java.io.File;
Expand All @@ -10,6 +11,7 @@ public interface FastBuildCompilerExtensionPoint {
ExtensionPointName<FastBuildCompilerExtensionPoint> EP_NAME =
ExtensionPointName.create("com.google.idea.blaze.FastBuildCompilerExtensionPoint");

FastBuildCompiler getCompiler(List<File> javacJars, List<File> bootClassPathJars, String sourceVersion, String targetVersion);
FastBuildCompiler getCompiler(List<File> javacJars, List<File> bootClassPathJars, String sourceVersion, String targetVersion,
BlazeInfo blazeInfo);

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public FastBuildCompiler getCompilerFor(Label label, Map<Label, FastBuildBlazeDa
// Hacky way to substitute FastBuildCompiler with Scala compiler
// Calls com.google.idea.blaze.scala.fastbuild.FastBuildScalaCompilerExtensionPoint
return FastBuildCompilerExtensionPoint.EP_NAME.getExtensions()[0]
.getCompiler(javacJars, bootJars, javaToolchain.sourceVersion(), javaToolchain.targetVersion());
.getCompiler(javacJars, bootJars, javaToolchain.sourceVersion(), javaToolchain.targetVersion(), projectData.getBlazeInfo());
} else {
Javac javac = createCompiler(javacJars);
return new JavacRunner(
Expand Down
65 changes: 64 additions & 1 deletion scala/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ load(
"//:build-visibility.bzl",
"PLUGIN_PACKAGES_VISIBILITY",
)
load(
"@io_bazel_rules_scala//scala:scala.bzl",
"scala_library",
)

licenses(["notice"])

Expand All @@ -30,11 +34,15 @@ _FAST_BUILD_SCALAC_IMPL_SRCS = [
"src/com/google/idea/blaze/scala/fastbuild/ScalaCompilerImpl.java",
]

_FAST_BUILD_SCALAC_IMPL_SRCS2 = [
"src/com/google/idea/blaze/scala/fastbuild/ScalaCompilerImpl2.scala",
]

java_library(
name = "scala",
srcs = glob(
["src/**/*.java"],
exclude = _FAST_BUILD_SCALAC_SRCS + _FAST_BUILD_SCALAC_IMPL_SRCS
exclude = _FAST_BUILD_SCALAC_SRCS + _FAST_BUILD_SCALAC_IMPL_SRCS,
),
visibility = ["//visibility:public"],
deps = [
Expand All @@ -60,6 +68,61 @@ java_library(
deps = [],
)

scala_library(
name = "fast_build_scalac2",
srcs = _FAST_BUILD_SCALAC_SRCS + _FAST_BUILD_SCALAC_IMPL_SRCS2,
visibility = [
"//aswb:__pkg__",
"//ijwb:__pkg__",
"//scala/com/google/devtools/intellij/blaze/plugin:__subpackages__",
],
deps = [
"//base",
"@org_scala_sbt_compiler_interface",
"@org_scala_sbt_util_control_2_12",
"@org_scala_sbt_util_interface",
"@org_scala_sbt_util_logging_2_12",
"@org_scala_sbt_zinc_2_12",
"@org_scala_sbt_zinc_classpath_2_12",
"@org_scala_sbt_zinc_compile_core_2_12",
"@org_scala_sbt_zinc_core_2_12",
],
)

scala_library(
name = "fast_build_scalac2_deps",
srcs = [],
visibility = [
"//aswb:__pkg__",
"//ijwb:__pkg__",
"//scala/com/google/devtools/intellij/blaze/plugin:__subpackages__",
],
deps = [
"@org_scala_sbt_compiler_interface",
"@org_scala_sbt_util_control_2_12",
"@org_scala_sbt_util_interface",
"@org_scala_sbt_util_logging_2_12",
"@org_scala_sbt_zinc_2_12",
"@org_scala_sbt_zinc_classpath_2_12",
"@org_scala_sbt_zinc_compile_core_2_12",
"@org_scala_sbt_zinc_core_2_12",
],
)

scala_library(
name = "compiler_bridge_2_12",
srcs = [
"@compiler_bridge_2_12//:src",
],
visibility = ["//visibility:public"],
deps = [
"@org_scala_lang_scala_compiler",
"@org_scala_lang_scala_library",
"@org_scala_lang_scala_reflect",
"@org_scala_sbt_compiler_interface",
"@org_scala_sbt_util_interface",
],
)
optional_plugin_xml(
name = "optional_xml",
module = "org.intellij.scala",
Expand Down
Loading

0 comments on commit 5efcf69

Please sign in to comment.