<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/83066>83066</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Improve Bazel support to avoid legacy external links
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          fzakaria
      </td>
    </tr>
</table>

<pre>
    The current lit tests find FileCheck using the legacy way for finding external files in your runfiles structure.

Most lit_tests use [package_path](https://github.com/llvm/llvm-project/blob/15a7de697ae5ad88fd96ef7dc39ac479cc6e2eaf/utils/bazel/llvm-project-overlay/llvm/lit_test.bzl#L41) to find the directory for FileCheck.

[example](https://github.com/llvm/llvm-project/blob/15a7de697ae5ad88fd96ef7dc39ac479cc6e2eaf/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel#L32):
```
expand_template(
 name = "lit_site_cfg_py",
    testonly = True,
    out = "lit.site.cfg.py",
    substitutions = {
 "@LIT_SITE_CFG_IN_HEADER@": LIT_SITE_CFG_IN_HEADER,
 "@LLVM_TOOLS_DIR@": package_path("//llvm:BUILD"),
```

This can create a lot of inodes that are unecessary, especially if you use [rules_python](https://github.com/bazelbuild/rules_python) which adds python as a runfile for hermeticness.

The recommended solution by Bazel right now is to do the two settings:
```
# Disabling runfiles links drastically increases performance in slow disk IO situations
# Do not build runfile trees by default. If an execution strategy relies on runfile
# symlink teee, the tree is created on-demand. See: https://github.com/bazelbuild/bazel/issues/6627
# and https://github.com/bazelbuild/bazel/commit/03246077f948f2790a83520e7dccc2625650e6df
build --nobuild_runfile_links
test --nobuild_runfile_links

 # https://bazel.build/reference/command-line-reference#flag--legacy_external_runfiles
 build --nolegacy_external_runfiles
 test --nolegacy_external_runfiles
``

In order to remove the _legacy_external_runfiles_ however we have to change the mapping of LLVM_TOOLS_DIR.
The easy way to do this is as follows:
```
"@LLVM_TOOLS_DIR@": "../llvm-project/llvm",
```

The following wiki has a lot of good information: https://github.com/bazelbuild/bazel/wiki/Updating-the-runfiles-tree-structure
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVk1v2zgQ_TX0ZWBBpizbOviQxPWugXQLbNO9CiNyJHFDkQJJxXF__YKS7SQtmm73tECgJORwPt7MeyR6rxpDtGX5Lct3MxxCa922_oqP6BTOKitP24eWQAzOkQmgVYBAPniolZGwV5ruWhKPMHhlGggtgaYGxQmOeILautEubtFzIGdQQ600eVAGTnZw4AYzLfjgBhEGRwlLdyy9mb4frR-DllPQwROw_LZH8YgNlT2GluU7xjdtCL1n2Q3je8b3jQrtUCXCdozvtX66_Jr3zv5NIjC-r7StGN8vclxLWhVrpBzlZlPLYkX1WoqsQLFcF0KsiBPWjO-HoLSPJ_Er6W8czu0TOY2nV-HOOSfVV814dr9cMF5AsBNuESepHIlg3QTTFck35bP8lp6x6zX938rstHKM72OJjO9vvxzud8n5SHafccaLmOZUxCo9_4z_0nOPRpaBul5jIMY30zoY7AhYtgPGeYTPq0ClqJuyPzHOGb872wGMI2iNPo3mD26gN7t2CK_8JNFPIuom-d6PHyofVBiCssZPZ9a35-1ou0zvDw_l58PDh_Ju_1t5-KP8_cPN7sOfbJnG7ewGfrB_DXL2cv_Xx_Lh06f7z-Xu8Or0m0HmmzG9_aWZ2c0I67hYXD1-g-b0fWiVB4EGhCMMBAjaBrA1KGMleQgtBkBHMBgS5D26E-N3QL4noVDrE6g68vFCMDdo8mV_Cq01P528se3VoLRkfP_mJC_g2CrRAkrpYVoE9IAX2o-j35LrKChhyPvkbVUEjoTtOjKSJHirx05BdYLbGBScatoAxh5B-UguaUdqhaMFTyEo0_gfjSHjGeyUx0pHdbrKkFbm0YN06IMSEzImgurJQ0-utq5DIyjql9f2CFL5Rzh8Aq_CgOMYvXJvwdgAIzTXioMj8rECSTUOOiRwqAEN0DOJqTofHAZqTuBIK_JgzeXwi2t_6mKmEIji7E9VO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