Skip to content

Commit 56bfe4f

Browse files
authored
Tracking implicit compiler dependencies (#1459)
* Patch scala/tools/nsc/symtab/SymbolLoaders.scala and prepend on the compiler classpath to get loaded jars reported. * Patch must be applied only if dependency tracking is enabled (scala_config(enable_compiler_dependency_tracking = True)) * Produce sdeps (named after similar jdeps) with label, jar and usage info to be consumed by tools. Why not jdeps, because it breaks current Intellij support and does not contain label information. jdeps can be easily added later if there's a need. * Aggregation of compiler and analyzer plugins information and reporting happens in custom reporter
1 parent 22f0a80 commit 56bfe4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1078
-102
lines changed

WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ http_archive(
2222

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

25-
scala_config()
25+
scala_config(enable_compiler_dependency_tracking = True)
2626

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

dt_patches/BUILD

Whitespace-only changes.

dt_patches/dt_compiler_2.11.patch

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Subject: [PATCH] for patch
2+
IDEA additional info:
3+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
4+
<+>UTF-8
5+
===================================================================
6+
diff --git scala/tools/nsc/symtab/SymbolLoaders.scala scala/tools/nsc/symtab/SymbolLoaders.scala
7+
--- scala/tools/nsc/symtab/SymbolLoaders.scala (revision 2e2f65a201b0b06e01a39fec4ae232c5b94efcca)
8+
+++ scala/tools/nsc/symtab/SymbolLoaders.scala (revision 21ecced66f88cff2a81a7f69340be63dd0bc9b88)
9+
@@ -210,6 +210,11 @@
10+
val currentphase = phase
11+
doComplete(root)
12+
phase = currentphase
13+
+ val assocFile = root.associatedFile
14+
+ if (assocFile.underlyingSource.exists(_.isInstanceOf[scala.reflect.io.FileZipArchive])) {
15+
+ val archivePath = assocFile.underlyingSource.map(_.path).headOption.getOrElse("N/A")
16+
+ inform(s"DT:$archivePath")
17+
+ }
18+
informTime("loaded " + description, start)
19+
ok = true
20+
setSource(root)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Subject: [PATCH] for patch
2+
---
3+
Index: scala/tools/nsc/symtab/SymbolLoaders.scala
4+
<+>UTF-8
5+
===================================================================
6+
diff --git scala/tools/nsc/symtab/SymbolLoaders.scala scala/tools/nsc/symtab/SymbolLoaders.scala
7+
--- scala/tools/nsc/symtab/SymbolLoaders.scala (revision 8684ae833dcfeac6107343fcca5501301e509eef)
8+
+++ scala/tools/nsc/symtab/SymbolLoaders.scala (revision 74239a150e641ebfe220a6698dbc88c8c3f6f092)
9+
@@ -208,6 +208,11 @@
10+
val currentphase = phase
11+
doComplete(root)
12+
phase = currentphase
13+
+ val assocFile = root.associatedFile
14+
+ if (assocFile.underlyingSource.exists(_.isInstanceOf[scala.reflect.io.FileZipArchive])) {
15+
+ val archivePath = assocFile.underlyingSource.map(_.path).headOption.getOrElse("N/A")
16+
+ inform(s"DT:$archivePath")
17+
+ }
18+
informTime("loaded " + description, start)
19+
ok = true
20+
setSource(root)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Subject: [PATCH] for patch
2+
---
3+
Index: scala/tools/nsc/symtab/SymbolLoaders.scala
4+
<+>UTF-8
5+
===================================================================
6+
diff --git scala/tools/nsc/symtab/SymbolLoaders.scala scala/tools/nsc/symtab/SymbolLoaders.scala
7+
--- scala/tools/nsc/symtab/SymbolLoaders.scala (revision 38cd84d976880eab16af17a44d186bbddcd554f2)
8+
+++ scala/tools/nsc/symtab/SymbolLoaders.scala (revision 58793f164e13a93ab9114cc30c61a24c12a2277f)
9+
@@ -230,6 +230,10 @@
10+
val currentphase = phase
11+
doComplete(root)
12+
phase = currentphase
13+
+ if (assocFile.underlyingSource.exists(_.isInstanceOf[scala.reflect.io.FileZipArchive])) {
14+
+ val archivePath = assocFile.underlyingSource.map(_.path).headOption.getOrElse("N/A")
15+
+ inform(s"DT:$archivePath")
16+
+ }
17+
informTime("loaded " + description, start)
18+
ok = true
19+
setSource(root)

dt_patches/dt_compiler_2.12.patch

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Index: src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
2+
IDEA additional info:
3+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
4+
<+>UTF-8
5+
===================================================================
6+
diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
7+
--- scala/tools/nsc/symtab/SymbolLoaders.scala (revision 45183fa6a98f33ce468866a47d50e5508ac28ba5)
8+
+++ scala/tools/nsc/symtab/SymbolLoaders.scala (revision be2326549ffd607c3e57bb245e4c44d124438f21)
9+
@@ -249,6 +249,10 @@
10+
val currentphase = phase
11+
doComplete(root)
12+
phase = currentphase
13+
+ if (assocFile.underlyingSource.exists(_.isInstanceOf[scala.reflect.io.FileZipArchive])) {
14+
+ val archivePath = assocFile.underlyingSource.map(_.path).headOption.getOrElse("N/A")
15+
+ inform(s"DT:$archivePath")
16+
+ }
17+
if (settings.verbose) informTime("loaded " + description, start)
18+
ok = true
19+
setSource(root)

dt_patches/dt_compiler_2.13.patch

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Subject: [PATCH] for patch
2+
---
3+
Index: src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
4+
IDEA additional info:
5+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
6+
<+>UTF-8
7+
===================================================================
8+
diff --git scala/tools/nsc/symtab/SymbolLoaders.scala scala/tools/nsc/symtab/SymbolLoaders.scala
9+
--- scala/tools/nsc/symtab/SymbolLoaders.scala (revision d578a02ea6b41b662072759c82c19f9309a15176)
10+
+++ scala/tools/nsc/symtab/SymbolLoaders.scala (revision 03634634be5aed4ec5053196bfdef102ad349f14)
11+
@@ -244,6 +244,10 @@
12+
currentRunProfilerBeforeCompletion(root, assocFile)
13+
try {
14+
try {
15+
+ if (assocFile.underlyingSource.exists(_.isInstanceOf[scala.reflect.io.FileZipArchive])) {
16+
+ val archivePath = assocFile.underlyingSource.map(_.path).headOption.getOrElse("N/A")
17+
+ inform(s"DT:$archivePath")
18+
+ }
19+
informingProgress("loaded " + description) {
20+
val currentphase = phase
21+
try doComplete(root)

dt_patches/dt_patch_test.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
3+
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
4+
NC='\033[0m'
5+
GREEN='\033[0;32m'
6+
RED='\033[0;31m'
7+
8+
run_test_local() {
9+
# runs the tests locally
10+
set +e
11+
SECONDS=0
12+
TEST_ARG=$@
13+
echo "running test $TEST_ARG"
14+
RES=$($TEST_ARG 2>&1)
15+
RESPONSE_CODE=$?
16+
DURATION=$SECONDS
17+
if [ $RESPONSE_CODE -eq 0 ]; then
18+
echo -e "${GREEN} Test \"$TEST_ARG\" successful ($DURATION sec) $NC"
19+
else
20+
echo -e "${RED} Test \"$TEST_ARG\" failed $NC ($DURATION sec) $NC"
21+
return $RESPONSE_CODE
22+
fi
23+
}
24+
25+
run_in_test_repo() {
26+
local test_command=$1
27+
28+
cd "${dir}"/test_dt_patches
29+
${test_command}
30+
RESPONSE_CODE=$?
31+
cd ../..
32+
33+
return $RESPONSE_CODE
34+
}
35+
36+
test_compiler_patch() {
37+
local SCALA_VERSION="$1"
38+
39+
run_in_test_repo "bazel build //... --repo_env=SCALA_VERSION=${SCALA_VERSION} //..."
40+
}
41+
42+
#run_test_local test_compiler_patch 2.11.0
43+
#run_test_local test_compiler_patch 2.11.1
44+
#run_test_local test_compiler_patch 2.11.2
45+
#run_test_local test_compiler_patch 2.11.3
46+
#run_test_local test_compiler_patch 2.11.4
47+
#run_test_local test_compiler_patch 2.11.5
48+
#run_test_local test_compiler_patch 2.11.6
49+
#run_test_local test_compiler_patch 2.11.7
50+
#run_test_local test_compiler_patch 2.11.8
51+
#run_test_local test_compiler_patch 2.11.9
52+
#run_test_local test_compiler_patch 2.11.10
53+
#run_test_local test_compiler_patch 2.11.11
54+
run_test_local test_compiler_patch 2.11.12
55+
56+
#run_test_local test_compiler_patch 2.12.0
57+
run_test_local test_compiler_patch 2.12.1
58+
run_test_local test_compiler_patch 2.12.2
59+
run_test_local test_compiler_patch 2.12.3
60+
run_test_local test_compiler_patch 2.12.4
61+
run_test_local test_compiler_patch 2.12.5
62+
run_test_local test_compiler_patch 2.12.6
63+
run_test_local test_compiler_patch 2.12.7
64+
run_test_local test_compiler_patch 2.12.8
65+
run_test_local test_compiler_patch 2.12.9
66+
run_test_local test_compiler_patch 2.12.10
67+
run_test_local test_compiler_patch 2.12.11
68+
run_test_local test_compiler_patch 2.12.12
69+
run_test_local test_compiler_patch 2.12.13
70+
run_test_local test_compiler_patch 2.12.14
71+
run_test_local test_compiler_patch 2.12.15
72+
run_test_local test_compiler_patch 2.12.16
73+
74+
run_test_local test_compiler_patch 2.13.0
75+
run_test_local test_compiler_patch 2.13.1
76+
run_test_local test_compiler_patch 2.13.2
77+
run_test_local test_compiler_patch 2.13.3
78+
run_test_local test_compiler_patch 2.13.4
79+
run_test_local test_compiler_patch 2.13.5
80+
run_test_local test_compiler_patch 2.13.6
81+
run_test_local test_compiler_patch 2.13.7
82+
run_test_local test_compiler_patch 2.13.8
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5.3.1

dt_patches/test_dt_patches/BUILD

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
load(
2+
"@io_bazel_rules_scala//scala:scala.bzl",
3+
"setup_scala_toolchain",
4+
)
5+
6+
SCALA_LIBS = [
7+
"@scala_library",
8+
"@scala_reflect",
9+
]
10+
11+
setup_scala_toolchain(
12+
name = "dt_scala_toolchain",
13+
scala_compile_classpath = ["@scala_compiler"] + SCALA_LIBS,
14+
scala_library_classpath = SCALA_LIBS,
15+
scala_macro_classpath = SCALA_LIBS,
16+
)

0 commit comments

Comments
 (0)