提交记录修改scripts/bundle-qemu-sources.sh+8 −2看文件
修改scripts/bundle-qemu-sources.test.mjs+8 −5看文件
| @@ -6,7 +6,7 @@ runtime=$(cygpath -u "$2") | ||
| 6 | 6 | archive=$(cygpath -u "$3") |
| 7 | 7 | node_command=${CAGE_NODE:-node} |
| 8 | 8 | if [[ -n ${CAGE_NODE:-} ]]; then node_command=$(cygpath -u "$CAGE_NODE"); fi |
| 9 | 删除:for tool in "$node_command" git curl tar sha256sum find sort xargs pacman-key mkdir mktemp cp mv rm grep; do | |
| 9 | 新增:for tool in "$node_command" git curl tar sha256sum find sort xargs pacman-key pacman-conf mkdir mktemp cp mv rm grep; do | |
| 10 | 10 | command -v "$tool" >/dev/null 2>&1 || { echo "Missing source-collection tool: $tool" >&2; exit 1; } |
| 11 | 11 | done |
| 12 | 12 | commit=$("$node_command" -p "JSON.parse(require('fs').readFileSync(process.argv[1])).qemuSource.commit" "$repository/packaging/windows/dependencies.json") |
| @@ -15,6 +15,12 @@ source_repository=$("$node_command" -p "JSON.parse(require('fs').readFileSync(pr | ||
| 15 | 15 | stage=$(mktemp -d) |
| 16 | 16 | trap 'rm -rf "$stage"' EXIT |
| 17 | 17 | mkdir -p "$stage/source/packages" "$stage/source/cage" |
| 18 | 新增:# pacman-key requires lock-never for verification. Keep the installed public | |
| 19 | 新增:# keys and trust database intact; only the private verification copy gets it. | |
| 20 | 新增:installed_keyring=$(pacman-conf gpgdir) | |
| 21 | 新增:mkdir -p "$stage/keyring" | |
| 22 | 新增:cp "$installed_keyring/pubring.gpg" "$installed_keyring/trustdb.gpg" "$stage/keyring/" | |
| 23 | 新增:printf 'lock-never\n' > "$stage/keyring/gpg.conf" | |
| 18 | 24 | git -c core.autocrlf=false init -q "$stage/source/qemu" |
| 19 | 25 | git -C "$stage/source/qemu" fetch --depth=1 "$source_repository" "$commit" |
| 20 | 26 | git -c core.autocrlf=false -C "$stage/source/qemu" checkout -q --detach FETCH_HEAD |
| @@ -48,7 +54,7 @@ while read -r base version; do | ||
| 48 | 54 | url="https://repo.msys2.org/mingw/sources/$name" |
| 49 | 55 | if curl --fail --location --retry 2 -o "$stage/source/packages/$name" "$url"; then |
| 50 | 56 | curl --fail --location --retry 3 -o "$stage/source/packages/$name.sig" "$url.sig" |
| 51 | 删除: pacman-key --verify "$stage/source/packages/$name.sig" "$stage/source/packages/$name" | |
| 57 | 新增: pacman-key --gpgdir "$stage/keyring" --verify "$stage/source/packages/$name.sig" "$stage/source/packages/$name" | |
| 52 | 58 | found=true |
| 53 | 59 | break |
| 54 | 60 | fi |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | import assert from 'node:assert/strict'; |
| 2 | 2 | import {execFileSync} from 'node:child_process'; |
| 3 | 3 | import {createHash} from 'node:crypto'; |
| 4 | 删除:import {chmod,mkdir,mkdtemp,readFile,rm,writeFile} from 'node:fs/promises'; | |
| 4 | 新增:import {chmod,mkdir,mkdtemp,readFile,readdir,rm,writeFile} from 'node:fs/promises'; | |
| 5 | 5 | import {tmpdir} from 'node:os'; |
| 6 | 6 | import {join} from 'node:path'; |
| 7 | 7 | import {fileURLToPath} from 'node:url'; |
| @@ -9,8 +9,9 @@ import test from 'node:test'; | ||
| 9 | 9 | const collector=fileURLToPath(new URL('./bundle-qemu-sources.sh',import.meta.url)); |
| 10 | 10 | test('source collector includes pinned firmware and authenticated package sources with a complete manifest',async t=>{ |
| 11 | 11 | const root=await mkdtemp(join(tmpdir(),'cage-qemu-source-test-'));t.after(()=>rm(root,{recursive:true,force:true})); |
| 12 | 删除: const repository=join(root,'repository'),runtime=join(root,'runtime'),bin=join(root,'bin'),artifact=join(root,'bundle.tar.gz'); | |
| 13 | 删除: for(const path of [bin,runtime,join(repository,'packaging/windows'),join(repository,'scripts'),join(repository,'patches/qemu')])await mkdir(path,{recursive:true}); | |
| 12 | 新增: const repository=join(root,'repository'),runtime=join(root,'runtime'),bin=join(root,'bin'),artifact=join(root,'bundle.tar.gz'),keyring=join(root,'installed-keyring'); | |
| 13 | 新增: for(const path of [bin,runtime,keyring,join(repository,'packaging/windows'),join(repository,'scripts'),join(repository,'patches/qemu')])await mkdir(path,{recursive:true}); | |
| 14 | 新增: for(const name of ['pubring.gpg','trustdb.gpg','private-keys-must-not-copy'])await writeFile(join(keyring,name),name); | |
| 14 | 15 | const sha='a'.repeat(40),content='fixture source archive\n'; |
| 15 | 16 | await writeFile(join(repository,'packaging/windows/dependencies.json'),JSON.stringify({qemuSource:{repository:'https://source.invalid/locked-qemu.git',commit:sha},qemuKeycodemap:{url:'https://source.invalid/keymap.tar.gz',hash:createHash('sha256').update(content).digest('hex')}})); |
| 16 | 17 | for(const name of ['build-source-packages.txt','build-packages.txt','cage-build.json'])await writeFile(join(runtime,name),name==='build-source-packages.txt'?'mingw-w64-fixture 1.2.3-1\n':'fixture'); |
| @@ -19,14 +20,16 @@ test('source collector includes pinned firmware and authenticated package source | ||
| 19 | 20 | const command=async(name,body)=>{const path=join(bin,name);await writeFile(path,'#!/bin/bash\nset -e\n'+body+'\n');await chmod(path,0o755)}; |
| 20 | 21 | await command('cygpath','printf "%s\\n" "$2"'); |
| 21 | 22 | await command('node','echo "The collector must use the explicit CAGE_NODE path" >&2; exit 99'); |
| 23 | 新增: await command('pacman-conf','[[ "$1" == gpgdir ]]; printf "%s\\n" "$SOURCE_TEST_KEYRING"'); | |
| 22 | 24 | await command('git',`if [[ "$*" == *' init '* ]];then mkdir -p "\${@: -1}/.git";fi |
| 23 | 25 | if [[ "$*" == *' fetch '* ]];then [[ "$*" == *'fetch --depth=1 https://source.invalid/locked-qemu.git ${sha}' ]] || exit 98;fi |
| 24 | 26 | if [[ "$*" == *rev-parse* ]];then printf '${sha}\\n';fi |
| 25 | 27 | if [[ "$*" == *'submodule update'* ]];then for ((i=1;i<=$#;i++));do if [[ "\${!i}" == -C ]];then j=$((i+1));q="\${!j}";fi;done;mkdir -p "$q/roms/seabios";echo 'firmware code' > "$q/roms/seabios/code.c";echo 'gitdir: private' > "$q/roms/seabios/.git";fi |
| 26 | 28 | if [[ "$*" == *'submodule status'* ]];then printf ' ${sha} roms/seabios\\n';fi`); |
| 27 | 29 | await command('curl',`while [[ $# -gt 0 ]];do if [[ "$1" == -o ]];then shift;destination=$1;fi;shift;done;printf '${content.replaceAll('\n','\\n')}' > "$destination"`); |
| 28 | 删除: await command('pacman-key','printf "%s\\n" "$*" >> "$SOURCE_TEST_VERIFICATIONS"'); | |
| 29 | 删除: execFileSync('bash',[collector,repository,runtime,artifact],{env:{...process.env,PATH:bin+':'+process.env.PATH,CAGE_NODE:process.execPath,SOURCE_TEST_VERIFICATIONS:join(root,'verified')},stdio:'pipe'}); | |
| 30 | 新增: await command('pacman-key','[[ "$1" == --gpgdir && "$3" == --verify && "$2" != "$SOURCE_TEST_KEYRING" ]]; [[ $(cat "$2/pubring.gpg") == pubring.gpg && $(cat "$2/trustdb.gpg") == trustdb.gpg ]]; [[ ! -e "$2/private-keys-must-not-copy" ]]; grep -qx lock-never "$2/gpg.conf"; printf "%s\\n" "$*" >> "$SOURCE_TEST_VERIFICATIONS"'); | |
| 31 | 新增: execFileSync('bash',[collector,repository,runtime,artifact],{env:{...process.env,PATH:bin+':'+process.env.PATH,CAGE_NODE:process.execPath,SOURCE_TEST_KEYRING:keyring,SOURCE_TEST_VERIFICATIONS:join(root,'verified')},stdio:'pipe'}); | |
| 32 | 新增: assert.deepEqual((await readdir(keyring)).sort(),['private-keys-must-not-copy','pubring.gpg','trustdb.gpg']); | |
| 30 | 33 | const listing=execFileSync('tar',['-tzf',artifact],{encoding:'utf8'}); |
| 31 | 34 | for(const path of ['source/firmware-revisions.txt','source/qemu/roms/seabios/code.c','source/packages/mingw-w64-fixture-1.2.3-1.src.tar.zst','source/cage/patches/fixture.patch','source/SHA256SUMS'])assert.ok(listing.includes(path),path); |
| 32 | 35 | assert.ok(!listing.includes('/.git')); |

