61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
def _dev_server_impl(ctx):
|
|
script = ctx.actions.declare_file(ctx.label.name + "_runner")
|
|
content = """
|
|
#!/bin/sh
|
|
set -eux
|
|
|
|
echo hi\n
|
|
cp -f '%s' server.jar
|
|
printf eula=true > eula.txt
|
|
mkdir -p plugins
|
|
rm -f plugins/*.jar
|
|
for plugin in %s
|
|
do
|
|
cp -v \"$plugin\" plugins/
|
|
done
|
|
exec java -jar server.jar --nogui %s
|
|
""" % (
|
|
ctx.file.server_jar.short_path,
|
|
" ".join([p.short_path for p in ctx.files.plugins]),
|
|
" ".join(["--add-plugin %s" % p.short_path for p in ctx.files.local_plugins]),
|
|
)
|
|
ctx.actions.write(
|
|
output = script,
|
|
content = content,
|
|
is_executable = True,
|
|
)
|
|
return DefaultInfo(
|
|
executable = script,
|
|
runfiles = ctx.runfiles(files = [ctx.file.server_jar] + ctx.files.plugins + ctx.files.local_plugins)
|
|
)
|
|
|
|
dev_server = rule(
|
|
implementation = _dev_server_impl,
|
|
executable = True,
|
|
attrs = {
|
|
"server_jar": attr.label(allow_single_file = True, mandatory = True),
|
|
"plugins": attr.label_list(),
|
|
"local_plugins": attr.label_list(),
|
|
},
|
|
)
|
|
|
|
def _fetch_plugin_impl(ctx):
|
|
out_file = ctx.actions.declare_file(ctx.attr.filename)
|
|
ctx.actions.run_shell(
|
|
outputs = [out_file],
|
|
command = "curl -Lso \"$1\" \"$2\"",
|
|
arguments = [out_file.path, ctx.attr.url],
|
|
execution_requirements = {
|
|
"requires-network": "1",
|
|
},
|
|
progress_message = "Downloading plugin %s" % ctx.attr.filename,
|
|
)
|
|
return [DefaultInfo(files = depset([out_file]))]
|
|
|
|
fetch_file = rule(
|
|
implementation = _fetch_plugin_impl,
|
|
attrs = {
|
|
"url": attr.string(mandatory = True),
|
|
"filename": attr.string(mandatory = True),
|
|
},
|
|
)
|