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