toolchain_tar_test.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python3
  2. """Check that a release tar contains the same files as a prefix root."""
  3. __copyright__ = """
  4. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  5. Exceptions. See /LICENSE for license information.
  6. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. """
  8. from pathlib import Path
  9. import os
  10. import re
  11. import tarfile
  12. import unittest
  13. class ToolchainTarTest(unittest.TestCase):
  14. def test_tar(self) -> None:
  15. install_data_manifest = Path(os.environ["INSTALL_DATA_MANIFEST"])
  16. tar_file = Path(os.environ["TAR_FILE"])
  17. # Gather install data files.
  18. with open(install_data_manifest) as manifest:
  19. # Remove everything up to and including `prefix_root`.
  20. install_files = set(
  21. [
  22. re.sub("^.*/prefix_root/", "", entry.strip())
  23. for entry in manifest.readlines()
  24. ]
  25. )
  26. self.assertTrue(install_files, f"`{install_data_manifest}` is empty.")
  27. # Gather tar files.
  28. with tarfile.open(tar_file) as tar:
  29. # Remove the first path component.
  30. tar_files = set(
  31. [
  32. str(Path(*Path(tarinfo.name).parts[1:]))
  33. for tarinfo in tar
  34. if not tarinfo.isdir()
  35. ]
  36. )
  37. self.assertTrue(tar_files, f"`{tar_file}` is empty.")
  38. self.assertSetEqual(install_files, tar_files)
  39. if __name__ == "__main__":
  40. unittest.main()