tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

loop-ff.sh (11965B)


      1 #!/bin/bash
      2 
      3 source dom/media/webrtc/third_party_build/use_config_env.sh
      4 
      5 # file for logging loop script output
      6 LOOP_OUTPUT_LOG=$LOG_DIR/log-loop-ff.txt
      7 
      8 function echo_log()
      9 {
     10  echo "===loop-ff=== $@" 2>&1| tee -a $LOOP_OUTPUT_LOG
     11 }
     12 
     13 function show_error_msg()
     14 {
     15  echo_log "*** ERROR *** $? line $1 $0 did not complete successfully!"
     16  echo_log "$ERROR_HELP"
     17 }
     18 ERROR_HELP=""
     19 
     20 # Print an Error message if `set -eE` causes the script to exit due to a failed command
     21 trap 'show_error_msg $LINENO' ERR
     22 
     23 # If DEBUG_LOOP_FF is set all commands should be printed as they are executed
     24 if [ ! "x$DEBUG_LOOP_FF" = "x" ]; then
     25  set -x
     26 fi
     27 
     28 if [ "x$MOZ_LIBWEBRTC_SRC" = "x" ]; then
     29  echo "MOZ_LIBWEBRTC_SRC is not defined, see README.md"
     30  exit
     31 fi
     32 
     33 if [ ! -d $MOZ_LIBWEBRTC_SRC ]; then
     34  echo "Path $MOZ_LIBWEBRTC_SRC is not found, see README.md"
     35  exit
     36 fi
     37 
     38 if [ "x$MOZ_LIBWEBRTC_BRANCH" = "x" ]; then
     39  echo "MOZ_LIBWEBRTC_BRANCH is not defined, see README.md"
     40  exit
     41 fi
     42 
     43 if [ "x$MOZ_STOP_AFTER_COMMIT" = "x" ]; then
     44  MOZ_STOP_AFTER_COMMIT=`cd $MOZ_LIBWEBRTC_SRC ; git show $MOZ_TARGET_UPSTREAM_BRANCH_HEAD --format='%h' --name-only | head -1`
     45  echo "No MOZ_STOP_AFTER_COMMIT variable defined - stopping at $MOZ_TARGET_UPSTREAM_BRANCH_HEAD"
     46 fi
     47 
     48 if [ "x$MOZ_ADVANCE_ONE_COMMIT" = "x" ]; then
     49  MOZ_ADVANCE_ONE_COMMIT=""
     50 fi
     51 
     52 MOZ_CHANGED=0
     53 GIT_CHANGED=0
     54 HANDLE_NOOP_COMMIT=""
     55 
     56 # After this point:
     57 # * eE: All commands should succeed.
     58 # * u: All variables should be defined before use.
     59 # * o pipefail: All stages of all pipes should succeed.
     60 set -eEuo pipefail
     61 
     62 find_repo_type
     63 echo "repo type: $MOZ_REPO"
     64 
     65 # start a new log with every run of this script
     66 rm -f $LOOP_OUTPUT_LOG
     67 # make sure third_party/libwebrtc/README.mozilla.last-vendor is the committed version
     68 # so we properly determine MOZ_LIBWEBRTC_BASE and MOZ_LIBWEBRTC_NEXT_BASE
     69 # in the loop below
     70 if [ "x$MOZ_REPO" == "xgit" ]; then
     71  git restore third_party/libwebrtc/README.mozilla.last-vendor &> /dev/null
     72 else
     73  hg revert -C third_party/libwebrtc/README.mozilla.last-vendor &> /dev/null
     74 fi
     75 
     76 # check for a resume situation from fast-forward-libwebrtc.sh
     77 RESUME_FILE=$STATE_DIR/fast_forward.resume
     78 RESUME=""
     79 if [ -f $RESUME_FILE ]; then
     80  RESUME=`tail -1 $RESUME_FILE`
     81 fi
     82 
     83 # check for the situation where we've encountered an error when running
     84 # detect_upstream_revert.sh and should skip running it a second time.
     85 SKIP_NEXT_REVERT_CHK=""
     86 if [ -f $STATE_DIR/loop.skip-revert-detect ]; then
     87  SKIP_NEXT_REVERT_CHK=`tail -1 $STATE_DIR/loop.skip-revert-detect`
     88 fi
     89 echo "SKIP_NEXT_REVERT_CHK: '$SKIP_NEXT_REVERT_CHK'" 2>&1| tee -a $LOOP_OUTPUT_LOG
     90 
     91 ERROR_HELP=$"
     92 It appears that verification of initial vendoring from our local copy
     93 of the moz-libwebrtc git repo containing our patch-stack has failed.
     94 - If you have never previously run the fast-forward (loop-ff.sh) script,
     95  you may need to prepare the github repository by running prep_repo.sh.
     96 - If you have previously run loop-ff.sh successfully, there may be a new
     97  change to third_party/libwebrtc that should be extracted from mercurial
     98  and added to the patch stack in github.  It may be as easy as running:
     99      ./mach python $SCRIPT_DIR/extract-for-git.py tip::tip
    100      mv mailbox.patch $MOZ_LIBWEBRTC_SRC
    101      (cd $MOZ_LIBWEBRTC_SRC && \\
    102       git am mailbox.patch)
    103 
    104 To verify vendoring, run:
    105    bash $SCRIPT_DIR/verify_vendoring.sh
    106 
    107 When verify_vendoring.sh is successful, please run the following command
    108 in bash:
    109    (source $SCRIPT_DIR/use_config_env.sh ; \\
    110     ./mach python $SCRIPT_DIR/save_patch_stack.py \\
    111      --repo-path $MOZ_LIBWEBRTC_SRC \\
    112      --target-branch-head $MOZ_TARGET_UPSTREAM_BRANCH_HEAD )
    113 
    114 You may resume running this script with the following command:
    115    bash $SCRIPT_DIR/loop-ff.sh
    116 "
    117 # if we're not in the resume situation from fast-forward-libwebrtc.sh
    118 if [ "x$RESUME" = "x" ]; then
    119  # start off by verifying the vendoring process to make sure no changes have
    120  # been added to elm to fix bugs.
    121  echo_log "Verifying vendoring..."
    122  # The script outputs its own error message when verifying fails, so
    123  # capture that output of verify_vendoring.sh quietly.
    124  bash $SCRIPT_DIR/verify_vendoring.sh &> $LOG_DIR/log-verify.txt
    125  echo_log "Done verifying vendoring."
    126 fi
    127 ERROR_HELP=""
    128 
    129 for (( ; ; )); do
    130 
    131 find_base_commit
    132 find_next_commit
    133 
    134 if [ $MOZ_LIBWEBRTC_BASE == $MOZ_LIBWEBRTC_NEXT_BASE ]; then
    135  echo_log "Processing complete, already at upstream $MOZ_LIBWEBRTC_BASE"
    136  exit
    137 fi
    138 
    139 echo_log "==================="
    140 
    141 COMMITS_REMAINING=`cd $MOZ_LIBWEBRTC_SRC ; \
    142   git log --oneline $MOZ_LIBWEBRTC_BASE..$MOZ_TARGET_UPSTREAM_BRANCH_HEAD \
    143   | wc -l | tr -d " "`
    144 echo_log "Commits remaining: $COMMITS_REMAINING"
    145 
    146 echo "Before revert detection, SKIP_NEXT_REVERT_CHK: '$SKIP_NEXT_REVERT_CHK'" 2>&1| tee -a $LOOP_OUTPUT_LOG
    147 echo "Before revert detection, RESUME: '$RESUME'" 2>&1| tee -a $LOOP_OUTPUT_LOG
    148 ERROR_HELP=$"Some portion of the detection and/or fixing of upstream revert commits
    149 has failed.  Please fix the state of the git hub repo at: $MOZ_LIBWEBRTC_SRC.
    150 When fixed, please resume this script with the following command:
    151    bash $SCRIPT_DIR/loop-ff.sh
    152 "
    153 if [ "x$SKIP_NEXT_REVERT_CHK" == "x" ] && [ "x$RESUME" == "x" ]; then
    154  echo_log "Check for upcoming revert commit"
    155  echo "true" > $STATE_DIR/loop.skip-revert-detect
    156  AUTO_FIX_REVERT_AS_NOOP=1 bash $SCRIPT_DIR/detect_upstream_revert.sh \
    157      2>&1| tee -a $LOOP_OUTPUT_LOG
    158 fi
    159 echo "" > $STATE_DIR/loop.skip-revert-detect
    160 ERROR_HELP=""
    161 
    162 echo_log "Looking for $STATE_DIR/$MOZ_LIBWEBRTC_NEXT_BASE.no-op-cherry-pick-msg"
    163 if [ -f $STATE_DIR/$MOZ_LIBWEBRTC_NEXT_BASE.no-op-cherry-pick-msg ]; then
    164  echo_log "Detected special commit msg, setting HANDLE_NOOP_COMMIT=1"
    165  HANDLE_NOOP_COMMIT="1"
    166 fi
    167 
    168 echo_log "Moving from moz-libwebrtc commit $MOZ_LIBWEBRTC_BASE to $MOZ_LIBWEBRTC_NEXT_BASE"
    169 bash $SCRIPT_DIR/fast-forward-libwebrtc.sh 2>&1| tee -a $LOOP_OUTPUT_LOG
    170 
    171 if [ "x$MOZ_REPO" == "xgit" ]; then
    172  MOZ_CHANGED=`git show --format='' --name-status \
    173    | grep -E -ve "README.mozilla.last-vendor|README.mozilla" \
    174    | wc -l | tr -d " " || true`
    175 else
    176  MOZ_CHANGED=`hg diff -c tip --stat \
    177     | grep -E -ve "README.mozilla.last-vendor|README.mozilla|files changed," \
    178     | wc -l | tr -d " " || true`
    179 fi
    180 GIT_CHANGED=`./mach python $SCRIPT_DIR/filter_git_changes.py \
    181   --repo-path $MOZ_LIBWEBRTC_SRC --commit-sha $MOZ_LIBWEBRTC_NEXT_BASE \
    182   | wc -l | tr -d " "`
    183 FILE_CNT_MISMATCH_MSG=$"
    184 The number of files changed in the upstream commit ($GIT_CHANGED) does
    185 not match the number of files changed in the local Mozilla repo
    186 commit ($MOZ_CHANGED).  This may indicate a mismatch between the vendoring
    187 script and this script, or it could be a true error in the import
    188 processing.  Once the issue has been resolved, the following steps
    189 remain for this commit:
    190  # save the patch-stack
    191  ./mach python $SCRIPT_DIR/save_patch_stack.py \\
    192    --skip-startup-sanity \\
    193    --repo-path $MOZ_LIBWEBRTC_SRC \\
    194    --branch $MOZ_LIBWEBRTC_BRANCH \\
    195    --patch-path \"third_party/libwebrtc/moz-patch-stack\" \\
    196    --state-path $STATE_DIR \\
    197    --target-branch-head $MOZ_TARGET_UPSTREAM_BRANCH_HEAD
    198  # generate moz.build files (may not be necessary)
    199  ./mach python build/gn_processor.py \\
    200      $SCRIPT_DIR/gn-configs/webrtc.json
    201  # commit the updated moz.build files with the appropriate commit msg
    202  bash $SCRIPT_DIR/commit-build-file-changes.sh
    203  # do a (hopefully) quick test build
    204  ./mach build && ./mach build recurse_gtest && echo \"Successful build\"
    205 
    206 After a successful build, you may resume this script:
    207    bash $SCRIPT_DIR/loop-ff.sh
    208 "
    209 echo_log "Verify number of files changed MOZ($MOZ_CHANGED) GIT($GIT_CHANGED)"
    210 if [ "x$HANDLE_NOOP_COMMIT" == "x1" ]; then
    211  echo_log "NO-OP commit detected, we expect file changed counts to differ"
    212 elif [ $MOZ_CHANGED -ne $GIT_CHANGED ]; then
    213  echo_log "MOZ_CHANGED $MOZ_CHANGED should equal GIT_CHANGED $GIT_CHANGED"
    214  echo "$FILE_CNT_MISMATCH_MSG" 2>&1| tee -a $LOOP_OUTPUT_LOG
    215  exit 1
    216 fi
    217 HANDLE_NOOP_COMMIT=""
    218 
    219 # save the current patch stack in case we need to reconstitute it later
    220 echo_log "Save patch-stack"
    221 ./mach python $SCRIPT_DIR/save_patch_stack.py \
    222    --skip-startup-sanity \
    223    --repo-path $MOZ_LIBWEBRTC_SRC \
    224    --branch $MOZ_LIBWEBRTC_BRANCH \
    225    --patch-path "third_party/libwebrtc/moz-patch-stack" \
    226    --state-path $STATE_DIR \
    227    --target-branch-head $MOZ_TARGET_UPSTREAM_BRANCH_HEAD \
    228    2>&1| tee -a $LOOP_OUTPUT_LOG
    229 
    230 MODIFIED_BUILD_RELATED_FILE_CNT=`bash $SCRIPT_DIR/get_build_file_changes.sh \
    231    | wc -l | tr -d " "`
    232 ERROR_HELP=$"
    233 Generating build files has failed.  This likely means changes to one or more
    234 BUILD.gn files are required.  Commit those changes following the instructions
    235 in https://wiki.mozilla.org/Media/WebRTC/libwebrtc_Update_Process#Operational_notes
    236 Then complete these steps:
    237  # generate moz.build files (may not be necessary)
    238  ./mach python build/gn_processor.py \\
    239      $SCRIPT_DIR/gn-configs/webrtc.json
    240  # commit the updated moz.build files with the appropriate commit msg
    241  bash $SCRIPT_DIR/commit-build-file-changes.sh
    242  # do a (hopefully) quick test build
    243  ./mach build && ./mach build recurse_gtest && echo \"Successful build\"
    244 
    245 After a successful build, you may resume this script:
    246    bash $SCRIPT_DIR/loop-ff.sh
    247 "
    248 echo_log "Modified .gn, **/BUILD.gn, or **/*.gni files: $MODIFIED_BUILD_RELATED_FILE_CNT"
    249 MOZ_BUILD_CHANGE_CNT=0
    250 if [ "x$MODIFIED_BUILD_RELATED_FILE_CNT" != "x0" ]; then
    251  echo_log "Regenerate build files"
    252  ./mach python build/gn_processor.py \
    253      $SCRIPT_DIR/gn-configs/webrtc.json 2>&1| tee -a $LOOP_OUTPUT_LOG
    254 
    255  if [ "x$MOZ_REPO" == "xgit" ]; then
    256    MOZ_BUILD_CHANGE_CNT=`git status --porcelain 'third_party/libwebrtc/**moz.build' \
    257        | wc -l | tr -d " "`
    258  else
    259    MOZ_BUILD_CHANGE_CNT=`hg status third_party/libwebrtc \
    260        --include 'third_party/libwebrtc/**moz.build' | wc -l | tr -d " "`
    261  fi
    262  if [ "x$MOZ_BUILD_CHANGE_CNT" != "x0" ]; then
    263    echo_log "Detected modified moz.build files, commiting"
    264    bash $SCRIPT_DIR/commit-build-file-changes.sh 2>&1| tee -a $LOOP_OUTPUT_LOG
    265  fi
    266 fi
    267 ERROR_HELP=""
    268 
    269 ERROR_HELP=$"
    270 The test build has failed.  Most likely this is due to an upstream api
    271 change that must be reflected in Mozilla code outside of the
    272 third_party/libwebrtc directory. After fixing the build, you may resume
    273 running this script with the following command:
    274    ./mach build && ./mach build recurse_gtest && \\
    275    bash $SCRIPT_DIR/loop-ff.sh
    276 "
    277 echo_log "Test build - ./mach build"
    278 ./mach build 2>&1| tee -a $LOOP_OUTPUT_LOG
    279 echo_log "Test build - ./mach build recurse_gtest"
    280 ./mach build recurse_gtest 2>&1| tee -a $LOOP_OUTPUT_LOG
    281 ERROR_HELP=""
    282 
    283 # If we've committed moz.build changes, spin up try builds.
    284 if [ "x$MOZ_BUILD_CHANGE_CNT" != "x0" ]; then
    285  TRY_FUZZY_QUERY_STRING="^build-"
    286  PUSH_TO_VCS="--push-to-vcs"
    287  if [ "x$MOZ_REPO" == "xgit" ]; then
    288    PUSH_TO_VCS=""
    289  fi
    290  CURRENT_TIME=`date`
    291  echo_log "Detected modified moz.build files, starting try builds with"
    292  echo_log "'$TRY_FUZZY_QUERY_STRING' at $CURRENT_TIME"
    293  echo_log "This try push is started to help earlier detection of build issues"
    294  echo_log "across different platforms supported by Mozilla."
    295  echo_log "Note - this step can take a long time (occasionally in the 10min range)"
    296  echo_log "       with little or no feedback."
    297  # Show the time used for this command, and don't let it fail if the
    298  # command times out so the script continues running.  This command
    299  # can take quite long, occasionally 10min.
    300  (time ./mach try fuzzy $PUSH_TO_VCS --full -q $TRY_FUZZY_QUERY_STRING) 2>&1| tee -a $LOOP_OUTPUT_LOG || true
    301 fi
    302 
    303 if [ ! "x$MOZ_STOP_AFTER_COMMIT" = "x" ]; then
    304 if [ $MOZ_LIBWEBRTC_NEXT_BASE = $MOZ_STOP_AFTER_COMMIT ]; then
    305  break
    306 fi
    307 fi
    308 
    309 if [ ! "x$MOZ_ADVANCE_ONE_COMMIT" = "x" ]; then
    310  echo_log "Done advancing one commit."
    311  exit
    312 fi
    313 
    314 # successfully completed one iteration through the loop, so we can reset RESUME
    315 RESUME=""
    316 
    317 done
    318 
    319 echo_log "Completed fast-foward to $MOZ_STOP_AFTER_COMMIT"