├── .bazelignore ├── .bazelrc ├── .bazelrc_shared ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .scalafmt.conf ├── AUTHORS ├── BUILD ├── CONTRIBUTING.md ├── CONTRIBUTORS ├── LICENSE ├── README.md ├── WORKSPACE ├── annex_install.json ├── annex_proto_install.json ├── annex_scalafmt_install.json ├── docs ├── configure_zinc_scala.md ├── newdocs │ ├── macros.md │ ├── phases.md │ ├── scala_versions.md │ └── zinc_flags.md ├── scala.md ├── scalafmt.md ├── stardoc │ ├── external.md │ ├── jvm.md │ ├── providers.md │ ├── rules_scala.md │ ├── scala.md │ ├── scala_proto.md │ ├── scala_with_scalafmt.md │ └── scalafmt.md └── stateful.md ├── rules ├── BUILD ├── common │ ├── BUILD │ └── private │ │ └── utils.bzl ├── external.bzl ├── external │ └── third_party │ │ └── bazel │ │ └── tools │ │ └── build_defs │ │ └── repo │ │ ├── BUILD │ │ └── java.bzl ├── jvm.bzl ├── jvm │ ├── BUILD │ └── private │ │ └── label.bzl ├── private │ ├── BUILD │ ├── coverage_replacements_provider.bzl │ ├── phases.bzl │ └── phases │ │ ├── api.bzl │ │ ├── phase_binary_deployjar.bzl │ │ ├── phase_binary_launcher.bzl │ │ ├── phase_bootstrap_compile.bzl │ │ ├── phase_classpaths.bzl │ │ ├── phase_coda.bzl │ │ ├── phase_coverage_jacoco.bzl │ │ ├── phase_ijinfo.bzl │ │ ├── phase_javainfo.bzl │ │ ├── phase_library_defaultinfo.bzl │ │ ├── phase_noop.bzl │ │ ├── phase_resources.bzl │ │ ├── phase_scalafmt_nondefault_outputs.bzl │ │ ├── phase_singlejar.bzl │ │ ├── phase_test_launcher.bzl │ │ ├── phase_zinc_compile.bzl │ │ └── phase_zinc_depscheck.bzl ├── providers.bzl ├── rules_scala.bzl ├── rules_scala │ ├── BUILD │ └── private │ │ └── compat.bzl ├── scala.bzl ├── scala │ ├── BUILD │ ├── private │ │ ├── doc.bzl │ │ ├── import.bzl │ │ ├── provider.bzl │ │ └── repl.bzl │ └── workspace.bzl ├── scala_proto.bzl ├── scala_proto │ ├── BUILD │ ├── private │ │ ├── ScalaProtoWorker.scala │ │ └── core.bzl │ └── workspace.bzl ├── scala_with_scalafmt.bzl ├── scalafmt.bzl └── scalafmt │ ├── BUILD │ ├── ext.bzl │ ├── private │ ├── format-test.template.sh │ ├── format.template.sh │ └── test.bzl │ ├── scalafmt │ └── ScalafmtRunner.scala │ └── workspace.bzl ├── scripts ├── ci.sh ├── format.sh ├── gen-deps.sh ├── gen-docs.sh ├── prepare-path.sh └── test.sh ├── src └── main │ └── scala │ ├── BUILD │ └── higherkindness │ └── rules_scala │ ├── common │ ├── args │ │ ├── BUILD │ │ └── Implicits.scala │ ├── sbt-testing │ │ ├── AnnexTestingLogger.scala │ │ ├── BUILD │ │ ├── CLassLoaders.scala │ │ ├── JUnitXmlReporter.scala │ │ ├── PrefixedTestingLogger.scala │ │ ├── SubprocessRunner.scala │ │ ├── Test.scala │ │ ├── TestRequest.scala │ │ └── fingerprints.scala │ └── worker │ │ ├── BUILD │ │ └── WorkerMain.scala │ └── workers │ ├── bloop │ └── compile │ │ ├── BUILD │ │ └── BloopRunner.scala │ ├── common │ ├── AnnexLogger.scala │ ├── AnnexScalaInstance.scala │ ├── BUILD │ ├── Color.scala │ ├── CommonArguments.scala │ ├── FileUtil.scala │ └── LoggedReporter.scala │ ├── deps │ ├── BUILD │ └── DepsRunner.scala │ ├── jacoco │ └── instrumenter │ │ ├── BUILD │ │ └── JacocoInstrumenter.scala │ └── zinc │ ├── compile │ ├── AnalysisStore.scala │ ├── BUILD │ ├── Deps.scala │ ├── ZincPersistence.scala │ └── ZincRunner.scala │ ├── doc │ ├── BUILD │ └── DocRunner.scala │ ├── repl │ ├── BUILD │ └── ReplRunner.scala │ └── test │ ├── BUILD │ ├── TestDiscovery.scala │ ├── TestFrameworkRunner.scala │ └── TestRunner.scala ├── tests ├── .bazelrc ├── .scalafmt.conf ├── BUILD ├── WORKSPACE ├── annex_test_install.json ├── binary │ ├── reflect │ │ ├── BUILD │ │ ├── Reflect.scala │ │ └── test │ ├── resource │ │ ├── BUILD │ │ ├── example.scala │ │ ├── example.txt │ │ └── test │ └── simple │ │ ├── BUILD │ │ ├── one_discovered.scala │ │ └── test ├── bloop │ └── simple │ │ ├── BUILD │ │ ├── bazel.rc │ │ ├── test │ │ └── welcome_to_bloop.scala ├── common.sh ├── compat │ ├── ported_tests │ │ ├── BUILD │ │ ├── Exported.scala │ │ ├── HelloLib.scala │ │ ├── HelloLibTest.scala │ │ ├── HelloLibTest2.scala │ │ ├── MacroTest.scala │ │ ├── NOTICE │ │ ├── OtherJavaLib.java │ │ ├── OtherLib.scala │ │ ├── Runtime.scala │ │ ├── ScalaBinary.scala │ │ └── test │ └── scalacopts │ │ ├── BUILD │ │ ├── Deprecated.scala │ │ └── test ├── compile │ ├── error │ │ ├── BUILD │ │ ├── Example.scala │ │ └── test │ ├── log_level │ │ ├── BUILD │ │ ├── Example.scala │ │ └── test │ ├── logger │ │ ├── BUILD │ │ ├── Example.scala │ │ └── test │ ├── srcjar │ │ ├── .gitignore │ │ ├── BUILD │ │ ├── Example.scala │ │ ├── expected │ │ └── test │ ├── xml │ │ ├── BUILD │ │ ├── Main.scala │ │ └── test │ └── zinc-inc │ │ ├── BUILD │ │ └── test ├── coverage │ ├── A1.scala │ ├── A2.scala │ ├── B1.scala │ ├── B2.java │ ├── BUILD │ ├── C2.scala │ ├── TestAll.scala │ ├── TestB2.java │ ├── expected-test-all-coverage.dat │ ├── expected-test-b2-coverage.dat │ └── test ├── dependencies │ ├── diamond │ │ ├── A.scala │ │ ├── B1.scala │ │ ├── B2.scala │ │ ├── BUILD │ │ ├── C.scala │ │ └── test │ ├── indirect │ │ ├── A.scala │ │ ├── B.scala │ │ ├── BUILD │ │ ├── C.scala │ │ └── test │ ├── neverlink │ │ ├── BUILD │ │ ├── Binary.scala │ │ ├── Library.scala │ │ └── test │ └── unused │ │ ├── 0_unused.scala │ │ ├── 0_used.scala │ │ ├── BUILD │ │ ├── indirect_unused.scala │ │ └── test ├── deployjar │ ├── BUILD │ ├── TestBinary.scala │ ├── TestClass.scala │ ├── expected │ └── test ├── format │ └── scalafmt │ │ ├── BUILD │ │ ├── formatted.scala │ │ ├── test │ │ ├── unformatted.scala │ │ ├── unformatted.template.scala │ │ ├── utf8-formatted.scala │ │ └── utf8-unformatted.template.scala ├── mockutil │ ├── BUILD.bazel │ └── MockLib.scala ├── plugins │ ├── classpath │ │ ├── BUILD │ │ ├── plugin-lib.scala │ │ ├── plugin.scala │ │ ├── test │ │ └── usage.scala │ ├── kind-projector │ │ ├── BUILD │ │ ├── KindProjector.scala │ │ └── test │ ├── macros │ │ ├── BUILD │ │ ├── Macro.scala │ │ ├── MacroOnly.scala │ │ ├── MacroUtil.scala │ │ ├── TestMacro.scala │ │ ├── TestMacroOnly.scala │ │ └── test │ └── outputs │ │ ├── BUILD │ │ ├── plugin.scala │ │ ├── rules.bzl │ │ ├── test │ │ └── usage.scala ├── proto │ ├── BUILD │ ├── expected_one │ ├── expected_zero │ ├── one.proto │ ├── test │ └── zero.proto ├── providers │ ├── BUILD │ ├── build.bzl │ └── test ├── repl │ └── simple │ │ ├── BUILD │ │ ├── Example.scala │ │ └── test ├── resources │ ├── maven │ │ ├── BUILD │ │ ├── expected │ │ ├── src │ │ │ └── main │ │ │ │ └── resources │ │ │ │ └── example.txt │ │ └── test │ ├── plain │ │ ├── BUILD │ │ ├── example │ │ │ └── example.txt │ │ ├── expected_merged │ │ ├── expected_plain │ │ └── test │ ├── prefix │ │ ├── BUILD │ │ ├── example │ │ │ └── example.txt │ │ ├── expected │ │ └── test │ └── reference_conf │ │ ├── BUILD │ │ ├── example │ │ └── example.txt │ │ ├── expected_plain │ │ ├── reference.conf │ │ └── test ├── scala │ ├── BUILD │ ├── scalaimport │ │ ├── BUILD │ │ ├── scalaimport.scala │ │ └── test │ └── typelevel │ │ ├── BUILD │ │ ├── Example.scala │ │ └── test ├── scalacopts │ └── rule │ │ ├── BUILD │ │ ├── Deprecated.scala │ │ └── test ├── scaladoc │ ├── A.scala │ ├── B.scala │ ├── BUILD │ └── test ├── strategy │ ├── local │ │ ├── BUILD │ │ ├── bazel │ │ ├── bazel.rc │ │ ├── code.scala │ │ └── test │ └── worker_extra_flag │ │ ├── BUILD │ │ ├── bazel.rc │ │ ├── code.scala │ │ └── test ├── tagging │ ├── A.scala │ ├── BUILD │ └── test ├── test-frameworks │ ├── classpath │ │ ├── BUILD │ │ ├── ContextTest.scala │ │ ├── Test.scala │ │ └── test │ ├── isolation │ │ ├── BUILD │ │ ├── Global.scala │ │ ├── Test.scala │ │ ├── TestJvm.scala │ │ └── test │ └── mixed │ │ ├── BUILD │ │ ├── junit.scala │ │ ├── scalacheck.scala │ │ ├── scalatest.scala │ │ ├── specs2.scala │ │ └── test ├── tools │ └── bazel └── workspace.bzl ├── third_party └── bazel │ └── src │ ├── java_tools │ └── buildjar │ │ └── java │ │ └── com │ │ └── google │ │ └── devtools │ │ └── build │ │ └── buildjar │ │ └── jarhelper │ │ ├── BUILD │ │ ├── JarCreator.java │ │ └── JarHelper.java │ └── main │ └── protobuf │ ├── BUILD │ └── worker_protocol.proto └── tools └── bazel /.bazelignore: -------------------------------------------------------------------------------- 1 | tests/ 2 | external-tools/ 3 | -------------------------------------------------------------------------------- /.bazelrc: -------------------------------------------------------------------------------- 1 | common --config=rules 2 | import %workspace%/.bazelrc_shared 3 | -------------------------------------------------------------------------------- /.bazelrc_shared: -------------------------------------------------------------------------------- 1 | common --announce_rc 2 | common --color=yes 3 | 4 | build --experimental_strict_action_env 5 | build --javacopt="-source 8 -target 8" 6 | 7 | build --strategy=ScalaCompile=worker 8 | build --worker_max_instances=4 9 | build --worker_sandboxing 10 | build --verbose_failures 11 | 12 | test --test_output=all 13 | 14 | build:rules --disk_cache=.bazel_cache 15 | build:tests --disk_cache=../.bazel_cache 16 | 17 | common:rules_v3.2 --config=noop 18 | common:rules_v3.3 --config=noop 19 | 20 | # route potentially unrouted configs to a terminating noop config 21 | # it's a noop because we use the default value 22 | common:rules --config=noop 23 | common:tests --config=noop 24 | common:v3.2 --config=rules_v3.2 25 | common:v3.3 --config=rules_v3.3 26 | 27 | # pick something trivial as a "noop" 28 | common:noop --logging=3 29 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | pull_request: 4 | push: 5 | branches: 6 | - master 7 | jobs: 8 | build-lint-and-test: 9 | runs-on: ${{ matrix.os }} 10 | env: 11 | BAZEL_VERSION: ${{ matrix.bazel_version }} 12 | strategy: 13 | matrix: 14 | os: [ubuntu-18.04, macos-10.15] 15 | bazel_version: [3.2.0, 3.3.0] 16 | steps: 17 | - uses: actions/checkout@v2 18 | - run: ./scripts/ci.sh build 19 | - run: ./scripts/ci.sh lint 20 | - run: ./scripts/ci.sh test 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bazel-* 2 | *.gen.scala 3 | *.swp 4 | *.idea 5 | hash1 6 | hash2 7 | .DS_store 8 | .bazel_cache 9 | /external-tools/ 10 | target/ 11 | 12 | !bazel-*.rc 13 | 14 | # Ignore files generated by IDEs. 15 | /.classpath 16 | /.factorypath 17 | /.idea/ 18 | /.ijwb/ 19 | /.project 20 | /.settings 21 | /.vscode/ 22 | /bazel.iml 23 | -------------------------------------------------------------------------------- /.scalafmt.conf: -------------------------------------------------------------------------------- 1 | align.openParenCallSite = false 2 | align.openParenDefnSite = false 3 | continuationIndent.defnSite = 2 4 | danglingParentheses = true 5 | docstrings = JavaDoc 6 | importSelectors = singleLine 7 | maxColumn = 120 8 | verticalMultiline.newlineBeforeImplicitKW = true 9 | rewrite.redundantBraces.stringInterpolation = true 10 | rewrite.rules = [ 11 | RedundantParens, 12 | PreferCurlyFors, 13 | SortImports 14 | ] 15 | unindentTopLevelOperators = false 16 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of rules_scala authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | 5 | # Names should be added to this file as: 6 | # Name or Organization 7 | # The email address is not required for organizations. 8 | 9 | Andy Scott 10 | -------------------------------------------------------------------------------- /BUILD: -------------------------------------------------------------------------------- 1 | load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier") 2 | 3 | buildifier( 4 | name = "buildifier", 5 | ) 6 | 7 | buildifier( 8 | name = "buildifier_check", 9 | mode = "check", 10 | ) 11 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing guidelines 2 | 3 | Contributions should follow the [principals](../README.md#principals) of rules_scala_annex. 4 | 5 | ## Documentation 6 | 7 | To generate the [Stardoc](https://github.com/bazelbuild/skydoc), 8 | 9 | ``` 10 | $ ./scripts/gen-docs.sh 11 | ``` 12 | 13 | ## Formatting 14 | 15 | [Buildifier](https://github.com/bazelbuild/buildtools/blob/master/buildifier) is used to format Skylark files, 16 | and [Scalafmt](https://scalameta.org/scalafmt/) is used to format Scala files. To run them, 17 | 18 | ``` 19 | $ ./scripts/format.sh 20 | ``` 21 | 22 | ## Maven deps 23 | 24 | [rules_jvm_external](https://github.com/bazelbuild/rules_jvm_external) is used to generate maven deps. If you need to change 25 | dependencies, modify `maven_install` in the following different `workspace.bzl` files 26 | 27 | ``` 28 | rules/scala/workspace.bzl 29 | rules/scala_proto/workspace.bzl 30 | rules/scalafmt/workspace.bzl 31 | tests/workspace.bzl 32 | ``` 33 | To reference the dependency, use the `name` attribute of the `maven_install` rule as the repository name and the versionless dependency as the target. E.g. `@//:`. 34 | 35 | For example, if you'd like to add `org.scala-sbt:compiler-interface:1.2.1` as a dependency, simply add it to the `artifacts` list in `maven_install` with the attribute `name = "annex"`, and then refer to it with `@annex//:org_scala_sbt_compiler_interface`. 36 | 37 | ``` 38 | maven_install( 39 | name = "annex", 40 | artifacts = [ 41 | "org.scala-sbt:compiler-interface:1.2.1", 42 | ], 43 | repositories = [ 44 | "https://repo.maven.apache.org/maven2", 45 | ], 46 | ) 47 | ``` 48 | 49 | ## Tests 50 | 51 | Tests are bash shell scripts that may be run individually or together. 52 | rules_scala_annex is tested on Ubuntu and OS X for the most recent thee minor versions of Bazel. 53 | 54 | ``` 55 | $ # runs all tests 56 | $ ./scripts/test.sh 57 | ``` 58 | 59 | ``` 60 | $ # runs all tests in tests/dependencies/ 61 | $ ./scripts/test.sh tests/dependencies/ 62 | ``` 63 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # People who have agreed to one of the CLAs and can contribute patches. 2 | # The AUTHORS file lists the copyright holders; this file 3 | # lists people. 4 | # 5 | # https://developers.google.com/open-source/cla/individual 6 | # https://developers.google.com/open-source/cla/corporate 7 | # 8 | # Names should be added to this file as: 9 | # Name 10 | 11 | Andy Scott 12 | Bor Kae Hwang 13 | Igal Tabachnik 14 | James Judd 15 | James Judd 16 | Jared Neil 17 | Paul Draper 18 | Paul Draper 19 | borkaehw 20 | jvican 21 | 22 | # 23 | # this was generated with: 24 | # git log --format='%aN <%aE>' | grep -v 'users.noreply.github.com>$' | sort | uniq rules_scala/git/master + 25 | -------------------------------------------------------------------------------- /docs/newdocs/macros.md: -------------------------------------------------------------------------------- 1 | ## Macros and ijars 2 | 3 | Using [ijar](https://github.com/bazelbuild/bazel/tree/master/third_party/ijar) poses a challenge in Scala because Scala macros are resolved during compilation. If a Scala macro references methods stripped away by ijar, things break. 4 | However, forgoing `ijar` use altogether is sub-optimal---using `ijar` dramatically decreases unnecessary recompilation between builds. 5 | 6 | `higherkindness/rules_scala` strives to optimally integrate `ijar` and Scala macros as follows: 7 | 8 | 1. `scala_library`, `scala_binary`, and `scala_test` have a Boolean `macro` attribute which must be set to true if the rule contains any Scala macros 9 | 2. During the classpath resolution phase, we set `macro_classpath` to contain the transitive runtime classpaths of all `deps` for which `macro = true` 10 | 3. We let `JavaInfo` always use `ijar` 11 | * If `macro` was false, we get useful ijars 12 | * If `macro` was true, we get problematic ijars; however, this won't be an issue: 13 | 4. During compilation, we have `macro_classpath` precede the compile classpath of the merged `JavaInfo`, forcing the compiler to use the full classes 14 | 15 | This lets us make use of ijars as much as possible, without breaking things due to Scala macro usage. -------------------------------------------------------------------------------- /docs/newdocs/phases.md: -------------------------------------------------------------------------------- 1 | ## Phases 2 | 3 | Most rules in `higherkindness/rules_scala` are architected using phases. Phases break down the Bazel Analysis stage into logical chunks. 4 | For example, the implementation of `scala_binary` is: 5 | 6 | ```python 7 | def _scala_binary_implementation(ctx): 8 | return _run_phases(ctx, [ 9 | ("resources", _phase_resources), 10 | ("classpaths", _phase_classpaths), 11 | ("javainfo", _phase_javainfo), 12 | ("compile", _phase_noop), 13 | ("singlejar", _phase_singlejar), 14 | ("coverage", _phase_coverage_jacoco), 15 | ("ijinfo", _phase_ijinfo), 16 | ("binary_deployjar", _phase_binary_deployjar), 17 | ("binary_launcher", _phase_binary_launcher), 18 | ("coda", _phase_coda), 19 | ]).coda 20 | ``` 21 | The `_run_phases` method does two things: 22 | 23 | * First, it checks for any phase alternations. New phases can be insterted before, after, or instead of an existing phase (more on this [below](#customizing-the-core-rules)) 24 | * Then, the phases are evaluated one at a time. Providers returned by each phase are available to all following phases. 25 | 26 | ## Customizing the core rules 27 | 28 | _NOTE: This is a work in progress_ 29 | 30 | Bazel scala annex allows users to customize `scala_binary`, `scala_library`, and `scala_test` by adding/replacing [phases](#phases). 31 | Each of these rules has a corresponding `make_(*extras)` method which takes as arguments a list of of extra config items. 32 | 33 | For an example of this in action, see [/rules/scala_with_scalafmt.bzl](/rules/scala_with_scalafmt.bzl) and [/rules/scalafmt/ext.blz](/rules/scalafmt/ext.bzl) -------------------------------------------------------------------------------- /docs/newdocs/zinc_flags.md: -------------------------------------------------------------------------------- 1 | ## Pass flags to Zinc compiler 2 | 3 | ### Persistence Directory Path 4 | Use `--persistence_dir` to specify the path to save Zinc state files. 5 | 6 | ### Use Persistence Directory 7 | Use `--use_persistence` to enable or disable the persistence directory. The default is `true`. 8 | 9 | ### Maximum Error Number 10 | Use `--max_errors` to specify the number of errors to be shown from Zinc. The default is `10`. 11 | 12 | ## Example 13 | In `.bazelrc` file, add the following snippet 14 | ```sh 15 | build --worker_extra_flag=ScalaCompile=--persistence_dir=bazel-zinc 16 | build --worker_extra_flag=ScalaCompile=--use_persistence=true 17 | build --worker_extra_flag=ScalaCompile=--max_errors=20 18 | ``` 19 | -------------------------------------------------------------------------------- /docs/scalafmt.md: -------------------------------------------------------------------------------- 1 | # Scalafmt 2 | 3 | Create .scalafmt.conf at the repo root (may be empty). And add to the WORKSPACE 4 | 5 | ```python 6 | load("@rules_scala_annex//rules/scalafmt:workspace.bzl", "scalafmt_repositories", "scalafmt_default_config") 7 | scalafmt_repositories() 8 | scalafmt_default_config() 9 | ``` 10 | 11 | And in BUILD 12 | 13 | ```python 14 | load("@rules_scala_annex//rules:scalafmt.bzl", "scala_format_test") 15 | scala_format_test( 16 | name = "format", 17 | srcs = glob(["**/*.scala"]), 18 | ) 19 | ``` 20 | 21 | Then 22 | 23 | ``` 24 | # check format, with diffs and non-zero exit in case of differences 25 | $ bazel test :format 26 | 27 | # format files in-place 28 | $ bazel run :format 29 | ``` 30 | -------------------------------------------------------------------------------- /docs/stardoc/external.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ## scala_import_external 6 | 7 |
 8 | scala_import_external(rule_load, kwargs)
 9 | 
10 | 11 | 12 | 13 | ### Parameters 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 28 | 29 | 32 | 33 | 34 |
rule_load 24 | optional. default is "load(\"@rules_scala_annex//rules:scala.bzl\", \"scala_import\")" 25 |
kwargs 30 | optional. 31 |
35 | 36 | 37 | 38 | 39 | ## scala_maven_import_external 40 | 41 |
42 | scala_maven_import_external(artifact, server_urls, rule_load, kwargs)
43 | 
44 | 45 | 46 | 47 | ### Parameters 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 60 | 61 | 62 | 63 | 66 | 67 | 68 | 69 | 72 | 73 | 74 | 75 | 78 | 79 | 80 |
artifact 58 | required. 59 |
server_urls 64 | required. 65 |
rule_load 70 | optional. default is "load(\"@rules_scala_annex//rules:scala.bzl\", \"scala_import\")" 71 |
kwargs 76 | optional. 77 |
81 | 82 | 83 | -------------------------------------------------------------------------------- /docs/stardoc/jvm.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /docs/stardoc/rules_scala.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ## emulate_rules_scala_repository 6 | 7 |
 8 | emulate_rules_scala_repository(name, extra_deps)
 9 | 
10 | 11 | 12 | 13 | ### Attributes 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 29 | 30 | 31 | 32 | 35 | 36 | 37 |
name 24 | Name; required 25 |

26 | A unique name for this repository. 27 |

28 |
extra_deps 33 | List of labels; optional 34 |
38 | 39 | 40 | 41 | 42 | ## emulate_rules_scala 43 | 44 |
45 | emulate_rules_scala(scala, scalatest, extra_deps)
46 | 
47 | 48 | 49 | 50 | ### Parameters 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 63 | 64 | 65 | 66 | 69 | 70 | 71 | 72 | 75 | 76 | 77 |
scala 61 | required. 62 |
scalatest 67 | required. 68 |
extra_deps 73 | optional. default is [] 74 |
78 | 79 | 80 | -------------------------------------------------------------------------------- /docs/stardoc/scalafmt.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ## scala_format_test 6 | 7 |
 8 | scala_format_test(name, config, srcs)
 9 | 
10 | 11 | 12 | 13 | ### Attributes 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 29 | 30 | 31 | 32 | 38 | 39 | 40 | 41 | 47 | 48 | 49 |
name 24 | Name; required 25 |

26 | A unique name for this target. 27 |

28 |
config 33 | Label; optional 34 |

35 | The Scalafmt configuration file. 36 |

37 |
srcs 42 | List of labels; optional 43 |

44 | The Scala files. 45 |

46 |
50 | 51 | 52 | -------------------------------------------------------------------------------- /docs/stateful.md: -------------------------------------------------------------------------------- 1 | # Stateful compilation 2 | 3 | Beyond the normal per-target incremental compilation, [Zinc](https://github.com/sbt/zinc) can achieve even finer-grained 4 | compilation by reusing dependency information collected on previous runs. 5 | 6 | Stateful compilers like Zinc [operate outside](https://groups.google.com/forum/#!topic/bazel-discuss/3iUy5jxS3S0) the 7 | Bazel paradigm, and Bazel cannot enforce correctness. Technically, this caveat applies to all worker strategies: 8 | performance is improving by maintaining state, but improper state may be shared across actions. In Zinc's case, the risk 9 | is higher, because the sharing is (intentionally) aggressive. 10 | 11 | To enable Zinc's stateful compilation, add 12 | 13 | ``` 14 | --worker_extra_flag=ScalaCompile=--persistence_dir=.bazel-zinc 15 | ``` 16 | 17 | Additionally, intermediate inputs to compilation can be cached, for a significant performance benefit in some cases, by 18 | ``` 19 | --worker_extra_flag=ScalaCompile=--extracted_file_cache=.bazel-zinc-outputs 20 | ``` 21 | -------------------------------------------------------------------------------- /rules/BUILD: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 2 | load("@bazel_skylib//lib:paths.bzl", "paths") 3 | load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar") 4 | load("@io_bazel_skydoc//stardoc:stardoc.bzl", "stardoc") 5 | 6 | [ 7 | stardoc( 8 | name = paths.replace_extension(file, "_doc").replace("/", "_"), 9 | out = paths.replace_extension(file, ".md").replace("/", "_"), 10 | input = file, 11 | deps = [ 12 | ":bzl_internal", 13 | "@rules_scala_annex//rules:bzl", 14 | ], 15 | ) 16 | for file in glob(["**/*.bzl"]) 17 | ] 18 | 19 | pkg_tar( 20 | name = "docs", 21 | srcs = [paths.replace_extension(file, ".md").replace("/", "_") for file in glob(["**/*.bzl"])], 22 | mode = "0644", 23 | ) 24 | 25 | bzl_library( 26 | name = "bzl", 27 | srcs = glob(["**/*.bzl"]), 28 | visibility = ["//visibility:public"], 29 | deps = [":private_bzl"], 30 | ) 31 | 32 | # Bizzaro @rules_scala_annex// vs // differences 33 | bzl_library( 34 | name = "bzl_internal", 35 | srcs = glob(["**/*.bzl"]), 36 | visibility = ["//visibility:public"], 37 | deps = [":private_bzl"], 38 | ) 39 | 40 | bzl_library( 41 | name = "jdk_toolchain_utils", 42 | srcs = ["@bazel_tools//tools/jdk:toolchain_utils.bzl"], 43 | ) 44 | 45 | bzl_library( 46 | name = "private_bzl", 47 | srcs = [ 48 | "//rules/common:bzl", 49 | "//rules/external/third_party/bazel/tools/build_defs/repo:bzl", 50 | "//rules/jvm:bzl", 51 | "//rules/private:bzl", 52 | "//rules/scala:bzl", 53 | "//rules/scala_proto:bzl", 54 | "//rules/scalafmt:bzl", 55 | ], 56 | deps = [ 57 | ":jdk_toolchain_utils", 58 | "@bazel_skylib//lib:dicts", 59 | "@bazel_skylib//lib:paths", 60 | ], 61 | ) 62 | -------------------------------------------------------------------------------- /rules/common/BUILD: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "bzl", 3 | srcs = glob(["**/*.bzl"]), 4 | visibility = ["//rules:__pkg__"], 5 | ) 6 | -------------------------------------------------------------------------------- /rules/external.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "//rules/external/third_party/bazel/tools/build_defs/repo:java.bzl", 3 | _jvm_import_external = "jvm_import_external", 4 | _jvm_maven_import_external = "jvm_maven_import_external", 5 | ) 6 | 7 | def scala_maven_import_external( 8 | artifact, 9 | server_urls, 10 | rule_load = "load(\"@rules_scala_annex//rules:scala.bzl\", \"scala_import\")", 11 | **kwargs): 12 | _jvm_maven_import_external( 13 | rule_name = "scala_import", 14 | rule_load = rule_load, 15 | artifact = artifact, 16 | server_urls = server_urls, 17 | #additional string attributes' values have to be escaped in order to accomodate non-string types 18 | # additional_rule_attrs = {"foo": "'bar'"}, 19 | **kwargs 20 | ) 21 | 22 | def scala_import_external( 23 | rule_load = "load(\"@rules_scala_annex//rules:scala.bzl\", \"scala_import\")", 24 | **kwargs): 25 | _jvm_import_external( 26 | rule_name = "scala_import", 27 | rule_load = rule_load, 28 | **kwargs 29 | ) 30 | -------------------------------------------------------------------------------- /rules/external/third_party/bazel/tools/build_defs/repo/BUILD: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "bzl", 3 | srcs = glob(["**/*.bzl"]), 4 | visibility = ["//rules:__pkg__"], 5 | ) 6 | -------------------------------------------------------------------------------- /rules/jvm.bzl: -------------------------------------------------------------------------------- 1 | load("//rules/jvm:private/label.bzl", _labeled_jars_implementation = "labeled_jars_implementation") 2 | 3 | # For bedtime reading: 4 | # https://github.com/bazelbuild/bazel/issues/4584 5 | # https://groups.google.com/forum/#!topic/bazel-discuss/mt2llfwzmac 6 | 7 | labeled_jars = aspect( 8 | implementation = _labeled_jars_implementation, 9 | attr_aspects = ["deps"], # assumption 10 | ) 11 | -------------------------------------------------------------------------------- /rules/jvm/BUILD: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "bzl", 3 | srcs = glob(["**/*.bzl"]), 4 | visibility = ["//rules:__pkg__"], 5 | ) 6 | -------------------------------------------------------------------------------- /rules/jvm/private/label.bzl: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:providers.bzl", "LabeledJars") 2 | 3 | def labeled_jars_implementation(target, ctx): 4 | if JavaInfo not in target: 5 | return [] 6 | 7 | deps_labeled_jars = [dep[LabeledJars] for dep in getattr(ctx.rule.attr, "deps", []) if LabeledJars in dep] 8 | java_info = target[JavaInfo] 9 | return [ 10 | LabeledJars( 11 | values = depset( 12 | [struct(label = ctx.label, jars = depset(transitive = [java_info.compile_jars, java_info.full_compile_jars]))], 13 | order = "preorder", 14 | transitive = [labeled_jars.values for labeled_jars in deps_labeled_jars], 15 | ), 16 | ), 17 | ] 18 | -------------------------------------------------------------------------------- /rules/private/BUILD: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "bzl", 3 | srcs = glob(["**/*.bzl"]), 4 | visibility = ["//rules:__pkg__"], 5 | ) 6 | -------------------------------------------------------------------------------- /rules/private/coverage_replacements_provider.bzl: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//lib:dicts.bzl", _dicts = "dicts") 2 | 3 | # 4 | # Coverage Replacements are a mapping of normal compiled artifacts to 5 | # instrumented compiled artifacts. 6 | # 7 | # The intention is that the final test runner inspects the test 8 | # classpath and replaces artifacts by any mappings found in the 9 | # `replacements` field. 10 | # 11 | # Rules producing replacement artifacts should _not_ link the 12 | # replacement files as any of the default outputs via DefaultInfo, 13 | # JavaInfo, etc. This way, actions producing the replacement artifacts 14 | # will be executed on an as needed basis. 15 | # 16 | # Coverage Replacements use a provider and a helper aspect to 17 | # aggregate replacements files across the dependency graph. 18 | # 19 | # Under the hood, two providers are needed because Bazel doesn't allow 20 | # duplicate providers. All we really want is semigroupal <> like 21 | # behavior over `replacements` as we fold the dependency graph. 22 | # 23 | 24 | _CoverageReplacements = provider( 25 | fields = { 26 | "replacements": "hash of files to swap out", 27 | }, 28 | ) 29 | 30 | _CombinedCoverageReplacements = provider( 31 | fields = { 32 | "replacements": "hash of files to swap out", 33 | }, 34 | ) 35 | 36 | # the attributes used to form the dependency graph that we'll fold 37 | # over for our aggregation 38 | _dependency_attributes = [ 39 | "deps", 40 | "exports", 41 | ] 42 | 43 | def _combine(*entriess, base = {}): 44 | return _CombinedCoverageReplacements(replacements = _dicts.add(base, *( 45 | [ 46 | entry[_CoverageReplacements].replacements 47 | for entries in entriess 48 | for entry in entries 49 | if _CoverageReplacements in entry 50 | ] + [ 51 | entry[_CombinedCoverageReplacements].replacements 52 | for entries in entriess 53 | for entry in entries 54 | if _CombinedCoverageReplacements in entry 55 | ] 56 | ))) 57 | 58 | def _from_ctx(ctx, base = {}): 59 | return _combine( 60 | base = base, 61 | *[getattr(ctx.attr, name, []) for name in _dependency_attributes] 62 | ) 63 | 64 | def _aspect_impl(target, ctx): 65 | if JavaInfo not in target: 66 | return [] 67 | else: 68 | return [_from_ctx(ctx.rule)] 69 | 70 | _aspect = aspect( 71 | attr_aspects = _dependency_attributes, 72 | implementation = _aspect_impl, 73 | ) 74 | 75 | coverage_replacements_provider = struct( 76 | aspect = _aspect, 77 | dependency_attributes = _dependency_attributes, 78 | combine = _combine, 79 | from_ctx = _from_ctx, 80 | create = _CoverageReplacements, 81 | ) 82 | -------------------------------------------------------------------------------- /rules/private/phases.bzl: -------------------------------------------------------------------------------- 1 | load(":phases/api.bzl", _adjust_phases = "adjust_phases", _run_phases = "run_phases") 2 | load(":phases/phase_binary_deployjar.bzl", _phase_binary_deployjar = "phase_binary_deployjar") 3 | load(":phases/phase_binary_launcher.bzl", _phase_binary_launcher = "phase_binary_launcher") 4 | load(":phases/phase_bootstrap_compile.bzl", _phase_bootstrap_compile = "phase_bootstrap_compile") 5 | load(":phases/phase_classpaths.bzl", _phase_classpaths = "phase_classpaths") 6 | load(":phases/phase_coda.bzl", _phase_coda = "phase_coda") 7 | load(":phases/phase_coverage_jacoco.bzl", _phase_coverage_jacoco = "phase_coverage_jacoco") 8 | load(":phases/phase_ijinfo.bzl", _phase_ijinfo = "phase_ijinfo") 9 | load(":phases/phase_javainfo.bzl", _phase_javainfo = "phase_javainfo") 10 | load(":phases/phase_library_defaultinfo.bzl", _phase_library_defaultinfo = "phase_library_defaultinfo") 11 | load(":phases/phase_noop.bzl", _phase_noop = "phase_noop") 12 | load(":phases/phase_resources.bzl", _phase_resources = "phase_resources") 13 | load(":phases/phase_scalafmt_nondefault_outputs.bzl", _phase_scalafmt_nondefault_outputs = "phase_scalafmt_nondefault_outputs") 14 | load(":phases/phase_singlejar.bzl", _phase_singlejar = "phase_singlejar") 15 | load(":phases/phase_test_launcher.bzl", _phase_test_launcher = "phase_test_launcher") 16 | load(":phases/phase_zinc_compile.bzl", _phase_zinc_compile = "phase_zinc_compile") 17 | load(":phases/phase_zinc_depscheck.bzl", _phase_zinc_depscheck = "phase_zinc_depscheck") 18 | 19 | adjust_phases = _adjust_phases 20 | 21 | run_phases = _run_phases 22 | 23 | phase_bootstrap_compile = _phase_bootstrap_compile 24 | 25 | phase_classpaths = _phase_classpaths 26 | 27 | phase_coda = _phase_coda 28 | 29 | phase_coverage_jacoco = _phase_coverage_jacoco 30 | 31 | phase_ijinfo = _phase_ijinfo 32 | 33 | phase_noop = _phase_noop 34 | 35 | phase_resources = _phase_resources 36 | 37 | phase_zinc_compile = _phase_zinc_compile 38 | 39 | phase_zinc_depscheck = _phase_zinc_depscheck 40 | 41 | phase_javainfo = _phase_javainfo 42 | 43 | phase_library_defaultinfo = _phase_library_defaultinfo 44 | 45 | phase_singlejar = _phase_singlejar 46 | 47 | phase_binary_deployjar = _phase_binary_deployjar 48 | 49 | phase_binary_launcher = _phase_binary_launcher 50 | 51 | phase_scalafmt_nondefault_outputs = _phase_scalafmt_nondefault_outputs 52 | 53 | phase_test_launcher = _phase_test_launcher 54 | -------------------------------------------------------------------------------- /rules/private/phases/api.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_scala_annex//rules:providers.bzl", 3 | _ScalaConfiguration = "ScalaConfiguration", 4 | _ScalaRulePhase = "ScalaRulePhase", 5 | ) 6 | 7 | def run_phases(ctx, phases): 8 | phase_providers = [ 9 | p[_ScalaRulePhase] 10 | for p in [ctx.attr.scala] + ctx.attr.plugins + ctx.attr._phase_providers 11 | if _ScalaRulePhase in p 12 | ] 13 | 14 | if phase_providers != []: 15 | phases = adjust_phases(phases, [p for pp in phase_providers for p in pp.phases]) 16 | 17 | gd = { 18 | "init": struct( 19 | scala_configuration = ctx.attr.scala[_ScalaConfiguration], 20 | ), 21 | "out": struct( 22 | output_groups = {}, 23 | providers = [], 24 | ), 25 | } 26 | g = struct(**gd) 27 | for (name, function) in phases: 28 | p = function(ctx, g) 29 | if p != None: 30 | gd[name] = p 31 | g = struct(**gd) 32 | 33 | return g 34 | 35 | def adjust_phases(phases, adjustments): 36 | if len(adjustments) == 0: 37 | return phases 38 | phases = phases[:] 39 | for (relation, peer_name, name, function) in adjustments: 40 | for idx, (needle, _) in enumerate(phases): 41 | if needle == peer_name: 42 | if relation in ["-", "before"]: 43 | phases.insert(idx, (name, function)) 44 | elif relation in ["+", "after"]: 45 | phases.insert(idx + 1, (name, function)) 46 | elif relation in ["=", "replace"]: 47 | phases[idx] = (name, function) 48 | return phases 49 | -------------------------------------------------------------------------------- /rules/private/phases/phase_binary_deployjar.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "//rules/common:private/utils.bzl", 3 | _action_singlejar = "action_singlejar", 4 | ) 5 | 6 | # 7 | # PHASE: binary_deployjar 8 | # 9 | # Writes the optional deploy jar that includes all of the dependencies 10 | # 11 | 12 | def phase_binary_deployjar(ctx, g): 13 | main_class = None 14 | if getattr(ctx.attr, "main_class", ""): 15 | main_class = ctx.attr.main_class 16 | 17 | _action_singlejar( 18 | ctx, 19 | inputs = depset( 20 | [ctx.outputs.jar], 21 | transitive = [g.javainfo.java_info.transitive_runtime_jars], 22 | ), 23 | main_class = main_class, 24 | output = ctx.outputs.deploy_jar, 25 | progress_message = "scala deployable %s" % ctx.label, 26 | ) 27 | -------------------------------------------------------------------------------- /rules/private/phases/phase_binary_launcher.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "//rules/common:private/utils.bzl", 3 | _write_launcher = "write_launcher", 4 | ) 5 | 6 | # 7 | # PHASE: binary_launcher 8 | # 9 | # Writes a Scala binary launcher 10 | # 11 | 12 | def phase_binary_launcher(ctx, g): 13 | inputs = ctx.files.data 14 | 15 | if ctx.attr.main_class != "": 16 | main_class = ctx.attr.main_class 17 | else: 18 | mains_file = g.compile.mains_file 19 | inputs = inputs + [mains_file] 20 | main_class = "$(head -1 $JAVA_RUNFILES/{}/{})".format(ctx.workspace_name, mains_file.short_path) 21 | 22 | files = _write_launcher( 23 | ctx, 24 | "{}/".format(ctx.label.name), 25 | ctx.outputs.bin, 26 | g.javainfo.java_info.transitive_runtime_deps, 27 | jvm_flags = [ctx.expand_location(f, ctx.attr.data) for f in ctx.attr.jvm_flags], 28 | main_class = main_class, 29 | ) 30 | 31 | g.out.providers.append(DefaultInfo( 32 | executable = ctx.outputs.bin, 33 | files = depset([ctx.outputs.bin, ctx.outputs.jar]), 34 | runfiles = ctx.runfiles( 35 | files = inputs + files, 36 | transitive_files = depset( 37 | order = "default", 38 | transitive = [ctx.attr._target_jdk[java_common.JavaRuntimeInfo].files, g.javainfo.java_info.transitive_runtime_deps], 39 | ), 40 | collect_default = True, 41 | ), 42 | )) 43 | -------------------------------------------------------------------------------- /rules/private/phases/phase_bootstrap_compile.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "//rules/common:private/utils.bzl", 3 | _strip_margin = "strip_margin", 4 | ) 5 | load( 6 | "//rules/common:private/utils.bzl", 7 | _resolve_execution_reqs = "resolve_execution_reqs", 8 | ) 9 | 10 | # 11 | # PHASE: bootstrap compile 12 | # 13 | # An alternative compile phase that shells out to scalac directly 14 | # 15 | 16 | def phase_bootstrap_compile(ctx, g): 17 | if g.classpaths.plugin: 18 | fail("plugins aren't supported for bootstrap_scala rules") 19 | if g.classpaths.src_jars: 20 | fail("source jars supported for bootstrap_scala rules") 21 | 22 | inputs = depset( 23 | ctx.files.srcs, 24 | transitive = [ctx.attr._jdk[java_common.JavaRuntimeInfo].files, g.classpaths.compile, g.classpaths.compiler], 25 | ) 26 | 27 | compiler_classpath = ":".join([f.path for f in g.classpaths.compiler.to_list()]) 28 | compile_classpath = ":".join([f.path for f in g.classpaths.compile.to_list()]) 29 | srcs = " ".join([f.path for f in g.classpaths.srcs]) 30 | 31 | ctx.actions.run_shell( 32 | inputs = inputs, 33 | tools = [ctx.executable._jar_creator], 34 | outputs = [g.classpaths.jar], 35 | command = _strip_margin( 36 | """ 37 | |set -eo pipefail 38 | | 39 | |mkdir -p tmp/classes 40 | | 41 | |{java} \\ 42 | | -cp {compiler_classpath} \\ 43 | | scala.tools.nsc.Main \\ 44 | | -cp {compile_classpath} \\ 45 | | -d tmp/classes \\ 46 | | {srcs} 47 | | 48 | |{jar_creator} {output_jar} tmp/classes 2> /dev/null 49 | |""".format( 50 | java = ctx.attr._jdk[java_common.JavaRuntimeInfo].java_executable_exec_path, 51 | jar_creator = ctx.executable._jar_creator.path, 52 | compiler_classpath = compiler_classpath, 53 | compile_classpath = compile_classpath, 54 | srcs = srcs, 55 | output_jar = g.classpaths.jar.path, 56 | ), 57 | ), 58 | execution_requirements = _resolve_execution_reqs(ctx, {}), 59 | ) 60 | -------------------------------------------------------------------------------- /rules/private/phases/phase_coda.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # PHASE: coda 3 | # 4 | # Creates the final rule return structure 5 | # 6 | 7 | def phase_coda(ctx, g): 8 | dynamic = {} 9 | if hasattr(g, "coverage"): 10 | dynamic["instrumented_files"] = g.coverage.instrumented_files 11 | 12 | return struct( 13 | java = g.ijinfo.intellij_info, 14 | providers = g.out.providers, 15 | **dynamic 16 | ) 17 | -------------------------------------------------------------------------------- /rules/private/phases/phase_coverage_jacoco.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_scala_annex//rules:providers.bzl", 3 | _CodeCoverageConfiguration = "CodeCoverageConfiguration", 4 | ) 5 | load( 6 | "@rules_scala_annex//rules/private:coverage_replacements_provider.bzl", 7 | _coverage_replacements_provider = "coverage_replacements_provider", 8 | ) 9 | load( 10 | "@rules_scala_annex//rules/common:private/utils.bzl", 11 | _resolve_execution_reqs = "resolve_execution_reqs", 12 | ) 13 | 14 | def phase_coverage_jacoco(ctx, g): 15 | if not ctx.configuration.coverage_enabled: 16 | return 17 | 18 | if _CodeCoverageConfiguration not in ctx.attr.scala: 19 | #print("WARNING: code coverage is not supported by scala configuration: %s " % ctx.attr.scala) 20 | return 21 | 22 | code_coverage_configuration = ctx.attr.scala[_CodeCoverageConfiguration] 23 | 24 | worker_inputs, _, worker_input_manifests = ctx.resolve_command( 25 | tools = [code_coverage_configuration.instrumentation_worker], 26 | ) 27 | 28 | args = ctx.actions.args() 29 | 30 | instrumented_output_jar = ctx.actions.declare_file( 31 | "{}-offline.jar".format(ctx.outputs.jar.basename.split(".")[0]), 32 | ) 33 | in_out_pairs = [ 34 | (ctx.outputs.jar, instrumented_output_jar), 35 | ] 36 | 37 | args.add_all(in_out_pairs, map_each = _format_in_out_pairs) 38 | 39 | args.set_param_file_format("multiline") 40 | args.use_param_file("@%s", use_always = True) 41 | ctx.actions.run( 42 | mnemonic = "JacocoInstrumenter", 43 | inputs = [in_out_pair[0] for in_out_pair in in_out_pairs] + worker_inputs, 44 | outputs = [in_out_pair[1] for in_out_pair in in_out_pairs], 45 | executable = code_coverage_configuration.instrumentation_worker.files_to_run.executable, 46 | input_manifests = worker_input_manifests, 47 | execution_requirements = _resolve_execution_reqs(ctx, {"supports-workers": "1"}), 48 | arguments = [args], 49 | ) 50 | 51 | replacements = {i: o for (i, o) in in_out_pairs} 52 | 53 | g.out.providers.extend([ 54 | _coverage_replacements_provider.create( 55 | replacements = replacements, 56 | ), 57 | ]) 58 | 59 | return struct( 60 | instrumented_files = struct( 61 | dependency_attributes = _coverage_replacements_provider.dependency_attributes, 62 | extensions = ["scala", "java"], 63 | source_attributes = ["srcs"], 64 | ), 65 | replacements = replacements, 66 | ) 67 | 68 | def _format_in_out_pairs(in_out_pair): 69 | return (["--jar", "%s=%s" % (in_out_pair[0].path, in_out_pair[1].path)]) 70 | -------------------------------------------------------------------------------- /rules/private/phases/phase_ijinfo.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "//rules/scala:private/import.bzl", 3 | _create_intellij_info = "create_intellij_info", 4 | ) 5 | 6 | # 7 | # PHASE: ijinfo 8 | # 9 | # Creates IntelliJ info 10 | # 11 | 12 | def phase_ijinfo(ctx, g): 13 | intellij_info = _create_intellij_info(ctx.label, ctx.attr.deps, g.javainfo.java_info) 14 | g.out.providers.append(intellij_info) 15 | return struct(intellij_info = intellij_info) 16 | -------------------------------------------------------------------------------- /rules/private/phases/phase_javainfo.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "@bazel_tools//tools/jdk:toolchain_utils.bzl", 3 | "find_java_runtime_toolchain", 4 | "find_java_toolchain", 5 | ) 6 | load( 7 | "@rules_scala_annex//rules:providers.bzl", 8 | _ScalaInfo = "ScalaInfo", 9 | ) 10 | load( 11 | "//rules/common:private/utils.bzl", 12 | _collect = "collect", 13 | ) 14 | 15 | # 16 | # PHASE: javainfo 17 | # 18 | # Builds up the JavaInfo provider. And the ScalaInfo, while we're at it. 19 | # And DefaultInfo. 20 | # 21 | 22 | def phase_javainfo(ctx, g): 23 | sruntime_deps = java_common.merge(_collect(JavaInfo, ctx.attr.runtime_deps)) 24 | sexports = java_common.merge(_collect(JavaInfo, getattr(ctx.attr, "exports", []))) 25 | scala_configuration_runtime_deps = _collect(JavaInfo, g.init.scala_configuration.runtime_classpath) 26 | 27 | if len(ctx.attr.srcs) == 0 and len(ctx.attr.resources) == 0: 28 | java_info = java_common.merge([g.classpaths.sdeps, sexports]) 29 | else: 30 | compile_jar = java_common.run_ijar( 31 | ctx.actions, 32 | jar = ctx.outputs.jar, 33 | target_label = ctx.label, 34 | java_toolchain = find_java_toolchain(ctx, ctx.attr._java_toolchain), 35 | ) 36 | 37 | source_jar = java_common.pack_sources( 38 | ctx.actions, 39 | output_jar = ctx.outputs.jar, 40 | sources = ctx.files.srcs, 41 | host_javabase = find_java_runtime_toolchain(ctx, ctx.attr._host_javabase), 42 | java_toolchain = find_java_toolchain(ctx, ctx.attr._java_toolchain), 43 | ) 44 | 45 | java_info = JavaInfo( 46 | compile_jar = compile_jar, 47 | neverlink = getattr(ctx.attr, "neverlink", False), 48 | output_jar = ctx.outputs.jar, 49 | source_jar = source_jar, 50 | exports = [sexports], 51 | runtime_deps = [sruntime_deps] + scala_configuration_runtime_deps, 52 | deps = [g.classpaths.sdeps], 53 | ) 54 | 55 | scala_info = _ScalaInfo( 56 | macro = getattr(ctx.attr, "macro", False), 57 | scala_configuration = g.init.scala_configuration, 58 | ) 59 | 60 | output_group_info = OutputGroupInfo( 61 | **g.out.output_groups 62 | ) 63 | 64 | g.out.providers.extend([ 65 | output_group_info, 66 | java_info, 67 | scala_info, 68 | ]) 69 | 70 | return struct( 71 | java_info = java_info, 72 | output_group_info = output_group_info, 73 | scala_info = scala_info, 74 | ) 75 | -------------------------------------------------------------------------------- /rules/private/phases/phase_library_defaultinfo.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # PHASE: library_defaultinfo 3 | # 4 | # Creates DefaultInfo for Scala libraries 5 | # 6 | 7 | def phase_library_defaultinfo(ctx, g): 8 | g.out.providers.append(DefaultInfo( 9 | files = depset([ctx.outputs.jar]), 10 | )) 11 | -------------------------------------------------------------------------------- /rules/private/phases/phase_noop.bzl: -------------------------------------------------------------------------------- 1 | def phase_noop(ctx, g): 2 | print("noop phase") 3 | -------------------------------------------------------------------------------- /rules/private/phases/phase_resources.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "//rules/common:private/utils.bzl", 3 | _action_singlejar = "action_singlejar", 4 | ) 5 | # 6 | # PHASE: resources 7 | # 8 | # Resource files are merged into a zip archive. 9 | # 10 | # The output is returned in the jar field so the singlejar 11 | # phase will merge it into the final jar. 12 | # 13 | 14 | def phase_resources(ctx, g): 15 | if ctx.files.resources: 16 | resource_jar = ctx.actions.declare_file("{}/resources.jar".format(ctx.label.name)) 17 | _action_singlejar( 18 | ctx, 19 | inputs = [], 20 | output = resource_jar, 21 | progress_message = "singlejar resources %s" % ctx.label.name, 22 | resources = { 23 | _resources_make_path(file, ctx.attr.resource_strip_prefix): file 24 | for file in ctx.files.resources 25 | }, 26 | ) 27 | return struct(jar = resource_jar) 28 | else: 29 | return struct() 30 | 31 | def _resources_make_path(file, strip_prefix): 32 | if strip_prefix: 33 | if not file.short_path.startswith(strip_prefix): 34 | fail("{} does not have prefix {}".format(file.short_path, strip_prefix)) 35 | return file.short_path[len(strip_prefix) + 1 - int(file.short_path.endswith("/")):] 36 | conventional = [ 37 | "src/main/resources/", 38 | "src/test/resources/", 39 | ] 40 | for path in conventional: 41 | dir1, dir2, rest = file.short_path.partition(path) 42 | if rest: 43 | return rest 44 | return file.short_path 45 | -------------------------------------------------------------------------------- /rules/private/phases/phase_scalafmt_nondefault_outputs.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "//rules/scalafmt:private/test.bzl", 3 | _build_format = "build_format", 4 | _format_runner = "format_runner", 5 | _format_tester = "format_tester", 6 | ) 7 | 8 | # 9 | # PHASE: phase_scalafmt_nondefault_outputs 10 | # 11 | # Outputs to format the scala files when it is explicitly specified 12 | # 13 | 14 | def phase_scalafmt_nondefault_outputs(ctx, g): 15 | if ctx.attr.format: 16 | manifest, files = _build_format(ctx) 17 | _format_runner(ctx, manifest, files) 18 | _format_tester(ctx, manifest, files) 19 | else: 20 | ctx.actions.write( 21 | output = ctx.outputs.scalafmt_runner, 22 | content = "", 23 | is_executable = True, 24 | ) 25 | ctx.actions.write( 26 | output = ctx.outputs.scalafmt_testrunner, 27 | content = "", 28 | is_executable = True, 29 | ) 30 | -------------------------------------------------------------------------------- /rules/private/phases/phase_singlejar.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "//rules/common:private/utils.bzl", 3 | _action_singlejar = "action_singlejar", 4 | ) 5 | 6 | # 7 | # PHASE: singlejar 8 | # 9 | # Creates a single jar output from any resource jars as well 10 | # as any jar entries from previous phases. The output is the 11 | # output is written to ctx.outputs.jar. 12 | # 13 | # Additionally, this phase checks for missing outputs from previous 14 | # phases. This allows phases to error, cleanly, by declaring a file 15 | # in the outputs field but _without_ actually creating it. 16 | # 17 | 18 | def phase_singlejar(ctx, g): 19 | # We're going to declare all phase outputs as inputs but skip 20 | # including them in the args for singlejar to process. This will 21 | # cause the build to fail, cleanly, if any declared outputs are 22 | # missing from previous phases. 23 | inputs = [f for f in ctx.files.resource_jars if f.extension.lower() in ["jar"]] 24 | phantom_inputs = [] 25 | for v in [getattr(g, k) for k in dir(g) if k not in ["to_json", "to_proto"]]: 26 | if hasattr(v, "jar"): 27 | jar = getattr(v, "jar") 28 | inputs.append(jar) 29 | if hasattr(v, "outputs"): 30 | phantom_inputs.extend(getattr(v, "outputs")) 31 | 32 | _action_singlejar(ctx, inputs, ctx.outputs.jar, phantom_inputs) 33 | -------------------------------------------------------------------------------- /rules/rules_scala.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "//rules/common:private/utils.bzl", 3 | _strip_margin = "strip_margin", 4 | ) 5 | 6 | def _emulate_rules_scala_repository_impl(repository_ctx): 7 | repository_ctx.file("WORKSPACE", content = "workspace(name = \"io_bazel_rules_scala\")") 8 | repository_ctx.file( 9 | "scala/scala.bzl", 10 | content = _strip_margin(""" 11 | |load("@rules_scala_annex//rules/rules_scala:private/compat.bzl", 12 | | _scala_library = "scala_library", 13 | | _scala_macro_library = "scala_macro_library", 14 | | _scala_binary = "scala_binary", 15 | | _scala_test = "scala_test", 16 | | _scala_test_suite = "scala_test_suite", 17 | |) 18 | | 19 | |scala_library = _scala_library 20 | |scala_macro_library = _scala_macro_library 21 | |scala_binary = _scala_binary 22 | |scala_test = _scala_test 23 | |scala_test_suite = _scala_test_suite 24 | |"""), 25 | ) 26 | repository_ctx.file( 27 | "scala/scala_import.bzl", 28 | content = _strip_margin(""" 29 | |load("@rules_scala_annex//rules:scala.bzl", 30 | | _scala_import = "scala_import", 31 | |) 32 | | 33 | |scala_import = _scala_import 34 | |"""), 35 | ) 36 | extra_deps = ", ".join(["\"{}\"".format(dep) for dep in repository_ctx.attr.extra_deps]) 37 | repository_ctx.file( 38 | "scala/BUILD", 39 | content = _strip_margin(""" 40 | |java_import( 41 | | name = "extra_deps", 42 | | exports = [ 43 | | {extra_deps} 44 | | ], 45 | | jars = [], 46 | | visibility = ["//visibility:public"], 47 | |) 48 | |""".format(extra_deps = extra_deps)), 49 | ) 50 | 51 | emulate_rules_scala_repository = repository_rule( 52 | attrs = { 53 | "extra_deps": attr.label_list(default = []), 54 | }, 55 | local = True, 56 | implementation = _emulate_rules_scala_repository_impl, 57 | ) 58 | 59 | def emulate_rules_scala(scala, scalatest, extra_deps = []): 60 | native.bind( 61 | name = "scala_annex/compat/rules_scala/scala", 62 | actual = scala, 63 | ) 64 | 65 | native.bind( 66 | name = "scala_annex/compat/rules_scala/extra_deps", 67 | actual = "@io_bazel_rules_scala//scala:extra_deps", 68 | ) 69 | 70 | native.bind( 71 | name = "scala_annex/compat/rules_scala/scalatest_dep", 72 | actual = scalatest, 73 | ) 74 | 75 | emulate_rules_scala_repository( 76 | name = "io_bazel_rules_scala", 77 | extra_deps = extra_deps, 78 | ) 79 | -------------------------------------------------------------------------------- /rules/rules_scala/BUILD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/higherkindness/rules_scala/aed5cc8a433824e23dc82119de1b98904ab1bb9e/rules/rules_scala/BUILD -------------------------------------------------------------------------------- /rules/scala/BUILD: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "bzl", 3 | srcs = glob(["**/*.bzl"]), 4 | visibility = ["//rules:__pkg__"], 5 | ) 6 | -------------------------------------------------------------------------------- /rules/scala/private/doc.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_scala_annex//rules:providers.bzl", 3 | _ScalaConfiguration = "ScalaConfiguration", 4 | _ZincConfiguration = "ZincConfiguration", 5 | ) 6 | load( 7 | "//rules/common:private/utils.bzl", 8 | _collect = "collect", 9 | ) 10 | load( 11 | "//rules/common:private/utils.bzl", 12 | _resolve_execution_reqs = "resolve_execution_reqs", 13 | ) 14 | 15 | scaladoc_private_attributes = { 16 | "_runner": attr.label( 17 | cfg = "host", 18 | executable = True, 19 | default = "//src/main/scala/higherkindness/rules_scala/workers/zinc/doc", 20 | ), 21 | } 22 | 23 | def scaladoc_implementation(ctx): 24 | scala_configuration = ctx.attr.scala[_ScalaConfiguration] 25 | zinc_configuration = ctx.attr.scala[_ZincConfiguration] 26 | 27 | scompiler_classpath = java_common.merge( 28 | _collect(JavaInfo, scala_configuration.compiler_classpath), 29 | ) 30 | 31 | html = ctx.actions.declare_directory("html") 32 | tmp = ctx.actions.declare_directory("tmp") 33 | 34 | classpath = depset(transitive = [dep[JavaInfo].transitive_deps for dep in ctx.attr.deps]) 35 | compiler_classpath = depset( 36 | transitive = 37 | [scompiler_classpath.transitive_runtime_deps] + 38 | [dep[JavaInfo].transitive_runtime_deps for dep in ctx.attr.compiler_deps], 39 | ) 40 | 41 | srcs = [file for file in ctx.files.srcs if file.extension.lower() in ["java", "scala"]] 42 | src_jars = [file for file in ctx.files.srcs if file.extension.lower() == "srcjar"] 43 | 44 | scalacopts = ["-doc-title", ctx.attr.title or ctx.label] + ctx.attr.scalacopts 45 | 46 | args = ctx.actions.args() 47 | args.add("--compiler_bridge", zinc_configuration.compiler_bridge) 48 | args.add_all("--compiler_classpath", compiler_classpath) 49 | args.add_all("--classpath", classpath) 50 | args.add_all(scalacopts, format_each = "--option=%s") 51 | args.add("--output_html", html.path) 52 | args.add_all("--source_jars", src_jars) 53 | args.add("--tmp", tmp.path) 54 | args.add_all("--", srcs) 55 | args.set_param_file_format("multiline") 56 | args.use_param_file("@%s", use_always = True) 57 | 58 | runner_inputs, _, input_manifests = ctx.resolve_command(tools = [ctx.attr._runner]) 59 | 60 | ctx.actions.run( 61 | arguments = [args], 62 | executable = ctx.attr._runner.files_to_run.executable, 63 | execution_requirements = _resolve_execution_reqs(ctx, {"supports-workers": "1"}), 64 | input_manifests = input_manifests, 65 | inputs = depset( 66 | src_jars + srcs + [zinc_configuration.compiler_bridge], 67 | transitive = [classpath, compiler_classpath], 68 | ), 69 | mnemonic = "ScalaDoc", 70 | outputs = [html, tmp], 71 | ) 72 | 73 | return [ 74 | DefaultInfo( 75 | files = depset([html]), 76 | ), 77 | ] 78 | -------------------------------------------------------------------------------- /rules/scala/private/provider.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_scala_annex//rules:providers.bzl", 3 | _CodeCoverageConfiguration = "CodeCoverageConfiguration", 4 | _DepsConfiguration = "DepsConfiguration", 5 | _ScalaConfiguration = "ScalaConfiguration", 6 | _ScalaRulePhase = "ScalaRulePhase", 7 | _ZincConfiguration = "ZincConfiguration", 8 | ) 9 | load( 10 | "//rules/private:phases.bzl", 11 | _phase_bootstrap_compile = "phase_bootstrap_compile", 12 | _phase_zinc_compile = "phase_zinc_compile", 13 | _phase_zinc_depscheck = "phase_zinc_depscheck", 14 | ) 15 | 16 | def configure_bootstrap_scala_implementation(ctx): 17 | return [ 18 | _ScalaConfiguration( 19 | compiler_classpath = ctx.attr.compiler_classpath, 20 | global_plugins = ctx.attr.global_plugins, 21 | global_scalacopts = ctx.attr.global_scalacopts, 22 | runtime_classpath = ctx.attr.runtime_classpath, 23 | version = ctx.attr.version, 24 | ), 25 | _ScalaRulePhase( 26 | phases = [ 27 | ("=", "compile", "compile", _phase_bootstrap_compile), 28 | ], 29 | ), 30 | ] 31 | 32 | def configure_zinc_scala_implementation(ctx): 33 | return [ 34 | _ScalaConfiguration( 35 | compiler_classpath = ctx.attr.compiler_classpath, 36 | global_plugins = ctx.attr.global_plugins, 37 | global_scalacopts = ctx.attr.global_scalacopts, 38 | runtime_classpath = ctx.attr.runtime_classpath, 39 | version = ctx.attr.version, 40 | ), 41 | _CodeCoverageConfiguration( 42 | instrumentation_worker = ctx.attr._code_coverage_instrumentation_worker, 43 | ), 44 | _ZincConfiguration( 45 | compile_worker = ctx.attr._compile_worker, 46 | compiler_bridge = ctx.file.compiler_bridge, 47 | log_level = ctx.attr.log_level, 48 | ), 49 | _DepsConfiguration( 50 | direct = ctx.attr.deps_direct, 51 | used = ctx.attr.deps_used, 52 | worker = ctx.attr._deps_worker, 53 | ), 54 | _ScalaRulePhase( 55 | phases = [ 56 | ("=", "compile", "compile", _phase_zinc_compile), 57 | ("+", "compile", "depscheck", _phase_zinc_depscheck), 58 | ], 59 | ), 60 | ] 61 | -------------------------------------------------------------------------------- /rules/scala/private/repl.bzl: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//lib:dicts.bzl", _dicts = "dicts") 2 | load( 3 | "@rules_scala_annex//rules:providers.bzl", 4 | _ScalaConfiguration = "ScalaConfiguration", 5 | _ZincConfiguration = "ZincConfiguration", 6 | ) 7 | load("//rules/common:private/utils.bzl", "write_launcher", _collect = "collect") 8 | 9 | def scala_repl_implementation(ctx): 10 | scala_configuration = ctx.attr.scala[_ScalaConfiguration] 11 | zinc_configuration = ctx.attr.scala[_ZincConfiguration] 12 | 13 | scompiler_classpath = java_common.merge( 14 | _collect(JavaInfo, scala_configuration.compiler_classpath), 15 | ) 16 | 17 | classpath = depset(transitive = [dep[JavaInfo].transitive_runtime_deps for dep in ctx.attr.deps]) 18 | runner_classpath = ctx.attr._runner[JavaInfo].transitive_runtime_deps 19 | 20 | args = ctx.actions.args() 21 | args.add("--compiler_bridge", zinc_configuration.compiler_bridge.short_path) 22 | args.add_all("--compiler_classpath", scompiler_classpath.transitive_runtime_jars, map_each = _short_path) 23 | args.add_all("--classpath", classpath, map_each = _short_path) 24 | args.add_all(scala_configuration.global_scalacopts, format_each = "--compiler_option=%s") 25 | args.add_all(ctx.attr.scalacopts, format_each = "--compiler_option=%s") 26 | args.set_param_file_format("multiline") 27 | args_file = ctx.actions.declare_file("{}/repl.params".format(ctx.label.name)) 28 | ctx.actions.write(args_file, args) 29 | 30 | launcher_files = write_launcher( 31 | ctx, 32 | "{}/".format(ctx.label.name), 33 | ctx.outputs.bin, 34 | runner_classpath, 35 | "higherkindness.rules_scala.workers.zinc.repl.ReplRunner", 36 | [ctx.expand_location(f, ctx.attr.data) for f in ctx.attr.jvm_flags] + [ 37 | "-Dbazel.runPath=$RUNPATH", 38 | "-DscalaAnnex.test.args=${{RUNPATH}}{}".format(args_file.short_path), 39 | ], 40 | "export TERM=xterm-color", # https://github.com/sbt/sbt/issues/3240 41 | ) 42 | 43 | files = depset( 44 | [args_file, zinc_configuration.compiler_bridge] + launcher_files, 45 | transitive = [classpath, runner_classpath, scompiler_classpath.transitive_runtime_deps], 46 | ) 47 | return [ 48 | DefaultInfo( 49 | executable = ctx.outputs.bin, 50 | files = depset([ctx.outputs.bin], transitive = [files]), 51 | runfiles = ctx.runfiles( 52 | collect_default = True, 53 | collect_data = True, 54 | files = ctx.attr._target_jdk[java_common.JavaRuntimeInfo].files.to_list(), 55 | transitive_files = files, 56 | ), 57 | ), 58 | ] 59 | 60 | def _short_path(file): 61 | return file.short_path 62 | -------------------------------------------------------------------------------- /rules/scala_proto/BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "//rules:scala.bzl", 3 | "scala_binary", 4 | ) 5 | load( 6 | "//rules:scala_proto.bzl", 7 | "scala_proto_toolchain", 8 | ) 9 | 10 | toolchain_type( 11 | name = "compiler_toolchain_type", 12 | visibility = ["//visibility:public"], 13 | ) 14 | 15 | scala_binary( 16 | name = "worker", 17 | srcs = glob(["private/ScalaProtoWorker.scala"]), 18 | main_class = "annex.scala.proto.ScalaProtoWorker", 19 | scala = "//src/main/scala:zinc", 20 | visibility = ["//visibility:public"], 21 | deps = [ 22 | "//src/main/scala/higherkindness/rules_scala/common/args", 23 | "//src/main/scala/higherkindness/rules_scala/common/worker", 24 | "@annex//:net_sourceforge_argparse4j_argparse4j", 25 | "@annex_proto//:com_github_os72_protoc_jar", 26 | "@annex_proto//:com_thesamet_scalapb_compilerplugin_2_12", 27 | "@annex_proto//:com_thesamet_scalapb_protoc_bridge_2_12", 28 | ], 29 | ) 30 | 31 | scala_proto_toolchain( 32 | name = "scalapb_scala_proto_toolchain_implementation", 33 | compiler = ":worker", 34 | compiler_supports_workers = True, 35 | visibility = ["//visibility:public"], 36 | ) 37 | 38 | toolchain( 39 | name = "scalapb_scala_proto_toolchain", 40 | toolchain = ":scalapb_scala_proto_toolchain_implementation", 41 | toolchain_type = "@rules_scala_annex//rules/scala_proto:compiler_toolchain_type", 42 | visibility = ["//visibility:public"], 43 | ) 44 | 45 | filegroup( 46 | name = "bzl", 47 | srcs = glob(["**/*.bzl"]), 48 | visibility = ["//rules:__pkg__"], 49 | ) 50 | -------------------------------------------------------------------------------- /rules/scala_proto/private/ScalaProtoWorker.scala: -------------------------------------------------------------------------------- 1 | package annex.scala.proto 2 | 3 | import higherkindness.rules_scala.common.args.implicits._ 4 | import higherkindness.rules_scala.common.worker.WorkerMain 5 | import java.io.File 6 | import java.nio.file.Files 7 | import java.util.Collections 8 | import net.sourceforge.argparse4j.ArgumentParsers 9 | import net.sourceforge.argparse4j.impl.Arguments 10 | import net.sourceforge.argparse4j.inf.ArgumentParser 11 | import protocbridge.ProtocBridge 12 | import scala.collection.JavaConverters._ 13 | import scalapb.ScalaPbCodeGenerator 14 | 15 | object ScalaProtoWorker extends WorkerMain[Unit] { 16 | 17 | private[this] val argParser: ArgumentParser = { 18 | val parser = ArgumentParsers.newFor("proto").addHelp(true).fromFilePrefix("@").build 19 | parser 20 | .addArgument("--output_dir") 21 | .help("Output dir") 22 | .metavar("output_dir") 23 | .`type`(Arguments.fileType.verifyCanCreate) 24 | parser 25 | .addArgument("--proto_paths") 26 | .help("Paths to be passed to protoc as --proto_path arguments") 27 | .metavar("proto_paths") 28 | .nargs("*") 29 | .`type`(Arguments.fileType.verifyCanRead.verifyIsDirectory) 30 | .setDefault_(Collections.emptyList) 31 | parser 32 | .addArgument("sources") 33 | .help("Source files") 34 | .metavar("source") 35 | .nargs("*") 36 | .`type`(Arguments.fileType.verifyCanRead.verifyIsFile) 37 | .setDefault_(Collections.emptyList) 38 | parser 39 | } 40 | 41 | override def init(args: Option[Array[String]]): Unit = () 42 | 43 | protected[this] def work(ctx: Unit, args: Array[String]): Unit = { 44 | val namespace = argParser.parseArgs(args) 45 | val sources = namespace.getList[File]("sources").asScala.toList 46 | val protoPaths = namespace.getList[File]("proto_paths").asScala.toList 47 | 48 | val scalaOut = namespace.get[File]("output_dir").toPath 49 | Files.createDirectories(scalaOut) 50 | 51 | val params = s"--scala_out=$scalaOut" :: 52 | sources.map(_.getPath) ::: 53 | protoPaths.map(dir => s"--proto_path=${dir.getPath}") 54 | 55 | ProtocBridge.runWithGenerators( 56 | protoc = a => com.github.os72.protocjar.Protoc.runProtoc(a.toArray), 57 | namedGenerators = List("scala" -> ScalaPbCodeGenerator), 58 | params = params) 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /rules/scala_proto/private/core.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "//rules/common:private/utils.bzl", 3 | _safe_name = "safe_name", 4 | ) 5 | load( 6 | "//rules/common:private/utils.bzl", 7 | _resolve_execution_reqs = "resolve_execution_reqs", 8 | ) 9 | 10 | scala_proto_library_private_attributes = {} 11 | 12 | def scala_proto_library_implementation(ctx): 13 | protos = [dep[ProtoInfo] for dep in ctx.attr.deps] 14 | 15 | sources = depset(direct = [source for proto in protos for source in proto.direct_sources]) 16 | transitive_proto_path = depset(transitive = [proto.transitive_proto_path for proto in protos]) 17 | 18 | compiler = ctx.toolchains["@rules_scala_annex//rules/scala_proto:compiler_toolchain_type"] 19 | 20 | compiler_inputs, _, _ = ctx.resolve_command(tools = [compiler.compiler]) 21 | 22 | srcjar = ctx.outputs.srcjar 23 | 24 | gendir_base_path = "tmp" 25 | gendir = ctx.actions.declare_directory( 26 | gendir_base_path + "/" + _safe_name(ctx.attr.name), 27 | ) 28 | 29 | args = ctx.actions.args() 30 | args.add("--output_dir", gendir.path) 31 | args.add_all("--proto_paths", transitive_proto_path) 32 | args.add_all("--", sources) 33 | args.set_param_file_format("multiline") 34 | args.use_param_file("@%s", use_always = True) 35 | 36 | if compiler.compiler_supports_workers: 37 | supports_workers = "1" 38 | else: 39 | supports_workers = "0" 40 | 41 | ctx.actions.run( 42 | mnemonic = "ScalaProtoCompile", 43 | inputs = depset(transitive = [proto.transitive_sources for proto in protos]), 44 | outputs = [gendir], 45 | executable = compiler.compiler.files_to_run.executable, 46 | tools = compiler_inputs, 47 | execution_requirements = _resolve_execution_reqs(ctx, {"supports-workers": supports_workers}), 48 | arguments = [args], 49 | ) 50 | 51 | ctx.actions.run_shell( 52 | inputs = [gendir], 53 | outputs = [srcjar], 54 | arguments = [ctx.executable._zipper.path, gendir.path, gendir.short_path, srcjar.path], 55 | command = """$1 c $4 META-INF/= $(find -L $2 -type f | while read v; do echo ${v#"${2%$3}"}=$v; done)""", 56 | progress_message = "Bundling compiled Scala into srcjar", 57 | tools = [ctx.executable._zipper], 58 | execution_requirements = _resolve_execution_reqs(ctx, {}), 59 | ) 60 | -------------------------------------------------------------------------------- /rules/scala_proto/workspace.bzl: -------------------------------------------------------------------------------- 1 | load("@rules_jvm_external//:defs.bzl", "maven_install") 2 | 3 | def scala_proto_register_toolchains(): 4 | native.register_toolchains("@rules_scala_annex//rules/scala_proto:scalapb_scala_proto_toolchain") 5 | 6 | def scala_proto_artifacts(): 7 | return [ 8 | "com.github.os72:protoc-jar:3.8.0", 9 | "com.thesamet.scalapb:compilerplugin_2.12:0.9.0", 10 | "com.thesamet.scalapb:protoc-bridge_2.12:0.7.8", 11 | ] 12 | 13 | def scala_proto_repositories(): 14 | maven_install( 15 | name = "annex_proto", 16 | artifacts = scala_proto_artifacts(), 17 | repositories = [ 18 | "https://repo.maven.apache.org/maven2", 19 | "https://maven-central.storage-download.googleapis.com/maven2", 20 | "https://mirror.bazel.build/repo1.maven.org/maven2", 21 | ], 22 | fetch_sources = True, 23 | maven_install_json = "@rules_scala_annex//:annex_proto_install.json", 24 | ) 25 | -------------------------------------------------------------------------------- /rules/scala_with_scalafmt.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_scala_annex//rules:scala.bzl", 3 | "make_scala_binary", 4 | "make_scala_library", 5 | "make_scala_test", 6 | ) 7 | load( 8 | "@rules_scala_annex//rules/scalafmt:ext.bzl", 9 | "ext_with_non_default_format", 10 | ) 11 | 12 | scala_binary = make_scala_binary(ext_with_non_default_format) 13 | 14 | scala_library = make_scala_library(ext_with_non_default_format) 15 | 16 | scala_test = make_scala_test(ext_with_non_default_format) 17 | -------------------------------------------------------------------------------- /rules/scalafmt.bzl: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//lib:dicts.bzl", _dicts = "dicts") 2 | load( 3 | "//rules/scalafmt:private/test.bzl", 4 | _scala_format_attributes = "scala_format_attributes", 5 | _scala_format_test_implementation = "scala_format_test_implementation", 6 | ) 7 | 8 | """ 9 | Formats and checks the format of Scala. 10 | 11 | See [scalafmt.md](../scalafmt.md) 12 | """ 13 | 14 | scala_format_test = rule( 15 | attrs = _dicts.add( 16 | _scala_format_attributes, 17 | { 18 | "srcs": attr.label_list( 19 | allow_files = [".scala"], 20 | doc = "The Scala files.", 21 | ), 22 | }, 23 | ), 24 | outputs = { 25 | "scalafmt_runner": "%{name}-format", 26 | }, 27 | test = True, 28 | implementation = _scala_format_test_implementation, 29 | ) 30 | -------------------------------------------------------------------------------- /rules/scalafmt/BUILD: -------------------------------------------------------------------------------- 1 | load("//rules:scala.bzl", "scala_binary") 2 | load("//rules:scalafmt.bzl", "scala_format_test") 3 | 4 | filegroup( 5 | name = "runner", 6 | srcs = ["private/format.template.sh"], 7 | visibility = ["//visibility:public"], 8 | ) 9 | 10 | filegroup( 11 | name = "testrunner", 12 | srcs = ["private/format-test.template.sh"], 13 | visibility = ["//visibility:public"], 14 | ) 15 | 16 | scala_binary( 17 | name = "scalafmt", 18 | srcs = glob(["scalafmt/**/*.scala"]), 19 | main_class = "annex.scalafmt.ScalafmtRunner", 20 | scala = "//src/main/scala:bootstrap", 21 | visibility = ["//visibility:public"], 22 | deps = [ 23 | "//src/main/scala/higherkindness/rules_scala/common/worker", 24 | "//src/main/scala/higherkindness/rules_scala/workers/common", 25 | "@annex//:net_sourceforge_argparse4j_argparse4j", 26 | "@annex_scalafmt//:com_geirsson_metaconfig_core_2_12", 27 | "@annex_scalafmt//:org_scalameta_parsers_2_12", 28 | "@annex_scalafmt//:org_scalameta_scalafmt_core_2_12", 29 | ], 30 | ) 31 | 32 | scala_format_test( 33 | name = "format", 34 | srcs = glob(["**/*.scala"]), 35 | ) 36 | 37 | filegroup( 38 | name = "bzl", 39 | srcs = glob(["**/*.bzl"]), 40 | visibility = ["//rules:__pkg__"], 41 | ) 42 | 43 | load( 44 | ":ext.bzl", 45 | _add_non_default_format_phase_singleton = "add_non_default_format_phase_singleton", 46 | ) 47 | 48 | _add_non_default_format_phase_singleton( 49 | name = "add_non_default_format_phase", 50 | visibility = ["//visibility:public"], 51 | ) 52 | -------------------------------------------------------------------------------- /rules/scalafmt/ext.bzl: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//lib:dicts.bzl", _dicts = "dicts") 2 | load( 3 | "@rules_scala_annex//rules:providers.bzl", 4 | _ScalaRulePhase = "ScalaRulePhase", 5 | ) 6 | load( 7 | "//rules/scalafmt:private/test.bzl", 8 | _scala_format_attributes = "scala_format_attributes", 9 | _scala_non_default_format_attributes = "scala_non_default_format_attributes", 10 | ) 11 | load( 12 | "//rules/private:phases.bzl", 13 | _phase_scalafmt_nondefault_outputs = "phase_scalafmt_nondefault_outputs", 14 | ) 15 | 16 | ext_with_non_default_format = { 17 | "attrs": _dicts.add( 18 | _scala_format_attributes, 19 | _scala_non_default_format_attributes, 20 | ), 21 | "outputs": { 22 | "scalafmt_runner": "%{name}.format", 23 | "scalafmt_testrunner": "%{name}.format-test", 24 | }, 25 | "phase_providers": [ 26 | "//rules/scalafmt:add_non_default_format_phase", 27 | ], 28 | } 29 | 30 | def _add_non_default_format_phase_singleton_implementation(ctx): 31 | return [ 32 | _ScalaRulePhase( 33 | phases = [ 34 | ("-", "coda", "non_default_format", _phase_scalafmt_nondefault_outputs), 35 | ], 36 | ), 37 | ] 38 | 39 | add_non_default_format_phase_singleton = rule( 40 | implementation = _add_non_default_format_phase_singleton_implementation, 41 | ) 42 | -------------------------------------------------------------------------------- /rules/scalafmt/private/format-test.template.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | RUNPATH="${TEST_SRCDIR-$0.runfiles}"/%workspace% 3 | WORKSPACE_ROOT="${1:-$BUILD_WORKSPACE_DIRECTORY}" 4 | NONDEFAULTPATH=(${RUNPATH//bin/ }) 5 | NONDEFAULTPATH="${NONDEFAULTPATH[0]}"bin 6 | 7 | EXIT=0 8 | while read original formatted; do 9 | if [[ ! -z "$original" ]] && [[ ! -z "$formatted" ]]; then 10 | if ! cmp -s "$WORKSPACE_ROOT/$original" "$NONDEFAULTPATH/$formatted"; then 11 | echo $original 12 | diff "$WORKSPACE_ROOT/$original" "$NONDEFAULTPATH/$formatted" || true 13 | EXIT=1 14 | fi 15 | fi 16 | done < "$NONDEFAULTPATH"/%manifest% 17 | 18 | exit $EXIT 19 | -------------------------------------------------------------------------------- /rules/scalafmt/private/format.template.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | RUNPATH="${TEST_SRCDIR-$0.runfiles}"/%workspace% 3 | WORKSPACE_ROOT="${1:-$BUILD_WORKSPACE_DIRECTORY}" 4 | 5 | if [ -f "$RUNPATH"/%manifest% ]; then 6 | while read original formatted; do 7 | if [[ ! -z "$original" ]] && [[ ! -z "$formatted" ]]; then 8 | if ! cmp -s "$RUNPATH/$original" "$RUNPATH/$formatted"; then 9 | if [ -z "$WORKSPACE_ROOT" ]; then 10 | echo "$original" 11 | diff "$RUNPATH/$original" "$RUNPATH/$formatted" || true 12 | EXIT=1 13 | else 14 | echo "Formatting $original" 15 | cp "$RUNPATH/$formatted" "$WORKSPACE_ROOT/$original" 16 | fi 17 | fi 18 | fi 19 | done < "$RUNPATH"/%manifest% 20 | else 21 | NONDEFAULTPATH=(${RUNPATH//bin/ }) 22 | NONDEFAULTPATH="${NONDEFAULTPATH[0]}"bin 23 | while read original formatted; do 24 | if [[ ! -z "$original" ]] && [[ ! -z "$formatted" ]]; then 25 | if ! cmp -s "$WORKSPACE_ROOT/$original" "$NONDEFAULTPATH/$formatted"; then 26 | echo "Formatting $original" 27 | cp "$NONDEFAULTPATH/$formatted" "$WORKSPACE_ROOT/$original" 28 | fi 29 | fi 30 | done < "$NONDEFAULTPATH"/%manifest% 31 | fi 32 | 33 | exit $EXIT 34 | -------------------------------------------------------------------------------- /rules/scalafmt/scalafmt/ScalafmtRunner.scala: -------------------------------------------------------------------------------- 1 | package annex.scalafmt 2 | 3 | import higherkindness.rules_scala.common.worker.WorkerMain 4 | import higherkindness.rules_scala.workers.common.Color 5 | import java.io.File 6 | import java.nio.file.Files 7 | import net.sourceforge.argparse4j.ArgumentParsers 8 | import net.sourceforge.argparse4j.impl.Arguments 9 | import org.scalafmt.Scalafmt 10 | import org.scalafmt.config.Config 11 | import org.scalafmt.util.FileOps 12 | import scala.annotation.tailrec 13 | import scala.io.Codec 14 | 15 | object ScalafmtRunner extends WorkerMain[Unit] { 16 | 17 | protected[this] def init(args: Option[Array[String]]): Unit = {} 18 | 19 | protected[this] def work(worker: Unit, args: Array[String]): Unit = { 20 | 21 | val parser = ArgumentParsers.newFor("scalafmt").addHelp(true).defaultFormatWidth(80).fromFilePrefix("@").build 22 | parser.addArgument("--config").required(true).`type`(Arguments.fileType) 23 | parser.addArgument("input").`type`(Arguments.fileType) 24 | parser.addArgument("output").`type`(Arguments.fileType) 25 | 26 | val namespace = parser.parseArgsOrFail(args) 27 | 28 | val source = FileOps.readFile(namespace.get[File]("input"))(Codec.UTF8) 29 | 30 | val config = Config.fromHoconFile(namespace.get[File]("config")).get 31 | @tailrec 32 | def format(code: String): String = { 33 | val formatted = Scalafmt.format(code, config).get 34 | if (code == formatted) code else format(formatted) 35 | } 36 | 37 | val output = 38 | try { 39 | format(source) 40 | } catch { 41 | case e @ (_: org.scalafmt.Error | _: scala.meta.parsers.ParseException) => { 42 | if (config.runner.fatalWarnings) { 43 | System.err.println(Color.Error("Exception thrown by Scalafmt and fatalWarnings is enabled")) 44 | throw e 45 | } else { 46 | System.err.println(Color.Warning("Unable to format file due to bug in scalafmt")) 47 | System.err.println(Color.Warning(e.toString)) 48 | source 49 | } 50 | } 51 | } 52 | 53 | Files.write(namespace.get[File]("output").toPath, output.getBytes) 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /rules/scalafmt/workspace.bzl: -------------------------------------------------------------------------------- 1 | load("@rules_jvm_external//:defs.bzl", "maven_install") 2 | 3 | def scalafmt_artifacts(): 4 | return [ 5 | "org.scalameta:parsers_2.12:4.3.0", 6 | "com.geirsson:metaconfig-core_2.12:0.9.4", 7 | "org.scalameta:scalafmt-core_2.12:2.3.2", 8 | ] 9 | 10 | def scalafmt_repositories(): 11 | maven_install( 12 | name = "annex_scalafmt", 13 | artifacts = scalafmt_artifacts(), 14 | repositories = [ 15 | "https://repo.maven.apache.org/maven2", 16 | "https://maven-central.storage-download.googleapis.com/maven2", 17 | "https://mirror.bazel.build/repo1.maven.org/maven2", 18 | ], 19 | fetch_sources = True, 20 | maven_install_json = "@rules_scala_annex//:annex_scalafmt_install.json", 21 | ) 22 | 23 | def scalafmt_default_config(path = ".scalafmt.conf"): 24 | build = [] 25 | build.append("filegroup(") 26 | build.append(" name = \"config\",") 27 | build.append(" srcs = [\"{}\"],".format(path)) 28 | build.append(" visibility = [\"//visibility:public\"],") 29 | build.append(")") 30 | native.new_local_repository(name = "scalafmt_default", build_file_content = "\n".join(build), path = "") 31 | -------------------------------------------------------------------------------- /scripts/ci.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Acts as a front end script for use for CI 5 | # 6 | 7 | set -eox pipefail 8 | cd "$(dirname "$0")/.." 9 | 10 | . ./scripts/prepare-path.sh --force 11 | 12 | case "$1" in 13 | 14 | "build") 15 | bazel build --show_progress_rate_limit=2 //... 16 | ;; 17 | 18 | "build-sans-doc") 19 | bazel query '//... except(//rules:*)' | xargs bazel build --show_progress_rate_limit=2 20 | ;; 21 | 22 | "test") 23 | ./scripts/test.sh 24 | ;; 25 | 26 | "lint") 27 | ./scripts/format.sh check 28 | ./scripts/gen-docs.sh && git diff --exit-code 29 | ;; 30 | "") 31 | echo "command not specified" 32 | exit 1 33 | ;; 34 | *) 35 | echo "$1 not understood" 36 | exit 1 37 | ;; 38 | esac 39 | -------------------------------------------------------------------------------- /scripts/format.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # 4 | # Reformats various files (.bzl, .scala) throughout the project 5 | # 6 | 7 | set -o pipefail 8 | cd "$(dirname "$0")/.." 9 | 10 | . ./scripts/prepare-path.sh --force 11 | 12 | if [ "$1" != check ]; then 13 | bazel build $(bazel query 'kind("scala_format_test", //...)') 14 | bazel query 'kind("scala_format_test", //...)' --output package | while read package; do bazel-bin/"$package"/*-format .; done 15 | else 16 | bazel query 'kind("scala_format_test", //...)' | xargs bazel test 17 | fi 18 | 19 | if [ "$1" != check ]; then 20 | bazel run buildifier 21 | else 22 | bazel run buildifier_check 23 | fi 24 | -------------------------------------------------------------------------------- /scripts/gen-deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | # 4 | # Regenerates the external dependencies lock file using rules_jvm_external 5 | # 6 | 7 | cd "$(dirname "$0")/.." 8 | echo "$(dirname "$0")/.." 9 | 10 | echo "generating dependencies for main workspace" 11 | bazel run @unpinned_annex//:pin 12 | bazel run @unpinned_annex_scalafmt//:pin 13 | bazel run @unpinned_annex_proto//:pin 14 | 15 | echo "generating dependencies for tests workspace" 16 | cd "tests" 17 | bazel run @unpinned_annex_test//:pin 18 | -------------------------------------------------------------------------------- /scripts/gen-docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Regenerates stardoc for the rules 5 | # 6 | 7 | cd "$(dirname "$0")/.." 8 | set -x 9 | 10 | rm -fr docs/stardoc 11 | mkdir -p docs/stardoc 12 | 13 | bazel build rules:docs 14 | tar xf "$(bazel info bazel-bin)/rules/docs.tar" -C docs/stardoc 15 | find docs/stardoc -size 0 -print0 | while read path; do 16 | rm $path 17 | done 18 | -------------------------------------------------------------------------------- /scripts/prepare-path.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # 4 | # Ensures that the 'bazel' launcher command is on the current path, creating 5 | # a very trivial one that forwards to ./tools/bazel if needed. 6 | # 7 | 8 | set -o pipefail 9 | cd "$(dirname "$0")/.." 10 | 11 | if [[ ! -z "$__ALREADY_PREPARED_BAZEL_PATH" ]]; then 12 | echo "prepare-path: bazel already prepared" 13 | elif ([ "$1" = "--force" ] || ! hash bazel >/dev/null 2>&1); then 14 | echo 'prepare-path: creating one-off bazel launcher' 15 | path_entry=$(mktemp -d) 16 | runner="$path_entry/bazel" 17 | cat > "$runner" <<'EOF' 18 | #!/bin/bash 19 | find_workspace() { 20 | if [ ! -f WORKSPACE ]; then 21 | cd .. 22 | find_workspace 23 | fi 24 | } 25 | workspace=$(find_workspace; pwd) 26 | # use parent workspace, if needed 27 | if ! [ -f "$workspace/tools/bazel" ]; then 28 | workspace=$(cd $workspace/..; find_workspace; pwd) 29 | fi 30 | (>&2 echo :: exec "$workspace/tools/bazel" "$@") 31 | exec "$workspace/tools/bazel" "$@" 32 | EOF 33 | chmod +x "$runner" 34 | export __ALREADY_PREPARED_BAZEL_PATH=1 35 | export PATH=$path_entry:$PATH 36 | else 37 | echo 'prepare-path: using host bazel launcher' 38 | fi 39 | -------------------------------------------------------------------------------- /scripts/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # 4 | # Runs the integration test suite. 5 | # 6 | 7 | set -o pipefail 8 | cd "$(dirname "$0")/.." 9 | 10 | . ./scripts/prepare-path.sh --force 11 | 12 | find tests -name test -type f | sort | while read f; do 13 | echo running ${f#"tests/"}... 14 | output=$($f 2>&1) || ( echo "$output" && exit 1 ) 15 | done 16 | 17 | trap echo ERR 18 | -------------------------------------------------------------------------------- /src/main/scala/BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_scala_annex//rules:scala.bzl", 3 | "configure_bootstrap_scala", 4 | "configure_zinc_scala", 5 | "scala_library", 6 | ) 7 | 8 | alias( 9 | name = "bootstrap", 10 | actual = ":bootstrap_2_12_10", 11 | visibility = ["//visibility:public"], 12 | ) 13 | 14 | alias( 15 | name = "zinc", 16 | actual = ":zinc_2_12_10", 17 | visibility = ["//visibility:public"], 18 | ) 19 | 20 | compiler_classpath_2_12_10 = [ 21 | "@annex//:org_scala_lang_scala_compiler", 22 | "@annex//:org_scala_lang_scala_library", 23 | "@annex//:org_scala_lang_scala_reflect", 24 | ] 25 | 26 | runtime_classpath_2_12_10 = [ 27 | "@annex//:org_scala_lang_scala_library", 28 | ] 29 | 30 | configure_bootstrap_scala( 31 | name = "bootstrap_2_12_10", 32 | compiler_classpath = compiler_classpath_2_12_10, 33 | runtime_classpath = runtime_classpath_2_12_10, 34 | version = "2.12.8", 35 | visibility = ["//visibility:public"], 36 | ) 37 | 38 | scala_library( 39 | name = "compiler_bridge_2_12_10", 40 | srcs = [ 41 | "@compiler_bridge_2_12//:src", 42 | ], 43 | scala = ":bootstrap_2_12_10", 44 | visibility = ["//visibility:public"], 45 | deps = compiler_classpath_2_12_10 + [ 46 | "@annex//:org_scala_sbt_compiler_interface", 47 | "@annex//:org_scala_sbt_util_interface", 48 | ], 49 | ) 50 | 51 | configure_zinc_scala( 52 | name = "zinc_2_12_10", 53 | compiler_bridge = ":compiler_bridge_2_12_10", 54 | compiler_classpath = compiler_classpath_2_12_10, 55 | runtime_classpath = runtime_classpath_2_12_10, 56 | version = "2.12.8", 57 | visibility = ["//visibility:public"], 58 | ) 59 | 60 | config_setting( 61 | name = "deps_used_off", 62 | define_values = { 63 | "scala_deps_used": "off", 64 | }, 65 | ) 66 | 67 | config_setting( 68 | name = "deps_direct_off", 69 | define_values = { 70 | "scala_deps_direct": "off", 71 | }, 72 | ) 73 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/common/args/BUILD: -------------------------------------------------------------------------------- 1 | load("//rules:scalafmt.bzl", "scala_format_test") 2 | load("//rules:scala.bzl", "scala_library") 3 | 4 | scala_library( 5 | name = "args", 6 | srcs = glob(["**/*.scala"]), 7 | scala = "//src/main/scala:bootstrap", 8 | visibility = ["//visibility:public"], 9 | deps = [ 10 | "@annex//:net_sourceforge_argparse4j_argparse4j", 11 | ], 12 | ) 13 | 14 | scala_format_test( 15 | name = "format", 16 | srcs = glob(["**/*.scala"]), 17 | ) 18 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/common/args/Implicits.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package common.args 3 | 4 | import scala.language.reflectiveCalls 5 | import net.sourceforge.argparse4j.inf.Argument 6 | 7 | object implicits { 8 | implicit final class SetArgumentDefault(val argument: Argument) extends AnyVal { 9 | // https://issues.scala-lang.org/browse/SI-2991 10 | private[this] type SetDefault = { def setDefault(value: AnyRef) } 11 | def setDefault_[A](value: A) = argument.asInstanceOf[SetDefault].setDefault(value.asInstanceOf[AnyRef]) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/common/sbt-testing/AnnexTestingLogger.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package common.sbt_testing 3 | 4 | import sbt.testing.Logger 5 | 6 | final class AnnexTestingLogger(color: Boolean, verbosity: String) extends Logger with Serializable { 7 | def ansiCodesSupported = color 8 | 9 | def error(msg: String) = println(s"$msg") 10 | 11 | def warn(msg: String) = println(s"$msg") 12 | 13 | def info(msg: String) = verbosity match { 14 | case "HIGH" | "MEDIUM" => println(s"$msg") 15 | case _ => 16 | } 17 | 18 | def debug(msg: String) = verbosity match { 19 | case "HIGH" => println(s"$msg") 20 | } 21 | 22 | def trace(err: Throwable) = println(s"${err.getMessage}") 23 | } 24 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/common/sbt-testing/BUILD: -------------------------------------------------------------------------------- 1 | load("//rules:scalafmt.bzl", "scala_format_test") 2 | load("//rules:scala.bzl", "scala_library") 3 | 4 | _subprocess_srcs = glob(["SubprocessRunner.scala"]) 5 | 6 | _common_srcs = [ 7 | f 8 | for f in glob(["**/*.scala"]) 9 | if f not in _subprocess_srcs 10 | ] 11 | 12 | scala_library( 13 | name = "subprocess", 14 | srcs = _subprocess_srcs, 15 | scala = "//src/main/scala:zinc", 16 | visibility = ["//visibility:public"], 17 | deps = [ 18 | ":common", 19 | "@annex//:org_scala_sbt_test_interface", 20 | ], 21 | ) 22 | 23 | scala_library( 24 | name = "common", 25 | srcs = _common_srcs, 26 | scala = "//src/main/scala:zinc", 27 | visibility = ["//visibility:public"], 28 | deps = [ 29 | "@annex//:org_scala_lang_modules_scala_xml_2_12", 30 | "@annex//:org_scala_sbt_test_interface", 31 | ], 32 | ) 33 | 34 | scala_format_test( 35 | name = "format", 36 | srcs = glob(["**/*.scala"]), 37 | ) 38 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/common/sbt-testing/CLassLoaders.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package common.sbt_testing 3 | 4 | import java.net.{URL, URLClassLoader} 5 | 6 | object ClassLoaders { 7 | def withContextClassLoader[A](classLoader: ClassLoader)(f: => A) = { 8 | val thread = Thread.currentThread 9 | val previous = thread.getContextClassLoader 10 | thread.setContextClassLoader(classLoader) 11 | try f 12 | finally thread.setContextClassLoader(previous) 13 | } 14 | 15 | def sbtTestClassLoader(urls: Seq[URL]) = new URLClassLoader(urls.toArray, null) { 16 | private[this] val current = getClass.getClassLoader() 17 | override protected def findClass(className: String): Class[_] = 18 | if (className.startsWith("sbt.testing.")) current.loadClass(className) 19 | else if (className.startsWith("org.jacoco.agent.rt.")) current.loadClass(className) 20 | else super.findClass(className) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/common/sbt-testing/PrefixedTestingLogger.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package common.sbt_testing 3 | 4 | import sbt.testing.Logger 5 | 6 | class PrefixedTestingLogger(delegate: Logger, prefix: String) extends Logger { 7 | def ansiCodesSupported() = delegate.ansiCodesSupported() 8 | def error(msg: String) = delegate.error(prefix + msg) 9 | def warn(msg: String) = delegate.warn(prefix + msg) 10 | def info(msg: String) = delegate.info(prefix + msg) 11 | def debug(msg: String) = delegate.debug(prefix + msg) 12 | def trace(t: Throwable) = delegate.trace(t) 13 | } 14 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/common/sbt-testing/SubprocessRunner.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package common.sbt_testing 3 | 4 | import java.io.ObjectInputStream 5 | import java.nio.file.Paths 6 | import scala.collection.mutable 7 | 8 | object SubprocessTestRunner { 9 | 10 | def main(args: Array[String]): Unit = { 11 | val input = new ObjectInputStream(System.in) 12 | val request = input.readObject().asInstanceOf[TestRequest] 13 | val classLoader = ClassLoaders.sbtTestClassLoader(request.classpath.map(path => Paths.get(path).toUri.toURL)) 14 | 15 | val loader = new TestFrameworkLoader(classLoader, request.logger) 16 | val framework = loader.load(request.framework).get 17 | 18 | val passed = ClassLoaders.withContextClassLoader(classLoader) { 19 | TestHelper.withRunner(framework, request.scopeAndTestName, classLoader, request.testArgs) { runner => 20 | val tasks = runner.tasks(Array(TestHelper.taskDef(request.test, request.scopeAndTestName))) 21 | tasks.length == 0 || { 22 | val reporter = new TestReporter(request.logger) 23 | val taskExecutor = new TestTaskExecutor(request.logger) 24 | val failures = mutable.Set[String]() 25 | tasks.foreach { task => 26 | reporter.preTask(task) 27 | taskExecutor.execute(task, failures) 28 | reporter.postTask() 29 | } 30 | !failures.nonEmpty 31 | } 32 | } 33 | } 34 | 35 | sys.exit(if (passed) 0 else 1) 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/common/sbt-testing/TestRequest.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package common.sbt_testing 3 | 4 | import sbt.testing.Logger 5 | 6 | class TestRequest( 7 | val framework: String, 8 | val test: TestDefinition, 9 | val scopeAndTestName: String, 10 | val classpath: Seq[String], 11 | val logger: Logger with Serializable, 12 | val testArgs: Seq[String] 13 | ) extends Serializable 14 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/common/sbt-testing/fingerprints.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package common.sbt_testing 3 | 4 | import sbt.testing.{AnnotatedFingerprint, SubclassFingerprint} 5 | 6 | sealed trait TestFingerprint extends Serializable 7 | 8 | class TestAnnotatedFingerprint(val annotationName: String, val isModule: Boolean) 9 | extends AnnotatedFingerprint 10 | with TestFingerprint 11 | 12 | object TestAnnotatedFingerprint { 13 | def apply(fingerprint: AnnotatedFingerprint) = 14 | new TestAnnotatedFingerprint(fingerprint.annotationName, fingerprint.isModule) 15 | } 16 | 17 | class TestSubclassFingerprint(val isModule: Boolean, val requireNoArgConstructor: Boolean, val superclassName: String) 18 | extends SubclassFingerprint 19 | with TestFingerprint 20 | 21 | object TestSubclassFingerprint { 22 | def apply(fingerprint: SubclassFingerprint) = 23 | new TestSubclassFingerprint(fingerprint.isModule, fingerprint.requireNoArgConstructor, fingerprint.superclassName) 24 | } 25 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/common/worker/BUILD: -------------------------------------------------------------------------------- 1 | load("//rules:scalafmt.bzl", "scala_format_test") 2 | load("//rules:scala.bzl", "scala_library") 3 | 4 | scala_library( 5 | name = "worker", 6 | srcs = glob(["**/*.scala"]), 7 | scala = "//src/main/scala:bootstrap", 8 | visibility = ["//visibility:public"], 9 | deps = [ 10 | "//third_party/bazel/src/main/protobuf:worker_protocol_java_proto", 11 | ], 12 | ) 13 | 14 | scala_format_test( 15 | name = "format", 16 | srcs = glob(["**/*.scala"]), 17 | ) 18 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/common/worker/WorkerMain.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package common.worker 3 | 4 | import com.google.devtools.build.lib.worker.WorkerProtocol 5 | import java.io.ByteArrayInputStream 6 | import java.io.ByteArrayOutputStream 7 | import java.io.InputStream 8 | import java.io.PrintStream 9 | import java.lang.SecurityManager 10 | import java.security.Permission 11 | import scala.annotation.tailrec 12 | import scala.util.control.NonFatal 13 | 14 | trait WorkerMain[S] { 15 | 16 | private[this] final case class ExitTrapped(code: Int) extends Throwable 17 | 18 | protected[this] def init(args: Option[Array[String]]): S 19 | 20 | protected[this] def work(ctx: S, args: Array[String]): Unit 21 | 22 | final def main(args: Array[String]): Unit = { 23 | args.toList match { 24 | case "--persistent_worker" :: args => 25 | val stdin = System.in 26 | val stdout = System.out 27 | val stderr = System.err 28 | 29 | System.setSecurityManager(new SecurityManager { 30 | val Exit = raw"exitVM\.(-?\d+)".r 31 | override def checkPermission(permission: Permission): Unit = { 32 | permission.getName match { 33 | case Exit(code) => throw new ExitTrapped(code.toInt) 34 | case _ => 35 | } 36 | } 37 | }) 38 | 39 | val outStream = new ByteArrayOutputStream 40 | val out = new PrintStream(outStream) 41 | 42 | System.setIn(new ByteArrayInputStream(Array.emptyByteArray)) 43 | System.setOut(out) 44 | System.setErr(out) 45 | 46 | try { 47 | @tailrec 48 | def process(ctx: S): S = { 49 | val request = WorkerProtocol.WorkRequest.parseDelimitedFrom(stdin) 50 | val args = request.getArgumentsList.toArray(Array.empty[String]) 51 | 52 | val code = 53 | try { 54 | work(ctx, args) 55 | 0 56 | } catch { 57 | case ExitTrapped(code) => code 58 | case NonFatal(e) => 59 | e.printStackTrace() 60 | 1 61 | } 62 | 63 | WorkerProtocol.WorkResponse.newBuilder 64 | .setOutput(outStream.toString) 65 | .setExitCode(code) 66 | .build 67 | .writeDelimitedTo(stdout) 68 | 69 | out.flush() 70 | outStream.reset() 71 | 72 | process(ctx) 73 | } 74 | process(init(Some(args.toArray))) 75 | } finally { 76 | System.setIn(stdin) 77 | System.setOut(stdout) 78 | System.setErr(stderr) 79 | } 80 | 81 | case args => work(init(None), args.toArray) 82 | } 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/bloop/compile/BUILD: -------------------------------------------------------------------------------- 1 | load("//rules:scala.bzl", "scala_binary") 2 | load("//rules:scalafmt.bzl", "scala_format_test") 3 | 4 | scala_binary( 5 | name = "compile", 6 | srcs = glob(["**/*.scala"]), 7 | scala = "//src/main/scala:zinc", 8 | visibility = ["//visibility:public"], 9 | deps = [ 10 | "//src/main/scala/higherkindness/rules_scala/common/worker", 11 | "@annex//:ch_epfl_scala_bloop_frontend_2_12", 12 | ], 13 | ) 14 | 15 | scala_format_test( 16 | name = "format", 17 | srcs = glob(["**/*.scala"]), 18 | ) 19 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/bloop/compile/BloopRunner.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package workers.bloop.compile 3 | 4 | import common.worker.WorkerMain 5 | 6 | import bloop.Bloop 7 | 8 | object BloopRunner extends WorkerMain[Unit] { 9 | override def init(args: Option[Array[String]]): Unit = () 10 | override def work(ctx: Unit, args: Array[String]): Unit = Bloop 11 | } 12 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/common/AnnexLogger.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package workers.common 3 | 4 | import xsbti.Logger 5 | 6 | import java.io.PrintWriter 7 | import java.io.StringWriter 8 | import java.nio.file.Paths 9 | import java.util.function.Supplier 10 | 11 | import CommonArguments.LogLevel 12 | 13 | final class AnnexLogger(level: String) extends Logger { 14 | 15 | private[this] val root = s"${Paths.get("").toAbsolutePath}/" 16 | 17 | private[this] def format(value: String): String = value.replace(root, "") 18 | 19 | def debug(msg: Supplier[String]): Unit = level match { 20 | case LogLevel.Debug => System.err.println(format(msg.get)) 21 | case _ => 22 | } 23 | 24 | def error(msg: Supplier[String]): Unit = level match { 25 | case LogLevel.Debug | LogLevel.Error | LogLevel.Info | LogLevel.Warn => System.err.println(format(msg.get)) 26 | case _ => 27 | } 28 | 29 | def info(msg: Supplier[String]): Unit = level match { 30 | case LogLevel.Debug | LogLevel.Info => System.err.println(format(msg.get)) 31 | case _ => 32 | } 33 | 34 | def trace(err: Supplier[Throwable]): Unit = level match { 35 | case LogLevel.Debug | LogLevel.Error | LogLevel.Info | LogLevel.Warn => 36 | val trace = new StringWriter(); 37 | err.get.printStackTrace(new PrintWriter(trace)); 38 | println(format(trace.toString)) 39 | case _ => 40 | } 41 | 42 | def warn(msg: Supplier[String]): Unit = level match { 43 | case LogLevel.Debug | LogLevel.Info | LogLevel.Warn => System.err.println(format(msg.get)) 44 | case _ => 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/common/AnnexScalaInstance.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package workers.common 3 | 4 | import xsbti.compile.ScalaInstance 5 | 6 | import java.io.File 7 | import java.net.URLClassLoader 8 | import java.util.Properties 9 | 10 | final class AnnexScalaInstance(val allJars: Array[File]) extends ScalaInstance { 11 | 12 | override def version: String = actualVersion 13 | override lazy val actualVersion: String = { 14 | val stream = loader.getResourceAsStream("compiler.properties") 15 | try { 16 | val props = new Properties 17 | props.load(stream) 18 | props.getProperty("version.number") 19 | } finally stream.close() 20 | } 21 | 22 | override def compilerJar: File = null 23 | override lazy val libraryJars: Array[File] = allJars 24 | .filter(f => new URLClassLoader(Array(f.toURI.toURL)).findResource("library.properties") != null) 25 | 26 | override def otherJars: Array[File] = Array.empty[File] 27 | override lazy val loader: ClassLoader = 28 | new URLClassLoader(allJars.map(_.toURI.toURL), null) 29 | override def loaderLibraryOnly: ClassLoader = null 30 | } 31 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/common/BUILD: -------------------------------------------------------------------------------- 1 | load("//rules:scala.bzl", "scala_library") 2 | load("//rules:scalafmt.bzl", "scala_format_test") 3 | 4 | scala_library( 5 | name = "common", 6 | srcs = glob(["**/*.scala"]), 7 | scala = "//src/main/scala:bootstrap", 8 | visibility = ["//visibility:public"], 9 | deps = [ 10 | "//src/main/scala/higherkindness/rules_scala/common/args", 11 | "@annex//:net_sourceforge_argparse4j_argparse4j", 12 | "@annex//:org_scala_sbt_zinc_2_12", 13 | ], 14 | ) 15 | 16 | scala_format_test( 17 | name = "format", 18 | srcs = glob(["**/*.scala"]), 19 | ) 20 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/common/Color.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package workers.common 3 | 4 | import xsbti.Problem 5 | import Console.{RED => CR, YELLOW => CY, GREEN => CG, RESET => CRESET} 6 | 7 | object Color { 8 | def Info(problem: Problem): String = colorProblem(problem, CG) 9 | 10 | def Info(message: String): String = colorString(message, CG, "Info") 11 | 12 | def Warning(problem: Problem): String = colorProblem(problem, CY) 13 | 14 | def Warning(message: String): String = colorString(message, CY, "Warn") 15 | 16 | def Error(problem: Problem): String = colorProblem(problem, CR) 17 | 18 | def Error(message: String): String = colorString(message, CR, "Error") 19 | 20 | private def colorProblem(problem: Problem, color: String): String = { 21 | val header = s"[$color${problem.severity}$CRESET]" 22 | problem.position.toString.size match { 23 | case 0 => s"$header " + problem.message.replaceAll("\n", s"\n$header ") 24 | case _ => s"$header ${problem.position} " + problem.message.replaceAll("\n", s"\n$header ") 25 | } 26 | } 27 | 28 | private def colorString(message: String, color: String, severity: String): String = { 29 | val header = s"[$color$severity$CRESET]" 30 | s"$header " + message.replaceAll("\n", s"\n$header ") 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/common/LoggedReporter.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package workers.common 3 | 4 | import xsbti.{Logger, Problem} 5 | import sbt.internal.inc.{LoggedReporter => SbtLoggedReporter} 6 | 7 | class LoggedReporter(logger: Logger) extends SbtLoggedReporter(0, logger) { 8 | override protected def logError(problem: Problem): Unit = logger.error(() => Color.Error(problem)) 9 | override protected def logInfo(problem: Problem): Unit = logger.info(() => Color.Info(problem)) 10 | override protected def logWarning(problem: Problem): Unit = logger.warn(() => Color.Warning(problem)) 11 | } 12 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/deps/BUILD: -------------------------------------------------------------------------------- 1 | load("//rules:scala.bzl", "scala_binary") 2 | load("//rules:scalafmt.bzl", "scala_format_test") 3 | 4 | scala_binary( 5 | name = "deps", 6 | srcs = glob(["**/*.scala"]), 7 | main_class = "higherkindness.rules_scala.workers.deps.DepsRunner", 8 | scala = "//src/main/scala:bootstrap", 9 | visibility = ["//visibility:public"], 10 | deps = [ 11 | "//src/main/scala/higherkindness/rules_scala/common/args", 12 | "//src/main/scala/higherkindness/rules_scala/common/worker", 13 | "@annex//:net_sourceforge_argparse4j_argparse4j", 14 | ], 15 | ) 16 | 17 | scala_format_test( 18 | name = "format", 19 | srcs = glob(["**/*.scala"]), 20 | ) 21 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/jacoco/instrumenter/BUILD: -------------------------------------------------------------------------------- 1 | load("//rules:scala.bzl", "scala_binary") 2 | load("//rules:scalafmt.bzl", "scala_format_test") 3 | 4 | scala_binary( 5 | name = "instrumenter", 6 | srcs = glob(["**/*.scala"]), 7 | main_class = "higherkindness.rules_scala.workers.jacoco.instrumenter.JacocoInstrumenter", 8 | scala = "//src/main/scala:bootstrap", 9 | visibility = ["//visibility:public"], 10 | deps = [ 11 | "//src/main/scala/higherkindness/rules_scala/common/args", 12 | "//src/main/scala/higherkindness/rules_scala/common/worker", 13 | "@annex//:net_sourceforge_argparse4j_argparse4j", 14 | "@annex//:org_jacoco_org_jacoco_core", 15 | ], 16 | ) 17 | 18 | scala_format_test( 19 | name = "format", 20 | srcs = glob(["**/*.scala"]), 21 | ) 22 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/zinc/compile/BUILD: -------------------------------------------------------------------------------- 1 | load("//rules:scala.bzl", "scala_binary") 2 | load("//rules:scalafmt.bzl", "scala_format_test") 3 | 4 | scala_binary( 5 | name = "compile", 6 | srcs = glob(["**/*.scala"]), 7 | main_class = "higherkindness.rules_scala.workers.zinc.compile.ZincRunner", 8 | scala = "//src/main/scala:bootstrap", 9 | visibility = ["//visibility:public"], 10 | runtime_deps = [ 11 | "@annex//:com_lihaoyi_sourcecode_2_12", 12 | ], 13 | deps = [ 14 | "//src/main/scala/higherkindness/rules_scala/common/worker", 15 | "//src/main/scala/higherkindness/rules_scala/workers/common", 16 | "//third_party/bazel/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper", 17 | "@annex//:org_scala_sbt_test_interface", 18 | "@annex//:org_scala_sbt_zinc_2_12", 19 | ], 20 | ) 21 | 22 | scala_format_test( 23 | name = "format", 24 | srcs = glob(["**/*.scala"]), 25 | ) 26 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/zinc/compile/Deps.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package workers.zinc.compile 3 | 4 | import workers.common.FileUtil 5 | import java.math.BigInteger 6 | import java.nio.file.{Files, Path} 7 | import java.security.MessageDigest 8 | 9 | import sbt.internal.inc.Relations 10 | 11 | import xsbti.compile.PerClasspathEntryLookup 12 | 13 | sealed trait Dep { 14 | def file: Path 15 | def classpath: Path 16 | } 17 | 18 | case class LibraryDep(file: Path) extends Dep { 19 | def classpath = file 20 | } 21 | 22 | case class DepAnalysisFiles(apis: Path, relations: Path) 23 | 24 | case class ExternalDep(file: Path, classpath: Path, analysis: DepAnalysisFiles) extends Dep 25 | 26 | object Dep { 27 | 28 | def sha256(file: Path): String = { 29 | val digest = MessageDigest.getInstance("SHA-256") 30 | new BigInteger(1, digest.digest(Files.readAllBytes(file))).toString(16) 31 | } 32 | 33 | def create(depsCache: Option[Path], classpath: Seq[Path], analyses: Map[Path, (Path, DepAnalysisFiles)]): Seq[Dep] = { 34 | val roots = scala.collection.mutable.Set[Path]() 35 | classpath.flatMap { original => 36 | analyses.get(original).fold[Option[Dep]](Some(LibraryDep(original))) { analysis => 37 | val root = analysis._1 38 | if (roots.add(root)) { 39 | depsCache match { 40 | case Some(cacheRoot) => { 41 | val cachedPath = cacheRoot.resolve(sha256(original)) 42 | FileUtil.extractZipIdempotently(original, cachedPath) 43 | Some(ExternalDep(original, cachedPath, analysis._2)) 44 | } 45 | case _ => { 46 | FileUtil.extractZip(original, root) 47 | Some(ExternalDep(original, root, analysis._2)) 48 | } 49 | } 50 | } else { 51 | None 52 | } 53 | } 54 | } 55 | } 56 | 57 | def used(deps: Iterable[Dep], relations: Relations, lookup: PerClasspathEntryLookup): Dep => Boolean = { 58 | val externalDeps = relations.allExternalDeps 59 | val libraryDeps = relations.allLibraryDeps 60 | ({ 61 | case ExternalDep(file, _, _) => externalDeps.exists(lookup.definesClass(file.toFile).apply) 62 | case LibraryDep(file) => libraryDeps(file.toAbsolutePath.toFile) 63 | }) 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincPersistence.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package workers.zinc.compile 3 | 4 | import workers.common.FileUtil 5 | 6 | import java.nio.file.Files 7 | import java.nio.file.Path 8 | 9 | trait ZincPersistence { 10 | def load(): Unit 11 | def save(): Unit 12 | } 13 | 14 | class FilePersistence(cacheDir: Path, analysisFiles: AnalysisFiles, jar: Path) extends ZincPersistence { 15 | private[this] val cacheAnalysisFiles = 16 | AnalysisFiles( 17 | apis = cacheDir.resolve("apis.gz"), 18 | miniSetup = cacheDir.resolve("setup.gz"), 19 | relations = cacheDir.resolve("relations.gz"), 20 | sourceInfos = cacheDir.resolve("infos.gz"), 21 | stamps = cacheDir.resolve("stamps.gz") 22 | ) 23 | private[this] val cacheJar = cacheDir.resolve("classes.jar") 24 | 25 | /** 26 | * Existance indicates that files are incomplete. 27 | */ 28 | private[this] val tmpMarker = cacheDir.resolve(".tmp") 29 | 30 | def load() = { 31 | if (Files.exists(cacheDir) && Files.notExists(tmpMarker)) { 32 | Files.copy(cacheAnalysisFiles.apis, analysisFiles.apis) 33 | Files.copy(cacheAnalysisFiles.miniSetup, analysisFiles.miniSetup) 34 | Files.copy(cacheAnalysisFiles.relations, analysisFiles.relations) 35 | Files.copy(cacheAnalysisFiles.sourceInfos, analysisFiles.sourceInfos) 36 | Files.copy(cacheAnalysisFiles.stamps, analysisFiles.stamps) 37 | Files.copy(cacheJar, jar) 38 | } 39 | } 40 | def save() = { 41 | if (Files.exists(cacheDir)) { 42 | FileUtil.delete(cacheDir) 43 | } 44 | Files.createDirectories(cacheDir) 45 | Files.createFile(tmpMarker) 46 | Files.copy(analysisFiles.apis, cacheAnalysisFiles.apis) 47 | Files.copy(analysisFiles.miniSetup, cacheAnalysisFiles.miniSetup) 48 | Files.copy(analysisFiles.relations, cacheAnalysisFiles.relations) 49 | Files.copy(analysisFiles.sourceInfos, cacheAnalysisFiles.sourceInfos) 50 | Files.copy(analysisFiles.stamps, cacheAnalysisFiles.stamps) 51 | Files.copy(jar, cacheJar) 52 | Files.delete(tmpMarker) 53 | } 54 | } 55 | 56 | object NullPersistence extends ZincPersistence { 57 | def load() = () 58 | def save() = () 59 | } 60 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/zinc/doc/BUILD: -------------------------------------------------------------------------------- 1 | load("//rules:scala.bzl", "scala_binary") 2 | load("//rules:scalafmt.bzl", "scala_format_test") 3 | 4 | scala_binary( 5 | name = "doc", 6 | srcs = glob(["**/*.scala"]), 7 | scala = "//src/main/scala:zinc", 8 | visibility = ["//visibility:public"], 9 | deps = [ 10 | "//src/main/scala/higherkindness/rules_scala/common/args", 11 | "//src/main/scala/higherkindness/rules_scala/common/worker", 12 | "//src/main/scala/higherkindness/rules_scala/workers/common", 13 | "@annex//:net_sourceforge_argparse4j_argparse4j", 14 | "@annex//:org_scala_sbt_compiler_interface", 15 | "@annex//:org_scala_sbt_util_interface", 16 | "@annex//:org_scala_sbt_util_logging_2_12", 17 | "@annex//:org_scala_sbt_zinc_2_12", 18 | "@annex//:org_scala_sbt_zinc_classpath_2_12", 19 | "@annex//:org_scala_sbt_zinc_compile_core_2_12", 20 | ], 21 | ) 22 | 23 | scala_format_test( 24 | name = "format", 25 | srcs = glob(["**/*.scala"]), 26 | ) 27 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/zinc/repl/BUILD: -------------------------------------------------------------------------------- 1 | load("//rules:scala.bzl", "scala_binary") 2 | load("//rules:scalafmt.bzl", "scala_format_test") 3 | 4 | scala_binary( 5 | name = "repl", 6 | srcs = glob(["**/*.scala"]), 7 | scala = "//src/main/scala:zinc", 8 | visibility = ["//visibility:public"], 9 | deps = [ 10 | "//src/main/scala/higherkindness/rules_scala/common/args", 11 | "//src/main/scala/higherkindness/rules_scala/workers/common", 12 | "@annex//:net_sourceforge_argparse4j_argparse4j", 13 | "@annex//:org_scala_sbt_compiler_interface", 14 | "@annex//:org_scala_sbt_util_interface", 15 | "@annex//:org_scala_sbt_util_logging_2_12", 16 | "@annex//:org_scala_sbt_zinc_2_12", 17 | "@annex//:org_scala_sbt_zinc_compile_core_2_12", 18 | ], 19 | ) 20 | 21 | scala_format_test( 22 | name = "format", 23 | srcs = glob(["**/*.scala"]), 24 | ) 25 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/zinc/test/BUILD: -------------------------------------------------------------------------------- 1 | load("//rules:scala.bzl", "scala_library") 2 | load("//rules:scalafmt.bzl", "scala_format_test") 3 | 4 | scala_library( 5 | name = "test", 6 | srcs = glob(["**/*.scala"]), 7 | scala = "//src/main/scala:zinc", 8 | visibility = ["//visibility:public"], 9 | deps = [ 10 | "//src/main/scala/higherkindness/rules_scala/common/args", 11 | "//src/main/scala/higherkindness/rules_scala/common/sbt-testing:common", 12 | "@annex//:com_trueaccord_scalapb_scalapb_runtime_2_12", 13 | "@annex//:net_sourceforge_argparse4j_argparse4j", 14 | "@annex//:org_scala_sbt_compiler_interface", 15 | "@annex//:org_scala_sbt_test_interface", 16 | "@annex//:org_scala_sbt_zinc_apiinfo_2_12", 17 | "@annex//:org_scala_sbt_zinc_core_2_12", 18 | "@annex//:org_scala_sbt_zinc_persist_2_12", 19 | ], 20 | ) 21 | 22 | scala_format_test( 23 | name = "format", 24 | srcs = glob(["**/*.scala"]), 25 | ) 26 | -------------------------------------------------------------------------------- /src/main/scala/higherkindness/rules_scala/workers/zinc/test/TestDiscovery.scala: -------------------------------------------------------------------------------- 1 | package higherkindness.rules_scala 2 | package workers.zinc.test 3 | 4 | import common.sbt_testing.TestAnnotatedFingerprint 5 | import common.sbt_testing.TestDefinition 6 | import common.sbt_testing.TestSubclassFingerprint 7 | 8 | import sbt.testing.{AnnotatedFingerprint, Fingerprint, Framework, SubclassFingerprint, SuiteSelector} 9 | import scala.collection.{breakOut, mutable} 10 | import xsbt.api.Discovery 11 | import xsbti.api.{AnalyzedClass, ClassLike, Definition} 12 | 13 | class TestDiscovery(framework: Framework) { 14 | private[this] val (annotatedPrints, subclassPrints) = { 15 | val annotatedPrints = mutable.ArrayBuffer.empty[TestAnnotatedFingerprint] 16 | val subclassPrints = mutable.ArrayBuffer.empty[TestSubclassFingerprint] 17 | framework.fingerprints.foreach { 18 | case fingerprint: AnnotatedFingerprint => annotatedPrints += TestAnnotatedFingerprint(fingerprint) 19 | case fingerprint: SubclassFingerprint => subclassPrints += TestSubclassFingerprint(fingerprint) 20 | } 21 | (annotatedPrints.toSet, subclassPrints.toSet) 22 | } 23 | 24 | private[this] def definitions(classes: Set[AnalyzedClass]) = { 25 | classes.toSeq 26 | .flatMap(`class` => Seq(`class`.api.classApi, `class`.api.objectApi)) 27 | .flatMap(api => Seq(api, api.structure.declared, api.structure.inherited)) 28 | .collect { case cl: ClassLike if cl.topLevel => cl } 29 | } 30 | 31 | private[this] def discover(definitions: Seq[Definition]) = 32 | Discovery(subclassPrints.map(_.superclassName)(breakOut), annotatedPrints.map(_.annotationName)(breakOut))( 33 | definitions 34 | ) 35 | 36 | def apply(classes: Set[AnalyzedClass]) = 37 | for { 38 | (definition, discovered) <- discover(definitions(classes)) 39 | fingerprint <- subclassPrints.collect { 40 | case print if discovered.baseClasses(print.superclassName) && discovered.isModule == print.isModule => print 41 | } ++ 42 | annotatedPrints.collect { 43 | case print if discovered.annotations(print.annotationName) && discovered.isModule == print.isModule => print 44 | } 45 | } yield new TestDefinition(definition.name, fingerprint) 46 | } 47 | -------------------------------------------------------------------------------- /tests/.bazelrc: -------------------------------------------------------------------------------- 1 | common --config=tests 2 | 3 | build --javabase="//:jdk" 4 | build --java_toolchain="@bazel_tools//tools/jdk:toolchain_hostjdk8" 5 | build --host_javabase="//:jdk" 6 | build --host_java_toolchain="@bazel_tools//tools/jdk:toolchain_hostjdk8" 7 | 8 | import %workspace%/../.bazelrc_shared 9 | -------------------------------------------------------------------------------- /tests/.scalafmt.conf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/higherkindness/rules_scala/aed5cc8a433824e23dc82119de1b98904ab1bb9e/tests/.scalafmt.conf -------------------------------------------------------------------------------- /tests/BUILD: -------------------------------------------------------------------------------- 1 | java_runtime( 2 | name = "jdk", 3 | srcs = select({ 4 | "@bazel_tools//src/conditions:linux_x86_64": ["@jdk8-linux//:jdk"], 5 | "@bazel_tools//src/conditions:darwin_x86_64": ["@jdk8-osx//:jdk"], 6 | "@bazel_tools//src/conditions:darwin": ["@jdk8-osx//:jdk"], 7 | }), 8 | java = select({ 9 | "@bazel_tools//src/conditions:linux_x86_64": "@jdk8-linux//:java", 10 | "@bazel_tools//src/conditions:darwin_x86_64": "@jdk8-osx//:java", 11 | "@bazel_tools//src/conditions:darwin": "@jdk8-osx//:java", 12 | }), 13 | visibility = ["//visibility:public"], 14 | ) 15 | -------------------------------------------------------------------------------- /tests/binary/reflect/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_binary", "scala_library") 2 | 3 | scala_library( 4 | name = "bad", 5 | srcs = ["Reflect.scala"], 6 | scala = "//scala:2_12", 7 | ) 8 | 9 | scala_binary( 10 | name = "good", 11 | srcs = ["Reflect.scala"], 12 | deps_used_whitelist = ["@annex//:org_scala_lang_scala_reflect"], 13 | scala = "//scala:2_12", 14 | deps = ["@annex//:org_scala_lang_scala_reflect"], 15 | ) 16 | -------------------------------------------------------------------------------- /tests/binary/reflect/Reflect.scala: -------------------------------------------------------------------------------- 1 | import scala.reflect.runtime.universe 2 | 3 | class Item(name: String) 4 | 5 | object Reflect { 6 | 7 | def main(args: Array[String]): Unit = { 8 | val `type` = universe.typeOf[Item] 9 | val mirror = universe.runtimeMirror(getClass.getClassLoader) 10 | val classMirror = mirror.reflectClass(`type`.typeSymbol.asClass) 11 | val methodMirror = classMirror.reflectConstructor(`type`.decl(universe.termNames.CONSTRUCTOR).asMethod) 12 | methodMirror("example").asInstanceOf[Item] 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /tests/binary/reflect/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | ! bazel build :bad || false 5 | bazel run :good 6 | -------------------------------------------------------------------------------- /tests/binary/resource/BUILD: -------------------------------------------------------------------------------- 1 | # https://github.com/higherkindness/rules_scala/issues/193 2 | 3 | load("@rules_scala_annex//rules:scala.bzl", "scala_binary", "scala_library") 4 | 5 | scala_library( 6 | name = "lib", 7 | srcs = ["example.scala"], 8 | ) 9 | 10 | scala_binary( 11 | name = "bin", 12 | main_class = "Example", 13 | resource_strip_prefix = package_name(), 14 | resources = ["example.txt"], 15 | runtime_deps = [":lib"], 16 | ) 17 | -------------------------------------------------------------------------------- /tests/binary/resource/example.scala: -------------------------------------------------------------------------------- 1 | import scala.io.Source 2 | 3 | object Example { 4 | def main(args: Array[String]): Unit = { 5 | val stream = getClass.getResourceAsStream("/example.txt") 6 | for (line <- Source.fromInputStream(stream).getLines()) { 7 | println(line) 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/binary/resource/example.txt: -------------------------------------------------------------------------------- 1 | Example 2 | -------------------------------------------------------------------------------- /tests/binary/resource/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel run :bin | grep -q Example 5 | -------------------------------------------------------------------------------- /tests/binary/simple/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_binary") 2 | 3 | scala_binary( 4 | name = "one_discovered", 5 | srcs = ["one_discovered.scala"], 6 | scala = "//scala:2_11", 7 | tags = ["manual"], 8 | ) 9 | -------------------------------------------------------------------------------- /tests/binary/simple/one_discovered.scala: -------------------------------------------------------------------------------- 1 | package anx 2 | 3 | object OneDiscovered { 4 | def main(args: Array[String]): Unit = { 5 | println("Hello from OneDiscovered.main") 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/binary/simple/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel run :one_discovered 5 | -------------------------------------------------------------------------------- /tests/bloop/simple/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "welcome_to_bloop", 5 | srcs = ["welcome_to_bloop.scala"], 6 | scala = "//scala:2_12", 7 | tags = ["manual"], 8 | ) 9 | -------------------------------------------------------------------------------- /tests/bloop/simple/bazel.rc: -------------------------------------------------------------------------------- 1 | build --define=use_bloop=true 2 | -------------------------------------------------------------------------------- /tests/bloop/simple/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | # no work has been done on this; disable for now 5 | # bazel build :welcome_to_bloop 6 | -------------------------------------------------------------------------------- /tests/bloop/simple/welcome_to_bloop.scala: -------------------------------------------------------------------------------- 1 | package anx 2 | 3 | object welcome_to_bloop 4 | -------------------------------------------------------------------------------- /tests/common.sh: -------------------------------------------------------------------------------- 1 | cd "$(dirname "$0")" 2 | FILE="$0" 3 | 4 | printf "\u001b[1;39m:::\u001b[0m\n" 5 | printf "\u001b[1;39m test file: $0\u001b[0m\n" 6 | printf "\u001b[1;39m:::\u001b[0m\n" 7 | 8 | error() { 9 | set +x 10 | printf "\u001b[1;31m::FAILURE::\u001b[0m $FILE:$2 exited with code $1\n" 11 | } 12 | 13 | finish() { 14 | set +x 15 | [ $1 != 0 ] || printf "\u001b[1;32m::SUCCESS::\u001b[0m\n" 16 | } 17 | 18 | trap 'error $? $LINENO' ERR 19 | trap 'finish $?' EXIT 20 | 21 | set -x 22 | -------------------------------------------------------------------------------- /tests/compat/ported_tests/BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@io_bazel_rules_scala//scala:scala.bzl", 3 | "scala_binary", 4 | "scala_library", 5 | "scala_macro_library", 6 | "scala_test", 7 | "scala_test_suite", 8 | ) 9 | 10 | scala_library( 11 | name = "Runtime", 12 | srcs = ["Runtime.scala"], 13 | ) 14 | 15 | scala_library( 16 | name = "Exported", 17 | srcs = ["Exported.scala"], 18 | runtime_deps = [":Runtime"], 19 | ) 20 | 21 | scala_library( 22 | name = "ExportOnly", 23 | exports = [":Exported"], 24 | ) 25 | 26 | scala_library( 27 | name = "OtherLib", 28 | srcs = ["OtherLib.scala"], 29 | deps = [":ExportOnly"], 30 | ) 31 | 32 | scala_macro_library( 33 | name = "MacroTest", 34 | srcs = ["MacroTest.scala"], 35 | ) 36 | 37 | java_library( 38 | name = "OtherJavaLib", 39 | srcs = ["OtherJavaLib.java"], 40 | ) 41 | 42 | scala_library( 43 | name = "HelloLib", 44 | srcs = ["HelloLib.scala"], 45 | deps = [ 46 | ":Exported", 47 | ":MacroTest", 48 | ":OtherJavaLib", 49 | ":OtherLib", 50 | ], 51 | ) 52 | 53 | scala_binary( 54 | name = "ScalaBinary", 55 | srcs = ["ScalaBinary.scala"], 56 | main_class = "scala.test.ScalaBinary", 57 | print_compile_time = True, 58 | deps = [ 59 | ":HelloLib", 60 | ":MacroTest", 61 | ], 62 | ) 63 | 64 | scala_test( 65 | name = "HelloLibTest", 66 | size = "small", # Not a macro, can pass test-specific attributes. 67 | srcs = ["HelloLibTest.scala"], 68 | deps = [ 69 | ":HelloLib", 70 | ], 71 | ) 72 | 73 | scala_test_suite( 74 | name = "HelloLibTestSuite", 75 | size = "small", # Not a macro, can pass test-specific attributes. 76 | srcs = glob(["HelloLibTest*.scala"]), 77 | deps = [ 78 | ":HelloLib", 79 | ], 80 | ) 81 | -------------------------------------------------------------------------------- /tests/compat/ported_tests/Exported.scala: -------------------------------------------------------------------------------- 1 | package scala.test 2 | 3 | object Exported { 4 | def message: String = { 5 | // terrible, don't do this in real code: 6 | val msg = Class.forName("scala.test.Runtime") 7 | .newInstance 8 | .toString 9 | "you all, everybody. " + msg 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/compat/ported_tests/HelloLib.scala: -------------------------------------------------------------------------------- 1 | package scala.test 2 | 3 | object HelloLib { 4 | 5 | def printMessage(arg: String) { 6 | MacroTest.hello(arg == "yo") 7 | println(getOtherLibMessage(arg)) 8 | println(getOtherJavaLibMessage(arg)) 9 | println(Exported.message) 10 | } 11 | 12 | def getOtherLibMessage(arg: String) : String = { 13 | arg + " " + OtherLib.getMessage() 14 | } 15 | 16 | def getOtherJavaLibMessage(arg: String) : String = { 17 | arg + " " + OtherJavaLib.getMessage() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/compat/ported_tests/HelloLibTest.scala: -------------------------------------------------------------------------------- 1 | package scala.test 2 | 3 | import org.scalatest._ 4 | 5 | object TestUtil { 6 | def foo: String = "bar" 7 | } 8 | 9 | class ScalaSuite extends FlatSpec { 10 | "HelloLib" should "call scala" in { 11 | assert(HelloLib.getOtherLibMessage("hello").equals("hello you all, everybody. I am Runtime")) 12 | } 13 | } 14 | 15 | class JavaSuite extends FlatSpec { 16 | "HelloLib" should "call java" in { 17 | assert(HelloLib.getOtherJavaLibMessage("hello").equals("hello java!")) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/compat/ported_tests/HelloLibTest2.scala: -------------------------------------------------------------------------------- 1 | package scala.test 2 | 3 | import org.scalatest._ 4 | 5 | object TestUtil2 { 6 | def foo: String = "bar" 7 | } 8 | 9 | class ScalaSuite2 extends FlatSpec { 10 | "HelloLib" should "call scala" in { 11 | assert(HelloLib.getOtherLibMessage("hello").equals("hello you all, everybody. I am Runtime")) 12 | } 13 | } 14 | 15 | class JavaSuite2 extends FlatSpec { 16 | "HelloLib" should "call java" in { 17 | assert(HelloLib.getOtherJavaLibMessage("hello").equals("hello java!")) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/compat/ported_tests/MacroTest.scala: -------------------------------------------------------------------------------- 1 | package scala.test 2 | 3 | import language.experimental.macros 4 | 5 | import reflect.macros.Context 6 | 7 | object MacroTest { 8 | def hello(param: Any): Unit = macro hello_impl 9 | 10 | def hello_impl(c: Context)(param: c.Expr[Any]): c.Expr[Unit] = { 11 | import c.universe._ 12 | val paramRep = show(param.tree) 13 | val paramRepTree = Literal(Constant(paramRep)) 14 | val paramRepExpr = c.Expr[String](paramRepTree) 15 | reify { println(paramRepExpr.splice + " = " + param.splice) } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/compat/ported_tests/NOTICE: -------------------------------------------------------------------------------- 1 | Everything in this directory was ported over from rules_scala 2 | ------------------------------------------------------------- 3 | 4 | Copyright 2016 The Bazel Authors. All rights reserved. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | -------------------------------------------------------------------------------- /tests/compat/ported_tests/OtherJavaLib.java: -------------------------------------------------------------------------------- 1 | package scala.test; 2 | 3 | /** Example class */ 4 | public class OtherJavaLib { 5 | public static String getMessage() { 6 | return "java!"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/compat/ported_tests/OtherLib.scala: -------------------------------------------------------------------------------- 1 | package scala.test 2 | 3 | // It is just to show how a Scala library can depend on another Scala library. 4 | object OtherLib { 5 | def getMessage(): String = Exported.message 6 | } 7 | -------------------------------------------------------------------------------- /tests/compat/ported_tests/Runtime.scala: -------------------------------------------------------------------------------- 1 | package scala.test 2 | 3 | class Runtime { 4 | override def toString = "I am Runtime" 5 | } 6 | -------------------------------------------------------------------------------- /tests/compat/ported_tests/ScalaBinary.scala: -------------------------------------------------------------------------------- 1 | package scala.test 2 | 3 | object ScalaBinary { 4 | def main(args: Array[String]) { 5 | println(MacroTest.hello(1 + 2)) 6 | HelloLib.printMessage("Hello"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/compat/ported_tests/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :Runtime 5 | bazel build :Exported 6 | bazel build :ExportOnly 7 | #bazel build :OtherLib 8 | bazel build :MacroTest 9 | bazel build :OtherJavaLib 10 | #bazel build :HelloLib 11 | #bazel run :ScalaBinary 12 | #bazel test :HelloLibTest 13 | #bazel test :HelloLibTestSuite_test_suite_HelloLibTest.scala 14 | #bazel test :HelloLibTestSuite_test_suite_HelloLibTest2.scala 15 | #bazel test :HelloLibTestSuite 16 | -------------------------------------------------------------------------------- /tests/compat/scalacopts/BUILD: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "default", 5 | srcs = ["Deprecated.scala"], 6 | ) 7 | 8 | scala_library( 9 | name = "fatal", 10 | srcs = ["Deprecated.scala"], 11 | scalacopts = [ 12 | "-deprecation", 13 | "-Xfatal-warnings", 14 | ], 15 | ) 16 | 17 | scala_library( 18 | name = "warn", 19 | srcs = ["Deprecated.scala"], 20 | scalacopts = [ 21 | "-deprecation", 22 | ], 23 | ) 24 | -------------------------------------------------------------------------------- /tests/compat/scalacopts/Deprecated.scala: -------------------------------------------------------------------------------- 1 | package tests.compat.scalacopts 2 | 3 | @deprecated("deprecated", "the dawn of time") 4 | class Deprecated { 5 | } 6 | 7 | class App { 8 | new Deprecated 9 | } 10 | -------------------------------------------------------------------------------- /tests/compat/scalacopts/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :default 5 | 6 | ! bazel build :fatal || false 7 | 8 | bazel build :warn 9 | -------------------------------------------------------------------------------- /tests/compile/error/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "lib", 5 | srcs = ["Example.scala"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/compile/error/Example.scala: -------------------------------------------------------------------------------- 1 | trait Example1 { 2 | def impl 3 | } 4 | 5 | class Example2 extends Example1 {} 6 | -------------------------------------------------------------------------------- /tests/compile/error/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :lib 2>&1 | grep -q $'\[\e\[31mError\e\[0m\] compile/error/Example\.scala:' 5 | -------------------------------------------------------------------------------- /tests/compile/log_level/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_binary") 2 | 3 | scala_binary( 4 | name = "lib", 5 | srcs = ["Example.scala"], 6 | scala = "//scala:zinc_2_12_6_log_level_debug", 7 | deps = [], 8 | ) 9 | -------------------------------------------------------------------------------- /tests/compile/log_level/Example.scala: -------------------------------------------------------------------------------- 1 | object Example { 2 | def foo = 42 3 | } 4 | -------------------------------------------------------------------------------- /tests/compile/log_level/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :lib > output 2>&1 5 | 6 | cat output | grep "Compiling 1 Scala source" 7 | rm output 8 | -------------------------------------------------------------------------------- /tests/compile/logger/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_binary") 2 | 3 | scala_binary( 4 | name = "lib", 5 | srcs = ["Example.scala"], 6 | deps = [ 7 | "@annex//:org_scala_sbt_util_interface", 8 | "@annex//:org_scala_sbt_util_logging_2_12", 9 | "@annex//:org_scala_sbt_zinc_compile_core_2_12", 10 | "@rules_scala_annex//src/main/scala/higherkindness/rules_scala/workers/common", 11 | ], 12 | ) 13 | -------------------------------------------------------------------------------- /tests/compile/logger/Example.scala: -------------------------------------------------------------------------------- 1 | import higherkindness.rules_scala.workers.common.AnnexLogger 2 | import higherkindness.rules_scala.workers.common.Color 3 | import higherkindness.rules_scala.workers.common.CommonArguments.LogLevel 4 | import higherkindness.rules_scala.workers.common.LoggedReporter 5 | 6 | import sbt.internal.inc.javac.JavaPosition 7 | import sbt.util.InterfaceUtil.problem 8 | import xsbti.Severity 9 | 10 | object Example { 11 | def main(args: Array[String]) { 12 | val logger = new AnnexLogger(LogLevel.Info) 13 | val reporter = new LoggedReporter(logger) 14 | val problem1 = problem("", new JavaPosition("Test Line", 100, "", 100), "Info Message 1", Severity.Info) 15 | val problem2 = problem("", new JavaPosition("Test Line", 200, "", 200), "Warning Message 2", Severity.Warn) 16 | val problem3 = problem("", new JavaPosition("Test Line", 300, "", 300), "Error Message 3", Severity.Error) 17 | // Test logger 18 | reporter.log(problem1) 19 | reporter.log(problem2) 20 | reporter.log(problem3) 21 | // Test Color object 22 | System.err.println(Color.Info("This is an info")) 23 | System.err.println(Color.Warning("This is a warning")) 24 | System.err.println(Color.Error("This is an error")) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/compile/logger/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel run :lib > output 2>&1 5 | cat output | grep -q $'\[\e\[32mInfo\e\[0m\] Test Line:100:100 Info Message 1' 6 | cat output | grep -q $'\[\e\[33mWarn\e\[0m\] Test Line:200:200 Warning Message 2' 7 | cat output | grep -q $'\[\e\[31mError\e\[0m\] Test Line:300:300 Error Message 3' 8 | cat output | grep -q $'\[\e\[32mInfo\e\[0m\] This is an info' 9 | cat output | grep -q $'\[\e\[33mWarn\e\[0m\] This is a warning' 10 | cat output | grep -q $'\[\e\[31mError\e\[0m\] This is an error' 11 | rm output 12 | -------------------------------------------------------------------------------- /tests/compile/srcjar/.gitignore: -------------------------------------------------------------------------------- 1 | example.srcjar -------------------------------------------------------------------------------- /tests/compile/srcjar/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "lib", 5 | srcs = ["example.srcjar"], 6 | scala = "//scala:2_11", 7 | ) 8 | -------------------------------------------------------------------------------- /tests/compile/srcjar/Example.scala: -------------------------------------------------------------------------------- 1 | object Example {} 2 | -------------------------------------------------------------------------------- /tests/compile/srcjar/expected: -------------------------------------------------------------------------------- 1 | -rw---- 2.0 fat 0 bx 0% stor 20100101.000000 META-INF/ 2 | -rw---- 2.0 fat 48 b- 0% stor 20100101.000000 META-INF/MANIFEST.MF 3 | -rw---- 2.0 fat 377 b- 0% stor 20100101.000002 Example$.class 4 | -rw---- 2.0 fat 328 b- 0% stor 20100101.000002 Example.class 5 | -------------------------------------------------------------------------------- /tests/compile/srcjar/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | zip example.srcjar Example.scala 5 | bazel build :lib 6 | diff expected <( 7 | zipinfo -m -T --h-t "$(bazel info bazel-bin)/compile/srcjar/lib.jar" 8 | ) 9 | -------------------------------------------------------------------------------- /tests/compile/xml/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_binary") 2 | 3 | scala_binary( 4 | name = "bad", 5 | srcs = ["Main.scala"], 6 | ) 7 | 8 | scala_binary( 9 | name = "good", 10 | srcs = ["Main.scala"], 11 | deps = ["@annex_test//:org_scala_lang_modules_scala_xml_2_12"], 12 | ) 13 | -------------------------------------------------------------------------------- /tests/compile/xml/Main.scala: -------------------------------------------------------------------------------- 1 | object Main { 2 | def main(args: Array[String]): Unit = { 3 | val xml = 4 | println(xml) 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/compile/xml/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | ! bazel build :bad || false 5 | [ $(bazel run :good) = "" ] 6 | -------------------------------------------------------------------------------- /tests/compile/zinc-inc/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "lib", 5 | srcs = ["Example.gen.scala"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/compile/zinc-inc/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | echo "class A$RANDOM" > Example.gen.scala 5 | 6 | rm -fr "$(bazel info execution_root)/.bazel-zinc" 7 | bazel build --noworker_sandboxing --worker_extra_flag=ScalaCompile=--persistence_dir=.bazel-zinc :lib 8 | # TODO: figure out breakage 9 | #[ "$(unzip -l "$(bazel info execution_root)/.bazel-zinc/compile/zinc_inc_lib/classes.jar" | grep '\.class' | wc -l | xargs echo)" = 1 ] 10 | -------------------------------------------------------------------------------- /tests/coverage/A1.scala: -------------------------------------------------------------------------------- 1 | object A1 { 2 | def a1(flag: Boolean): B1.type = 3 | if (flag) B1 4 | else sys.error("oh noes") 5 | } 6 | -------------------------------------------------------------------------------- /tests/coverage/A2.scala: -------------------------------------------------------------------------------- 1 | object A2 { 2 | def a2(): Unit = { 3 | println("a2: " + B2.b2_a()) 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/coverage/B1.scala: -------------------------------------------------------------------------------- 1 | object B1 { 2 | 3 | def not_called(): Unit = { 4 | println("hello world") 5 | } 6 | 7 | } 8 | -------------------------------------------------------------------------------- /tests/coverage/B2.java: -------------------------------------------------------------------------------- 1 | class B2 { 2 | public static String b2_a() { 3 | return C2.c2("hello from b2_a"); 4 | } 5 | 6 | public static void b2_b() { 7 | System.out.println("this is b2_b"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/coverage/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library", "scala_test") 2 | 3 | scala_test( 4 | name = "test-all", 5 | srcs = [ 6 | "TestAll.scala", 7 | ], 8 | scala = "//scala:2_12", 9 | runtime_deps = [ 10 | "@hamcrest_core//jar", 11 | "@junit_interface//jar", 12 | ], 13 | deps = [ 14 | ":a1", 15 | ":a2", 16 | ":b1", 17 | "@junit//jar", 18 | ], 19 | ) 20 | 21 | java_test( 22 | name = "test-b2", 23 | srcs = [ 24 | "TestB2.java", 25 | ], 26 | test_class = "TestB2", 27 | deps = [ 28 | ":b2", 29 | "@junit//jar", 30 | ], 31 | ) 32 | 33 | scala_library( 34 | name = "a1", 35 | srcs = [ 36 | "A1.scala", 37 | ], 38 | scala = "//scala:2_12", 39 | deps = [ 40 | ":b1", 41 | ], 42 | ) 43 | 44 | scala_library( 45 | name = "b1", 46 | srcs = [ 47 | "B1.scala", 48 | ], 49 | scala = "//scala:2_12", 50 | ) 51 | 52 | scala_library( 53 | name = "a2", 54 | srcs = [ 55 | "A2.scala", 56 | ], 57 | scala = "//scala:2_12", 58 | deps = [ 59 | ":b2", 60 | ], 61 | ) 62 | 63 | # 64 | # As it stands I can't seem to generate coverage for Java libraries pulled into 65 | # a scala_test target. 66 | # 67 | # The java_library is instrumented, but doesn't have the .uninstrumented files 68 | # that Bazel seems to expect. There are a few code paths for code coverage, so 69 | # down the road we can explore how to fix this... 70 | # 71 | 72 | java_library( 73 | name = "b2", 74 | srcs = [ 75 | "B2.java", 76 | ], 77 | deps = [ 78 | ":c2", 79 | ], 80 | ) 81 | 82 | scala_library( 83 | name = "c2", 84 | srcs = [ 85 | "C2.scala", 86 | ], 87 | scala = "//scala:2_12", 88 | ) 89 | -------------------------------------------------------------------------------- /tests/coverage/C2.scala: -------------------------------------------------------------------------------- 1 | object C2 { 2 | def c2(input: String): String = 3 | input.reverse 4 | 5 | } 6 | -------------------------------------------------------------------------------- /tests/coverage/TestAll.scala: -------------------------------------------------------------------------------- 1 | import org.junit.Test 2 | import org.junit.Assert._ 3 | 4 | class TestAll { 5 | 6 | @Test 7 | def testA1: Unit = { 8 | assert(A1.a1(true) == B1) 9 | } 10 | 11 | @Test 12 | def testA2: Unit = { 13 | A2.a2() 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /tests/coverage/TestB2.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import org.junit.Assert.*; 3 | 4 | public class TestB2 { 5 | 6 | @Test 7 | public void testB2() { 8 | B2.b2_b(); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /tests/coverage/expected-test-all-coverage.dat: -------------------------------------------------------------------------------- 1 | SF:/A1.scala 2 | FN:-1,A1$:: ()V 3 | FN:1,A1$:: ()V 4 | FN:3,A1$::a1 (Z)LB1$; 5 | FN:-1,A1::a1 (Z)LB1$; 6 | FNDA:1,A1$:: ()V 7 | FNDA:1,A1$:: ()V 8 | FNDA:1,A1$::a1 (Z)LB1$; 9 | FNDA:0,A1::a1 (Z)LB1$; 10 | FNF:4 11 | FNH:3 12 | BA:3,2 13 | BRF:1 14 | BRH:1 15 | DA:1,1 16 | DA:3,4 17 | DA:4,1 18 | DA:5,4 19 | LH:4 20 | LF:4 21 | end_of_record 22 | SF:/A2.scala 23 | FN:-1,A2$:: ()V 24 | FN:1,A2$:: ()V 25 | FN:3,A2$::a2 ()V 26 | FN:-1,A2::a2 ()V 27 | FNDA:1,A2$:: ()V 28 | FNDA:1,A2$:: ()V 29 | FNDA:1,A2$::a2 ()V 30 | FNDA:0,A2::a2 ()V 31 | FNF:4 32 | FNH:3 33 | DA:1,1 34 | DA:3,12 35 | DA:5,4 36 | LH:3 37 | LF:3 38 | end_of_record 39 | SF:/B1.scala 40 | FN:-1,B1$:: ()V 41 | FN:1,B1$:: ()V 42 | FN:4,B1$::not_called ()V 43 | FN:-1,B1::not_called ()V 44 | FNDA:1,B1$:: ()V 45 | FNDA:1,B1$:: ()V 46 | FNDA:0,B1$::not_called ()V 47 | FNDA:0,B1::not_called ()V 48 | FNF:4 49 | FNH:2 50 | DA:1,1 51 | DA:4,0 52 | DA:7,4 53 | LH:2 54 | LF:3 55 | end_of_record 56 | SF:/C2.scala 57 | FN:-1,C2$:: ()V 58 | FN:1,C2$:: ()V 59 | FN:3,C2$::c2 (Ljava/lang/String;)Ljava/lang/String; 60 | FN:-1,C2::c2 (Ljava/lang/String;)Ljava/lang/String; 61 | FNDA:1,C2$:: ()V 62 | FNDA:1,C2$:: ()V 63 | FNDA:1,C2$::c2 (Ljava/lang/String;)Ljava/lang/String; 64 | FNDA:1,C2::c2 (Ljava/lang/String;)Ljava/lang/String; 65 | FNF:4 66 | FNH:4 67 | DA:1,1 68 | DA:3,9 69 | DA:5,4 70 | LH:3 71 | LF:3 72 | end_of_record 73 | SF:/TestAll.scala 74 | FN:4,TestAll:: ()V 75 | FN:8,TestAll::testA1 ()V 76 | FN:13,TestAll::testA2 ()V 77 | FNDA:1,TestAll:: ()V 78 | FNDA:1,TestAll::testA1 ()V 79 | FNDA:1,TestAll::testA2 ()V 80 | FNF:3 81 | FNH:3 82 | BA:8,2 83 | BRF:1 84 | BRH:1 85 | DA:4,1 86 | DA:8,15 87 | DA:13,3 88 | DA:16,2 89 | LH:4 90 | LF:4 91 | end_of_record 92 | -------------------------------------------------------------------------------- /tests/coverage/expected-test-b2-coverage.dat: -------------------------------------------------------------------------------- 1 | SF:/B2.java 2 | FN:1,B2:: ()V 3 | FN:3,B2::b2_a ()Ljava/lang/String; 4 | FN:7,B2::b2_b ()V 5 | FNDA:0,B2:: ()V 6 | FNDA:0,B2::b2_a ()Ljava/lang/String; 7 | FNDA:1,B2::b2_b ()V 8 | FNF:3 9 | FNH:1 10 | DA:1,0 11 | DA:3,0 12 | DA:7,3 13 | DA:8,1 14 | LH:2 15 | LF:4 16 | end_of_record 17 | SF:/TestB2.java 18 | FN:4,TestB2:: ()V 19 | FN:8,TestB2::testB2 ()V 20 | FNDA:1,TestB2:: ()V 21 | FNDA:1,TestB2::testB2 ()V 22 | FNF:2 23 | FNH:2 24 | DA:4,3 25 | DA:8,1 26 | DA:9,1 27 | LH:3 28 | LF:3 29 | end_of_record 30 | -------------------------------------------------------------------------------- /tests/coverage/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # TODO(Andy Scott): Reenable this test after fixing coverage in Bazel 25 4 | # 5 | # 6 | # . "$(dirname "$0")"/../common.sh 7 | 8 | # bazel_bin=$(bazel info bazel-bin) 9 | 10 | # rm -rf "$bazel_bin/coverage/" 11 | 12 | # bazel test :test-all 13 | 14 | # if [ -f "$bazel_bin/coverage/a1-offline.jar" ]; then 15 | # echo "a1-offline.jar shouldn't exist yet" 16 | # exit 1 17 | # fi 18 | 19 | # bazel coverage \ 20 | # --instrumentation_filter=.* \ 21 | # --instrument_test_targets \ 22 | # :all 23 | 24 | # # in theory, these should work to build a combined report: 25 | # #--coverage_report_generator="@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main" 26 | # #--combined_report=lcov \ 27 | 28 | # if [ ! -f "$bazel_bin/coverage/a1-offline.jar" ]; then 29 | # echo "a1-offline.jar expected" 30 | # exit 1 31 | # fi 32 | 33 | 34 | # diff expected-test-all-coverage.dat $(bazel info bazel-testlogs)/coverage/test-all/coverage.dat 35 | # diff expected-test-b2-coverage.dat $(bazel info bazel-testlogs)/coverage/test-b2/coverage.dat 36 | 37 | # exit 0 38 | 39 | # # 40 | # # fun extras for generating HTML reports 41 | # # 42 | 43 | # set +e 44 | # rm -r test-all-report/* 45 | # set -e 46 | # cat ../bazel-testlogs/coverage/test-all/coverage.dat | sed -e s/SF:\\//SF:/ > test-all-coverage.dat 47 | # genhtml -o test-all-report test-all-coverage.dat 48 | # rm test-all-coverage.dat 49 | 50 | # set +e 51 | # rm -r test-b2-report/* 52 | # set -e 53 | # cat ../bazel-testlogs/coverage/test-b2/coverage.dat | sed -e s/SF:\\//SF:/ > test-b2-coverage.dat 54 | # genhtml -o test-b2-report test-b2-coverage.dat 55 | # rm test-b2-coverage.dat 56 | -------------------------------------------------------------------------------- /tests/dependencies/diamond/A.scala: -------------------------------------------------------------------------------- 1 | package anx 2 | 3 | trait A { 4 | def a: String 5 | } 6 | -------------------------------------------------------------------------------- /tests/dependencies/diamond/B1.scala: -------------------------------------------------------------------------------- 1 | package anx 2 | 3 | trait B1 extends A { 4 | def b1: String 5 | } 6 | -------------------------------------------------------------------------------- /tests/dependencies/diamond/B2.scala: -------------------------------------------------------------------------------- 1 | package anx 2 | 3 | trait B2 extends A { 4 | def b2: String 5 | } 6 | -------------------------------------------------------------------------------- /tests/dependencies/diamond/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | # 4 | # diamond dep DAG: 5 | # 6 | # /--> B1 --\ 7 | # C > A 8 | # \--> B2 --/ 9 | # 10 | 11 | scala_library( 12 | name = "A", 13 | srcs = ["A.scala"], 14 | scala = "//scala:2_11", 15 | tags = ["manual"], 16 | ) 17 | 18 | scala_library( 19 | name = "B1", 20 | srcs = ["B1.scala"], 21 | scala = "//scala:2_11", 22 | tags = ["manual"], 23 | deps = [":A"], 24 | ) 25 | 26 | scala_library( 27 | name = "B2", 28 | srcs = ["B2.scala"], 29 | scala = "//scala:2_11", 30 | tags = ["manual"], 31 | deps = [":A"], 32 | ) 33 | 34 | scala_library( 35 | name = "C", 36 | srcs = ["C.scala"], 37 | scala = "//scala:2_11", 38 | tags = ["manual"], 39 | deps = [ 40 | ":B1", 41 | ":B2", 42 | ], 43 | ) 44 | -------------------------------------------------------------------------------- /tests/dependencies/diamond/C.scala: -------------------------------------------------------------------------------- 1 | package anx 2 | 3 | trait C extends B1 with B2 4 | -------------------------------------------------------------------------------- /tests/dependencies/diamond/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :A 5 | bazel build :B1 :B2 6 | bazel build :C 7 | -------------------------------------------------------------------------------- /tests/dependencies/indirect/A.scala: -------------------------------------------------------------------------------- 1 | object A { 2 | } 3 | -------------------------------------------------------------------------------- /tests/dependencies/indirect/B.scala: -------------------------------------------------------------------------------- 1 | object B { 2 | } -------------------------------------------------------------------------------- /tests/dependencies/indirect/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | load("@rules_scala_annex//rules:providers.bzl", "reconfigure_deps_configuration") 3 | 4 | # used_deps off 5 | reconfigure_deps_configuration( 6 | name = "scala_used_deps_off", 7 | provider = "//scala:2_12", 8 | used = "off", 9 | ) 10 | 11 | scala_library( 12 | name = "used_deps_off_a", 13 | srcs = ["A.scala"], 14 | scala = ":scala_used_deps_off", 15 | ) 16 | 17 | scala_library( 18 | name = "used_deps_off_b", 19 | srcs = ["B.scala"], 20 | scala = ":scala_used_deps_off", 21 | deps = [":used_deps_off_a"], 22 | ) 23 | 24 | scala_library( 25 | name = "used_deps_off_c", 26 | srcs = ["C.scala"], 27 | scala = ":scala_used_deps_off", 28 | deps = [":used_deps_off_b"], 29 | ) 30 | 31 | # direct_deps off 32 | reconfigure_deps_configuration( 33 | name = "scala_direct_deps_off", 34 | direct = "off", 35 | provider = "//scala:2_12", 36 | ) 37 | 38 | scala_library( 39 | name = "direct_deps_off_a", 40 | srcs = ["A.scala"], 41 | scala = ":scala_direct_deps_off", 42 | ) 43 | 44 | scala_library( 45 | name = "direct_deps_off_b", 46 | srcs = ["B.scala"], 47 | scala = ":scala_direct_deps_off", 48 | deps = [":direct_deps_off_a"], 49 | ) 50 | 51 | scala_library( 52 | name = "direct_deps_off_c", 53 | srcs = ["C.scala"], 54 | scala = ":scala_direct_deps_off", 55 | deps = [":direct_deps_off_b"], 56 | ) 57 | 58 | # toggle used_deps and direct_deps via --define 59 | scala_library( 60 | name = "define_a", 61 | srcs = ["A.scala"], 62 | scala = "@rules_scala_annex//src/main/scala:zinc_2_12_10", 63 | ) 64 | 65 | scala_library( 66 | name = "define_b", 67 | srcs = ["B.scala"], 68 | scala = "@rules_scala_annex//src/main/scala:zinc_2_12_10", 69 | deps = [":define_a"], 70 | ) 71 | 72 | scala_library( 73 | name = "define_c", 74 | srcs = ["C.scala"], 75 | scala = "@rules_scala_annex//src/main/scala:zinc_2_12_10", 76 | deps = [":define_b"], 77 | ) 78 | -------------------------------------------------------------------------------- /tests/dependencies/indirect/C.scala: -------------------------------------------------------------------------------- 1 | object C { 2 | A 3 | B 4 | } 5 | -------------------------------------------------------------------------------- /tests/dependencies/indirect/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | # used_deps off 5 | ! bazel build :used_deps_off_c || false 6 | bazel build :used_deps_off_c |& grep "buildozer 'add deps //dependencies/indirect:used_deps_off_a' //dependencies/indirect:used_deps_off_c" 7 | 8 | # direct_deps off 9 | ! bazel build :direct_deps_off_c || false 10 | bazel build :direct_deps_off_c |& grep "buildozer 'remove deps //dependencies/indirect:direct_deps_off_a' //dependencies/indirect:direct_deps_off_b" 11 | 12 | # toggle used_deps and direct_deps via --define 13 | ! bazel build --define=scala_deps_used=off :define_c || false 14 | bazel build --define=scala_deps_used=off :define_c |& grep "buildozer 'add deps //dependencies/indirect:define_a' //dependencies/indirect:define_c" 15 | 16 | ! bazel build --define=scala_deps_direct=off :define_c || false 17 | bazel build --define=scala_deps_direct=off :define_c |& grep "buildozer 'remove deps //dependencies/indirect:define_a' //dependencies/indirect:define_b" 18 | 19 | bazel build --define=scala_deps_used=off --define=scala_deps_direct=off :define_c 20 | -------------------------------------------------------------------------------- /tests/dependencies/neverlink/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_binary", "scala_library") 2 | 3 | scala_library( 4 | name = "library", 5 | srcs = ["Library.scala"], 6 | neverlink = True, 7 | scala = "//scala:2_12", 8 | ) 9 | 10 | scala_binary( 11 | name = "binary", 12 | srcs = ["Binary.scala"], 13 | scala = "//scala:2_12", 14 | deps = [":library"], 15 | ) 16 | -------------------------------------------------------------------------------- /tests/dependencies/neverlink/Binary.scala: -------------------------------------------------------------------------------- 1 | object Binary { 2 | def main(args: Array[String]): Unit = Library 3 | } 4 | -------------------------------------------------------------------------------- /tests/dependencies/neverlink/Library.scala: -------------------------------------------------------------------------------- 1 | object Library {} 2 | -------------------------------------------------------------------------------- /tests/dependencies/neverlink/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :binary 5 | bazel run :binary 2>&1 | grep -q 'java.lang.NoClassDefFoundError: Library' 6 | -------------------------------------------------------------------------------- /tests/dependencies/unused/0_unused.scala: -------------------------------------------------------------------------------- 1 | package anx 2 | 3 | object Unused0 4 | -------------------------------------------------------------------------------- /tests/dependencies/unused/0_used.scala: -------------------------------------------------------------------------------- 1 | package anx 2 | 3 | import org.scalacheck.Properties 4 | 5 | object Used0 extends Properties("Used0") 6 | -------------------------------------------------------------------------------- /tests/dependencies/unused/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "0_used", 5 | srcs = ["0_used.scala"], 6 | scala = "//scala:2_12", 7 | tags = ["manual"], 8 | deps = [ 9 | "@annex_test//:org_scalacheck_scalacheck_2_12", 10 | ], 11 | ) 12 | 13 | scala_library( 14 | name = "0_unused", 15 | srcs = ["0_unused.scala"], 16 | scala = "//scala:2_12", 17 | tags = ["manual"], 18 | deps = [ 19 | "@annex_test//:org_scalacheck_scalacheck_2_12", 20 | ], 21 | ) 22 | 23 | scala_library( 24 | name = "0_unused_whitelist", 25 | srcs = ["0_unused.scala"], 26 | deps_used_whitelist = [ 27 | "@annex_test//:org_scalacheck_scalacheck_2_12", 28 | ], 29 | scala = "//scala:2_12", 30 | tags = ["manual"], 31 | deps = [ 32 | "@annex_test//:org_scalacheck_scalacheck_2_12", 33 | ], 34 | ) 35 | 36 | scala_library( 37 | name = "indirect_unused", 38 | srcs = ["indirect_unused.scala"], 39 | scala = "//scala:2_12", 40 | tags = ["manual"], 41 | deps = [ 42 | "@annex_test//:org_specs2_specs2_common_2_12", 43 | "@annex_test//:org_specs2_specs2_core_2_12", 44 | "@annex_test//:org_specs2_specs2_matcher_2_12", 45 | ], 46 | ) 47 | 48 | scala_library( 49 | name = "indirect_unused_missing", 50 | srcs = ["indirect_unused.scala"], 51 | scala = "//scala:2_12", 52 | tags = ["manual"], 53 | deps = [ 54 | "@annex_test//:org_specs2_specs2_common_2_12", 55 | "@annex_test//:org_specs2_specs2_core_2_12", 56 | ], 57 | ) 58 | 59 | scala_library( 60 | name = "indirect_unused_whitelist", 61 | srcs = ["indirect_unused.scala"], 62 | deps_unused_whitelist = [ 63 | "@annex_test//:org_specs2_specs2_matcher_2_12", 64 | ], 65 | scala = "//scala:2_12", 66 | tags = ["manual"], 67 | deps = [ 68 | "@annex_test//:org_specs2_specs2_common_2_12", 69 | "@annex_test//:org_specs2_specs2_core_2_12", 70 | ], 71 | ) 72 | -------------------------------------------------------------------------------- /tests/dependencies/unused/indirect_unused.scala: -------------------------------------------------------------------------------- 1 | import org.specs2.mutable.Specification 2 | 3 | class IndirectUnused extends Specification { 4 | 5 | "Equality" should { 6 | "be reflexive" in { 7 | val a = 1 8 | a must_== a 9 | } 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /tests/dependencies/unused/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :0_used 5 | ! bazel build :0_unused || false 6 | bazel build :0_unused |& grep "buildozer 'remove deps @annex_test//:org_scalacheck_scalacheck_2_12' //dependencies/unused:0_unused" 7 | bazel build :0_unused_whitelist 8 | bazel build :indirect_unused 9 | ! bazel build :indirect_unused_missing || false 10 | bazel build :indirect_unused_missing |& grep "buildozer 'add deps @annex_test//:org_specs2_specs2_matcher_2_12' //dependencies/unused:indirect_unused_missing" 11 | bazel build :indirect_unused_whitelist 12 | -------------------------------------------------------------------------------- /tests/deployjar/BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_scala_annex//rules:scala.bzl", 3 | "scala_binary", 4 | "scala_library", 5 | ) 6 | 7 | scala_binary( 8 | name = "TestBinary", 9 | srcs = ["TestBinary.scala"], 10 | deps = [":TestClass"], 11 | ) 12 | 13 | scala_library( 14 | name = "TestClass", 15 | srcs = ["TestClass.scala"], 16 | ) 17 | -------------------------------------------------------------------------------- /tests/deployjar/TestBinary.scala: -------------------------------------------------------------------------------- 1 | package foo 2 | 3 | object TestBinary { 4 | def main(args: Array[String]) { 5 | println("Hello, world1") 6 | println("Hello, world2") 7 | println("Hello, world3") 8 | 9 | val test = new TestClass 10 | test.print 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/deployjar/TestClass.scala: -------------------------------------------------------------------------------- 1 | package foo 2 | 3 | class TestClass { 4 | def print { 5 | println("Hello, from test1") 6 | println("Hello, from test2") 7 | println("Hello, from test3") 8 | } 9 | } -------------------------------------------------------------------------------- /tests/deployjar/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../common.sh 3 | 4 | bazel build :TestBinary_deploy.jar 5 | 6 | diff expected <( 7 | zipinfo -m -T --h-t "$(bazel info bazel-bin)/deployjar/TestBinary_deploy.jar" 8 | ) 9 | -------------------------------------------------------------------------------- /tests/format/scalafmt/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scalafmt.bzl", "scala_format_test") 2 | load("@rules_scala_annex//rules:scala_with_scalafmt.bzl", "scala_binary", "scala_library", "scala_test") 3 | 4 | ### scala_format_test ### 5 | scala_format_test( 6 | name = "formatted", 7 | srcs = ["formatted.scala"], 8 | ) 9 | 10 | scala_format_test( 11 | name = "unformatted", 12 | srcs = ["unformatted.scala"], 13 | ) 14 | 15 | scala_format_test( 16 | name = "unformatted-copy", 17 | srcs = ["unformatted.tmp.scala"], 18 | ) 19 | 20 | ### scala_binary ### 21 | scala_binary( 22 | name = "formatted-binary", 23 | srcs = ["formatted.scala"], 24 | format = True, 25 | ) 26 | 27 | scala_binary( 28 | name = "unformatted-binary", 29 | srcs = ["unformatted.scala"], 30 | format = True, 31 | ) 32 | 33 | scala_binary( 34 | name = "unformatted-binary-copy", 35 | srcs = ["unformatted.tmp.scala"], 36 | format = True, 37 | ) 38 | 39 | ### scala_library ### 40 | scala_library( 41 | name = "formatted-library", 42 | srcs = ["formatted.scala"], 43 | format = True, 44 | ) 45 | 46 | scala_library( 47 | name = "unformatted-library", 48 | srcs = ["unformatted.scala"], 49 | format = True, 50 | ) 51 | 52 | scala_library( 53 | name = "unformatted-library-copy", 54 | srcs = ["unformatted.tmp.scala"], 55 | format = True, 56 | ) 57 | 58 | ### scala_test ### 59 | scala_test( 60 | name = "formatted-test", 61 | srcs = ["formatted.scala"], 62 | format = True, 63 | ) 64 | 65 | scala_test( 66 | name = "unformatted-test", 67 | srcs = ["unformatted.scala"], 68 | format = True, 69 | ) 70 | 71 | scala_test( 72 | name = "unformatted-test-copy", 73 | srcs = ["unformatted.tmp.scala"], 74 | format = True, 75 | ) 76 | 77 | ### utf8 encoding test ### 78 | scala_format_test( 79 | name = "utf8-encoding-test-default", 80 | srcs = ["utf8-unformatted.tmp.scala"], 81 | ) 82 | 83 | scala_binary( 84 | name = "utf8-encoding-test-non-default", 85 | srcs = ["utf8-unformatted.tmp.scala"], 86 | format = True, 87 | ) 88 | -------------------------------------------------------------------------------- /tests/format/scalafmt/formatted.scala: -------------------------------------------------------------------------------- 1 | object Formatted 2 | -------------------------------------------------------------------------------- /tests/format/scalafmt/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | # scala_format_test 5 | ## check 6 | bazel test :formatted 7 | ! bazel test :unformatted 8 | ## copy 9 | cp unformatted.template.scala unformatted.tmp.scala 10 | ! bazel test :unformatted-copy 11 | bazel run :unformatted-copy 12 | bazel test :unformatted-copy 13 | rm unformatted.tmp.scala 14 | 15 | # non-default output format test: binary 16 | ## check 17 | bazel run :formatted-binary.format-test 18 | ! bazel run :unformatted-binary.format-test 19 | ## copy 20 | cp unformatted.template.scala unformatted.tmp.scala 21 | ! bazel run :unformatted-binary-copy.format-test 22 | bazel run :unformatted-binary-copy.format 23 | bazel run :unformatted-binary-copy.format-test 24 | rm unformatted.tmp.scala 25 | 26 | # non-default output format test: library 27 | ## check 28 | bazel run :formatted-library.format-test 29 | ! bazel run :unformatted-library.format-test 30 | ## copy 31 | cp unformatted.template.scala unformatted.tmp.scala 32 | ! bazel run :unformatted-library-copy.format-test 33 | bazel run :unformatted-library-copy.format 34 | bazel run :unformatted-library-copy.format-test 35 | rm unformatted.tmp.scala 36 | 37 | # non-default output format test: test 38 | ## check 39 | bazel run :formatted-test.format-test 40 | ! bazel run :unformatted-test.format-test 41 | ## copy 42 | cp unformatted.template.scala unformatted.tmp.scala 43 | ! bazel run :unformatted-test-copy.format-test 44 | bazel run :unformatted-test-copy.format 45 | bazel run :unformatted-test-copy.format-test 46 | rm unformatted.tmp.scala 47 | 48 | # utf-8 encoding formatting test 49 | ## scala_format_test 50 | cp utf8-unformatted.template.scala utf8-unformatted.tmp.scala 51 | bazel run :utf8-encoding-test-default 52 | diff utf8-unformatted.tmp.scala utf8-formatted.scala 53 | rm utf8-unformatted.tmp.scala 54 | ## scala_binary (non-default) 55 | cp utf8-unformatted.template.scala utf8-unformatted.tmp.scala 56 | bazel run :utf8-encoding-test-non-default.format 57 | diff utf8-unformatted.tmp.scala utf8-formatted.scala 58 | rm utf8-unformatted.tmp.scala 59 | -------------------------------------------------------------------------------- /tests/format/scalafmt/unformatted.scala: -------------------------------------------------------------------------------- 1 | object Unformatted 2 | -------------------------------------------------------------------------------- /tests/format/scalafmt/unformatted.template.scala: -------------------------------------------------------------------------------- 1 | object HelloWorld { 2 | def main ( args: 3 | 4 | 5 | Array [String ]) { 6 | println ( 7 | "Hello, world!" 8 | ) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/format/scalafmt/utf8-formatted.scala: -------------------------------------------------------------------------------- 1 | object HelloWorld { 2 | def main(args: Array[String]) { 3 | println("Be careful with this test") 4 | println("小心這個測試") 5 | println("このテストに注意してください") 6 | println("이 시험에 조심하십시오") 7 | println("كن حذرا مع هذا الاختبار") 8 | println("Hãy cẩn thận với bài kiểm tra này") 9 | println("Будьте осторожны с этим тестом") 10 | println("😁✊🚀🍟💯") 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/format/scalafmt/utf8-unformatted.template.scala: -------------------------------------------------------------------------------- 1 | object HelloWorld { 2 | def main(args: Array[String]) { 3 | println("Be careful with this test") 4 | println ("小心這個測試") 5 | println ("このテストに注意してください") 6 | println ("이 시험에 조심하십시오") 7 | println ("كن حذرا مع هذا الاختبار") 8 | println ("Hãy cẩn thận với bài kiểm tra này") 9 | println ("Будьте осторожны с этим тестом") 10 | println ("😁✊🚀🍟💯") 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/mockutil/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "mocklib", 5 | srcs = ["MockLib.scala"], 6 | visibility = ["//visibility:public"], 7 | ) 8 | -------------------------------------------------------------------------------- /tests/mockutil/MockLib.scala: -------------------------------------------------------------------------------- 1 | package mockutil 2 | 3 | /** Mocklib 4 | * 5 | * Utility functions 6 | */ 7 | object MockLib { 8 | def add(i1: Int, i2: Int): Int = { 9 | i1 + i2 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/plugins/classpath/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "plugin-lib", 5 | srcs = ["plugin-lib.scala"], 6 | scala = "//scala:2_12", 7 | tags = ["manual"], 8 | ) 9 | 10 | _gen_plugin_xml_cmd = """ 11 | cat > $@ << EOF 12 | 13 | plugin 14 | plug.it.in.Plugin 15 | 16 | """ 17 | 18 | genrule( 19 | name = "gen-scalac-plugin.xml", 20 | outs = ["scalac-plugin.xml"], 21 | cmd = _gen_plugin_xml_cmd, 22 | ) 23 | 24 | java_binary( 25 | name = "resources", 26 | classpath_resources = [ 27 | ":gen-scalac-plugin.xml", 28 | ], 29 | create_executable = False, 30 | ) 31 | 32 | scala_library( 33 | name = "plugin", 34 | srcs = ["plugin.scala"], 35 | resource_jars = [ 36 | ":resources", 37 | ], 38 | scala = "//scala:2_12", 39 | tags = ["manual"], 40 | deps = [ 41 | ":plugin-lib", 42 | "@scala_compiler_2_12_6//jar", 43 | "@scala_reflect_2_12_6//jar", 44 | ], 45 | ) 46 | 47 | scala_library( 48 | name = "inefficient-usage", 49 | srcs = ["usage.scala"], 50 | plugins = [ 51 | ":plugin", 52 | ], 53 | scala = "//scala:2_12", 54 | tags = ["manual"], 55 | ) 56 | -------------------------------------------------------------------------------- /tests/plugins/classpath/plugin-lib.scala: -------------------------------------------------------------------------------- 1 | package plug.it.in 2 | 3 | object Lib { 4 | val name: String = "just-a-name" 5 | val description: String = "just another plugin" 6 | } 7 | -------------------------------------------------------------------------------- /tests/plugins/classpath/plugin.scala: -------------------------------------------------------------------------------- 1 | package plug.it.in 2 | 3 | import scala.tools.nsc.Global 4 | import scala.tools.nsc.Phase 5 | import scala.tools.nsc.plugins.{ Plugin => NscPlugin } 6 | import scala.tools.nsc.plugins.{ PluginComponent => NscPluginComponent } 7 | 8 | final class Plugin(override val global: Global) extends NscPlugin { 9 | override val name: String = Lib.name 10 | override val description: String = Lib.description 11 | override val components: List[NscPluginComponent] = 12 | PluginComponent :: Nil 13 | 14 | private object PluginComponent extends NscPluginComponent { 15 | override val global: Global = Plugin.this.global 16 | override val phaseName: String = "dummy-phase" 17 | override val runsAfter: List[String] = "parser" :: Nil 18 | 19 | override def newPhase(prev: Phase): Phase = 20 | new StdPhase(prev) { 21 | val global = Plugin.this.global 22 | def apply(unit: PluginComponent.global.CompilationUnit): Unit = { 23 | println("scalac plugin phase success") 24 | System.exit(0) 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/plugins/classpath/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :inefficient-usage 2>&1 | \ 5 | awk ' 6 | BEGIN {z = 2} 7 | /slightly inefficient/ {z -= 1} 8 | /scalac plugin phase success/ {z -= 1} 9 | END {exit z}' 10 | -------------------------------------------------------------------------------- /tests/plugins/classpath/usage.scala: -------------------------------------------------------------------------------- 1 | package anx 2 | 3 | object Usage 4 | -------------------------------------------------------------------------------- /tests/plugins/kind-projector/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "configure_zinc_scala", "scala_library") 2 | 3 | scala_library( 4 | name = "kind-projector", 5 | srcs = ["KindProjector.scala"], 6 | plugins = [ 7 | "@kind_projector_2_12//jar", 8 | ], 9 | tags = ["manual"], 10 | ) 11 | 12 | configure_zinc_scala( 13 | name = "scala_2_12_6_with_kind_projector", 14 | compiler_bridge = "//scala:compiler_bridge_2_12_6", 15 | compiler_classpath = [ 16 | "@scala_compiler_2_12_6//jar", 17 | "@scala_reflect_2_12_6//jar", 18 | "@scala_library_2_12_6//jar", 19 | ], 20 | global_plugins = [ 21 | "@kind_projector_2_12//jar", 22 | ], 23 | runtime_classpath = [ 24 | "@scala_library_2_12_6//jar", 25 | ], 26 | version = "2.12.6", 27 | ) 28 | 29 | scala_library( 30 | name = "kind-projector-via-global-plugins", 31 | srcs = ["KindProjector.scala"], 32 | scala = ":scala_2_12_6_with_kind_projector", 33 | tags = ["manual"], 34 | ) 35 | -------------------------------------------------------------------------------- /tests/plugins/kind-projector/KindProjector.scala: -------------------------------------------------------------------------------- 1 | package anx 2 | 3 | trait Functor[F[_]] { 4 | def map[A, B](fa: F[A])(f: A => B): F[B] 5 | } 6 | 7 | trait EitherInstances { 8 | def defaultFunctorForEither[X]: Functor[Either[X, ?]] = 9 | new Functor[Either[X, ?]] { 10 | def map[A, B](fa: Either[X, A])(f: A => B): Either[X, B] = 11 | fa.map(f) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/plugins/kind-projector/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :kind-projector 5 | bazel build :kind-projector-via-global-plugins 6 | -------------------------------------------------------------------------------- /tests/plugins/macros/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_binary", "scala_library") 2 | 3 | scala_library( 4 | name = "bad_compile", 5 | srcs = ["TestMacro.scala"], 6 | scala = "//scala:2_12", 7 | deps = [ 8 | ":macro_bad", 9 | "@scala_reflect_2_12_6//jar", 10 | ], 11 | ) 12 | 13 | scala_library( 14 | name = "macro", 15 | srcs = ["Macro.scala"], 16 | macro = True, 17 | scala = "//scala:2_12", 18 | deps = [ 19 | ":util", 20 | "@scala_reflect_2_12_6//jar", 21 | ], 22 | ) 23 | 24 | scala_library( 25 | name = "macro_only", 26 | srcs = ["MacroOnly.scala"], 27 | macro = True, 28 | scala = "//scala:2_12", 29 | deps = [ 30 | ":macro", 31 | "@scala_reflect_2_12_6//jar", 32 | ], 33 | ) 34 | 35 | scala_library( 36 | name = "macro_bad", 37 | srcs = ["Macro.scala"], 38 | scala = "//scala:2_12", 39 | deps = [ 40 | ":util", 41 | "@scala_reflect_2_12_6//jar", 42 | ], 43 | ) 44 | 45 | scala_library( 46 | name = "util", 47 | srcs = ["MacroUtil.scala"], 48 | scala = "//scala:2_12", 49 | deps = ["@scala_reflect_2_12_6//jar"], 50 | ) 51 | 52 | scala_binary( 53 | name = "test_macro", 54 | srcs = ["TestMacro.scala"], 55 | scala = "//scala:2_12", 56 | deps = [":macro"], 57 | ) 58 | 59 | scala_binary( 60 | name = "test_macro_only", 61 | srcs = ["TestMacroOnly.scala"], 62 | deps_used_whitelist = [ 63 | ":macro_only", 64 | ], 65 | scala = "//scala:2_12", 66 | deps = [ 67 | ":macro", 68 | ":macro_only", 69 | ], 70 | ) 71 | -------------------------------------------------------------------------------- /tests/plugins/macros/Macro.scala: -------------------------------------------------------------------------------- 1 | import scala.collection.mutable.{ListBuffer, Stack} 2 | import scala.language.experimental.macros 3 | import scala.reflect.macros.Context 4 | 5 | // https://docs.scala-lang.org/overviews/macros/overview.html#a-complete-example 6 | object Macro { 7 | def printf(format: String, params: Any*): Unit = macro printf_impl 8 | 9 | def printf_impl(c: Context)(format: c.Expr[String], params: c.Expr[Any]*): c.Expr[Unit] = { 10 | import c.universe._ 11 | val Literal(Constant(s_format: String)) = format.tree 12 | 13 | val evals = ListBuffer[ValDef]() 14 | 15 | val paramsStack = Stack[Tree]((params map (_.tree)): _*) 16 | val refs = s_format.split("(?<=%[\\w%])|(?=%[\\w%])") map { 17 | case "%d" => MacroUtil.precompute(c)(evals, paramsStack.pop, typeOf[Int]) 18 | case "%s" => MacroUtil.precompute(c)(evals, paramsStack.pop, typeOf[String]) 19 | case "%%" => Literal(Constant("%")) 20 | case part => Literal(Constant(part)) 21 | } 22 | 23 | val stats = evals ++ refs.map(ref => reify(print(c.Expr[Any](ref).splice)).tree) 24 | c.Expr[Unit](Block(stats.toList, Literal(Constant(())))) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/plugins/macros/MacroOnly.scala: -------------------------------------------------------------------------------- 1 | import scala.language.experimental.macros 2 | 3 | object MacroOnly { 4 | def printf(format: String, params: Any*): Unit = macro Macro.printf_impl 5 | } 6 | -------------------------------------------------------------------------------- /tests/plugins/macros/MacroUtil.scala: -------------------------------------------------------------------------------- 1 | import scala.collection.mutable.ListBuffer 2 | import scala.reflect.macros.Context 3 | 4 | object MacroUtil { 5 | def precompute(c: Context)(evals: ListBuffer[c.universe.ValDef], value: c.universe.Tree, tpe: c.universe.Type): c.universe.Ident = { 6 | import c.universe._ 7 | val freshName = TermName(c.fresh("eval$")) 8 | evals += ValDef(Modifiers(), freshName, TypeTree(tpe), value) 9 | Ident(freshName) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/plugins/macros/TestMacro.scala: -------------------------------------------------------------------------------- 1 | import Macro._ 2 | 3 | object TestMacro extends App { 4 | printf("hello %s!\n", "world") 5 | } 6 | -------------------------------------------------------------------------------- /tests/plugins/macros/TestMacroOnly.scala: -------------------------------------------------------------------------------- 1 | object TestMacroOnly extends App { 2 | Macro.printf("hello %s!\n", "world") 3 | MacroOnly.printf("world %s!\n", "hello") 4 | } 5 | -------------------------------------------------------------------------------- /tests/plugins/macros/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :bad_compile 2>&1 | grep 'You may be missing a `macro = True` attribute.' 5 | [ "$(bazel run :test_macro)" = "hello world!" ] 6 | [ "$(bazel run :test_macro_only)" = $'hello world!\nworld hello!' ] 7 | -------------------------------------------------------------------------------- /tests/plugins/outputs/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | load(":rules.bzl", "my_plugin") 3 | 4 | scala_library( 5 | name = "my_plugin_lib", 6 | srcs = ["plugin.scala"], 7 | scala = "//scala:2_12", 8 | tags = ["manual"], 9 | ) 10 | 11 | my_plugin( 12 | name = "my_plugin", 13 | tags = ["manual"], 14 | deps = [ 15 | ":my_plugin_lib", 16 | ], 17 | ) 18 | 19 | scala_library( 20 | name = "usage", 21 | srcs = ["usage.scala"], 22 | plugins = [ 23 | ":my_plugin", 24 | ], 25 | scala = "//scala:2_12", 26 | tags = ["manual"], 27 | ) 28 | -------------------------------------------------------------------------------- /tests/plugins/outputs/plugin.scala: -------------------------------------------------------------------------------- 1 | package annex 2 | 3 | object Plugin 4 | -------------------------------------------------------------------------------- /tests/plugins/outputs/rules.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_scala_annex//rules:providers.bzl", 3 | _ScalaRulePhase = "ScalaRulePhase", 4 | ) 5 | 6 | def _foo_before_javainfo(ctx, g): 7 | if hasattr(g, "javainfo"): 8 | fail("javainfo shouldn't be in the globals, yet") 9 | 10 | def _foo_after_javainfo(ctx, g): 11 | if not hasattr(g, "javainfo"): 12 | fail("javainfo should be in the globals by now") 13 | 14 | def _foo_after_coda(ctx, g): 15 | if not hasattr(g, "compile"): 16 | fail("expected to run after compilation") 17 | 18 | print("plugin phase success") 19 | 20 | def _my_plugin_implementation(ctx): 21 | sdeps = java_common.merge([dep[JavaInfo] for dep in ctx.attr.deps]) 22 | return [ 23 | sdeps, 24 | _ScalaRulePhase( 25 | phases = [ 26 | ("-", "javainfo", "foo_before_javainfo", _foo_before_javainfo), 27 | ("+", "javainfo", "foo_after_javainfo", _foo_after_javainfo), 28 | ("+", "coda", "foo_after_coda", _foo_after_coda), 29 | ], 30 | ), 31 | ] 32 | 33 | my_plugin = rule( 34 | attrs = { 35 | "deps": attr.label_list( 36 | mandatory = True, 37 | providers = [JavaInfo], 38 | ), 39 | }, 40 | implementation = _my_plugin_implementation, 41 | ) 42 | -------------------------------------------------------------------------------- /tests/plugins/outputs/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :usage 2>&1 | grep "plugin phase success" 5 | -------------------------------------------------------------------------------- /tests/plugins/outputs/usage.scala: -------------------------------------------------------------------------------- 1 | package anx 2 | 3 | object Usage 4 | -------------------------------------------------------------------------------- /tests/proto/BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_scala_annex//rules:scala_proto.bzl", 3 | "scala_proto_library", 4 | ) 5 | load( 6 | "@rules_scala_annex//rules:scala.bzl", 7 | "scala_library", 8 | ) 9 | 10 | proto_library( 11 | name = "zero_proto", 12 | srcs = ["zero.proto"], 13 | visibility = ["//visibility:public"], 14 | ) 15 | 16 | scala_proto_library( 17 | name = "zero_scala_proto", 18 | deps = [":zero_proto"], 19 | ) 20 | 21 | scala_library( 22 | name = "zero_scala", 23 | srcs = [":zero_scala_proto"], 24 | deps = [ 25 | "@annex_test//:com_google_protobuf_protobuf_java", 26 | "@annex_test//:com_thesamet_scalapb_lenses_2_12", 27 | "@annex_test//:com_thesamet_scalapb_scalapb_runtime_2_12", 28 | ], 29 | ) 30 | 31 | proto_library( 32 | name = "one_proto", 33 | srcs = ["one.proto"], 34 | visibility = ["//visibility:public"], 35 | deps = [ 36 | ":zero_proto", 37 | ], 38 | ) 39 | 40 | scala_proto_library( 41 | name = "one_scala_proto", 42 | deps = [ 43 | ":one_proto", 44 | ], 45 | ) 46 | 47 | scala_library( 48 | name = "one_scala", 49 | srcs = [":one_scala_proto"], 50 | deps = [ 51 | ":zero_scala", 52 | "@annex_test//:com_google_protobuf_protobuf_java", 53 | "@annex_test//:com_thesamet_scalapb_lenses_2_12", 54 | "@annex_test//:com_thesamet_scalapb_scalapb_runtime_2_12", 55 | ], 56 | ) 57 | -------------------------------------------------------------------------------- /tests/proto/expected_one: -------------------------------------------------------------------------------- 1 | -rw---- 2.0 fat 0 bx 0% stor 20100101.000000 META-INF/ 2 | -rw---- 2.0 fat 48 b- 0% stor 20100101.000000 META-INF/MANIFEST.MF 3 | -rw---- 1.0 fat 0 b- 0% stor 20100101.000000 anx/ 4 | -rw---- 1.0 fat 0 b- 0% stor 20100101.000000 anx/proto/ 5 | -rw---- 1.0 fat 0 b- 0% stor 20100101.000000 anx/proto/one/ 6 | -rw---- 2.0 fat 14827 b- 0% stor 20100101.000002 anx/proto/one/One$.class 7 | -rw---- 2.0 fat 3097 b- 0% stor 20100101.000002 anx/proto/one/One$OneLens.class 8 | -rw---- 2.0 fat 18959 b- 0% stor 20100101.000002 anx/proto/one/One.class 9 | -rw---- 2.0 fat 6376 b- 0% stor 20100101.000002 anx/proto/one/OneProto$.class 10 | -rw---- 2.0 fat 1937 b- 0% stor 20100101.000002 anx/proto/one/OneProto.class 11 | -------------------------------------------------------------------------------- /tests/proto/expected_zero: -------------------------------------------------------------------------------- 1 | -rw---- 2.0 fat 0 bx 0% stor 20100101.000000 META-INF/ 2 | -rw---- 2.0 fat 48 b- 0% stor 20100101.000000 META-INF/MANIFEST.MF 3 | -rw---- 1.0 fat 0 b- 0% stor 20100101.000000 anx/ 4 | -rw---- 1.0 fat 0 b- 0% stor 20100101.000000 anx/proto/ 5 | -rw---- 1.0 fat 0 b- 0% stor 20100101.000000 anx/proto/zero/ 6 | -rw---- 2.0 fat 15074 b- 0% stor 20100101.000002 anx/proto/zero/Zero$.class 7 | -rw---- 2.0 fat 4337 b- 0% stor 20100101.000002 anx/proto/zero/Zero$ZeroLens.class 8 | -rw---- 2.0 fat 19582 b- 0% stor 20100101.000002 anx/proto/zero/Zero.class 9 | -rw---- 2.0 fat 6648 b- 0% stor 20100101.000002 anx/proto/zero/ZeroProto$.class 10 | -rw---- 2.0 fat 1948 b- 0% stor 20100101.000002 anx/proto/zero/ZeroProto.class 11 | -------------------------------------------------------------------------------- /tests/proto/one.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | option java_package = "anx.proto"; 4 | 5 | import "proto/zero.proto"; 6 | 7 | message One { 8 | optional Zero zero = 1; 9 | } 10 | -------------------------------------------------------------------------------- /tests/proto/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../common.sh 3 | 4 | [[ "$(bazel version | head -n1 | cut -d: -f2 | tr -d ' ')" =~ 0.15.*|0.16.* ]] || bazel build :zero_scala_proto 5 | 6 | bazel build :zero_scala 7 | diff expected_zero <( 8 | zipinfo -m -T --h-t "$(bazel info bazel-bin)/proto/zero_scala.jar" 9 | ) 10 | 11 | bazel build :one_scala 12 | diff expected_one <( 13 | zipinfo -m -T --h-t "$(bazel info bazel-bin)/proto/one_scala.jar" 14 | ) 15 | -------------------------------------------------------------------------------- /tests/proto/zero.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | option java_package = "anx.proto"; 4 | 5 | message Zero { 6 | required string string_0 = 1; 7 | optional int32 int32_0 = 2; 8 | } 9 | -------------------------------------------------------------------------------- /tests/providers/BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_scala_annex//rules:providers.bzl", 3 | "declare_scala_configuration", 4 | "declare_zinc_configuration", 5 | "join_configurations", 6 | ) 7 | load( 8 | "@rules_scala_annex//rules:scala.bzl", 9 | "bootstrap_scala_library", 10 | ) 11 | load( 12 | ":build.bzl", 13 | "consume_scala_and_zinc_configuration", 14 | "consume_scala_configuration", 15 | "consume_zinc_configuration", 16 | ) 17 | 18 | declare_scala_configuration( 19 | name = "provided_scala_configuration", 20 | compiler_classpath = [ 21 | "@scala_compiler_2_12_6//jar", 22 | "@scala_reflect_2_12_6//jar", 23 | "@scala_library_2_12_6//jar", 24 | ], 25 | runtime_classpath = [ 26 | "@scala_library_2_12_6//jar", 27 | ], 28 | version = "2.12.6", 29 | ) 30 | 31 | bootstrap_scala_library( 32 | name = "compiler_bridge", 33 | srcs = ["@compiler_bridge_2_12//:src"], 34 | scala = ":provided_scala_configuration", 35 | deps = [ 36 | "@annex//:org_scala_sbt_util_interface", 37 | "@scala_annex_org_scala_sbt_compiler_interface", 38 | "@scala_compiler_2_12_6//jar", 39 | "@scala_library_2_12_6//jar", 40 | "@scala_reflect_2_12_6//jar", 41 | ], 42 | ) 43 | 44 | declare_zinc_configuration( 45 | name = "provided_zinc_configuration", 46 | compiler_bridge = ":compiler_bridge", 47 | ) 48 | 49 | join_configurations( 50 | name = "provided_scala_and_zinc_configuration", 51 | configurations = [ 52 | ":provided_scala_configuration", 53 | ":provided_zinc_configuration", 54 | ], 55 | ) 56 | 57 | consume_scala_configuration( 58 | name = "consume_scala_configuration", 59 | configuration = ":provided_scala_configuration", 60 | ) 61 | 62 | consume_scala_configuration( 63 | name = "consume_scala_as_zinc_configuration", 64 | configuration = ":provided_zinc_configuration", 65 | ) 66 | 67 | consume_zinc_configuration( 68 | name = "consume_zinc_configuration", 69 | configuration = ":provided_zinc_configuration", 70 | ) 71 | 72 | consume_zinc_configuration( 73 | name = "consume_zinc_as_scala_configuration", 74 | configuration = ":provided_scala_configuration", 75 | ) 76 | 77 | consume_scala_and_zinc_configuration( 78 | name = "consume_scala_and_zinc_configuration", 79 | configuration = ":provided_scala_and_zinc_configuration", 80 | ) 81 | 82 | consume_scala_configuration( 83 | name = "consume_scala_and_zinc_as_scala_configuration", 84 | configuration = ":provided_scala_and_zinc_configuration", 85 | ) 86 | 87 | consume_zinc_configuration( 88 | name = "consume_scala_and_zinc_as_zinc_configuration", 89 | configuration = ":provided_scala_and_zinc_configuration", 90 | ) 91 | -------------------------------------------------------------------------------- /tests/providers/build.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_scala_annex//rules:providers.bzl", 3 | "ScalaConfiguration", 4 | "ZincConfiguration", 5 | ) 6 | 7 | def _implementation(ctx): 8 | return [] 9 | 10 | consume_scala_configuration = rule( 11 | implementation = _implementation, 12 | attrs = { 13 | "configuration": attr.label( 14 | mandatory = True, 15 | providers = [ScalaConfiguration], 16 | ), 17 | }, 18 | ) 19 | 20 | consume_zinc_configuration = rule( 21 | implementation = _implementation, 22 | attrs = { 23 | "configuration": attr.label( 24 | mandatory = True, 25 | providers = [ZincConfiguration], 26 | ), 27 | }, 28 | ) 29 | 30 | consume_scala_and_zinc_configuration = rule( 31 | implementation = _implementation, 32 | attrs = { 33 | "configuration": attr.label( 34 | mandatory = True, 35 | providers = [ScalaConfiguration, ZincConfiguration], 36 | ), 37 | }, 38 | ) 39 | -------------------------------------------------------------------------------- /tests/providers/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../common.sh 3 | 4 | #bazel build :consume_scala_configuration 5 | #! bazel build :consume_scala_as_zinc_configuration || false 6 | #bazel build :consume_zinc_configuration 7 | #! bazel build :consume_zinc_as_scala_configuration || false 8 | #bazel build :consume_scala_and_zinc_configuration 9 | #bazel build :consume_scala_and_zinc_as_scala_configuration 10 | #bazel build :consume_scala_and_zinc_as_zinc_configuration 11 | -------------------------------------------------------------------------------- /tests/repl/simple/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library", "scala_repl") 2 | 3 | scala_library( 4 | name = "lib", 5 | srcs = ["Example.scala"], 6 | ) 7 | 8 | scala_repl( 9 | name = "lib.repl", 10 | deps = [":lib"], 11 | ) 12 | -------------------------------------------------------------------------------- /tests/repl/simple/Example.scala: -------------------------------------------------------------------------------- 1 | object Example { 2 | def add(a: Int, b: Int) = a + b 3 | } 4 | -------------------------------------------------------------------------------- /tests/repl/simple/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | echo 'Example.add(1, 1)' | bazel run --direct_run :lib.repl | grep -q 'res0: Int = 2' 5 | -------------------------------------------------------------------------------- /tests/resources/maven/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "maven", 5 | resources = glob(["src/main/resources/*"]), 6 | scala = "//scala:2_12", 7 | ) 8 | -------------------------------------------------------------------------------- /tests/resources/maven/expected: -------------------------------------------------------------------------------- 1 | -rw---- 2.0 fat 0 bx 0% stor 20100101.000000 META-INF/ 2 | -rw---- 2.0 fat 48 b- 0% stor 20100101.000000 META-INF/MANIFEST.MF 3 | -rw---- 2.0 fat 8 b- 0% stor 20100101.000000 example.txt 4 | -------------------------------------------------------------------------------- /tests/resources/maven/src/main/resources/example.txt: -------------------------------------------------------------------------------- 1 | example 2 | -------------------------------------------------------------------------------- /tests/resources/maven/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :maven 5 | diff expected <( 6 | zipinfo -m -T --h-t "$(bazel info bazel-bin)/resources/maven/maven.jar" 7 | ) 8 | -------------------------------------------------------------------------------- /tests/resources/plain/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "plain", 5 | resources = glob(["**/*.txt"]), 6 | scala = "//scala:2_11", 7 | ) 8 | 9 | scala_library( 10 | name = "merged", 11 | resource_jars = [":plain"], 12 | resource_strip_prefix = "resources", 13 | resources = glob(["**/*.txt"]), 14 | scala = "//scala:2_11", 15 | ) 16 | -------------------------------------------------------------------------------- /tests/resources/plain/example/example.txt: -------------------------------------------------------------------------------- 1 | example 2 | -------------------------------------------------------------------------------- /tests/resources/plain/expected_merged: -------------------------------------------------------------------------------- 1 | -rw---- 2.0 fat 0 bx 0% stor 20100101.000000 META-INF/ 2 | -rw---- 2.0 fat 48 b- 0% stor 20100101.000000 META-INF/MANIFEST.MF 3 | -rw---- 2.0 fat 0 b- 0% stor 20100101.000000 resources/ 4 | -rw---- 2.0 fat 0 b- 0% stor 20100101.000000 resources/plain/ 5 | -rw---- 2.0 fat 0 b- 0% stor 20100101.000000 resources/plain/example/ 6 | -rw---- 2.0 fat 8 b- 0% stor 20100101.000000 resources/plain/example/example.txt 7 | -rw---- 2.0 fat 0 b- 0% stor 20100101.000000 plain/ 8 | -rw---- 2.0 fat 0 b- 0% stor 20100101.000000 plain/example/ 9 | -rw---- 2.0 fat 8 b- 0% stor 20100101.000000 plain/example/example.txt 10 | -------------------------------------------------------------------------------- /tests/resources/plain/expected_plain: -------------------------------------------------------------------------------- 1 | -rw---- 2.0 fat 0 bx 0% stor 20100101.000000 META-INF/ 2 | -rw---- 2.0 fat 48 b- 0% stor 20100101.000000 META-INF/MANIFEST.MF 3 | -rw---- 2.0 fat 0 b- 0% stor 20100101.000000 resources/ 4 | -rw---- 2.0 fat 0 b- 0% stor 20100101.000000 resources/plain/ 5 | -rw---- 2.0 fat 0 b- 0% stor 20100101.000000 resources/plain/example/ 6 | -rw---- 2.0 fat 8 b- 0% stor 20100101.000000 resources/plain/example/example.txt 7 | -------------------------------------------------------------------------------- /tests/resources/plain/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :plain 5 | diff expected_plain <( 6 | zipinfo -m -T --h-t "$(bazel info bazel-bin)/resources/plain/plain.jar" 7 | ) 8 | 9 | bazel build :merged 10 | diff expected_merged <( 11 | zipinfo -m -T --h-t "$(bazel info bazel-bin)/resources/plain/merged.jar" 12 | ) 13 | -------------------------------------------------------------------------------- /tests/resources/prefix/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "prefix", 5 | resource_strip_prefix = package_name(), 6 | resources = glob(["**/*.txt"]), 7 | scala = "//scala:2_11", 8 | ) 9 | 10 | scala_library( 11 | name = "outside", 12 | resource_strip_prefix = "{}/other".format(package_name()), 13 | resources = glob(["**/*.txt"]), 14 | scala = "//scala:2_11", 15 | ) 16 | -------------------------------------------------------------------------------- /tests/resources/prefix/example/example.txt: -------------------------------------------------------------------------------- 1 | example 2 | -------------------------------------------------------------------------------- /tests/resources/prefix/expected: -------------------------------------------------------------------------------- 1 | -rw---- 2.0 fat 0 bx 0% stor 20100101.000000 META-INF/ 2 | -rw---- 2.0 fat 48 b- 0% stor 20100101.000000 META-INF/MANIFEST.MF 3 | -rw---- 2.0 fat 0 b- 0% stor 20100101.000000 example/ 4 | -rw---- 2.0 fat 8 b- 0% stor 20100101.000000 example/example.txt 5 | -------------------------------------------------------------------------------- /tests/resources/prefix/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :prefix 5 | diff expected <( 6 | zipinfo -m -T --h-t "$(bazel info bazel-bin)/resources/prefix/prefix.jar" 7 | ) 8 | 9 | ! bazel build :outside 10 | bazel build :outside |& grep 'does not have prefix' 11 | -------------------------------------------------------------------------------- /tests/resources/reference_conf/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "plain", 5 | resource_strip_prefix = "resources/reference_conf", 6 | resources = ["reference.conf"], 7 | scala = "//scala:2_11", 8 | ) 9 | 10 | java_library( 11 | name = "plain_java", 12 | resource_strip_prefix = "resources/reference_conf", 13 | resources = ["reference.conf"], 14 | ) 15 | -------------------------------------------------------------------------------- /tests/resources/reference_conf/example/example.txt: -------------------------------------------------------------------------------- 1 | example 2 | -------------------------------------------------------------------------------- /tests/resources/reference_conf/expected_plain: -------------------------------------------------------------------------------- 1 | -rw---- 2.0 fat 0 bx 0% stor 20100101.000000 META-INF/ 2 | -rw---- 2.0 fat 48 b- 0% stor 20100101.000000 META-INF/MANIFEST.MF 3 | -rw---- 2.0 fat 1 b- 0% stor 20100101.000000 reference.conf 4 | -------------------------------------------------------------------------------- /tests/resources/reference_conf/reference.conf: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/resources/reference_conf/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :plain_java 5 | diff expected_plain <( 6 | zipinfo -m -T --h-t "$(bazel info bazel-bin)/resources/reference_conf/libplain_java.jar" 7 | ) 8 | 9 | bazel build :plain 10 | diff expected_plain <( 11 | zipinfo -m -T --h-t "$(bazel info bazel-bin)/resources/reference_conf/plain.jar" 12 | ) 13 | -------------------------------------------------------------------------------- /tests/scala/scalaimport/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_import", "scala_library") 2 | 3 | scala_import( 4 | name = "shapeless", 5 | jars = [ 6 | "@shapeless_jar//file", 7 | "@shapeless_srcjar//file", 8 | ], 9 | visibility = [ 10 | "//visibility:public", 11 | ], 12 | ) 13 | 14 | scala_library( 15 | name = "scalaimport", 16 | srcs = ["scalaimport.scala"], 17 | deps = [ 18 | ":shapeless", 19 | "@annex_test//:org_scala_lang_modules_scala_xml_2_12", 20 | ], 21 | ) 22 | -------------------------------------------------------------------------------- /tests/scala/scalaimport/scalaimport.scala: -------------------------------------------------------------------------------- 1 | // This is a test for the correctness of scala_import. It intends to import 2 | // 3rdparty dependencies. 3 | 4 | import shapeless._ 5 | 6 | object Test { 7 | 8 | type T = Int :: HNil 9 | 10 | def main(args: Array[String]): Unit = { 11 | val xml = 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/scala/scalaimport/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :scalaimport 5 | -------------------------------------------------------------------------------- /tests/scala/typelevel/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "example", 5 | srcs = ["Example.scala"], 6 | scala = "//scala:zinc_typelevel_2_12_1", 7 | tags = ["manual"], 8 | ) 9 | -------------------------------------------------------------------------------- /tests/scala/typelevel/Example.scala: -------------------------------------------------------------------------------- 1 | trait Bind[F[_]] { 2 | def map[A, B](fa: F[A])(f: A => B): F[B] 3 | def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B] 4 | } 5 | 6 | object Example { 7 | def tupleTC[F[_], A, B](fa: F[A], fb: F[B])(implicit F: Bind[F]): F[(A, B)] = 8 | F.flatMap(fa)(a => F.map(fb)((a, _))) 9 | } 10 | -------------------------------------------------------------------------------- /tests/scala/typelevel/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :example 5 | -------------------------------------------------------------------------------- /tests/scalacopts/rule/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "default", 5 | srcs = ["Deprecated.scala"], 6 | scala = "//scala:2_12", 7 | ) 8 | 9 | scala_library( 10 | name = "fatal", 11 | srcs = ["Deprecated.scala"], 12 | scala = "//scala:2_12", 13 | scalacopts = [ 14 | "-deprecation", 15 | "-Xfatal-warnings", 16 | ], 17 | ) 18 | 19 | scala_library( 20 | name = "warn", 21 | srcs = ["Deprecated.scala"], 22 | scala = "//scala:2_12", 23 | scalacopts = [ 24 | "-deprecation", 25 | ], 26 | ) 27 | 28 | scala_library( 29 | name = "fatal_glob", 30 | srcs = ["Deprecated.scala"], 31 | scala = "//scala:zinc_2_12_6_fatal_deprecation_opt", 32 | ) 33 | -------------------------------------------------------------------------------- /tests/scalacopts/rule/Deprecated.scala: -------------------------------------------------------------------------------- 1 | @deprecated("deprecated", "the dawn of time") 2 | class Deprecated { 3 | } 4 | 5 | class App { 6 | new Deprecated 7 | } 8 | -------------------------------------------------------------------------------- /tests/scalacopts/rule/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :default 5 | 6 | ! bazel build :fatal || false 7 | 8 | bazel build :warn 9 | 10 | ! bazel build :fatal_glob || false 11 | -------------------------------------------------------------------------------- /tests/scaladoc/A.scala: -------------------------------------------------------------------------------- 1 | import mockutil.MockLib 2 | 3 | /** 4 | * A Scaladoc 5 | */ 6 | object A { 7 | def a = B 8 | def addOne(i: Int) = MockLib.add(i, 1) 9 | } 10 | -------------------------------------------------------------------------------- /tests/scaladoc/B.scala: -------------------------------------------------------------------------------- 1 | object B {} -------------------------------------------------------------------------------- /tests/scaladoc/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scaladoc") 2 | 3 | scaladoc( 4 | name = "a_doc", 5 | srcs = [ 6 | "A.scala", 7 | "B.scala", 8 | ], 9 | compiler_deps = [ 10 | "@annex_test//:org_scala_lang_modules_scala_xml_2_12", 11 | ], 12 | scala = "//scala:2_12", 13 | deps = [ 14 | "//mockutil:mocklib", 15 | ], 16 | ) 17 | -------------------------------------------------------------------------------- /tests/scaladoc/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../common.sh 3 | 4 | bazel build :a_doc 5 | grep -q '//scaladoc:a_doc' "$(bazel info bazel-bin)/scaladoc/html/index.html" 6 | -------------------------------------------------------------------------------- /tests/strategy/local/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "library", 5 | srcs = ["code.scala"], 6 | scala = "//scala:2_11", 7 | tags = ["manual"], 8 | ) 9 | -------------------------------------------------------------------------------- /tests/strategy/local/bazel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/higherkindness/rules_scala/aed5cc8a433824e23dc82119de1b98904ab1bb9e/tests/strategy/local/bazel -------------------------------------------------------------------------------- /tests/strategy/local/bazel.rc: -------------------------------------------------------------------------------- 1 | build --strategy=ScalaCompile=local 2 | -------------------------------------------------------------------------------- /tests/strategy/local/code.scala: -------------------------------------------------------------------------------- 1 | package anx 2 | 3 | object code 4 | -------------------------------------------------------------------------------- /tests/strategy/local/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :library 5 | -------------------------------------------------------------------------------- /tests/strategy/worker_extra_flag/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_library") 2 | 3 | scala_library( 4 | name = "library", 5 | srcs = ["code.scala"], 6 | scala = "//scala:2_11", 7 | tags = ["manual"], 8 | ) 9 | -------------------------------------------------------------------------------- /tests/strategy/worker_extra_flag/bazel.rc: -------------------------------------------------------------------------------- 1 | build --worker_extra_flag=ScalaCompile=--persistence_dir=~/.cache/bazel-zinc 2 | -------------------------------------------------------------------------------- /tests/strategy/worker_extra_flag/code.scala: -------------------------------------------------------------------------------- 1 | package anx 2 | 3 | object code 4 | -------------------------------------------------------------------------------- /tests/strategy/worker_extra_flag/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :library 5 | -------------------------------------------------------------------------------- /tests/tagging/A.scala: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/higherkindness/rules_scala/aed5cc8a433824e23dc82119de1b98904ab1bb9e/tests/tagging/A.scala -------------------------------------------------------------------------------- /tests/tagging/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_binary", "scala_library", "scala_test") 2 | load( 3 | "@rules_scala_annex//rules/common:private/utils.bzl", 4 | _PROPAGATABLE_TAGS = "PROPAGATABLE_TAGS", 5 | ) 6 | 7 | scala_binary( 8 | name = "binary-all-propagatable", 9 | srcs = ["A.scala"], 10 | scala = "//scala:2_11", 11 | tags = ["manual"] + _PROPAGATABLE_TAGS, 12 | ) 13 | 14 | scala_library( 15 | name = "library-no-propagatable", 16 | srcs = ["A.scala"], 17 | scala = "//scala:2_11", 18 | tags = [ 19 | "manual", 20 | "requires-network", 21 | ], 22 | ) 23 | 24 | scala_test( 25 | name = "test-no-remote-only", 26 | srcs = ["A.scala"], 27 | scala = "//scala:2_11", 28 | tags = [ 29 | "manual", 30 | "no-remote", 31 | ], 32 | ) 33 | -------------------------------------------------------------------------------- /tests/tagging/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../common.sh 3 | 4 | IFS=$'\n' 5 | 6 | function check_execution_info { 7 | target=$1 8 | all_exec_info=$((bazel aquery $target) | egrep "ExecutionInfo") 9 | 10 | for exec_info in $all_exec_info; do 11 | for arg in $@; do 12 | if [[ $arg == $1 || "$exec_info" =~ "$arg" ]]; then 13 | continue 14 | else 15 | echo "Failed. $arg not found in tags" 16 | exit 1 17 | fi 18 | done 19 | done 20 | } 21 | 22 | check_execution_info "library-no-propagatable" 23 | check_execution_info "binary-all-propagatable" "no-remote" "no-cache" "no-sandbox" "no-remote-exec" "no-remote-cache" 24 | check_execution_info "test-no-remote-only" "no-remote" 25 | echo "SUCCESS" 26 | -------------------------------------------------------------------------------- /tests/test-frameworks/classpath/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_test") 2 | 3 | scala_test( 4 | name = "bad", 5 | srcs = ["Test.scala"], 6 | scala = "//scala:2_12", 7 | deps = [ 8 | "@annex_test//:org_specs2_specs2_common_2_12", 9 | "@annex_test//:org_specs2_specs2_core_2_12", 10 | "@annex_test//:org_specs2_specs2_matcher_2_12", 11 | ], 12 | ) 13 | 14 | scala_test( 15 | name = "context", 16 | srcs = ["ContextTest.scala"], 17 | scala = "//scala:2_12", 18 | deps = [ 19 | "@annex_test//:org_specs2_specs2_common_2_12", 20 | "@annex_test//:org_specs2_specs2_core_2_12", 21 | "@annex_test//:org_specs2_specs2_matcher_2_12", 22 | ], 23 | ) 24 | 25 | scala_test( 26 | name = "good", 27 | srcs = ["Test.scala"], 28 | deps_used_whitelist = [ 29 | "@annex//:org_scala_sbt_zinc_persist_2_12", 30 | ], 31 | scala = "//scala:2_12", 32 | deps = [ 33 | "@annex//:org_scala_sbt_zinc_persist_2_12", 34 | "@annex_test//:org_specs2_specs2_common_2_12", 35 | "@annex_test//:org_specs2_specs2_core_2_12", 36 | "@annex_test//:org_specs2_specs2_matcher_2_12", 37 | ], 38 | ) 39 | -------------------------------------------------------------------------------- /tests/test-frameworks/classpath/ContextTest.scala: -------------------------------------------------------------------------------- 1 | import org.specs2.mutable.Specification 2 | 3 | object ContextTest extends Specification { 4 | 5 | class Item 6 | 7 | "Context classpath" should { 8 | "load class" in { 9 | Thread.currentThread.getContextClassLoader.loadClass(classOf[Item].getName) must_== classOf[Item] 10 | } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tests/test-frameworks/classpath/Test.scala: -------------------------------------------------------------------------------- 1 | import org.specs2.mutable.Specification 2 | 3 | object Test extends Specification { 4 | 5 | "Classpath" should { 6 | "load class" in { 7 | getClass.getClassLoader.loadClass("sbt.internal.inc.schema.APIsFile") 8 | ok 9 | } 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /tests/test-frameworks/classpath/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel test :context 5 | 6 | ! bazel test :bad || false 7 | bazel test :good 8 | -------------------------------------------------------------------------------- /tests/test-frameworks/isolation/Global.scala: -------------------------------------------------------------------------------- 1 | object Global { 2 | var value = 1 3 | } 4 | -------------------------------------------------------------------------------- /tests/test-frameworks/isolation/Test.scala: -------------------------------------------------------------------------------- 1 | import org.specs2.mutable.Specification 2 | 3 | object Test1 extends Specification { 4 | "Global" should { 5 | "be 2" in { 6 | Global.value = 2 7 | Global.value must_== 2 8 | } 9 | } 10 | } 11 | 12 | object Test2 extends Specification { 13 | "Global" should { 14 | "be 1" in { 15 | Global.value must_== 1 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/test-frameworks/isolation/TestJvm.scala: -------------------------------------------------------------------------------- 1 | import org.specs2.mutable.Specification 2 | 3 | object Test3 extends Specification { 4 | "-Dexample" should { 5 | "exist" in { 6 | sys.props += "example" -> "value" 7 | sys.props.get("example") must beSome("value") 8 | } 9 | } 10 | } 11 | 12 | object Test4 extends Specification { 13 | "-Dexample" should { 14 | "not exist" in { 15 | sys.props.get("example") must beNone 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/test-frameworks/isolation/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | bazel build :none :none-jvm 5 | ! bazel test :none 6 | ! bazel test :none-jvm 7 | 8 | bazel build :classloader-jvm 9 | bazel test :classloader 10 | ! bazel test :classloader-jvm 11 | 12 | bazel build :classloader-shared 13 | ! bazel test :classloader-shared 14 | 15 | bazel test :process :process-2_11 :process-jvm 16 | 17 | # verify framework args work for each level of isolation 18 | ! (bazel test :none | grep 'be 2.*ms') 19 | bazel test --test_arg=--framework_args=-showtimes :none | grep 'be 2.*ms' 20 | bazel test --test_arg=--framework_args=-showtimes :classloader | grep 'be 2.*ms' 21 | bazel test --test_arg=--framework_args=-showtimes :process | grep 'be 2.*ms' 22 | -------------------------------------------------------------------------------- /tests/test-frameworks/mixed/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_scala_annex//rules:scala.bzl", "scala_test") 2 | 3 | scala_test( 4 | name = "mixed_2_12", 5 | srcs = glob(["*.scala"]), 6 | scala = "//scala:2_12", 7 | shard_count = 2, 8 | tags = ["manual"], 9 | runtime_deps = [ 10 | "@hamcrest_core//jar", 11 | "@junit_interface//jar", 12 | ], 13 | deps = [ 14 | "@annex_test//:org_scalacheck_scalacheck_2_12", 15 | "@annex_test//:org_scalactic_scalactic_2_12", 16 | "@annex_test//:org_scalatest_scalatest_2_12", 17 | "@annex_test//:org_specs2_specs2_common_2_12", 18 | "@annex_test//:org_specs2_specs2_core_2_12", 19 | "@annex_test//:org_specs2_specs2_matcher_2_12", 20 | "@junit//jar", 21 | ], 22 | ) 23 | 24 | scala_test( 25 | name = "mixed_2_11", 26 | srcs = [ 27 | "scalacheck.scala", 28 | "specs2.scala", 29 | ], 30 | scala = "//scala:2_11", 31 | tags = ["manual"], 32 | deps = [ 33 | "@annex_test//:org_scalacheck_scalacheck_2_11", 34 | "@annex_test//:org_specs2_specs2_common_2_11", 35 | "@annex_test//:org_specs2_specs2_core_2_11", 36 | "@annex_test//:org_specs2_specs2_matcher_2_11", 37 | ], 38 | ) 39 | -------------------------------------------------------------------------------- /tests/test-frameworks/mixed/junit.scala: -------------------------------------------------------------------------------- 1 | package annex.scalacheck 2 | 3 | import org.junit.Test 4 | import org.junit.Assert._ 5 | 6 | class JUnitTests { 7 | 8 | @Test 9 | def whatever: Unit = { 10 | println("JUnit many success") 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tests/test-frameworks/mixed/scalacheck.scala: -------------------------------------------------------------------------------- 1 | package annex.scalacheck 2 | 3 | import org.scalacheck._ 4 | 5 | class DummyProperties extends Properties("Dummy") { 6 | property("foo") = true 7 | property("bar") = true 8 | } 9 | 10 | object Doof { 11 | def main(args: Array[String]): Unit = { 12 | println("lol") 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/test-frameworks/mixed/scalatest.scala: -------------------------------------------------------------------------------- 1 | package annex.specs2 2 | 3 | import org.scalatest._ 4 | import java.util.{EmptyStackException, Stack} 5 | 6 | class DummySpec extends FlatSpec with Matchers { 7 | 8 | "A Stack" should "pop values in last-in-first-out order" in { 9 | val stack = new Stack[Int] 10 | stack.push(1) 11 | stack.push(2) 12 | stack.pop() should be(2) 13 | stack.pop() should be(1) 14 | } 15 | 16 | it should "throw EmptyStackException if an empty stack is popped" in { 17 | val emptyStack = new Stack[Int] 18 | a[EmptyStackException] should be thrownBy emptyStack.pop() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/test-frameworks/mixed/specs2.scala: -------------------------------------------------------------------------------- 1 | package annex.specs2 2 | 3 | import org.specs2.mutable.Specification 4 | 5 | object DummySpec2 extends Specification { 6 | 7 | "Example" should { 8 | "work" in { 9 | 1 must_== 1 10 | } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tests/test-frameworks/mixed/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | . "$(dirname "$0")"/../../common.sh 3 | 4 | out_2_12=$(bazel test :mixed_2_12) 5 | echo "$out_2_12" | grep 'should pop values in last-in-first-out order' 6 | echo "$out_2_12" | grep 'JUnit many success' 7 | bazel test :mixed_2_11 | grep 'Dummy.bar: OK, proved property.' 8 | bazel test :mixed_2_11 --test_arg=--verbosity=HIGH | grep 'org.scalacheck.ScalaCheckFramework: 1 tests' 9 | bazel test :mixed_2_11 --test_arg=--verbosity=MEDIUM | grep -v 'org.scalacheck.ScalaCheckFramework: 1 tests' 10 | -------------------------------------------------------------------------------- /tests/tools/bazel: -------------------------------------------------------------------------------- 1 | ../../tools/bazel -------------------------------------------------------------------------------- /tests/workspace.bzl: -------------------------------------------------------------------------------- 1 | load("@rules_jvm_external//:defs.bzl", "maven_install") 2 | 3 | def test_artifacts(): 4 | return [ 5 | "org.scala-sbt:compiler-interface:1.2.1", 6 | "org.scala-lang.modules:scala-xml_2.12:1.0.6", 7 | "org.scalacheck:scalacheck_2.12:1.13.4", 8 | "org.scalacheck:scalacheck_2.11:1.13.4", 9 | "org.specs2:specs2-matcher_2.12:4.0.3", 10 | "org.specs2:specs2-common_2.12:4.0.3", 11 | "org.specs2:specs2-core_2.12:4.0.3", 12 | "org.specs2:specs2-matcher_2.11:3.9.5", 13 | "org.specs2:specs2-common_2.11:3.9.5", 14 | "org.specs2:specs2-core_2.11:3.9.5", 15 | "com.thesamet.scalapb:scalapb-runtime_2.12:0.9.0", 16 | "com.thesamet.scalapb:lenses_2.12:0.9.0", 17 | "com.google.protobuf:protobuf-java:3.9.0", 18 | "org.scalatest:scalatest_2.12:3.0.4", 19 | "org.scalactic:scalactic_2.12:3.0.4", 20 | ] 21 | 22 | def test_dependencies(): 23 | maven_install( 24 | name = "annex_test", 25 | artifacts = test_artifacts(), 26 | repositories = [ 27 | "https://repo.maven.apache.org/maven2", 28 | "https://maven-central.storage-download.googleapis.com/maven2", 29 | "https://mirror.bazel.build/repo1.maven.org/maven2", 30 | ], 31 | fetch_sources = True, 32 | maven_install_json = "@rules_scala_annex_test//:annex_test_install.json", 33 | ) 34 | -------------------------------------------------------------------------------- /third_party/bazel/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/BUILD: -------------------------------------------------------------------------------- 1 | licenses(["notice"]) 2 | # Copyright 2014 The Bazel Authors. Licensed under Apache License, Version 2.0 3 | 4 | java_library( 5 | name = "jarhelper", 6 | srcs = [ 7 | "JarCreator.java", 8 | "JarHelper.java", 9 | ], 10 | visibility = ["//visibility:public"], 11 | ) 12 | 13 | java_binary( 14 | name = "jarcreator_bin", 15 | main_class = "com.google.devtools.build.buildjar.jarhelper.JarCreator", 16 | visibility = ["//visibility:public"], 17 | runtime_deps = [":jarhelper"], 18 | ) 19 | -------------------------------------------------------------------------------- /third_party/bazel/src/main/protobuf/BUILD: -------------------------------------------------------------------------------- 1 | licenses(["notice"]) 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | FILES = [ 6 | "worker_protocol", 7 | ] 8 | 9 | [proto_library( 10 | name = s + "_proto", 11 | srcs = [s + ".proto"], 12 | ) for s in FILES] 13 | 14 | [java_proto_library( 15 | name = s + "_java_proto", 16 | deps = [":" + s + "_proto"], 17 | ) for s in FILES] 18 | -------------------------------------------------------------------------------- /third_party/bazel/src/main/protobuf/worker_protocol.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package blaze.worker; 18 | 19 | option java_package = "com.google.devtools.build.lib.worker"; 20 | 21 | // An input file. 22 | message Input { 23 | // The path in the file system where to read this input artifact from. This is 24 | // either a path relative to the execution root (the worker process is 25 | // launched with the working directory set to the execution root), or an 26 | // absolute path. 27 | string path = 1; 28 | 29 | // A hash-value of the contents. The format of the contents is unspecified and 30 | // the digest should be treated as an opaque token. 31 | bytes digest = 2; 32 | } 33 | 34 | // This represents a single work unit that Blaze sends to the worker. 35 | message WorkRequest { 36 | repeated string arguments = 1; 37 | 38 | // The inputs that the worker is allowed to read during execution of this 39 | // request. 40 | repeated Input inputs = 2; 41 | } 42 | 43 | // The worker sends this message to Blaze when it finished its work on the WorkRequest message. 44 | message WorkResponse { 45 | int32 exit_code = 1; 46 | 47 | // This is printed to the user after the WorkResponse has been received and is supposed to contain 48 | // compiler warnings / errors etc. - thus we'll use a string type here, which gives us UTF-8 49 | // encoding. 50 | string output = 2; 51 | } 52 | --------------------------------------------------------------------------------