From 16cb282ad266674de090cc5c6439944e242074c5 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 22 May 2022 04:21:33 -0700 Subject: feat(0.1.0): initial release --- cobol/internal/BUILD | 0 cobol/internal/actions.bzl | 23 +++++++++++++++++++++++ cobol/internal/rules.bzl | 30 ++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 cobol/internal/BUILD create mode 100644 cobol/internal/actions.bzl create mode 100644 cobol/internal/rules.bzl (limited to 'cobol/internal') diff --git a/cobol/internal/BUILD b/cobol/internal/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/cobol/internal/actions.bzl b/cobol/internal/actions.bzl new file mode 100644 index 0000000..a57bd58 --- /dev/null +++ b/cobol/internal/actions.bzl @@ -0,0 +1,23 @@ +"""Common functions for creating actions to build COBOL programs""" + +load("@bazel_skylib//lib:shell.bzl", "shell") + +def cobol_compile_executable(ctx, srcs, out): + """Compiles a single COBOL program from sources + + Args: + ctx: the build context + srcs: the source files to compile + out: the output file + """ + + ctx.actions.run_shell( + outputs = [out], + inputs = srcs, + command = "cobc -x -o {out} {srcs}".format( + out = shell.quote(out.path), + srcs = " ".join([shell.quote(src.path) for src in srcs]), + ), + mnemonic = "COBOLCompile", + use_default_shell_env = True, + ) diff --git a/cobol/internal/rules.bzl b/cobol/internal/rules.bzl new file mode 100644 index 0000000..8dac747 --- /dev/null +++ b/cobol/internal/rules.bzl @@ -0,0 +1,30 @@ +"Rules for building COBOL programs" + +load(":actions.bzl", "cobol_compile_executable") + +def _cobol_binary_impl(ctx): + prefix = ctx.label.name + "%/" + executable = ctx.actions.declare_file(prefix + ctx.label.name) + + cobol_compile_executable( + ctx, + srcs = ctx.files.srcs, + out = executable, + ) + + return [DefaultInfo( + files = depset([executable]), + executable = executable, + )] + +cobol_binary = rule( + _cobol_binary_impl, + attrs = { + "srcs": attr.label_list( + allow_files = True, + doc = "The COBOL source files to compile for this binary", + ), + }, + doc = "Builds an executable program from COBOL source code", + executable = True, +) -- cgit v1.2.3