From 2702878fe5cb53b07cc2baf233d7e45a1fad2b0b Mon Sep 17 00:00:00 2001 From: dimisa Date: Mon, 6 Nov 2023 00:27:54 +0300 Subject: [PATCH] M: Delete tools directory --- tools/RuAdList-uBO.template | 29 ------ tools/make-diffpatch.sh | 91 ---------------- tools/make-list.js | 201 ------------------------------------ tools/update-diffpatches.sh | 95 ----------------- 4 files changed, 416 deletions(-) delete mode 100644 tools/RuAdList-uBO.template delete mode 100644 tools/make-diffpatch.sh delete mode 100644 tools/make-list.js delete mode 100644 tools/update-diffpatches.sh diff --git a/tools/RuAdList-uBO.template b/tools/RuAdList-uBO.template deleted file mode 100644 index ead0ae9245..0000000000 --- a/tools/RuAdList-uBO.template +++ /dev/null @@ -1,29 +0,0 @@ -! Title: RU AdList for uBO only -! Last modified: %timestamp% -! Expires: 2 days (фильтр обновляется автоматически каждые 2 дня) -! Diff-Path: %diffpath%#ruadlistubo -! Diff-Expires: 6 hours -! Homepage: https://forums.lanik.us/viewforum.php?f=102 -! -! Комбинированная версия списков фильтров RU AdList против рекламы -! и экспериментальных списков RU AdList CSS Fixes и RU AdList JS Fixes -! На данный момент нормально работает только в uBlock Origin -! -! --- RU AdList Classic --- -%include ruadlist:advblock/adservers.txt% -%include ruadlist:advblock/first_level.txt% -%include ruadlist:advblock/general_block.txt% -%include ruadlist:advblock/general_hide.txt% -%include ruadlist:advblock/popup.txt% -%include ruadlist:advblock/specific_antisocial.txt% -%include ruadlist:advblock/specific_block.txt% -%include ruadlist:advblock/specific_hide.txt% -%include ruadlist:advblock/specific_special.txt% -%include ruadlist:advblock/thirdparty.txt% -%include ruadlist:advblock/whitelist.txt% -! --- RU AdList CSS Fixes --- -%include ruadlist:css-fixes-experimental.txt% -! --- RU AdList JS Fixes --- -%include ruadlist:js-fixes-experimental.txt% -! --- AWRL-non-sync --- -%include ruadlist:AWRL-non-sync.txt% diff --git a/tools/make-diffpatch.sh b/tools/make-diffpatch.sh deleted file mode 100644 index d89a7d5f53..0000000000 --- a/tools/make-diffpatch.sh +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env bash -# -# This script assumes a linux environment - -set -e - -# To be executed at the root of uAssetsCDN repo -# -# It's not being hosted at uAssetsCDN because that -# repo is also used as a website - -VERSION=$1 -if [[ -z $VERSION ]]; then - echo "Error: No version provided, aborting" - exit 1 -fi - -PREVIOUS_VERSION=$( "${PREVIOUS_PATCH_FILE}" - -NEXT_PATCH_FILE="patches/${VERSION}.patch" - -# Temporary file to receive the RCS patch data -DIFF=$(mktemp) - -FILES=( $(git diff --name-only) ) -for FILE in "${FILES[@]}"; do - - # Reference: - # https://github.com/ameshkov/diffupdates - - if [[ -n $(grep '^! Version: ' <(head $FILE)) ]]; then - sed -Ei "1,10s;^! Version: .+$;! Version: $VERSION;" $FILE - fi - - # Patches are for filter lists supporting differential updates - if [[ -n $(grep '^! Diff-Path: ' <(head $FILE)) ]]; then - - # Extract diff name from `! Diff-Path:` field - DIFF_NAME=$(grep -m 1 -oP '^! Diff-Path: [^#]+#?\K.*' $FILE) - # Fall back to `! Diff-Name:` field if no name found - # Remove once `! Diff-Name:` is no longer needed after transition - if [[ -z $DIFF_NAME ]]; then - DIFF_NAME=$(grep -m 1 -oP '^! Diff-Name: \K.+' $FILE) - fi - echo "Info: Diff name for ${FILE} is ${DIFF_NAME}" - - # We need a patch name to generate a valid patch - if [[ -n $DIFF_NAME ]]; then - - # Compute relative patch path - PATCH_PATH=$(realpath --relative-to=$(dirname $FILE) $NEXT_PATCH_FILE) - - # Fill in patch path to next version (do not clobber hash portion) - sed -Ei "1,10s;^! Diff-Path: [^#]+(#.+)?$;! Diff-Path: $PATCH_PATH\1;" $FILE - - # Compute the RCS diff between current version and new version - git show HEAD:$FILE | diff -n - $FILE > $DIFF || true - - FILE_CHECKSUM=$(sha1sum $FILE) - FILE_CHECKSUM=${FILE_CHECKSUM:0:10} - - DIFF_LINES=$(wc -l < $DIFF) - echo "Info: Computed patch for ${FILE} has ${DIFF_LINES} lines" - - # Populate output file with patch information - echo "Info: Adding patch data of ${FILE} to ${PREVIOUS_PATCH_FILE}" - echo "diff name:$DIFF_NAME lines:$DIFF_LINES checksum:$FILE_CHECKSUM" >> $PREVIOUS_PATCH_FILE - cat $DIFF >> $PREVIOUS_PATCH_FILE - - else - - echo "Error: Diff name not found, skipping" - - fi - fi - - # Stage changed file - echo "Info: Staging ${FILE}" - git add -u $FILE - -done - -echo "Info: Staging ${PREVIOUS_PATCH_FILE}" -git add $PREVIOUS_PATCH_FILE - -echo -n "$VERSION" > version -git add version - -rm -f $DIFF diff --git a/tools/make-list.js b/tools/make-list.js deleted file mode 100644 index ad8aac0a23..0000000000 --- a/tools/make-list.js +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - - uBlock Origin - a browser extension to block requests. - Copyright (C) 2022-present Raymond Hill - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see {http://www.gnu.org/licenses/}. - - Home: https://github.com/gorhill/uBlock -*/ - -// jshint node:true, esversion:9 - -'use strict'; - -/******************************************************************************/ - -import fs from 'fs/promises'; -import path from 'path'; -import process from 'process'; - -/******************************************************************************/ - -const expandedParts = new Set(); - -/******************************************************************************/ - -const commandLineArgs = (( ) => { - const args = new Map(); - let name, value; - for ( const arg of process.argv.slice(2) ) { - const pos = arg.indexOf('='); - if ( pos === -1 ) { - name = arg; - value = ''; - } else { - name = arg.slice(0, pos); - value = arg.slice(pos+1); - } - args.set(name, value); - } - return args; -})(); - -/******************************************************************************/ - -function expandTemplate(wd, parts) { - const out = []; - const reInclude = /^%include +(.+):(.+)%\s+/gm; - const trim = text => trimSublist(text); - for ( const part of parts ) { - if ( typeof part !== 'string' ) { - out.push(part); - continue; - } - let lastIndex = 0; - for (;;) { - const match = reInclude.exec(part); - if ( match === null ) { break; } - out.push(part.slice(lastIndex, match.index).trim()); - const repo = match[1].trim(); - const fpath = `${match[2].trim()}`; - if ( expandedParts.has(fpath) === false ) { - console.info(` Inserting ${fpath}`); - out.push( - out.push({ file: `${fpath}` }), - `! *** ${repo}:${fpath} ***`, - fs.readFile(`${wd}/${fpath}`, { encoding: 'utf8' }) - .then(text => trim(text)), - ); - expandedParts.add(fpath); - } - lastIndex = reInclude.lastIndex; - } - out.push(part.slice(lastIndex).trim()); - } - return out; -} - -/******************************************************************************/ - -function expandIncludeDirectives(wd, parts) { - const out = []; - const reInclude = /^!#include (.+)\s*/gm; - const trim = text => trimSublist(text); - let parentPath = ''; - for ( const part of parts ) { - if ( typeof part !== 'string' ) { - if ( typeof part === 'object' && part.file !== undefined ) { - parentPath = part.file; - } - out.push(part); - continue; - } - let lastIndex = 0; - for (;;) { - const match = reInclude.exec(part); - if ( match === null ) { break; } - out.push(part.slice(lastIndex, match.index).trim()); - const fpath = `${path.dirname(parentPath)}/${match[1].trim()}`; - if ( expandedParts.has(fpath) === false ) { - console.info(` Inserting ${fpath}`); - out.push( - { file: fpath }, - `! *** ${fpath} ***`, - fs.readFile(`${wd}/${fpath}`, { encoding: 'utf8' }) - .then(text => trim(text)), - ); - expandedParts.add(fpath); - } - lastIndex = reInclude.lastIndex; - } - out.push(part.slice(lastIndex).trim()); - } - return out; -} - -/******************************************************************************/ - -function trimSublist(text) { - // Remove empty comment lines - text = text.replace(/^!\s*$(?:\r\n|\n)/gm, ''); - // Remove sublist header information: the importing list will provide its - // own header. - text = text.trim().replace(/^(?:!\s+[^\r\n]+?(?:\r\n|\n))+/s, ''); - return text; -} - -/******************************************************************************/ - -function minify(text) { - // remove issue-related comments - text = text.replace(/^! https:\/\/.*?[\n\r]+/gm, ''); - // remove empty lines - text = text.replace(/^[\n\r]+/gm, ''); - // convert potentially present Windows-style newlines - text = text.replace(/\r\n/g, '\n'); - return text; -} - -/******************************************************************************/ - -function assemble(parts) { - const out = []; - for ( const part of parts ) { - if ( typeof part !== 'string' ) { continue; } - out.push(part); - } - return out.join('\n').trim() + '\n'; -} - -/******************************************************************************/ - -async function main() { - const workingDir = commandLineArgs.get('dir') || '.'; - const inFile = commandLineArgs.get('in'); - if ( typeof inFile !== 'string' || inFile === '' ) { - process.exit(1); - } - const outFile = commandLineArgs.get('out'); - if ( typeof outFile !== 'string' || outFile === '' ) { - process.exit(1); - } - - console.info(` Using template at ${inFile}`); - - const inText = fs.readFile(`${workingDir}/${inFile}`, { encoding: 'utf8' }); - - let parts = [ inText ]; - do { - parts = await Promise.all(parts); - parts = expandTemplate(workingDir, parts); - } while ( parts.some(v => v instanceof Promise) ); - - do { - parts = await Promise.all(parts); - parts = expandIncludeDirectives(workingDir, parts); - } while ( parts.some(v => v instanceof Promise)); - - let afterText = assemble(parts); - - if ( commandLineArgs.get('minify') !== undefined ) { - afterText = minify(afterText); - } - - console.info(` Creating ${outFile}`); - - fs.writeFile(outFile, afterText); -} - -main(); diff --git a/tools/update-diffpatches.sh b/tools/update-diffpatches.sh deleted file mode 100644 index 01dd182e58..0000000000 --- a/tools/update-diffpatches.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env bash -# -# This script assumes a linux environment - -set -e - -# To be executed at the root of uAssetsCDN repo -# -# It's not being hosted at uAssetsCDN because that -# repo is also used as a website - - -# Keep only the most recent (5-day x 4-per-day) patches -OBSOLETE_PATCHES=( $(ls -1v patches/*.patch | head -n -20) ) -for FILE in "${OBSOLETE_PATCHES[@]}"; do - echo "Removing obsolete patch $FILE" - git rm $FILE -done - - -# Revisit all patch files except the most recent one -PATCH_FILES=( $(ls -1v patches/*.patch | head -n -1) ) - -NEW_PATCH_FILE=$(mktemp) -DIFF_FILE=$(mktemp) - -for PATCH_FILE in "${PATCH_FILES[@]}"; do - - # Extract tag from patch file name - [[ ${PATCH_FILE} =~ ^patches/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\.patch$ ]] && \ - PREVIOUS_VERSION=${BASH_REMATCH[1]} - - # This will receive a clone of an old version of the current repo - echo "Fetching repo at $PREVIOUS_VERSION version" - OLD_REPO=$(mktemp -d) - git clone -q --single-branch --branch $PREVIOUS_VERSION --depth=1 https://github.com/easylist/ruadlist.git "$OLD_REPO" 2>/dev/null - - > "$NEW_PATCH_FILE" - - FILTER_LISTS=( $(ls -1 EasyDutch.all.txt) ) - for FILTER_LIST in "${FILTER_LISTS[@]}"; do - - if [ ! -f $OLD_REPO/$FILTER_LIST ]; then continue; fi - - # Patches are for filter lists supporting differential updates - if [[ -z $(grep '^! Diff-Path: ' <(head $OLD_REPO/$FILTER_LIST)) ]]; then - continue - fi - - # Reference: - # https://github.com/ameshkov/diffupdates - - # Extract diff name from `! Diff-Path:` field - DIFF_NAME=$(grep -m 1 -oP '^! Diff-Path: [^#]+#?\K.*' $FILTER_LIST) - # Fall back to `! Diff-Name:` field if no name found - # Remove once `! Diff-Name:` is no longer needed after transition - if [[ -z $DIFF_NAME ]]; then - DIFF_NAME=$(grep -m 1 -oP '^! Diff-Name: \K.+' $FILTER_LIST) - fi - - # We need a patch name to generate a valid patch - if [[ -z $DIFF_NAME ]]; then - echo "Info: $FILTER_LIST is missing a patch name, skipping" - continue - fi - - # Compute the RCS diff between current version and new version - diff -n $OLD_REPO/$FILTER_LIST $FILTER_LIST > "$DIFF_FILE" || true - - FILE_CHECKSUM=$(sha1sum $FILTER_LIST) - FILE_CHECKSUM=${FILE_CHECKSUM:0:10} - - DIFF_LINE_COUNT=$(cat "$DIFF_FILE" | wc -l) - - # Patch header - DIFF_HEAD="diff name:$DIFF_NAME lines:$DIFF_LINE_COUNT checksum:$FILE_CHECKSUM" - echo "\tAdding diff: $DIFF_HEAD" - echo "$DIFF_HEAD" >> "$NEW_PATCH_FILE" - # Patch data - cat "$DIFF_FILE" >> "$NEW_PATCH_FILE" - - done - - rm -rf "$OLD_REPO" - - # Stage changed patch file - mv -f "$NEW_PATCH_FILE" "$PATCH_FILE" - ls -l "$PATCH_FILE" - echo "Info: Staging ${PATCH_FILE}" - git add -u $PATCH_FILE - -done - -rm -f "$DIFF_FILE" -rm -f "$NEW_PATCH_FILE"