Skip to content

Commit 64e2403

Browse files
committed
Merge pull request #17 from bazelbuild/johnynek/fix-resources
Fix resources bug
2 parents 8745399 + c541451 commit 64e2403

File tree

7 files changed

+45
-13
lines changed

7 files changed

+45
-13
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,4 @@ before_install:
2323
- cat ~/.bazelrc >> .bazelrc
2424

2525
script:
26-
- bazel build test/...
27-
- bazel run test:ScalaBinary
28-
- bazel test test/...
26+
- bash test_run.sh

scala/scala.bzl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ def _adjust_resources_path(path):
2626
return dir_1 + dir_2, rel_path
2727
return "", path
2828

29-
def _build_nosrc_jar(ctx, buildijar):
29+
def _add_resources_cmd(ctx):
3030
res_cmd = ""
3131
for f in ctx.files.resources:
3232
c_dir, res_path = _adjust_resources_path(f.path)
3333
change_dir = "-C " + c_dir if c_dir else ""
34-
res_cmd = "\n{jar} uf {out} " + change_dir + " " + res_path
34+
res_cmd += "\n{jar} uf {out} " + change_dir + " " + res_path
35+
return res_cmd
36+
37+
def _build_nosrc_jar(ctx, buildijar):
38+
res_cmd = _add_resources_cmd(ctx)
3539
ijar_cmd = ""
3640
if buildijar:
3741
ijar_cmd = "\ncp {out} {ijar_out}".format(
@@ -61,11 +65,7 @@ touch -t 198001010000 {manifest}
6165
arguments=[])
6266

6367
def _compile(ctx, jars, buildijar):
64-
res_cmd = ""
65-
for f in ctx.files.resources:
66-
c_dir, res_path = _adjust_resources_path(f.path)
67-
change_dir = "-C " + c_dir if c_dir else ""
68-
res_cmd = "\n{jar} uf {out} " + change_dir + " " + res_path
68+
res_cmd = _add_resources_cmd(ctx)
6969
ijar_cmd = ""
7070
if buildijar:
7171
ijar_cmd = "\n{ijar} {out} {ijar_out}".format(

test/BUILD

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@ java_binary(
1414
# For now, we have to use a java_import proxy.
1515
java_import(
1616
name = "lib_import",
17-
jars = [":HelloLib_deploy.jar"],
17+
# these are the outputs of the scala_library targets
18+
jars = [":HelloLib_deploy.jar",
19+
"OtherLib_deploy.jar",
20+
"Exported_deploy.jar",
21+
"Runtime_deploy.jar",
22+
],
23+
runtime_deps = ["org_scala_lang__scala_library", "OtherJavaLib"]
24+
)
25+
26+
java_import(
27+
name = "org_scala_lang__scala_library",
28+
jars = ["@scala//:lib/scala-library.jar"]
1829
)
1930

2031
scala_binary(
@@ -79,7 +90,7 @@ java_library(
7990
scala_library(
8091
name = "ScalaLibResources",
8192
srcs = ["src/main/scala/scala/test/ScalaLibResources.scala"],
82-
resources = ["src/main/resources/scala/test/hellos"],
93+
resources = ["src/main/resources/scala/test/hellos", "src/main/resources/scala/test/byes"],
8394
)
8495

8596
scala_binary(
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
see ya
2+
later
3+
A hui hou

test/src/main/scala/scala/test/ScalaLibBinary.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ package scala.test
1717
object ScalaLibBinary {
1818
def main(args:Array[String]) {
1919
ScalaLibResources.getGreetings foreach println
20+
ScalaLibResources.getFarewells foreach println
2021
}
2122
}

test/src/main/scala/scala/test/ScalaLibResources.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,15 @@
1515
package scala.test
1616

1717
object ScalaLibResources {
18-
def getGreetings() = scala.io.Source.fromInputStream(getClass.getResourceAsStream("hellos")).getLines.toList
18+
def getGreetings() =
19+
scala.io.Source
20+
.fromInputStream(getClass.getResourceAsStream("hellos"))
21+
.getLines
22+
.toList
23+
24+
def getFarewells() =
25+
scala.io.Source
26+
.fromInputStream(getClass.getResourceAsStream("byes"))
27+
.getLines
28+
.toList
1929
}

test_run.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
bazel build test/... \
6+
&& bazel run test:ScalaBinary \
7+
&& bazel run test:ScalaLibBinary \
8+
&& bazel run test:JavaBinary \
9+
&& bazel test test/...

0 commit comments

Comments
 (0)