blob: 9053b03da98ef50e1958a951efad6f7ccb5031fa [file]
# -*- Python -*-
# Copyright 2017-2021 The Verible Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Bazel rule to run bison toolchain
"""
# Adapter rule around the @rules_bison toolchain.
def genyacc(
name,
src,
header_out,
source_out,
extra_options = [],
extra_outs = []):
"""Build rule for generating C or C++ sources with Bison.
"""
native.alias(
name = name + "_bison_toolchain",
actual = select({
"//bazel:use_local_flex_bison_enabled": "//bazel:no_toolchain",
"@platforms//os:windows": "//bazel:no_toolchain",
"//conditions:default": "@rules_bison//bison:current_bison_toolchain",
}),
)
native.alias(
name = name + "_m4_toolchain",
actual = select({
"//bazel:use_local_flex_bison_enabled": "//bazel:no_toolchain",
"@platforms//os:windows": "//bazel:no_toolchain",
"//conditions:default": "@rules_m4//m4:current_m4_toolchain",
}),
)
native.genrule(
name = name,
srcs = [src],
outs = [header_out, source_out] + extra_outs,
cmd = select({
"//bazel:use_local_flex_bison_enabled": "bison --defines=$(location " + header_out + ") --output-file=$(location " + source_out + ") " + " ".join(extra_options) + " $<",
"@platforms//os:windows": "win_bison.exe --defines=$(location " + header_out + ") --output-file=$(location " + source_out + ") " + " ".join(extra_options) + " $<",
"//conditions:default": "M4=$(M4) $(BISON) --defines=$(location " + header_out + ") --output-file=$(location " + source_out + ") " + " ".join(extra_options) + " $<",
}),
toolchains = [
":" + name + "_bison_toolchain",
":" + name + "_m4_toolchain",
],
)