Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Add test w/ tool to read zinc analysis output #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions rules/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,28 @@ ZincInfo = provider(
},
)

def _zinc_info_implementation(ctx):
input = ctx.attr.dep[ZincInfo].analysis
output = ctx.outputs.analysis
ctx.actions.run_shell(
inputs = [input],
outputs = [output],
command = "cp %s %s" % (input.path, output.path),
)

zinc_info = rule(
implementation = _zinc_info_implementation,
attrs = {
"dep": attr.label(
mandatory = True,
providers = [ZincInfo],
),
},
outputs = {
"analysis": "%{name}.gz",
},
)

def _collect(index, entries):
return [
entry[index]
Expand Down
12 changes: 12 additions & 0 deletions rules/scala.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ annex_scala_library = rule(
"deps": attr.label_list(),
"runtime_deps": attr.label_list(),
"exports": attr.label_list(),
"data": attr.label_list(
allow_files = True,
cfg = "data",
),
"scala": attr.label(
default = "@scala",
mandatory = True,
Expand Down Expand Up @@ -72,6 +76,10 @@ annex_scala_binary = rule(
"deps": attr.label_list(),
"runtime_deps": attr.label_list(),
"exports": attr.label_list(),
"data": attr.label_list(
allow_files = True,
cfg = "data",
),
"main_class": attr.string(),
"scala": attr.label(
default = "@scala",
Expand Down Expand Up @@ -106,6 +114,10 @@ annex_scala_test = rule(
"deps": attr.label_list(),
"runtime_deps": attr.label_list(),
"exports": attr.label_list(),
"data": attr.label_list(
allow_files = True,
cfg = "data",
),
"scala": attr.label(
default = "@scala",
mandatory = True,
Expand Down
9 changes: 7 additions & 2 deletions rules/scala/private/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def annex_scala_binary_implementation(ctx):
jvm_flags = [],
)

for entry in ctx.attr.data:
print(dir(entry))
print(entry.files)
data_files = [entry.files for entry in ctx.attr.data]

return struct(
providers = [
res.java_info,
Expand All @@ -37,13 +42,13 @@ def annex_scala_binary_implementation(ctx):
res.intellij_info,
DefaultInfo(
executable = ctx.outputs.bin,
files = depset(files, transitive = [res.files]),
files = depset(files, transitive = [res.files] + data_files),
runfiles = ctx.runfiles(
files = files + [mains_file],
transitive_files = depset(
order = "default",
direct = [ctx.executable._java],
transitive = [java_info.transitive_runtime_deps],
transitive = [java_info.transitive_runtime_deps] + data_files,
),
collect_default = True,
),
Expand Down
37 changes: 37 additions & 0 deletions tests/zinc/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
load(
"@rules_scala_annex//rules:scala.bzl",
"annex_scala_library",
"annex_scala_binary",
)
load(
"@rules_scala_annex//rules:providers.bzl",
"zinc_info",
)

annex_scala_library(
name = "source",
srcs = ["source.scala"],
scala = "@scala_2_12",
)

zinc_info(
name = "source-analysis",
dep = ":source",
)

annex_scala_binary(
name = "tool",
srcs = ["tool.scala"],
args = ["$(location :source-analysis)"],
data = [":source-analysis"],
scala = "@scala_2_12",
runtime_deps = [
"@scala_annex_org_scala_sbt_zinc_core_2_12",
],
deps = [
"@scala_annex_com_trueaccord_scalapb_scalapb_runtime_2_12",
#"@scala_annex_org_scala_sbt_compiler_interface",
#"@scala_annex_org_scala_sbt_zinc_core_2_12",
"@scala_annex_org_scala_sbt_zinc_persist_2_12",
],
)
6 changes: 6 additions & 0 deletions tests/zinc/source.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sealed trait A
sealed trait B extends A
sealed trait C extends B
sealed trait D extends C
sealed trait E extends D
sealed trait F extends E
4 changes: 4 additions & 0 deletions tests/zinc/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -e
. "$(dirname "$0")"/../common.sh

bazel run :tool | grep "inheritance {"
30 changes: 30 additions & 0 deletions tests/zinc/tool.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package anx

import java.nio.file.{Files, Paths}
import java.util.zip.GZIPInputStream
import sbt.internal.inc.schema.AnalysisFile
import sbt.internal.inc.binary.converters.ProtobufReaders
import xsbti.compile.analysis.ReadMapper
import xsbti.compile.FileAnalysisStore

object Tool {
def main(args: Array[String]): Unit =
args.toList match {
case path :: Nil =>
process(path)
case other =>
println(s"bad arguments: $other")
System.exit(-1)
}

private def process(path: String): Unit = {
val stream = Files.newInputStream(Paths.get(path))
val analysisFile = AnalysisFile.parseFrom(new GZIPInputStream(stream))
stream.close()
val readMapper = ReadMapper.getMachineIndependentMapper(Paths.get("."))
val reader = new ProtobufReaders(readMapper)
//val analysis = reader.fromAnalysisFile(analysisFile)
//print(analysis)
print(analysisFile)
}
}