| 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 |
|
| 10 |
from os import makedirs |
| 11 |
from os.path import isdir, isfile, join as joinpath |
| 12 |
from shutil import rmtree |
| 13 |
import sys |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
def downloadPackage(package, tarballsDir): |
| 19 |
if not isdir(tarballsDir): |
| 20 |
makedirs(tarballsDir) |
| 21 |
filePath = joinpath(tarballsDir, package.getTarballName()) |
| 22 |
if isfile(filePath): |
| 23 |
print('%s version %s - already downloaded' % ( |
| 24 |
package.niceName, package.version |
| 25 |
)) |
| 26 |
else: |
| 27 |
downloadURL(package.getURL(), tarballsDir) |
| 28 |
|
| 29 |
def verifyPackage(package, tarballsDir): |
| 30 |
filePath = joinpath(tarballsDir, package.getTarballName()) |
| 31 |
try: |
| 32 |
verifyFile(filePath, package.fileLength, package.checksums) |
| 33 |
except OSError as ex: |
| 34 |
print('%s corrupt: %s' % ( |
| 35 |
package.getTarballName(), ex |
| 36 |
), file=sys.stderr) |
| 37 |
sys.exit(1) |
| 38 |
|
| 39 |
def extractPackage(package, tarballsDir, sourcesDir, patchesDir): |
| 40 |
if not isdir(sourcesDir): |
| 41 |
makedirs(sourcesDir) |
| 42 |
sourceDirName = package.getSourceDirName() |
| 43 |
packageSrcDir = joinpath(sourcesDir, sourceDirName) |
| 44 |
if isdir(packageSrcDir): |
| 45 |
rmtree(packageSrcDir) |
| 46 |
extract( |
| 47 |
joinpath(tarballsDir, package.getTarballName()), |
| 48 |
sourcesDir, |
| 49 |
TopLevelDirRenamer(sourceDirName) |
| 50 |
) |
| 51 |
diffPath = joinpath(patchesDir, sourceDirName + '.diff') |
| 52 |
if isfile(diffPath): |
| 53 |
for diff in Diff.load(diffPath): |
| 54 |
patch(diff, sourcesDir) |
| 55 |
print('Patched:', diff.getPath()) |
| 56 |
|
| 57 |
|
| 58 |
def fetchPackageSource(makeName, tarballsDir, sourcesDir, patchesDir): |
| 59 |
package = getPackage(makeName) |
| 60 |
downloadPackage(package, tarballsDir) |
| 61 |
verifyPackage(package, tarballsDir) |
| 62 |
extractPackage(package, tarballsDir, sourcesDir, patchesDir) |
| 63 |
|
| 64 |
def main(platform, tarballsDir, sourcesDir, patchesDir): |
| 65 |
configuration = getConfiguration('3RD_STA') |
| 66 |
components = configuration.iterDesiredComponents() |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
thirdPartyLibs = set( |
| 71 |
makeName |
| 72 |
for makeName in allDependencies(requiredLibrariesFor(components)) |
| 73 |
if not librariesByName[makeName].isSystemLibrary(platform) |
| 74 |
) |
| 75 |
|
| 76 |
for makeName in sorted(thirdPartyLibs): |
| 77 |
fetchPackageSource(makeName, tarballsDir, sourcesDir, patchesDir) |
| 78 |
|
| 79 |
if __name__ == '__main__': |
| 80 |
if len(sys.argv) == 2: |
| 81 |
main( |
| 82 |
sys.argv[1], |
| 83 |
'derived/3rdparty/download', |
| 84 |
'derived/3rdparty/src', |
| 85 |
'build/3rdparty' |
| 86 |
) |
| 87 |
else: |
| 88 |
print('Usage: python3 thirdparty_download.py TARGET_OS', file=sys.stderr) |
| 89 |
sys.exit(2) |