Skip to content

Commit

Permalink
simplicity editing
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRyanSmith committed May 2, 2022
1 parent 7830008 commit 8315e77
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 36 deletions.
2 changes: 1 addition & 1 deletion tools/wpt/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def _get_chromium_download_url(self, version=None):
f"based on version. {url}")
# If no URL was used in a previous install
# and no version was passed, use the latest Chromium revision.
revision = self._get_latest_chromium_revision()
revision = self._get_pinned_chromium_revision()

# If the url is successfully used to download/install, it will be used again
# if another component is also installed during this run (browser/webdriver).
Expand Down
2 changes: 1 addition & 1 deletion tools/wpt/latest_chromium_revision.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
996554
998197
63 changes: 29 additions & 34 deletions tools/wpt/update_chromium_revision.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import requests
from time import time

from .utils import get


PLATFORM_INFO = [
("Win_x64", "chrome-win.zip"),
Expand All @@ -17,71 +15,68 @@ def main(timeout=600.0):
start = time()

# Load existing pinned revision.
existing_revision = None
start_revision = None
with open("tools/wpt/latest_chromium_revision.txt", "r") as f:
existing_revision = int(f.read())

# Find the lowest new revision number among latest revisions by platform.
# We need to find a revision number that is available for download for all platforms,
# so we start looking from the smallest of these latest revisions.
smallest_revision = existing_revision
for platform, filename in PLATFORM_INFO:
try:
url = f"{SNAPSHOTS_PATH}{platform}/LAST_CHANGE"
revision = get(url).text.strip()
smallest_revision = max(smallest_revision, int(revision))
except requests.RequestException as e:
print(f"failed LAST_CHANGE lookup for {platform}: {e}")
continue
# Get the latest revision for Linux as a starting point to check for
# a valid revision for all platforms.
try:
url = f"{SNAPSHOTS_PATH}Linux_x64/LAST_CHANGE"
start_revision = int(requests.get(url).text.strip())
except requests.RequestException as e:
raise requests.RequestException(f"Failed LAST_CHANGE lookup: {e}")

if smallest_revision == existing_revision:
if start_revision == existing_revision:
return

# Step backwards through revision numbers until we find one
# that is available for all platforms.
candidate_revision = smallest_revision
available_for_all = False
candidate_revision = start_revision
new_revision = None
timed_out = False
while not available_for_all and not timed_out:
while not timed_out and new_revision is None:
available_for_all = True
# For each platform, check if Chromium is available for download from snapshots.
for platform, filename in PLATFORM_INFO:
try:
url = (f"{SNAPSHOTS_PATH}{platform}/"
f"{largest_mutually_available_revision}/{filename}")
f"{candidate_revision}/{filename}")
# Check the headers of each possible download URL.
r = requests.head(url)
# If the "Accept-Ranges" header is not present, we know the file is not
# available for download. Decrement the revision number and try again.
if "Accept-Ranges" not in r.headers:
largest_mutually_available_revision -= 1
# If the file is not available for download, decrement the revision and try again.
if r.status_code != 200:
candidate_revision -= 1
available_for_all = False
break
except requests.RequestException as e:
print(e)
largest_mutually_available_revision -= 1
except requests.RequestException:
print(f"Failed to fetch headers for revision {candidate_revision}. Skipping it.")
candidate_revision -= 1
available_for_all = False
break

if available_for_all:
new_revision = candidate_revision
if time() - start > timeout:
timed_out = True

if timed_out:
raise TimeoutError(f"Reached timeout {timeout}s while checking revision "
f"{largest_mutually_available_revision}")
f"{candidate_revision}")

end = time()
if largest_mutually_available_revision == existing_revision:
if new_revision <= existing_revision:
print(f"No new mutually available revision found after "
f"{'{:.2f}'.format(end - start)} seconds.")
f"{'{:.2f}'.format(end - start)} seconds. Keeping revision {existing_revision}.")
return

print(f"Found mutually available revision at {largest_mutually_available_revision}.")
print(f"This process started at {smallest_revision} and checked "
f"{smallest_revision - largest_mutually_available_revision} revisions.")
print(f"Found mutually available revision at {new_revision}.")
print(f"This process started at {start_revision} and checked "
f"{start_revision - new_revision} revisions.")
print(f"The whole process took {'{:.2f}'.format(end - start)} seconds.")

with open("tools/wpt/latest_chromium_revision.txt", "w") as f:
f.write(f"{largest_mutually_available_revision}\n")
f.write(f"{new_revision}\n")


if __name__ == "__main__":
Expand Down

0 comments on commit 8315e77

Please sign in to comment.