Files
carbon-lang/toolchain/install/toolchain_tar_test.py
T
Chandler Carruth 774ada28a2 Fix the installable archive build. (#4064)
There was a file that got into the testing filegroups but not the actual
built tarball. The result was that the installation failed to locate
itself correctly.

We also didn't have any testing to catch this. I'd like to add a bit
more end-to-end testing long-term, but for now just add a Python test
that validates the same set of files are in both.

Sadly, building and testing the compressed release is really slow and
not likely worthwhile outside of the actual release, but it would be
good to catch this stuff earlier. I tried switching from `bz2` to `gz`,
which made very little file size difference (so we should do it
anyways), and it is still too slow to do routinely. Instead, I've added
a Starlark macro that builds both the `pkg_tar` and the `py_test` to
validate it for both uncompressed `tar` and compressed `tar.gz`. This
lets us continuously test the `tar` version, and just test the `tar.gz`
in the nightly release run.

Updates the nightly release workflow to both test, run this specific
test, and use `gz`.

Last but not least, removes the `pkg_zip` as I don't think we have a use
case for this yet and some TODOs that should have been removed when the
version got added.
2024-06-19 15:48:12 +00:00

65 lines
2.1 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
"""
import argparse
import sys
from pathlib import Path
import tarfile
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"tar_file",
type=Path,
help="The tar file to test.",
)
parser.add_argument(
"install_marker",
type=Path,
help="The path of the install marker in a prefix root to test against.",
)
args = parser.parse_args()
# Locate the prefix root from the install marker.
if not args.install_marker.exists():
sys.exit("ERROR: No install marker: " + args.install_marker)
prefix_root_path = args.install_marker.parent.parent.parent
# First check that every file and directory in the tar file exists in our
# prefix root, and build a set of those paths.
installed_paths = set()
with tarfile.open(args.tar_file) as tar:
for tarinfo in tar:
relative_path = Path(*Path(tarinfo.name).parts[1:])
installed_paths.add(relative_path)
if not prefix_root_path.joinpath(relative_path).exists():
sys.exit(
"ERROR: File `{0}` is not in prefix root: `{1}`".format(
tarinfo.name, prefix_root_path
)
)
# If we found an empty tar file, it's always an error.
if len(installed_paths) == 0:
sys.exit("ERROR: Tar file `{0}` was empty.".format(args.tar_file))
# Now check that every file and directory in the prefix root is in that set.
for prefix_path in prefix_root_path.glob("**/*"):
relative_path = prefix_path.relative_to(prefix_root_path)
if relative_path not in installed_paths:
sys.exit(
"ERROR: File `{0}` is not in tar file.".format(relative_path)
)
if __name__ == "__main__":
main()