Skip to content

Commit dcf82b4

Browse files
committed
Some formatting so my editor is less cranky
1 parent f11926a commit dcf82b4

File tree

1 file changed

+102
-84
lines changed

1 file changed

+102
-84
lines changed

scala/scala.bzl

Lines changed: 102 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ def _add_resources_cmd(ctx, dest):
4343
c_dir, res_path = _adjust_resources_path(f.path)
4444
target_path = res_path
4545
if res_path[0] != "/":
46-
target_path = "/" + res_path
47-
res_cmd += "\nmkdir -p $(dirname {out_dir}{target_path})\ncp {c_dir}{res_path} {out_dir}{target_path}".format(
46+
target_path = "/" + res_path
47+
res_cmd += """
48+
mkdir -p $(dirname {out_dir}{target_path})
49+
cp {c_dir}{res_path} {out_dir}{target_path}
50+
""".format(
4851
out_dir=dest,
4952
res_path=res_path,
5053
target_path=target_path,
@@ -59,72 +62,81 @@ def _get_jar_path(paths):
5962
return path
6063
return None
6164

65+
6266
def _get_scalac_jar_path(paths):
63-
for p in paths:
64-
path = p.path
65-
if path.endswith("/scalac_deploy.jar"):
66-
return path
67-
return None
67+
for p in paths:
68+
path = p.path
69+
if path.endswith("/scalac_deploy.jar"):
70+
return path
71+
return None
72+
6873

6974
def _build_nosrc_jar(ctx, buildijar):
70-
cp_resources = _add_resources_cmd(ctx, "{out}_tmp".format(out=ctx.outputs.jar.path))
71-
ijar_cmd = ""
72-
if buildijar:
73-
ijar_cmd = "\ncp {out} {ijar_out}".format(
74-
out=ctx.outputs.jar.path,
75-
ijar_out=ctx.outputs.ijar.path)
76-
cmd = """
77-
rm -rf {out}_tmp
78-
set -e
79-
mkdir -p {out}_tmp
80-
# copy any resources
81-
{cp_resources}
82-
{java} -jar {jar} -m {manifest} {out}
83-
""" + ijar_cmd
84-
cmd = cmd.format(
85-
cp_resources=cp_resources,
86-
out=ctx.outputs.jar.path,
87-
manifest=ctx.outputs.manifest.path,
88-
java=ctx.file._java.path,
89-
jar=_get_jar_path(ctx.files.__deploy_jar))
90-
outs = [ctx.outputs.jar]
91-
if buildijar:
92-
outs.extend([ctx.outputs.ijar])
93-
ctx.action(
94-
inputs=
95-
ctx.files.resources +
96-
ctx.files._jdk +
97-
ctx.files.__deploy_jar +
98-
[ctx.outputs.manifest, ctx.file._java],
99-
outputs=outs,
100-
command=cmd,
101-
progress_message="scala %s" % ctx.label,
102-
arguments=[])
75+
cp_resources = _add_resources_cmd(ctx, "{out}_tmp".format(
76+
out=ctx.outputs.jar.path)
77+
)
78+
ijar_cmd = ""
79+
if buildijar:
80+
ijar_cmd = "\ncp {out} {ijar_out}".format(
81+
out=ctx.outputs.jar.path,
82+
ijar_out=ctx.outputs.ijar.path)
83+
cmd = """
84+
rm -rf {out}_tmp
85+
set -e
86+
mkdir -p {out}_tmp
87+
# copy any resources
88+
{cp_resources}
89+
{java} -jar {jar} -m {manifest} {out}
90+
""" + ijar_cmd
91+
cmd = cmd.format(
92+
cp_resources=cp_resources,
93+
out=ctx.outputs.jar.path,
94+
manifest=ctx.outputs.manifest.path,
95+
java=ctx.file._java.path,
96+
jar=_get_jar_path(ctx.files.__deploy_jar))
97+
outs = [ctx.outputs.jar]
98+
if buildijar:
99+
outs.extend([ctx.outputs.ijar])
100+
101+
inputs = ctx.files.resources + ctx.files._jdk + ctx.files.__deploy_jar + [
102+
ctx.outputs.manifest, ctx.file._java
103+
]
104+
105+
ctx.action(
106+
inputs=inputs,
107+
outputs=outs,
108+
command=cmd,
109+
progress_message="scala %s" % ctx.label,
110+
arguments=[])
111+
103112

104113
def _collect_plugin_paths(plugins):
105-
paths = set()
106-
for p in plugins:
107-
if hasattr(p, "path"):
108-
paths += [p.path]
109-
elif hasattr(p, "scala"):
110-
paths += [p.scala.outputs.jar.path]
111-
elif hasattr(p, "java"):
112-
paths += [j.class_jar.path for j in p.java.outputs.jars]
113-
# support http_file pointed at a jar. http_jar uses ijar, which breaks scala macros
114-
elif hasattr(p, "files"):
115-
paths += [f.path for f in p.files]
116-
return paths
114+
paths = set()
115+
for p in plugins:
116+
if hasattr(p, "path"):
117+
paths += [p.path]
118+
elif hasattr(p, "scala"):
119+
paths += [p.scala.outputs.jar.path]
120+
elif hasattr(p, "java"):
121+
paths += [j.class_jar.path for j in p.java.outputs.jars]
122+
# support http_file pointed at a jar. http_jar uses ijar,
123+
# which breaks scala macros
124+
elif hasattr(p, "files"):
125+
paths += [f.path for f in p.files]
126+
return paths
117127

118128

119129
def _compile(ctx, _jars, dep_srcjars, buildijar):
120130
jars = _jars
121-
cp_resources = _add_resources_cmd(ctx, "{out}_tmp".format(out=ctx.outputs.jar.path))
131+
cp_resources = _add_resources_cmd(
132+
ctx, "{out}_tmp".format(out=ctx.outputs.jar.path)
133+
)
122134
ijar_cmd = ""
123135
if buildijar:
124-
ijar_cmd = "\n{ijar} {out} {ijar_out}".format(
125-
ijar=ctx.file._ijar.path,
126-
out=ctx.outputs.jar.path,
127-
ijar_out=ctx.outputs.ijar.path)
136+
ijar_cmd = "\n{ijar} {out} {ijar_out}".format(
137+
ijar=ctx.file._ijar.path,
138+
out=ctx.outputs.jar.path,
139+
ijar_out=ctx.outputs.ijar.path)
128140

129141
java_srcs = _java_filetype.filter(ctx.files.srcs)
130142
sources = _scala_filetype.filter(ctx.files.srcs) + java_srcs
@@ -183,17 +195,23 @@ def _compile(ctx, _jars, dep_srcjars, buildijar):
183195

184196
srcjar_cmd = ""
185197
if len(all_srcjars) > 0:
186-
srcjar_cmd = "\nmkdir -p {out}_tmp_expand_srcjars\n"
187-
for srcjar in all_srcjars:
188-
# Note: this is double escaped because we need to do one format call
189-
# per each srcjar, but then we are going to include this in the bigger format
190-
# call that is done to generate the full command
191-
192-
#TODO would like to be able to switch >/dev/null, -v, etc based on the user's settings
193-
srcjar_cmd += """
194-
unzip -o {srcjar} -d {{out}}_tmp_expand_srcjars >/dev/null
195-
""".format(srcjar = srcjar.path)
196-
srcjar_cmd += """find {out}_tmp_expand_srcjars -type f -name "*.scala" > {out}_args/files_from_jar\n"""
198+
srcjar_cmd = "\nmkdir -p {out}_tmp_expand_srcjars\n"
199+
for srcjar in all_srcjars:
200+
# Note: this is double escaped because
201+
# we need to do one format call
202+
# per each srcjar, but then we are going to include
203+
# this in the bigger format
204+
# call that is done to generate the full command
205+
206+
# TODO would like to be able to switch >/dev/null, -v,
207+
# etc based on the user's settings
208+
srcjar_cmd += """
209+
unzip -o {srcjar} -d {{out}}_tmp_expand_srcjars >/dev/null
210+
""".format(
211+
srcjar=srcjar.path)
212+
srcjar_cmd += """find {out}_tmp_expand_srcjars """
213+
srcjar_cmd += """-type f -name "*.scala"""
214+
srcjar_cmd += """ > {out}_args/files_from_jar\n"""
197215

198216
cmd = """
199217
rm -rf {out}_args
@@ -221,24 +239,24 @@ def _compile(ctx, _jars, dep_srcjars, buildijar):
221239
)
222240
outs = [ctx.outputs.jar]
223241
if buildijar:
224-
outs.extend([ctx.outputs.ijar])
242+
outs.extend([ctx.outputs.ijar])
225243
ins = (list(jars) +
226-
list(dep_srcjars) +
227-
list(srcjars) +
228-
list(sources) +
229-
ctx.files.srcs +
230-
ctx.files.plugins +
231-
ctx.files.resources +
232-
ctx.files._jdk +
233-
ctx.files._scalac +
234-
ctx.files.__deploy_jar +
235-
ctx.files._scalasdk +
236-
[ctx.outputs.manifest,
237-
ctx.file._ijar,
238-
ctx.file._java,
239-
scalac_args_file])
244+
list(dep_srcjars) +
245+
list(srcjars) +
246+
list(sources) +
247+
ctx.files.srcs +
248+
ctx.files.plugins +
249+
ctx.files.resources +
250+
ctx.files._jdk +
251+
ctx.files._scalac +
252+
ctx.files.__deploy_jar +
253+
ctx.files._scalasdk +
254+
[ctx.outputs.manifest,
255+
ctx.file._ijar,
256+
ctx.file._java,
257+
scalac_args_file])
240258
if compile_java_srcs:
241-
ins.extend([javac_args_file])
259+
ins.extend([javac_args_file])
242260
ctx.action(
243261
inputs=ins,
244262
outputs=outs,

0 commit comments

Comments
 (0)