<commit_before>def _GetPath(ctx, path):
    if ctx.label.workspace_root:
        return ctx.label.workspace_root + "/" + path
    else:
        return path

def _IsNewExternal(ctx):
    # Bazel 0.4.4 and older have genfiles paths that look like:
    #   bazel-out/local-fastbuild/genfiles/external/repo/foo
    # After the exec root rearrangement, they look like:
    #   ../repo/bazel-out/local-fastbuild/genfiles/foo
    return ctx.label.workspace_root.startswith("../")

def _GenDir(ctx):
    if _IsNewExternal(ctx):
        # We are using the fact that Bazel 0.4.4+ provides repository-relative paths
        # for ctx.genfiles_dir.
        return ctx.genfiles_dir.path + (
            "/" + ctx.attr.includes[0] if ctx.attr.includes and ctx.attr.includes[0] else ""
        )

    # This means that we're either in the old version OR the new version in the local repo.
    # Either way, appending the source path to the genfiles dir works.
    return ctx.var["GENDIR"] + "/" + _SourceDir(ctx)

def _SourceDir(ctx):
    if not ctx.attr.includes:
        return ctx.label.workspace_root
    if not ctx.attr.includes[0]:
        return _GetPath(ctx, ctx.label.package)
    if not ctx.label.package:
        return _GetPath(ctx, ctx.attr.includes[0])
    return _GetPath(ctx, ctx.label.package + "/" + ctx.attr.includes[0])

def _CcHdrs(srcs, use_grpc_plugin = False):
    ret = [s[:-len(".proto")] + ".pb.h" for s in srcs]
    if use_grpc_plugin:
        ret += [s[:-len(".proto")] + ".grpc.pb.h" for s in srcs]
    return ret

def _CcSrcs(srcs, use_grpc_plugin = False):
    ret = [s[:-len(".proto")] + ".pb.cc" for s in srcs]
    if use_grpc_plugin:
        ret += [s[:-len(".proto")] + ".grpc.pb.cc" for s in srcs]
    return ret

def _CcOuts(srcs, use_grpc_plugin = False):
    return _CcHdrs(srcs, use_grpc_plugin) + _CcSrcs(srcs, use_grpc_plugin)

def _PyOuts(srcs, use_grpc_plugin = False):
    ret = [s[:-len(".proto")] + "_pb2.py" for s in srcs]
    if use_grpc_plugin:
        ret += [s[:-len(".proto")] + "_pb2_grpc.py" for s in srcs]
    return ret

def _RelativeOutputPath(path, include, dest = ""):
    if include == None:
        return path

    if not path.startswith(include):
        fail("Include path %s isn't part of the path %s." % (include, path))

    if include and include[-1] != "/":
        include = include + "/"
    if dest and dest[-1] != "/":
        dest = dest + "/"

    path = path[len(include):]
    return dest + path

def _proto_gen_impl(ctx):
    """General implementation for generating protos"""
    srcs = ctx.files.srcs
    deps = []
    deps += ctx.files.srcs
    source_dir = _SourceDir(ctx)
    gen_dir = _GenDir(ctx)
    if source_dir:
        import_flags = ["-I" + source_dir, "-I" + gen_dir]
    else:
        import_flags = ["-I."]

    for dep in ctx.attr.deps:
        import_flags += dep.proto.import_flags
        deps += dep.proto.deps
    import_flags = depset(import_flags).to_list()
    deps = depset(deps).to_list()

    args = []
    if ctx.attr.gen_cc:
        args += ["--cpp_out=" + gen_dir]
    if ctx.attr.gen_py:
        args += ["--python_out=" + gen_dir]

    inputs = srcs + deps
    if ctx.executable.plugin:
        plugin = ctx.executable.plugin
        lang = ctx.attr.plugin_language
        if not lang and plugin.basename.startswith("protoc-gen-"):
            lang = plugin.basename[len("protoc-gen-"):]
        if not lang:
            fail("cannot infer the target language of plugin", "plugin_language")

        outdir = gen_dir
        if ctx.attr.plugin_options:
            outdir = ",".join(ctx.attr.plugin_options) + ":" + outdir
        args += ["--plugin=protoc-gen-%s=%s" % (lang, plugin.path)]
        args += ["--%s_out=%s" % (lang, outdir)]
        inputs += [plugin]

    if args:
        ctx.actions.run(
            inputs = inputs,
            outputs = ctx.outputs.outs,
            arguments = args + import_flags + [s.path for s in srcs],
            executable = ctx.executable.protoc,
            mnemonic = "ProtoCompile",
            use_default_shell_env = True,
        )

    return struct(
        proto = struct(
            srcs = srcs,<commit_msg>systemlibs: protobuf: update for --incompatible_no_support_tools_in_action_inputs<commit_after>def _GetPath(ctx, path):
    if ctx.label.workspace_root:
        return ctx.label.workspace_root + "/" + path
    else:
        return path

def _IsNewExternal(ctx):
    # Bazel 0.4.4 and older have genfiles paths that look like:
    #   bazel-out/local-fastbuild/genfiles/external/repo/foo
    # After the exec root rearrangement, they look like:
    #   ../repo/bazel-out/local-fastbuild/genfiles/foo
    return ctx.label.workspace_root.startswith("../")

def _GenDir(ctx):
    if _IsNewExternal(ctx):
        # We are using the fact that Bazel 0.4.4+ provides repository-relative paths
        # for ctx.genfiles_dir.
        return ctx.genfiles_dir.path + (
            "/" + ctx.attr.includes[0] if ctx.attr.includes and ctx.attr.includes[0] else ""
        )

    # This means that we're either in the old version OR the new version in the local repo.
    # Either way, appending the source path to the genfiles dir works.
    return ctx.var["GENDIR"] + "/" + _SourceDir(ctx)

def _SourceDir(ctx):
    if not ctx.attr.includes:
        return ctx.label.workspace_root
    if not ctx.attr.includes[0]:
        return _GetPath(ctx, ctx.label.package)
    if not ctx.label.package:
        return _GetPath(ctx, ctx.attr.includes[0])
    return _GetPath(ctx, ctx.label.package + "/" + ctx.attr.includes[0])

def _CcHdrs(srcs, use_grpc_plugin = False):
    ret = [s[:-len(".proto")] + ".pb.h" for s in srcs]
    if use_grpc_plugin:
        ret += [s[:-len(".proto")] + ".grpc.pb.h" for s in srcs]
    return ret

def _CcSrcs(srcs, use_grpc_plugin = False):
    ret = [s[:-len(".proto")] + ".pb.cc" for s in srcs]
    if use_grpc_plugin:
        ret += [s[:-len(".proto")] + ".grpc.pb.cc" for s in srcs]
    return ret

def _CcOuts(srcs, use_grpc_plugin = False):
    return _CcHdrs(srcs, use_grpc_plugin) + _CcSrcs(srcs, use_grpc_plugin)

def _PyOuts(srcs, use_grpc_plugin = False):
    ret = [s[:-len(".proto")] + "_pb2.py" for s in srcs]
    if use_grpc_plugin:
        ret += [s[:-len(".proto")] + "_pb2_grpc.py" for s in srcs]
    return ret

def _RelativeOutputPath(path, include, dest = ""):
    if include == None:
        return path

    if not path.startswith(include):
        fail("Include path %s isn't part of the path %s." % (include, path))

    if include and include[-1] != "/":
        include = include + "/"
    if dest and dest[-1] != "/":
        dest = dest + "/"

    path = path[len(include):]
    return dest + path

def _proto_gen_impl(ctx):
    """General implementation for generating protos"""
    srcs = ctx.files.srcs
    deps = []
    deps += ctx.files.srcs
    source_dir = _SourceDir(ctx)
    gen_dir = _GenDir(ctx)
    if source_dir:
        import_flags = ["-I" + source_dir, "-I" + gen_dir]
    else:
        import_flags = ["-I."]

    for dep in ctx.attr.deps:
        import_flags += dep.proto.import_flags
        deps += dep.proto.deps
    import_flags = depset(import_flags).to_list()
    deps = depset(deps).to_list()

    args = []
    if ctx.attr.gen_cc:
        args += ["--cpp_out=" + gen_dir]
    if ctx.attr.gen_py:
        args += ["--python_out=" + gen_dir]

    inputs = srcs + deps
    tools = [ctx.executable.protoc]
    if ctx.executable.plugin:
        plugin = ctx.executable.plugin
        lang = ctx.attr.plugin_language
        if not lang and plugin.basename.startswith("protoc-gen-"):
            lang = plugin.basename[len("protoc-gen-"):]
        if not lang:
            fail("cannot infer the target language of plugin", "plugin_language")

        outdir = gen_dir
        if ctx.attr.plugin_options:
            outdir = ",".join(ctx.attr.plugin_options) + ":" + outdir
        args += ["--plugin=protoc-gen-%s=%s" % (lang, plugin.path)]
        args += ["--%s_out=%s" % (lang, outdir)]
        tools.append(plugin)

    if args:
        ctx.actions.run(
            inputs = inputs,
            outputs = ctx.outputs.outs,
            arguments = args + import_flags + [s.path for s in srcs],
            executable = ctx.executable.protoc,
            mnemonic = "ProtoCompile",
            tools = tools,
            use_default_shell_env = True,
        )

    return struct(
        proto = struct(
            srcs = srcs,
{'fraction_non_alphanumeric': 0.1368956141387871, 'fraction_numerical': 0.003546518501004847, 'mean_word_length': 2.411290322580645, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1991702', 'n_tokens_mistral': 2882, 'n_tokens_neox': 2868, 'n_words': 704}