Skip to content

Commit

Permalink
Use new Bazel actions API
Browse files Browse the repository at this point in the history
  • Loading branch information
djungelorm committed Aug 29, 2019
1 parent d5ab5bd commit dba6024
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 67 deletions.
1 change: 0 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
test --legacy_bazel_java_test
build --incompatible_new_actions_api=false
4 changes: 2 additions & 2 deletions doc/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def _check_documented_impl(ctx):
'doc/test.py %s %s' % (expected, actual)
])

ctx.file_action(
ctx.actions.write(
output = ctx.outputs.executable,
content = '&& \\\n'.join(sub_commands)+'\n',
executable = True
is_executable = True
)

return struct(
Expand Down
2 changes: 1 addition & 1 deletion tools/ServiceDefinitions/build.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def _impl(ctx):
args = ['--output=%s' % ctx.outputs.out.path, ctx.attr.service] + [x.lib.path for x in ctx.attr.assemblies]
ctx.action(
ctx.actions.run(
inputs = ctx.files.assemblies,
outputs = [ctx.outputs.out],
arguments = args,
Expand Down
2 changes: 1 addition & 1 deletion tools/build/autotools.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _impl(ctx):
'zip --quiet -r $CWD/%s ./' % output.path
])

ctx.action(
ctx.actions.run_shell(
inputs = inputs + macros,
outputs = [output],
progress_message = 'Running autotools and creating package %s' % output.short_path,
Expand Down
4 changes: 2 additions & 2 deletions tools/build/client_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def _impl(ctx):
'kill $SERVER_PID',
'exit $RESULT'
])
ctx.file_action(
ctx.actions.write(
output = ctx.outputs.executable,
content = '\n'.join(sub_commands)+'\n',
executable = True
is_executable = True
)

return struct(
Expand Down
6 changes: 3 additions & 3 deletions tools/build/cpp.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def _check_impl(ctx):
args.extend(['-I%s' % x.short_path for x in includes])
args.extend([x.short_path for x in srcs])

ctx.file_action(
ctx.actions.write(
ctx.outputs.executable,
'/usr/bin/cppcheck %s\n' % ' '.join(args)
)
Expand Down Expand Up @@ -57,10 +57,10 @@ def _lint_impl(ctx):
args.extend([x.short_path for x in srcs + hdrs])
sub_commands.append('%s/%s %s' % (runfiles_dir, cpplint.basename, ' '.join(args)))

ctx.file_action(
ctx.actions.write(
ctx.outputs.executable,
content = ' &&\n'.join(sub_commands)+'\n',
executable = True
is_executable = True
)

return struct(
Expand Down
22 changes: 11 additions & 11 deletions tools/build/csharp.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def _ref_impl(ctx):
input = ctx.file.file
output = ctx.outputs.lib

ctx.action(
ctx.actions.run_shell(
mnemonic = 'CSharpReference',
inputs = [input],
outputs = [output],
Expand Down Expand Up @@ -56,7 +56,7 @@ def _lib_impl(ctx):
srcs, deps, lib=lib_output, doc=doc_output, optimize=ctx.attr.optimize,
warn=ctx.attr.warn, nowarn=ctx.attr.nowarn, warnaserror=ctx.attr.warnaserror, define=ctx.attr.define)

ctx.action(
ctx.actions.run_shell(
mnemonic = 'CSharpCompile',
inputs = inputs,
outputs = outputs,
Expand Down Expand Up @@ -86,7 +86,7 @@ def _bin_impl(ctx):
srcs, deps, exe=bin_output, doc=doc_output, optimize=ctx.attr.optimize,
warn=ctx.attr.warn, nowarn=ctx.attr.nowarn, warnaserror=ctx.attr.warnaserror, define=ctx.attr.define)

ctx.action(
ctx.actions.run_shell(
mnemonic = 'CSharpCompile',
inputs = inputs,
outputs = outputs,
Expand All @@ -101,7 +101,7 @@ def _bin_impl(ctx):
sub_commands.append('ln -f -s ../%s %s/%s/%s' % (dep.short_path, runfile_dir, tmp_dir, dep.basename))
sub_commands.append('/usr/bin/mono %s/%s/%s "$@" %s' % (runfile_dir, tmp_dir, bin_output.basename, ' '.join(ctx.attr.runargs)))
sub_commands.append('rm -rf %s/%s' % (runfile_dir, tmp_dir))
ctx.file_action(
ctx.actions.write(
ctx.outputs.executable,
' && \\\n'.join(sub_commands)+'\n'
)
Expand Down Expand Up @@ -131,7 +131,7 @@ def _nunit_impl(ctx):
'(if grep "FATAL UNHANDLED EXCEPTION" stderr.txt; then exit 1; fi)',
'exit $RESULT'
])
ctx.file_action(
ctx.actions.write(
ctx.outputs.executable,
' ; \\\n'.join(sub_commands)+'\n'
)
Expand Down Expand Up @@ -159,7 +159,7 @@ def _gendarme_impl(ctx):
args.append('--ignore=%s' % ctx.file.ignores.short_path)
args.append(src.short_path)

ctx.file_action(
ctx.actions.write(
ctx.outputs.executable,
'MONO_OPTIONS="--debug" /usr/bin/gendarme %s\n' % ' '.join(args)
)
Expand Down Expand Up @@ -198,7 +198,7 @@ def _assembly_info_impl(ctx):
com_visible = 'false'
content.append('[assembly: ComVisible (%s)]' % com_visible)

ctx.file_action(
ctx.actions.write(
output = ctx.outputs.out,
content = '\n'.join(content)+'\n'
)
Expand Down Expand Up @@ -294,8 +294,8 @@ def _nuget_package_out(id, version):
return {'out': '%s.%s.nupkg' % (id, version)}

def _nuget_package_impl(ctx):
nuspec = ctx.new_file(
ctx.attr.assembly.lib, ctx.attr.assembly.lib.basename.replace('.dll','.nuspec'))
nuspec = ctx.actions.declare_file(
ctx.attr.assembly.lib.basename.replace('.dll','.nuspec'), sibling=ctx.attr.assembly.lib)
assemblies = {
'net45': ctx.attr.assembly
}
Expand Down Expand Up @@ -341,7 +341,7 @@ def _nuget_package_impl(ctx):
'</package>'
])

ctx.file_action(
ctx.actions.write(
output = nuspec,
content = '\n'.join(nuspec_contents)
)
Expand All @@ -365,7 +365,7 @@ def _nuget_package_impl(ctx):
for _, assembly in assemblies.items():
inputs.extend([assembly.lib, assembly.doc])

ctx.action(
ctx.actions.run_shell(
mnemonic = 'NuGetPackage',
inputs = inputs,
outputs = [ctx.outputs.out],
Expand Down
2 changes: 1 addition & 1 deletion tools/build/image.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def _impl(ctx):
output = ctx.outputs.out
input = ctx.file.src
ctx.action(
ctx.actions.run_shell(
inputs = [input],
outputs = [output],
progress_message = 'Generating PNG image %s' % output.short_path,
Expand Down
4 changes: 2 additions & 2 deletions tools/build/java.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def _java_checkstyle_impl(ctx):
args.extend([x.short_path for x in srcs])
sub_commands.append('%s/%s %s' % (runfiles_dir, checkstyle.basename, ' '.join(args)))

ctx.file_action(
ctx.actions.write(
ctx.outputs.executable,
content = ' &&\n'.join(sub_commands)+'\n',
executable = True
is_executable = True
)

return struct(
Expand Down
4 changes: 2 additions & 2 deletions tools/build/lua.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def _test_impl(ctx):
'LUA_CPATH="lua-tree/lib/lua/'+_LUA_VERSION+'/?.so;lua-tree/lib/lua/'+_LUA_VERSION+'/?/init.so;;" ' + \
'lua'+_LUA_VERSION+' lua-tree/share/lua/'+_LUA_VERSION+'/krpc/test/init.lua -v'
])
ctx.file_action(
ctx.actions.write(
output = ctx.outputs.executable,
content = ' &&\n'.join(sub_commands)+'\n',
executable = True
is_executable = True
)

runfiles = ctx.runfiles(files = [ctx.file.src, ctx.file.rockspec, ctx.file._luaunit] + ctx.files.deps)
Expand Down
6 changes: 3 additions & 3 deletions tools/build/pkg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def _stage_files_impl(ctx):
outs = []
for src in ctx.files.srcs:
path = ctx.label.name + '/' + _apply_path_map(ctx.attr.path_map, src.short_path)
out = ctx.new_file(ctx.configuration.genfiles_dir, path)
out = ctx.actions.declare_file(path)

sub_commands = ['cp "%s" "%s"' % (src.path, out.path)]

ctx.action(
ctx.actions.run_shell(
mnemonic = 'StageFile',
inputs = [src],
outputs = [out],
Expand Down Expand Up @@ -84,7 +84,7 @@ def _pkg_zip_impl(ctx):
sub_commands.append('(CWD=`pwd` && cd %s && zip --quiet -r $CWD/%s ./)' % (staging_dir, output.path))

# Generate a zip file from the staging directory
ctx.action(
ctx.actions.run_shell(
inputs = inputs,
outputs = [output],
progress_message = 'Packaging files into %s' % output.short_path,
Expand Down
2 changes: 1 addition & 1 deletion tools/build/protobuf/cpp.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def _impl(ctx):
'sed -i \'s/#include ".\\+"/#include "%s"/g\' %s' % (include.replace('/', '\\/'), source.path)
]

ctx.action(
ctx.actions.run_shell(
inputs = [ctx.file.src, ctx.file._protoc],
command = ' && '.join(sub_commands),
outputs = [header, source],
Expand Down
2 changes: 1 addition & 1 deletion tools/build/protobuf/csharp.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def _impl(ctx):
'cp %s/*.cs %s' % (protoc_output, output.path)
]

ctx.action(
ctx.actions.run_shell(
inputs = [ctx.file.src, ctx.file._protoc],
outputs = [output],
command = ' && '.join(sub_commands),
Expand Down
2 changes: 1 addition & 1 deletion tools/build/protobuf/java.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def _impl(ctx):
'cp `find %s -name *.java` %s' % (protoc_output, output.path)
]

ctx.action(
ctx.actions.run_shell(
inputs = [ctx.file.src, ctx.file._protoc],
outputs = [output],
command = ' && '.join(sub_commands),
Expand Down
10 changes: 5 additions & 5 deletions tools/build/protobuf/lua.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _impl(ctx):
'cp %s/protobuf/*.lua %s' % (protoc_output, output.path)
])

ctx.action(
ctx.actions.run_shell(
inputs = [input, protoc, protoc_lua_env] + protoc_lua,
outputs = [output],
mnemonic = 'ProtobufLua',
Expand All @@ -60,13 +60,13 @@ protobuf_lua = rule(

def _env_impl(ctx):
pylibs = [ctx.file._protobuf, ctx.file._six]
setup = ctx.new_file(ctx.configuration.genfiles_dir, 'protoc-lua-setup')
ctx.file_action(
setup = ctx.actions.declare_file('protoc-lua-setup')
ctx.actions.write(
output = setup,
content = ' && \\\n'.join(_create_py_env(ctx.outputs.out.path, pylibs))+'\n',
executable = True
is_executable = True
)
ctx.action(
ctx.actions.run(
inputs = pylibs,
outputs = [ctx.outputs.out],
progress_message = 'Setting up protoc-lua python environment',
Expand Down
10 changes: 5 additions & 5 deletions tools/build/protobuf/nanopb.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _impl(ctx):
#'sed -i \'s/#include ".\\+"/#include "%s"/g\' %s' % (include.replace('/', '\\/'), source.path)
])

ctx.action(
ctx.actions.run_shell(
inputs = [input, options, protoc, protoc_nanopb_env] + protoc_nanopb,
outputs = [header, source],
mnemonic = 'ProtobufNanopb',
Expand All @@ -74,13 +74,13 @@ protobuf_nanopb = rule(

def _env_impl(ctx):
pylibs = [ctx.file._protobuf, ctx.file._six]
setup = ctx.new_file(ctx.configuration.genfiles_dir, 'protoc-nanopb-setup')
ctx.file_action(
setup = ctx.actions.declare_file('protoc-nanopb-setup')
ctx.actions.write(
output = setup,
content = ' && \\\n'.join(_create_py_env(ctx.outputs.out.path, pylibs))+'\n',
executable = True
is_executable = True
)
ctx.action(
ctx.actions.run(
inputs = pylibs,
outputs = [ctx.outputs.out],
progress_message = 'Setting up protoc-nanopb python environment',
Expand Down
2 changes: 1 addition & 1 deletion tools/build/protobuf/python.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def _impl(ctx):
'cp %s/protobuf/*.py %s' % (protoc_output, output.path)
]

ctx.action(
ctx.actions.run_shell(
inputs = [ctx.file.src, ctx.file._protoc],
outputs = [output],
command = ' && '.join(sub_commands),
Expand Down
Loading

0 comments on commit dba6024

Please sign in to comment.