File: roll_wpt.py

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (163 lines) | stat: -rwxr-xr-x 7,483 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python3
# Copyright 2022 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Pulls the latest revisions of the wpt tooling."""

import glob
import os
import shutil
import subprocess
import sys
import time

BUG_QUERY_URLS = ["https://issues.chromium.org/issues?q=status:open%20customfield1223031:WPT-Tooling-Roll",
                  "https://issues.chromium.org/issues?q=status:open%20customfield1223031:WPT-JS-Roll"]


def main():
    current_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
    current_branch = current_branch.rstrip().decode('utf-8')
    print("Roll wpt on branch: %s" % current_branch)
    print("Are there outstanding bugs at %s (Y/n)? " % BUG_QUERY_URLS[0],
          end='', flush=True)
    yesno = sys.stdin.readline().strip()
    if yesno not in ['N', 'n']:
        return 1

    remote_head = subprocess.check_output(['git',
                                           'ls-remote',
                                           'https://github.com/web-platform-tests/wpt',
                                           'refs/heads/master'])
    remote_head = remote_head.rstrip().decode('utf-8').split()
    remote_head = remote_head[0]
    print("Roll to remote head: %s" % remote_head)

    pattern = "s/^Revision: .*$/Revision: %s/g" % remote_head
    path_to_wpt_tools_dir = os.path.abspath(os.path.dirname(__file__))
    path_to_readme = os.path.join(path_to_wpt_tools_dir, "README.chromium")

    # Update Revision in //third_party/wpt_tools/README.chromium
    # This program only works on linux for now, as sed has slightly
    # different format on mac
    print("Update commit hash code for %s" % path_to_readme)
    subprocess.check_call(["sed", "-i", pattern, path_to_readme])

    path_to_checkout = os.path.join(path_to_wpt_tools_dir, "checkout.sh")
    print("Call %s\n" % path_to_checkout)
    subprocess.check_output([path_to_checkout, remote_head])
    patch(path_to_wpt_tools_dir)

    change_files = subprocess.check_output(['git',
                                            'diff',
                                            'HEAD',
                                            '--no-renames',
                                            '--name-only'])
    change_files = change_files.decode('utf-8').strip()
    if change_files == '':
        print("No tooling changes to roll!")
        return 0

    subprocess.check_call(['git', 'add', path_to_wpt_tools_dir])
    # Trigger linux-blink-rel should be good enough because webdriver tests are also
    # using Wptrunner now
    wpt_try_bots = ["linux-blink-rel"]
    upstream_url = "https://github.com/web-platform-tests/wpt"
    message = "Roll wpt tooling\n\nThis rolls wpt to latest commit at\n%s.\n" % upstream_url
    message += "REMOTE-WPT-HEAD: %s\n\n" % remote_head
    message += "Cq-Include-Trybots: luci.chromium.try:%s\n" % ','.join(wpt_try_bots)
    subprocess.check_call(['git', 'commit', '-m', message])
    subprocess.check_call(['git',
                           'cl',
                           'upload',
                           '--enable-auto-submit',
                           '--cq-dry-run',
                           '--bypass-hooks',
                           '-f'])

    output = subprocess.check_output(['git', 'cl', 'issue']).decode('utf-8')
    issue_number = output.strip().split()[2]
    print("\nCL uploaded to https://chromium-review.googlesource.com/%s" % issue_number)
    print("Please monitor the results on WPT try bots.")
    print("One common failure is that some dependency is not satisfied.")
    print("Please consider update WPTIncludeList in such case.")

    print("\n\nNow roll wpt javascript")
    print("Are there outstanding bugs at %s (Y/n)? " % BUG_QUERY_URLS[1],
          end='', flush=True)
    yesno = sys.stdin.readline().strip()
    if yesno not in ['N', 'n']:
        return 1
    javascript_branch = "%s-%d" % (current_branch, int(time.time()))
    print("Roll wpt javascript on branch: %s" % javascript_branch)
    subprocess.check_call(['git', 'new-branch', javascript_branch])
    files_to_roll = ["testharness.js", "testdriver.js", "testdriver-actions.js", "check-layout-th.js"]
    chromium_src_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
    source_dir = os.path.join(chromium_src_dir,
                              "third_party",
                              "blink",
                              "web_tests",
                              "external",
                              "wpt",
                              "resources")
    dst_dir = os.path.join(chromium_src_dir,
                           "third_party",
                           "blink",
                           "web_tests",
                           "resources")
    for f in files_to_roll:
        shutil.copy(os.path.join(source_dir, f),
                    os.path.join(dst_dir, f))

    change_files = subprocess.check_output(['git',
                                            'diff',
                                            'HEAD',
                                            '--no-renames',
                                            '--name-only'])
    change_files = change_files.decode('utf-8').strip()
    if change_files == '':
        print("No javascript changes to roll!")
    else:
        for f in files_to_roll:
            subprocess.check_call(['git', 'add', os.path.join(dst_dir, f)])
        message = ("Roll wpt javascript\n\nThis rolls wpt javascript to latest commit at\n"
                   "%s.\n" % upstream_url)
        subprocess.check_call(['git', 'commit', '-m', message])
        subprocess.check_call(['git',
                               'cl',
                               'upload',
                               '--enable-auto-submit',
                               '--cq-dry-run',
                               '--bypass-hooks',
                               '-f'])
        output = subprocess.check_output(['git', 'cl', 'issue']).decode('utf-8')
        issue_number = output.strip().split()[2]
        print("\nCL uploaded to https://chromium-review.googlesource.com/%s" % issue_number)


    print("Deleting branch %s.\nCurrent branch is %s." % (javascript_branch, current_branch))
    subprocess.check_call(['git', 'checkout', current_branch])
    subprocess.check_call(['git', 'branch', '-D', javascript_branch])
    return 0


def patch(path_to_wpt_tools_dir: str):
    """Apply Chromium-specific patches on top of vendored `wpt/tools`.

    Patching should be a last resort workaround when Chromium's infrastructure
    is incompatible with those of WPT/other vendors (e.g., Python dependency
    cannot be upgraded). Patches should contain paths relative to
    `//third_party/wpt_tools/wpt/` so that they are easy to upstream to the
    GitHub repo if needed. For example,
      $ cd third_party/wpt_tools/wpt
      $ git diff --relative HEAD^ > ../patches/0001-description.patch
    """
    path_to_wpt_tools_dir = os.path.abspath(path_to_wpt_tools_dir)
    patch_pattern = os.path.join(path_to_wpt_tools_dir, 'patches', '*.patch')
    for patch_path in sorted(filter(os.path.isfile, glob.iglob(patch_pattern))):
        subprocess.check_call(['patch', '-p1', '--fuzz=0', f'--input={patch_path}'],
                              cwd=os.path.join(path_to_wpt_tools_dir, 'wpt'))


if __name__ == '__main__':
    sys.exit(main())