thirdparty_download.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. from checksum import verifyFile
  2. from components import requiredLibrariesFor
  3. from configurations import getConfiguration
  4. from download import downloadURL
  5. from extract import TopLevelDirRenamer, extract
  6. from libraries import allDependencies, librariesByName
  7. from packages import getPackage
  8. from patch import Diff, patch
  9. from os import makedirs
  10. from os.path import isdir, isfile, join as joinpath
  11. from shutil import rmtree
  12. import sys
  13. # TODO: Make DirectX headers for MinGW a package and make the DirectX sound
  14. # driver a component.
  15. def downloadPackage(package, tarballsDir):
  16. if not isdir(tarballsDir):
  17. makedirs(tarballsDir)
  18. filePath = joinpath(tarballsDir, package.getTarballName())
  19. if isfile(filePath):
  20. print('%s version %s - already downloaded' % (
  21. package.niceName, package.version
  22. ))
  23. else:
  24. downloadURL(package.getURL(), tarballsDir)
  25. def verifyPackage(package, tarballsDir):
  26. filePath = joinpath(tarballsDir, package.getTarballName())
  27. try:
  28. verifyFile(filePath, package.fileLength, package.checksums)
  29. except OSError as ex:
  30. print('%s corrupt: %s' % (
  31. package.getTarballName(), ex
  32. ), file=sys.stderr)
  33. sys.exit(1)
  34. def extractPackage(package, tarballsDir, sourcesDir, patchesDir):
  35. if not isdir(sourcesDir):
  36. makedirs(sourcesDir)
  37. sourceDirName = package.getSourceDirName()
  38. packageSrcDir = joinpath(sourcesDir, sourceDirName)
  39. if isdir(packageSrcDir):
  40. rmtree(packageSrcDir)
  41. extract(
  42. joinpath(tarballsDir, package.getTarballName()),
  43. sourcesDir,
  44. TopLevelDirRenamer(sourceDirName)
  45. )
  46. diffPath = joinpath(patchesDir, sourceDirName + '.diff')
  47. if isfile(diffPath):
  48. for diff in Diff.load(diffPath):
  49. patch(diff, sourcesDir)
  50. print('Patched:', diff.getPath())
  51. def fetchPackageSource(makeName, tarballsDir, sourcesDir, patchesDir):
  52. package = getPackage(makeName)
  53. downloadPackage(package, tarballsDir)
  54. verifyPackage(package, tarballsDir)
  55. extractPackage(package, tarballsDir, sourcesDir, patchesDir)
  56. def main(platform, tarballsDir, sourcesDir, patchesDir):
  57. configuration = getConfiguration('3RD_STA')
  58. components = configuration.iterDesiredComponents()
  59. # Compute the set of all directly and indirectly required libraries,
  60. # then filter out system libraries.
  61. thirdPartyLibs = set(
  62. makeName
  63. for makeName in allDependencies(requiredLibrariesFor(components))
  64. if not librariesByName[makeName].isSystemLibrary(platform)
  65. )
  66. if platform == 'windows':
  67. # Avoid ALSA, since we won't be building it and extracting it will
  68. # fail on file systems that don't support symlinks.
  69. # TODO: 3rdparty.mk filters out ALSA on non-Linux platforms;
  70. # figure out a way to do that in a single location.
  71. thirdPartyLibs.discard('ALSA')
  72. for makeName in sorted(thirdPartyLibs):
  73. fetchPackageSource(makeName, tarballsDir, sourcesDir, patchesDir)
  74. if __name__ == '__main__':
  75. if len(sys.argv) == 2:
  76. main(
  77. sys.argv[1],
  78. 'derived/3rdparty/download',
  79. 'derived/3rdparty/src',
  80. 'build/3rdparty'
  81. )
  82. else:
  83. print('Usage: python3 thirdparty_download.py TARGET_OS', file=sys.stderr)
  84. sys.exit(2)