Browse Source

fix: replace `grep` with `ripgrep` due to excruciating timing (#1170)

Baptiste Augrain 2 years ago
parent
commit
2874277aa4
2 changed files with 46 additions and 10 deletions
  1. 9 0
      docs/build.md
  2. 37 10
      undo_telemetry.sh

+ 9 - 0
docs/build.md

@@ -35,6 +35,7 @@
 - dpkg
 - python3
 - imagemagick (for AppImage)
+- ripgrep
 
 ### <a id="dependencies-macos"></a>MacOS
 
@@ -65,6 +66,10 @@ Firstly, create the container with:
 ```
 docker run -ti --volume=<local vscodium source>:/root/vscodium --name=vscodium-build-agent vscodium/vscodium-linux-build-agent:bionic-x64 bash
 ```
+like
+```
+docker run -ti --volume=$(pwd):/root/vscodium --name=vscodium-build-agent vscodium/vscodium-linux-build-agent:bionic-x64 bash
+```
 
 When inside the container, you can use the following commands to build:
 ```
@@ -90,6 +95,10 @@ Firstly, create the container with:
 ```
 docker run -ti --volume=<local vscodium source>:/root/vscodium --name=vscodium-build-agent vscodium/vscodium-linux-build-agent:stretch-armhf bash
 ```
+like
+```
+docker run -ti --volume=$(pwd):/root/vscodium --name=vscodium-build-agent vscodium/vscodium-linux-build-agent:stretch-armhf bash
+```
 
 When inside the container, you can use the following commands to build:
 ```

+ 37 - 10
undo_telemetry.sh

@@ -1,17 +1,44 @@
-# mobile.events.data.microsoft.com
-# vortex.data.microsoft.com
-TELEMETRY_URLS="[^/]+\.data\.microsoft\.com"
-REPLACEMENT="s/${TELEMETRY_URLS}/0\.0\.0\.0/g"
+#!/bin/bash
 
-#include common functions
+set -ex
+
+# list of urls to match:
+# - mobile.events.data.microsoft.com
+# - vortex.data.microsoft.com
+
+SEARCH="\.data\.microsoft\.com"
+REPLACEMENT="s|//[^/]+\.data\.microsoft\.com|//0\.0\.0\.0|g"
+
+# include common functions
 . ../utils.sh
 
-if [[ "${OS_NAME}" == "osx" ]]; then
-  if is_gnu_sed; then
-    grep -rl --exclude-dir=.git -E "${TELEMETRY_URLS}" . | xargs sed -i -E "${REPLACEMENT}"
+if is_gnu_sed; then
+  replace_with_debug () {
+    echo "found: ${2} (`date`)"
+    sed -i -E "${1}" "${2}"
+  }
+else
+  replace_with_debug () {
+    echo "found: ${2} (`date`)"
+    sed -i '' -E "${1}" "${2}"
+  }
+fi
+export -f replace_with_debug
+
+d1=`date +%s`
+
+if [[ "${OS_NAME}" == "linux" ]]; then
+  if [[ ${VSCODE_ARCH} == "x64" ]]; then
+    rg --no-ignore -l "${SEARCH}" . | xargs -I {} bash -c 'replace_with_debug "${1}" "{}"' _ "${REPLACEMENT}"
   else
-    grep -rl --exclude-dir=.git -E "${TELEMETRY_URLS}" . | xargs sed -i '' -E "${REPLACEMENT}"
+    grep -rl --exclude-dir=.git -E "${SEARCH}" . | xargs -I {} bash -c 'replace_with_debug "${1}" "{}"' _ "${REPLACEMENT}"
   fi
+elif [[ "${OS_NAME}" == "osx" ]]; then
+  ./node_modules/@vscode/ripgrep/bin/rg --no-ignore -l "${SEARCH}" . | xargs -I {} bash -c 'replace_with_debug "${1}" "{}"' _ "${REPLACEMENT}"
 else
-  grep -rl --exclude-dir=.git -E "${TELEMETRY_URLS}" . | xargs sed -i -E "${REPLACEMENT}"
+  ./node_modules/@vscode/ripgrep/bin/rg --no-ignore --path-separator=// -l "${SEARCH}" . | xargs -I {} bash -c 'replace_with_debug "${1}" "{}"' _ "${REPLACEMENT}"
 fi
+
+d2=`date +%s`
+
+echo "undo_telemetry: $( echo $((${d2} - ${d1})) )s"