Philip P. Moltmann | ac3d58c | 2016-03-04 15:19:21 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import urllib2 |
| 4 | import os |
| 5 | import sys |
| 6 | from subprocess import call |
| 7 | |
| 8 | CHROMIUM_VERSION_TRACKING_URL = "https://omahaproxy.appspot.com/all" |
| 9 | CHROMIUM_BUILD_TYPE = "stable" |
| 10 | CHROMIUM_OS = "android" |
| 11 | |
| 12 | CHROMIUM_SOURCE_URL = "https://chromium.googlesource.com/chromium/src/+/refs/tags" |
| 13 | CHROMIUM_DEPS_FILE = "DEPS" |
| 14 | |
| 15 | PDFIUM_GIT_REPO = "https://pdfium.googlesource.com/pdfium.git" |
| 16 | |
Colin Cross | 961fd5e | 2017-04-19 20:32:09 -0700 | [diff] [blame] | 17 | MAKE_FILES = ["Android.bp", |
| 18 | "third_party/pdfiumopenjpeg.bp", |
| 19 | "third_party/pdfiumlcms.bp", |
| 20 | "third_party/pdfiumjpeg.bp", |
| 21 | "third_party/pdfiumagg23.bp", |
| 22 | "third_party/pdfiumzlib.bp", |
| 23 | "third_party/pdfiumbigint.bp", |
| 24 | "third_party/Android.bp", |
| 25 | "pdfiumfpdftext.bp", |
| 26 | "pdfiumfpdfdoc.bp", |
| 27 | "pdfiumfdrm.bp", |
| 28 | "pdfiumfxcodec.bp", |
| 29 | "pdfiumfpdfapi.bp", |
| 30 | "pdfiumfxcrt.bp", |
| 31 | "pdfiumfxge.bp", |
| 32 | "pdfiumjavascript.bp", |
| 33 | "pdfiumformfiller.bp", |
| 34 | "pdfiumfxedit.bp", |
| 35 | "pdfiumpdfwindow.bp", |
| 36 | "pdfium.bp"] |
Philip P. Moltmann | ac3d58c | 2016-03-04 15:19:21 -0800 | [diff] [blame] | 37 | |
Chih-Hung Hsieh | ec72bb8 | 2017-02-23 15:32:15 -0800 | [diff] [blame] | 38 | OWNERS_FILES = ["OWNERS", "docs/OWNERS", "third_party/base/numerics/OWNERS"] |
| 39 | |
Philip P. Moltmann | ac3d58c | 2016-03-04 15:19:21 -0800 | [diff] [blame] | 40 | COPY_FILES = [os.path.basename(__file__), ".git", "MODULE_LICENSE_BSD", "NOTICE"] + MAKE_FILES |
Chih-Hung Hsieh | ec72bb8 | 2017-02-23 15:32:15 -0800 | [diff] [blame] | 41 | REMOVE_FILES = [os.path.basename(__file__), ".git", ".gitignore"] + OWNERS_FILES |
Philip P. Moltmann | ac3d58c | 2016-03-04 15:19:21 -0800 | [diff] [blame] | 42 | |
| 43 | def getStableChromiumVersion(): |
| 44 | """ :return the latest chromium version """ |
| 45 | |
| 46 | chromiumVersions = urllib2.urlopen(CHROMIUM_VERSION_TRACKING_URL) |
| 47 | |
| 48 | for chromiumVersionStr in chromiumVersions.read().split("\n"): |
| 49 | chromiumVersion = chromiumVersionStr.split(",") |
| 50 | |
| 51 | if chromiumVersion[0] == CHROMIUM_OS and chromiumVersion[1] == CHROMIUM_BUILD_TYPE: |
| 52 | return chromiumVersion[2] |
| 53 | |
| 54 | raise Exception("Could not find latest %s chromium version for %s at %s" |
| 55 | % (CHROMIUM_BUILD_TYPE, CHROMIUM_OS, CHROMIUM_VERSION_TRACKING_URL)) |
| 56 | |
| 57 | |
| 58 | def getPdfiumRevision(): |
| 59 | """ :return the pdfium version used by the latest chromium version """ |
| 60 | |
| 61 | try: |
| 62 | deps = urllib2.urlopen("%s/%s/%s" % (CHROMIUM_SOURCE_URL, getStableChromiumVersion(), |
| 63 | CHROMIUM_DEPS_FILE)) |
| 64 | |
| 65 | # I seem to not be able to get the raw file, hence grep the html file |
| 66 | return deps.read().split("pdfium_revision&")[1].split("'")[1] |
| 67 | except Exception as e: |
| 68 | raise Exception("Could not extract pdfium revision from %s/%s/%s: %s" |
| 69 | % (CHROMIUM_SOURCE_URL, getStableChromiumVersion(), CHROMIUM_DEPS_FILE, e)) |
| 70 | |
| 71 | |
| 72 | def downloadPdfium(newDir, rev): |
| 73 | """ Download the newest version of pdfium to the new directory |
| 74 | |
| 75 | :param newDir: The new files |
| 76 | :param rev: The revision to change to |
| 77 | """ |
| 78 | |
| 79 | call(["git", "clone", PDFIUM_GIT_REPO, newDir]) |
| 80 | os.chdir(newDir) |
| 81 | call(["git", "reset", "--hard", rev]) |
| 82 | |
| 83 | |
| 84 | def removeFiles(newDir): |
| 85 | """ Remove files that should not be checked in from the original download |
| 86 | |
| 87 | :param newDir: The new files |
| 88 | """ |
| 89 | |
| 90 | for fileName in REMOVE_FILES: |
| 91 | call(["rm", "-rf", os.path.join(newDir, fileName)]) |
| 92 | |
| 93 | |
| 94 | def copyFiles(currentDir, newDir): |
| 95 | """ Copy files needed to make pdfium work with android |
| 96 | |
| 97 | :param currentDir: The current files |
| 98 | :param newDir: The new files |
| 99 | """ |
| 100 | |
| 101 | for fileName in COPY_FILES: |
| 102 | call(["cp", "-r", os.path.join(currentDir, fileName), os.path.join(newDir, fileName)]) |
| 103 | |
| 104 | |
| 105 | def exchange(currentDir, newDir, oldDir): |
| 106 | """ Update current to new and save current in old. |
| 107 | |
| 108 | :param currentDir: The current files |
| 109 | :param newDir: The new files |
| 110 | :param oldDir: The old files |
| 111 | """ |
| 112 | |
| 113 | call(["mv", currentDir, oldDir]) |
| 114 | call(["mv", newDir, currentDir]) |
| 115 | |
| 116 | |
| 117 | if __name__ == "__main__": |
| 118 | rev = getPdfiumRevision() |
| 119 | targetDir = os.path.dirname(os.path.realpath(__file__)) |
| 120 | newDir = targetDir + ".new" |
| 121 | oldDir = targetDir + ".old" |
| 122 | |
| 123 | try: |
| 124 | downloadPdfium(newDir, rev) |
| 125 | removeFiles(newDir) |
| 126 | copyFiles(targetDir, newDir) |
| 127 | exchange(targetDir, newDir, oldDir) |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 128 | print("Updated pdfium to " + rev + " (Chrome " + getStableChromiumVersion() + "). Old files " |
| 129 | "are in " + oldDir + ". Please verify if build files need to be updated.") |
Philip P. Moltmann | ac3d58c | 2016-03-04 15:19:21 -0800 | [diff] [blame] | 130 | |
| 131 | sys.exit(0) |
| 132 | except: |
| 133 | call(["rm", "-rf", newDir]) |
| 134 | sys.exit(1) |
| 135 | |