<commit_before># Copyright 2015 The Bazel Authors. All rights reserved.
#
# 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.

"""Rules for supporting the Scala language."""

load("//specs2:specs2_junit.bzl", "specs2_junit_dependencies")
_jar_filetype = FileType([".jar"])
_java_filetype = FileType([".java"])
_scala_filetype = FileType([".scala"])
_srcjar_filetype = FileType([".srcjar"])
# TODO is there a way to derive this from the above?
_scala_srcjar_filetype = FileType([".scala", ".srcjar", ".java"])

def _get_runfiles(target):
    runfiles = depset()
    runfiles += target.data_runfiles.files
    runfiles += target.default_runfiles.files
    return runfiles

def _get_all_runfiles(targets):
    runfiles = depset()
    for target in targets:
      runfiles += _get_runfiles(target)
    return runfiles


def _adjust_resources_path_by_strip_prefix(path, resource_strip_prefix):
    if not path.startswith(resource_strip_prefix):
      fail("Resource file %s is not under the specified prefix to strip" % path)

    clean_path = path[len(resource_strip_prefix):]
    return resource_strip_prefix, clean_path

def _adjust_resources_path_by_default_prefixes(path):
      #  Here we are looking to find out the offset of this resource inside
      #  any resources folder. We want to return the root to the resources folder
      #  and then the sub path inside it
      dir_1, dir_2, rel_path = path.partition("resources")
      if rel_path:
          return  dir_1 + dir_2, rel_path

      #  The same as the above but just looking for java
      (dir_1, dir_2, rel_path) = path.partition("java")
      if rel_path:
          return  dir_1 + dir_2, rel_path

      return "", path

def _adjust_resources_path(path, resource_strip_prefix):
    if resource_strip_prefix:
      return _adjust_resources_path_by_strip_prefix(path,resource_strip_prefix)
    else:
      return _adjust_resources_path_by_default_prefixes(path)

def _add_resources_cmd(ctx):
    res_cmd = []
    for f in ctx.files.resources:
        c_dir, res_path = _adjust_resources_path(f.path, ctx.attr.resource_strip_prefix)
        target_path = res_path
        if target_path[0] == "/":
            target_path = target_path[1:]
        line = "{target_path}={c_dir}{res_path}\n".format(
            res_path=res_path,
            target_path=target_path,
            c_dir=c_dir)
        res_cmd.extend([line])
    return "".join(res_cmd)

def _build_nosrc_jar(ctx, buildijar):
    resources = _add_resources_cmd(ctx)
    ijar_cmd = ""
    if buildijar:
        ijar_cmd = "\ncp {jar_output} {ijar_output}\n".format(
          jar_output=ctx.outputs.jar.path,
          ijar_output=ctx.outputs.ijar.path)

    # this ensures the file is not empty
    resources += ctx.outputs.manifest.path + "\n"

    zipper_arg_path = ctx.actions.declare_file("%s_zipper_args" % ctx.outputs.jar.path)
    ctx.file_action(zipper_arg_path, resources)<commit_msg>write the manifest to the correct path<commit_after># Copyright 2015 The Bazel Authors. All rights reserved.
#
# 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.

"""Rules for supporting the Scala language."""

load("//specs2:specs2_junit.bzl", "specs2_junit_dependencies")
_jar_filetype = FileType([".jar"])
_java_filetype = FileType([".java"])
_scala_filetype = FileType([".scala"])
_srcjar_filetype = FileType([".srcjar"])
# TODO is there a way to derive this from the above?
_scala_srcjar_filetype = FileType([".scala", ".srcjar", ".java"])

def _get_runfiles(target):
    runfiles = depset()
    runfiles += target.data_runfiles.files
    runfiles += target.default_runfiles.files
    return runfiles

def _get_all_runfiles(targets):
    runfiles = depset()
    for target in targets:
      runfiles += _get_runfiles(target)
    return runfiles


def _adjust_resources_path_by_strip_prefix(path, resource_strip_prefix):
    if not path.startswith(resource_strip_prefix):
      fail("Resource file %s is not under the specified prefix to strip" % path)

    clean_path = path[len(resource_strip_prefix):]
    return resource_strip_prefix, clean_path

def _adjust_resources_path_by_default_prefixes(path):
      #  Here we are looking to find out the offset of this resource inside
      #  any resources folder. We want to return the root to the resources folder
      #  and then the sub path inside it
      dir_1, dir_2, rel_path = path.partition("resources")
      if rel_path:
          return  dir_1 + dir_2, rel_path

      #  The same as the above but just looking for java
      (dir_1, dir_2, rel_path) = path.partition("java")
      if rel_path:
          return  dir_1 + dir_2, rel_path

      return "", path

def _adjust_resources_path(path, resource_strip_prefix):
    if resource_strip_prefix:
      return _adjust_resources_path_by_strip_prefix(path,resource_strip_prefix)
    else:
      return _adjust_resources_path_by_default_prefixes(path)

def _add_resources_cmd(ctx):
    res_cmd = []
    for f in ctx.files.resources:
        c_dir, res_path = _adjust_resources_path(f.path, ctx.attr.resource_strip_prefix)
        target_path = res_path
        if target_path[0] == "/":
            target_path = target_path[1:]
        line = "{target_path}={c_dir}{res_path}\n".format(
            res_path=res_path,
            target_path=target_path,
            c_dir=c_dir)
        res_cmd.extend([line])
    return "".join(res_cmd)

def _build_nosrc_jar(ctx, buildijar):
    resources = _add_resources_cmd(ctx)
    ijar_cmd = ""
    if buildijar:
        ijar_cmd = "\ncp {jar_output} {ijar_output}\n".format(
          jar_output=ctx.outputs.jar.path,
          ijar_output=ctx.outputs.ijar.path)

    # this ensures the file is not empty
    resources += "META-INF/MANIFEST.MF=%s\n" % ctx.outputs.manifest.path

    zipper_arg_path = ctx.actions.declare_file("%s_zipper_args" % ctx.outputs.jar.path)
    ctx.file_action(zipper_arg_path, resources)
{'fraction_non_alphanumeric': 0.093486478627508, 'fraction_numerical': 0.0061064262867112536, 'mean_word_length': 3.6668928086838535, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1405348', 'n_tokens_mistral': 2177, 'n_tokens_neox': 2126, 'n_words': 593}