Files
carbon-lang/toolchain/install/toolchain_tar_test.py
T
Chandler CarruthandGeoff Romer d66b2f899c Switch install to be based on the busybox root (#6579)
Previously, we used the FHS "prefix" concept as the basis of the
install, but this makes it hard to integrate an installed toolchain with
Bazel (or similar) build system where it wants the "root" of the
toolchain to have some specific files (`MODULES.bazel` or
`BUILD.bazel`), and cannot reference anything outside that directory
tree.

An easy solution is to make the `lib/carbon` directory the root of the
install and never walking up from it. Then we simply have a `bin/carbon`
symlink to the busybox that is useful for getting the command into the
PATH, but isn't used for anything else. The FHS-constrained install
paths surround a root we fully control the layout and files within.

While initially motivated by trying to make a single toolchain structure
that works both for installation and for Bazel, it actually makes the
paths we end up using in the toolchain much simpler. We no longer have
awkward `.../lib/carbon/../../lib/carbon/...` sequences in the toolchain
which is cleaner and even a (trivial) efficiency gain.

As I was doing this I noticed several out-of-date comments that I tried
to fix, and I tried to improve some code reuse rather than re-computing
paths.

---------

Co-authored-by: Geoff Romer <gromer@google.com>
2026-01-13 03:16:38 +00:00

51 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""Check that a release tar contains the same files as a prefix root."""
__copyright__ = """
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
Exceptions. See /LICENSE for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
from pathlib import Path
import os
import re
import tarfile
import unittest
class ToolchainTarTest(unittest.TestCase):
def test_tar(self) -> None:
install_data_manifest = Path(os.environ["INSTALL_DATA_MANIFEST"])
tar_file = Path(os.environ["TAR_FILE"])
# Gather install data files.
with open(install_data_manifest) as manifest:
# Remove everything up to and including `prefix`.
install_files = set(
[
re.sub("^.*/prefix/", "", entry.strip())
for entry in manifest.readlines()
]
)
self.assertTrue(install_files, f"`{install_data_manifest}` is empty.")
# Gather tar files.
with tarfile.open(tar_file) as tar:
# Remove the first path component.
tar_files = set(
[
str(Path(*Path(tarinfo.name).parts[1:]))
for tarinfo in tar
if not tarinfo.isdir()
]
)
self.assertTrue(tar_files, f"`{tar_file}` is empty.")
self.assertSetEqual(install_files, tar_files)
if __name__ == "__main__":
unittest.main()