Skip to content
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d185984
poc
liucijus Nov 22, 2022
cb6bb05
poc tested
liucijus Nov 30, 2022
d39a406
Add compiler patching
liucijus Dec 5, 2022
87477c8
Version with compiler patching
liucijus Dec 8, 2022
3487746
Add compiler_deps_mode attribute to scala toolchain
liucijus Dec 16, 2022
e0a3a11
Check if compiler deps need to be reported
liucijus Dec 17, 2022
492f2fa
Fix after rebase
liucijus Dec 17, 2022
a1933a3
Add dep tracking compiler patch
liucijus Dec 17, 2022
9e9cd73
Lint
liucijus Jan 2, 2023
1108088
Check if mode is verbose log
liucijus Jan 2, 2023
b7bfc52
Fixes
liucijus Jan 2, 2023
dedf5ce
Fix Scala 3 support
liucijus Jan 3, 2023
250bdd3
Patch compiler only if compiler dt is enabled
liucijus Jan 6, 2023
74bb915
Fix version tests
liucijus Jan 6, 2023
b5ccb9a
Rename verbose-log to ast-plus
liucijus Jan 6, 2023
1e1e205
Add patches for other supported version
liucijus Jan 9, 2023
a99ecaa
Fix versions test by adding 2.11.12 support
liucijus Jan 9, 2023
b755a1b
Expand dt messages to include jar information
liucijus Jan 11, 2023
de3538e
Exclude jars without labels from dep reporting
liucijus Jan 16, 2023
f3b004d
Add dependecy tracking method field to sdeps proto
liucijus Jan 16, 2023
6838998
Remove unused field
liucijus Jan 17, 2023
391111d
Fix test class after moving
liucijus Jan 17, 2023
2db9aec
Exclude jars without labels from dep reporting - fix for transitive jars
liucijus Jan 17, 2023
9e717af
Refactor reporting code
liucijus Jan 18, 2023
1c88ea6
Add integration tests
liucijus Jan 20, 2023
e810aa7
Remove sdeps reader leftover
liucijus Jan 25, 2023
ca13462
Remove unused symbol from load statement
liucijus Jan 25, 2023
4020140
Remove redundant flags
liucijus Feb 1, 2023
aa9faa3
Add scala minor version to scala config
liucijus Feb 1, 2023
2a3224e
Move strict and compiler mode resolution under the same control state…
liucijus Feb 6, 2023
4c5df85
Move strict and compiler mode resolution under the same control state…
liucijus Feb 6, 2023
4ff757c
Use simple equals
liucijus Feb 6, 2023
42835b9
Validate and report if dep tracking targets/jars parameter can pair
liucijus Feb 7, 2023
0de9ffa
Replace Dep class with generated; distinguish between warning and error
liucijus Feb 7, 2023
15dd54b
Uncomment tests commented by mistake
liucijus Feb 7, 2023
a3a6070
Restructure dep reporting message
liucijus Feb 7, 2023
f766a99
Don't catch exception
liucijus Feb 7, 2023
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
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ http_archive(

load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config()
scala_config(enable_compiler_dependency_tracking = True)

load("//scala:scala.bzl", "rules_scala_setup", "rules_scala_toolchain_deps_repositories")

Expand Down
Empty file added dt_patches/BUILD
Empty file.
20 changes: 20 additions & 0 deletions dt_patches/dt_compiler_2.11.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Subject: [PATCH] for patch
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git scala/tools/nsc/symtab/SymbolLoaders.scala scala/tools/nsc/symtab/SymbolLoaders.scala
--- scala/tools/nsc/symtab/SymbolLoaders.scala (revision 2e2f65a201b0b06e01a39fec4ae232c5b94efcca)
+++ scala/tools/nsc/symtab/SymbolLoaders.scala (revision 21ecced66f88cff2a81a7f69340be63dd0bc9b88)
@@ -210,6 +210,11 @@
val currentphase = phase
doComplete(root)
phase = currentphase
+ val assocFile = root.associatedFile
+ if (assocFile.underlyingSource.exists(_.isInstanceOf[scala.reflect.io.FileZipArchive])) {
+ val archivePath = assocFile.underlyingSource.map(_.path).headOption.getOrElse("N/A")
+ inform(s"DT:$archivePath")
+ }
informTime("loaded " + description, start)
ok = true
setSource(root)
20 changes: 20 additions & 0 deletions dt_patches/dt_compiler_2.12.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Subject: [PATCH] for patch
---
Index: scala/tools/nsc/symtab/SymbolLoaders.scala
<+>UTF-8
===================================================================
diff --git scala/tools/nsc/symtab/SymbolLoaders.scala scala/tools/nsc/symtab/SymbolLoaders.scala
--- scala/tools/nsc/symtab/SymbolLoaders.scala (revision 8684ae833dcfeac6107343fcca5501301e509eef)
+++ scala/tools/nsc/symtab/SymbolLoaders.scala (revision 74239a150e641ebfe220a6698dbc88c8c3f6f092)
@@ -208,6 +208,11 @@
val currentphase = phase
doComplete(root)
phase = currentphase
+ val assocFile = root.associatedFile
+ if (assocFile.underlyingSource.exists(_.isInstanceOf[scala.reflect.io.FileZipArchive])) {
+ val archivePath = assocFile.underlyingSource.map(_.path).headOption.getOrElse("N/A")
+ inform(s"DT:$archivePath")
+ }
informTime("loaded " + description, start)
ok = true
setSource(root)
19 changes: 19 additions & 0 deletions dt_patches/dt_compiler_2.12.8.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Subject: [PATCH] for patch
---
Index: scala/tools/nsc/symtab/SymbolLoaders.scala
<+>UTF-8
===================================================================
diff --git scala/tools/nsc/symtab/SymbolLoaders.scala scala/tools/nsc/symtab/SymbolLoaders.scala
--- scala/tools/nsc/symtab/SymbolLoaders.scala (revision 38cd84d976880eab16af17a44d186bbddcd554f2)
+++ scala/tools/nsc/symtab/SymbolLoaders.scala (revision 58793f164e13a93ab9114cc30c61a24c12a2277f)
@@ -230,6 +230,10 @@
val currentphase = phase
doComplete(root)
phase = currentphase
+ if (assocFile.underlyingSource.exists(_.isInstanceOf[scala.reflect.io.FileZipArchive])) {
+ val archivePath = assocFile.underlyingSource.map(_.path).headOption.getOrElse("N/A")
+ inform(s"DT:$archivePath")
+ }
informTime("loaded " + description, start)
ok = true
setSource(root)
19 changes: 19 additions & 0 deletions dt_patches/dt_compiler_2.12.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Index: src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
--- scala/tools/nsc/symtab/SymbolLoaders.scala (revision 45183fa6a98f33ce468866a47d50e5508ac28ba5)
+++ scala/tools/nsc/symtab/SymbolLoaders.scala (revision be2326549ffd607c3e57bb245e4c44d124438f21)
@@ -249,6 +249,10 @@
val currentphase = phase
doComplete(root)
phase = currentphase
+ if (assocFile.underlyingSource.exists(_.isInstanceOf[scala.reflect.io.FileZipArchive])) {
+ val archivePath = assocFile.underlyingSource.map(_.path).headOption.getOrElse("N/A")
+ inform(s"DT:$archivePath")
+ }
if (settings.verbose) informTime("loaded " + description, start)
ok = true
setSource(root)
21 changes: 21 additions & 0 deletions dt_patches/dt_compiler_2.13.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Subject: [PATCH] for patch
---
Index: src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git scala/tools/nsc/symtab/SymbolLoaders.scala scala/tools/nsc/symtab/SymbolLoaders.scala
--- scala/tools/nsc/symtab/SymbolLoaders.scala (revision d578a02ea6b41b662072759c82c19f9309a15176)
+++ scala/tools/nsc/symtab/SymbolLoaders.scala (revision 03634634be5aed4ec5053196bfdef102ad349f14)
@@ -244,6 +244,10 @@
currentRunProfilerBeforeCompletion(root, assocFile)
try {
try {
+ if (assocFile.underlyingSource.exists(_.isInstanceOf[scala.reflect.io.FileZipArchive])) {
+ val archivePath = assocFile.underlyingSource.map(_.path).headOption.getOrElse("N/A")
+ inform(s"DT:$archivePath")
+ }
informingProgress("loaded " + description) {
val currentphase = phase
try doComplete(root)
82 changes: 82 additions & 0 deletions dt_patches/dt_patch_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash

dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
NC='\033[0m'
GREEN='\033[0;32m'
RED='\033[0;31m'

run_test_local() {
# runs the tests locally
set +e
SECONDS=0
TEST_ARG=$@
echo "running test $TEST_ARG"
RES=$($TEST_ARG 2>&1)
RESPONSE_CODE=$?
DURATION=$SECONDS
if [ $RESPONSE_CODE -eq 0 ]; then
echo -e "${GREEN} Test \"$TEST_ARG\" successful ($DURATION sec) $NC"
else
echo -e "${RED} Test \"$TEST_ARG\" failed $NC ($DURATION sec) $NC"
return $RESPONSE_CODE
fi
}

run_in_test_repo() {
local test_command=$1

cd "${dir}"/test_dt_patches
${test_command}
RESPONSE_CODE=$?
cd ../..

return $RESPONSE_CODE
}

test_compiler_patch() {
local SCALA_VERSION="$1"

run_in_test_repo "bazel build //... --repo_env=SCALA_VERSION=${SCALA_VERSION} //..."
}

#run_test_local test_compiler_patch 2.11.0
#run_test_local test_compiler_patch 2.11.1
#run_test_local test_compiler_patch 2.11.2
#run_test_local test_compiler_patch 2.11.3
#run_test_local test_compiler_patch 2.11.4
#run_test_local test_compiler_patch 2.11.5
#run_test_local test_compiler_patch 2.11.6
#run_test_local test_compiler_patch 2.11.7
#run_test_local test_compiler_patch 2.11.8
#run_test_local test_compiler_patch 2.11.9
#run_test_local test_compiler_patch 2.11.10
#run_test_local test_compiler_patch 2.11.11
run_test_local test_compiler_patch 2.11.12

#run_test_local test_compiler_patch 2.12.0
run_test_local test_compiler_patch 2.12.1
run_test_local test_compiler_patch 2.12.2
run_test_local test_compiler_patch 2.12.3
run_test_local test_compiler_patch 2.12.4
run_test_local test_compiler_patch 2.12.5
run_test_local test_compiler_patch 2.12.6
run_test_local test_compiler_patch 2.12.7
run_test_local test_compiler_patch 2.12.8
run_test_local test_compiler_patch 2.12.9
run_test_local test_compiler_patch 2.12.10
run_test_local test_compiler_patch 2.12.11
run_test_local test_compiler_patch 2.12.12
run_test_local test_compiler_patch 2.12.13
run_test_local test_compiler_patch 2.12.14
run_test_local test_compiler_patch 2.12.15
run_test_local test_compiler_patch 2.12.16

run_test_local test_compiler_patch 2.13.0
run_test_local test_compiler_patch 2.13.1
run_test_local test_compiler_patch 2.13.2
run_test_local test_compiler_patch 2.13.3
run_test_local test_compiler_patch 2.13.4
run_test_local test_compiler_patch 2.13.5
run_test_local test_compiler_patch 2.13.6
run_test_local test_compiler_patch 2.13.7
run_test_local test_compiler_patch 2.13.8
1 change: 1 addition & 0 deletions dt_patches/test_dt_patches/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.3.1
16 changes: 16 additions & 0 deletions dt_patches/test_dt_patches/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load(
"@io_bazel_rules_scala//scala:scala.bzl",
"setup_scala_toolchain",
)

SCALA_LIBS = [
"@scala_library",
"@scala_reflect",
]

setup_scala_toolchain(
name = "dt_scala_toolchain",
scala_compile_classpath = ["@scala_compiler"] + SCALA_LIBS,
scala_library_classpath = SCALA_LIBS,
scala_macro_classpath = SCALA_LIBS,
)
76 changes: 76 additions & 0 deletions dt_patches/test_dt_patches/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
workspace(name = "test_dt_patches")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

skylib_version = "1.0.3"

http_archive(
name = "bazel_skylib",
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
type = "tar.gz",
url = "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{}/bazel-skylib-{}.tar.gz".format(skylib_version, skylib_version),
)

local_repository(
name = "io_bazel_rules_scala",
path = "../..",
)

load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config(enable_compiler_dependency_tracking = True)

load(
"@io_bazel_rules_scala//scala:scala.bzl",
"rules_scala_setup",
"rules_scala_toolchain_deps_repositories",
)
load(
"@io_bazel_rules_scala//scala:scala_cross_version.bzl",
"default_maven_server_urls",
)
load(
"@io_bazel_rules_scala//scala:scala_maven_import_external.bzl",
"scala_maven_import_external",
)
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSION")

scala_maven_import_external(
name = "scala_library",
artifact = "org.scala-lang:scala-library:%s" % SCALA_VERSION,
licenses = ["notice"],
server_urls = default_maven_server_urls(),
)

scala_maven_import_external(
name = "scala_compiler",
artifact = "org.scala-lang:scala-compiler:%s" % SCALA_VERSION,
licenses = ["notice"],
server_urls = default_maven_server_urls(),
)

scala_maven_import_external(
name = "scala_reflect",
artifact = "org.scala-lang:scala-reflect:%s" % SCALA_VERSION,
licenses = ["notice"],
server_urls = default_maven_server_urls(),
)

rules_scala_setup()

rules_scala_toolchain_deps_repositories(
fetch_sources = True,
validate_scala_version = False,
)

register_toolchains(":dt_scala_toolchain")

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")

rules_proto_dependencies()

rules_proto_toolchains()

load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")

scala_register_toolchains()
7 changes: 7 additions & 0 deletions dt_patches/test_dt_patches/dummy/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library")

scala_library(
name = "dummy",
srcs = ["Dummy.scala"],
visibility = ["//visibility:public"],
)
3 changes: 3 additions & 0 deletions dt_patches/test_dt_patches/dummy/Dummy.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package dummy

class Dummy
1 change: 1 addition & 0 deletions scala/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ setup_scala_toolchain(

setup_scala_toolchain(
name = "unused_dependency_checker_error_toolchain",
dependency_tracking_method = "ast-plus",
scala_compile_classpath = _SCALA_COMPILE_CLASSPATH_DEPS,
scala_library_classpath = _SCALA_LIBRARY_CLASSPATH_DEPS,
scala_macro_classpath = _SCALA_MACRO_CLASSPATH_DEPS,
Expand Down
1 change: 1 addition & 0 deletions scala/private/common_outputs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ common_outputs = {
"manifest": "%{name}_MANIFEST.MF",
"statsfile": "%{name}.statsfile",
"diagnosticsfile": "%{name}.diagnosticsproto",
"scaladepsfile": "%{name}.sdeps",
}
16 changes: 10 additions & 6 deletions scala/private/dependency.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ def new_dependency_info(
dependency_mode,
unused_deps_mode,
strict_deps_mode,
compiler_deps_mode,
dependency_tracking_method):
is_strict_deps_on = strict_deps_mode != "off"
is_unused_deps_on = unused_deps_mode != "off"

need_direct_jars = is_strict_deps_on or is_unused_deps_on
need_direct_targets = is_unused_deps_on

return struct(
dependency_mode = dependency_mode,
need_indirect_info = is_strict_deps_on,
need_direct_jars = need_direct_jars,
need_direct_targets = need_direct_targets,
need_direct_info = need_direct_jars or need_direct_targets,
need_direct_info = is_strict_deps_on or is_unused_deps_on,
dependency_tracking_method = dependency_tracking_method,
unused_deps_mode = unused_deps_mode,
strict_deps_mode = strict_deps_mode,
compiler_deps_mode = compiler_deps_mode,
use_analyzer = is_strict_deps_on or is_unused_deps_on,
)

Expand All @@ -31,6 +28,7 @@ def legacy_unclear_dependency_info_for_protobuf_scrooge(ctx):
dependency_mode = _legacy_unclear_dependency_mode_for_protobuf_scrooge(ctx),
unused_deps_mode = "off",
strict_deps_mode = get_strict_deps_mode(ctx),
compiler_deps_mode = get_compiler_deps_mode(ctx),
dependency_tracking_method = "high-level",
)

Expand All @@ -47,5 +45,11 @@ def get_strict_deps_mode(ctx):

return ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].strict_deps_mode

def get_compiler_deps_mode(ctx):
if not hasattr(ctx.attr, "_dependency_analyzer_plugin"):
return "off"

return ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].compiler_deps_mode

def _is_strict_deps_on(ctx):
return get_strict_deps_mode(ctx) != "off"
Loading