write_default_config.py (8070B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 import argparse 5 import os 6 import sys 7 from datetime import datetime 8 from string import Template 9 10 from run_operations import RepoType, detect_repo_type, run_shell 11 12 sys.path.insert(0, "./dom/media/webrtc/third_party_build") 13 import lookup_branch_head 14 15 script_name = os.path.basename(__file__) 16 repo_type = detect_repo_type() 17 18 text = """#!/bin/bash 19 20 # Edit {path-to} to match the location of your copy of Mozilla's 21 # fork of libwebrtc (at https://github.com/mozilla/libwebrtc). 22 export MOZ_LIBWEBRTC_SRC=$$STATE_DIR/moz-libwebrtc 23 24 # The previous fast-forward bug number is used for some error messaging. 25 export MOZ_PRIOR_FASTFORWARD_BUG="$priorbugnum" 26 27 # Fast-forwarding each Chromium version of libwebrtc should be done 28 # under a separate bugzilla bug. This bug number is used when crafting 29 # the commit summary as each upstream commit is vendored into the 30 # mercurial repository. The bug used for the v106 fast-forward was 31 # 1800920. 32 export MOZ_FASTFORWARD_BUG="$bugnum" 33 34 # MOZ_NEXT_LIBWEBRTC_MILESTONE and MOZ_NEXT_FIREFOX_REL_TARGET are 35 # not used during fast-forward processing, but facilitate generating this 36 # default config. To generate an default config for the next update, run 37 # bash dom/media/webrtc/third_party_build/update_default_config_env.sh 38 export MOZ_NEXT_LIBWEBRTC_MILESTONE=$m2 39 export MOZ_NEXT_FIREFOX_REL_TARGET=$t2 40 41 # For Chromium release branches, see: 42 # https://chromiumdash.appspot.com/branches 43 44 # Chromium's v$m1 release branch was $bh1. This is used to pre-stack 45 # the previous release branch's commits onto the appropriate base commit 46 # (the first common commit between trunk and the release branch). 47 export MOZ_PRIOR_UPSTREAM_BRANCH_HEAD_NUM="$bh1" 48 49 # New target release branch for v$m2 is branch-heads/$bh2. This is used 50 # to calculate the next upstream commit. 51 export MOZ_TARGET_UPSTREAM_BRANCH_HEAD="branch-heads/$bh2" 52 53 # For local development 'mozpatches' is fine for a branch name, but when 54 # pushing the patch stack to github, it should be named something like 55 # 'moz-mods-chr$m2-for-rel$t2'. 56 export MOZ_LIBWEBRTC_BRANCH="mozpatches" 57 """ 58 59 60 def get_availability_for_milestone(milestone): 61 availability_date = lookup_branch_head.get_branch_date(milestone) 62 # the try/except here will either return the datetime object if parsing 63 # succeeded, or the raw string found during lookup from google. 64 try: 65 availability_date = datetime.strptime( 66 availability_date, "%Y-%m-%dT%H:%M:%S" 67 ).date() 68 except Exception: 69 pass 70 71 return availability_date 72 73 74 # make sure there are 2 chromium releases ahead of the one we're 75 # attempting to start working 76 def check_for_version_gap_to_chromium(args): 77 next_milestone = args.milestone + 1 78 two_milestones_ahead = next_milestone + 2 79 if lookup_branch_head.get_branch_head(two_milestones_ahead) is None: 80 availability_date = get_availability_for_milestone(two_milestones_ahead) 81 availability_message = "" 82 if availability_date is not None: 83 availability_message = f"It will be available on {availability_date}." 84 print( 85 "\n" 86 "Processing this request ignores the Mozilla tradition of\n" 87 "staying two releases behind chromium's useage of libwebrtc.\n" 88 f"You're requesting milestone {next_milestone}, but milestone {two_milestones_ahead}\n" 89 f"is not yet available. {availability_message}\n" 90 "\n" 91 "If you know this operation is safe, you can run the following\n" 92 "command:\n" 93 f" ./mach python {args.script_path}/{script_name} \\\n" 94 f" --script-path {args.script_path} \\\n" 95 f" --prior-bug-number {args.prior_bug_number} \\\n" 96 f" --bug-number {args.bug_number} \\\n" 97 f" --milestone {args.milestone} \\\n" 98 f" --release-target {args.release_target} \\\n" 99 f" --output-path {args.output_path} \\\n" 100 f" --skip-gap-check\n" 101 ) 102 sys.exit(1) 103 104 105 def get_prior_branch_head(milestone): 106 prior_branch_head = lookup_branch_head.get_branch_head(milestone) 107 if prior_branch_head is None: 108 print(f"error: chromium milestone '{milestone}' is not found.") 109 sys.exit(1) 110 return prior_branch_head 111 112 113 def get_new_branch_head(next_milestone): 114 new_branch_head = lookup_branch_head.get_branch_head(next_milestone) 115 if new_branch_head is None: 116 availability_date = get_availability_for_milestone(next_milestone) 117 118 print( 119 "\n" 120 f"Milestone {next_milestone} is not found when attempting to lookup the\n" 121 "libwebrtc branch-head used for the Chromium release.\n" 122 "This may be because Chromium has not updated the info on page\n" 123 "https://chromiumdash.appspot.com/branches" 124 ) 125 if availability_date is not None: 126 print( 127 "\n" 128 "From https://chromiumdash.appspot.com/schedule we see that\n" 129 f"milestone {next_milestone} will be availabile on: {availability_date}" 130 ) 131 sys.exit(1) 132 return new_branch_head 133 134 135 def build_default_config_env( 136 prior_bug_number, bug_number, milestone, target, prior_branch_head, new_branch_head 137 ): 138 s = Template(text) 139 return s.substitute( 140 priorbugnum=prior_bug_number, 141 bugnum=bug_number, 142 m1=milestone, 143 m2=milestone + 1, 144 t2=target + 1, 145 bh1=prior_branch_head, 146 bh2=new_branch_head, 147 ) 148 149 150 if __name__ == "__main__": 151 # first, check which repo we're in, git or hg 152 if repo_type is None or not isinstance(repo_type, RepoType): 153 print("Unable to detect repo (git or hg)") 154 sys.exit(1) 155 156 default_script_dir = "dom/media/webrtc/third_party_build" 157 parser = argparse.ArgumentParser( 158 description="Updates the default_config_env file for new release/milestone" 159 ) 160 parser.add_argument( 161 "--script-path", 162 default=default_script_dir, 163 help=f"path to script directory (defaults to {default_script_dir})", 164 ) 165 parser.add_argument( 166 "--prior-bug-number", 167 required=True, 168 type=int, 169 help="integer Bugzilla number (example: 1800920)", 170 ) 171 parser.add_argument( 172 "--bug-number", 173 required=True, 174 type=int, 175 help="integer Bugzilla number (example: 1806510)", 176 ) 177 parser.add_argument( 178 "--milestone", 179 required=True, 180 type=int, 181 help="integer chromium milestone (example: 107)", 182 ) 183 parser.add_argument( 184 "--release-target", 185 required=True, 186 type=int, 187 help="integer firefox release (example: 111)", 188 ) 189 parser.add_argument( 190 "--output-path", 191 required=True, 192 help="path name of file to write", 193 ) 194 parser.add_argument( 195 "--skip-gap-check", 196 action="store_true", 197 default=False, 198 help="continue even when chromium version gap is too small", 199 ) 200 args = parser.parse_args() 201 202 if not args.skip_gap_check: 203 check_for_version_gap_to_chromium(args) 204 205 prior_branch_head = get_prior_branch_head(args.milestone) 206 new_branch_head = get_new_branch_head(args.milestone + 1) 207 208 with open(args.output_path, "w") as ofile: 209 ofile.write( 210 build_default_config_env( 211 args.prior_bug_number, 212 args.bug_number, 213 args.milestone, 214 args.release_target, 215 prior_branch_head, 216 new_branch_head, 217 ) 218 ) 219 220 run_shell( 221 f"{'git commit -m' if repo_type == RepoType.GIT else 'hg commit --message'} " 222 f'"Bug {args.bug_number} - ' 223 f'updated default_config_env for v{args.milestone + 1}"' 224 f" {args.output_path}" 225 )