thirdparty_download.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 IOError, ex:
  30. print >> sys.stderr, '%s corrupt: %s' % (
  31. package.getTarballName(), ex
  32. )
  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. if platform == 'android':
  58. fetchPackageSource('TCL_ANDROID', tarballsDir, sourcesDir, patchesDir)
  59. else:
  60. configuration = getConfiguration('3RD_STA')
  61. components = configuration.iterDesiredComponents()
  62. # Compute the set of all directly and indirectly required libraries,
  63. # then filter out system libraries.
  64. thirdPartyLibs = set(
  65. makeName
  66. for makeName in allDependencies(requiredLibrariesFor(components))
  67. if not librariesByName[makeName].isSystemLibrary(platform)
  68. )
  69. if platform == 'windows':
  70. # Avoid ALSA, since we won't be building it and extracting it will
  71. # fail on file systems that don't support symlinks.
  72. # TODO: 3rdparty.mk filters out ALSA on non-Linux platforms;
  73. # figure out a way to do that in a single location.
  74. thirdPartyLibs.discard('ALSA')
  75. for makeName in sorted(thirdPartyLibs):
  76. fetchPackageSource(makeName, tarballsDir, sourcesDir, patchesDir)
  77. if __name__ == '__main__':
  78. if len(sys.argv) == 2:
  79. main(
  80. sys.argv[1],
  81. 'derived/3rdparty/download',
  82. 'derived/3rdparty/src',
  83. 'build/3rdparty'
  84. )
  85. else:
  86. print >> sys.stderr, (
  87. 'Usage: python thirdparty_download.py TARGET_OS'
  88. )
  89. sys.exit(2)