forked from higherkindness/rules_scala
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Make error reporting match that of SBT's #53
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
load("@rules_scala_annex//rules:scala.bzl", "scala_library") | ||
|
||
scala_library( | ||
name = "error_reporting_2_13", | ||
srcs = ["ErrorReporting.scala"], | ||
scala = "//scala:2_13", | ||
tags = ["manual"], | ||
) | ||
|
||
scala_library( | ||
name = "error_reporting_bootstrap_3", | ||
srcs = ["ErrorReporting.scala"], | ||
scala = "//scala:bootstrap_3", | ||
tags = ["manual"], | ||
) | ||
|
||
scala_library( | ||
name = "error_reporting_zinc_3", | ||
srcs = ["ErrorReporting.scala"], | ||
scala = "//scala:zinc_3", | ||
tags = ["manual"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
object Main { | ||
private def printZooAnimals(animals: List[String]): Unit = println(s"The zoo has ${animals.mkString(",")}") | ||
jjudd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def main(arguments: Array[String]): Unit = printZooAnimals(Seq("kangaroos", "giraffes")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
This test is written in Python because Bash makes it unnecessarily difficult to check that the output of a command | ||
includes a multiline string. | ||
""" | ||
|
||
import os | ||
import subprocess | ||
|
||
os.chdir(os.path.dirname(os.path.realpath(__file__))) | ||
|
||
def output_from_failed_build(target: str) -> str: | ||
result = subprocess.run(["bazel", "build", target], stderr=subprocess.PIPE, text=True) | ||
|
||
assert result.returncode != 0 | ||
|
||
return result.stderr | ||
|
||
def string_must_contain(string: str, expected_substring: str): | ||
if expected_substring not in string: | ||
print(f'Expected """{string}""" to contain """{expected_substring}"""') | ||
|
||
assert False | ||
|
||
string_must_contain( | ||
output_from_failed_build(":error_reporting_2_13"), | ||
"""\ | ||
[\x1b[31mError\x1b[0m] zinc/ErrorReporting.scala:4:65: type mismatch; | ||
[\x1b[31mError\x1b[0m] found : Seq[String] | ||
[\x1b[31mError\x1b[0m] required: List[String] | ||
[\x1b[31mError\x1b[0m] def main(arguments: Array[String]): Unit = printZooAnimals(Seq("kangaroos", "giraffes")) | ||
[\x1b[31mError\x1b[0m] ^ | ||
one error found | ||
""" | ||
) | ||
|
||
string_must_contain( | ||
output_from_failed_build(":error_reporting_bootstrap_3"), | ||
"""\ | ||
\x1b[31m\x1b[31m-- [E007] Type Mismatch Error: zinc/ErrorReporting.scala:4:64 ------------------\x1b[0m\x1b[0m | ||
\x1b[31m4 |\x1b[0m \x1b[33mdef\x1b[0m \x1b[36mmain\x1b[0m(\x1b[36marguments\x1b[0m: \x1b[35mArray\x1b[0m[\x1b[35mString\x1b[0m]): \x1b[35mUnit\x1b[0m = printZooAnimals(Seq(\x1b[31m"kangaroos"\x1b[0m, \x1b[31m"giraffes"\x1b[0m)) | ||
\x1b[31m\x1b[31m |\x1b[0m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\x1b[0m | ||
\x1b[31m |\x1b[0m Found: \x1b[1m\x1b[31mSeq\x1b[0m[String] | ||
\x1b[31m |\x1b[0m Required: \x1b[1m\x1b[32mList\x1b[0m[String] | ||
\x1b[31m |\x1b[0m | ||
\x1b[31m |\x1b[0m longer explanation available when compiling with `-explain` | ||
1 error found | ||
""" | ||
) | ||
|
||
string_must_contain( | ||
output_from_failed_build(":error_reporting_zinc_3"), | ||
"""\ | ||
\x1b[31m\x1b[31m-- [E007] Type Mismatch Error: zinc/ErrorReporting.scala:4:64 \x1b[0m\x1b[0m | ||
\x1b[31m4 |\x1b[0m \x1b[33mdef\x1b[0m \x1b[36mmain\x1b[0m(\x1b[36marguments\x1b[0m: \x1b[35mArray\x1b[0m[\x1b[35mString\x1b[0m]): \x1b[35mUnit\x1b[0m = printZooAnimals(Seq(\x1b[31m"kangaroos"\x1b[0m, \x1b[31m"giraffes"\x1b[0m)) | ||
\x1b[31m\x1b[31m |\x1b[0m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\x1b[0m | ||
\x1b[31m |\x1b[0m Found: \x1b[1m\x1b[31mSeq\x1b[0m[String] | ||
\x1b[31m |\x1b[0m Required: \x1b[1m\x1b[32mList\x1b[0m[String] | ||
\x1b[31m |\x1b[0m | ||
\x1b[31m |\x1b[0m longer explanation available when compiling with `-explain` | ||
one error found | ||
""" | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there other other common compiler options that we know of which need a specific path?
This is a tricky issue because in theory there are infinite options which could do so. Even better yet they get specified by the user.
I suppose it's probably just not work thinking about for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought of this when I made this change and did feel slimy modifying compiler options like this, but I think it's better to modify compiler options than pass SemanticDB options separately. My reasoning is that because there are likely many compiler options that reference paths and some of those compiler options may be used outside of this ruleset (by those defining Scala libraries, binaries, tests, etc..), it's much less confusing to intercept compiler options than direct users to use another set of options instead.
I could go through every compiler option that references file paths, but that list is probably endless and I figured we can expand this list as necessary.