toolchain_tar_test.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 the package path
  20. # `toolchain/install`.
  21. install_files = set(
  22. [
  23. re.sub("^.*/toolchain/install/", "", entry.strip())
  24. for entry in manifest.readlines()
  25. ]
  26. )
  27. self.assertTrue(install_files, f"`{install_data_manifest}` is empty.")
  28. # Gather tar files.
  29. with tarfile.open(tar_file) as tar:
  30. # Remove the first path component.
  31. tar_files = set(
  32. [
  33. str(Path(*Path(tarinfo.name).parts[1:]))
  34. for tarinfo in tar
  35. if not tarinfo.isdir()
  36. ]
  37. )
  38. self.assertTrue(install_files, f"`{install_data_manifest}` is empty.")
  39. # Gather tar files.
  40. with tarfile.open(tar_file) as tar:
  41. # Remove the first path component.
  42. tar_files = set(
  43. [
  44. str(Path(*Path(tarinfo.name).parts[1:]))
  45. for tarinfo in tar
  46. if not tarinfo.isdir()
  47. ]
  48. )
  49. self.assertTrue(tar_files, f"`{tar_file}` is empty.")
  50. # Check that the `carbon` symlink is in the tar file.
  51. self.assertIn("bin/carbon", tar_files)
  52. tar_files.remove("bin/carbon")
  53. # Remove the `lib/carbon` prefix which should be on every other file.
  54. tar_files = set(
  55. [re.sub("^lib/carbon/", "", entry.strip()) for entry in tar_files]
  56. )
  57. # The install files and the tar files should now be identical.
  58. self.assertSetEqual(install_files, tar_files)
  59. if __name__ == "__main__":
  60. unittest.main()