thirdparty_download.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. for makeName in sorted(thirdPartyLibs):
  67. fetchPackageSource(makeName, tarballsDir, sourcesDir, patchesDir)
  68. if __name__ == '__main__':
  69. if len(sys.argv) == 2:
  70. main(
  71. sys.argv[1],
  72. 'derived/3rdparty/download',
  73. 'derived/3rdparty/src',
  74. 'build/3rdparty'
  75. )
  76. else:
  77. print('Usage: python3 thirdparty_download.py TARGET_OS', file=sys.stderr)
  78. sys.exit(2)