From 2b3c76c73e9b960e0fd0a92151730fb59b395fe0 Mon Sep 17 00:00:00 2001 From: Caleb Hattingh Date: Sat, 26 Jun 2021 10:39:34 +1000 Subject: [PATCH] Shamelessly copy github actions files from ripgrep (#63) * Shamelessly copy github actions files from ripgrep * Utils for ci * Solve the cross-platform openssl problem by using rust-tls * Ran cargo fmt * Disable fail-fast * Comment out the checking for build artifacts * Disable mips, ring doesn't work on it * More disabling of mips --- .github/workflows/ci.yml | 186 ++++++++++ .github/workflows/release.yml | 176 +++++++++ Cargo.lock | 333 ++++++------------ Cargo.toml | 8 +- ci/build-deb | 42 +++ ci/cargo-out-dir | 19 + ci/docker/README.md | 24 ++ .../arm-unknown-linux-gnueabihf/Dockerfile | 4 + ci/docker/arm-unknown-linux-gnueabihf/build | 5 + ci/docker/i686-unknown-linux-gnu/Dockerfile | 4 + ci/docker/i686-unknown-linux-gnu/build | 5 + .../mips64-unknown-linux-gnuabi64/Dockerfile | 4 + ci/docker/mips64-unknown-linux-gnuabi64/build | 5 + .../x86_64-unknown-linux-musl/Dockerfile | 4 + ci/docker/x86_64-unknown-linux-musl/build | 5 + ci/macos-install-packages | 3 + ci/sha256-releases | 25 ++ ci/test-complete | 97 +++++ ci/ubuntu-install-packages | 6 + ci/utils.sh | 107 ++++++ src/lib.rs | 96 ++--- src/main.rs | 7 +- 22 files changed, 905 insertions(+), 260 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml create mode 100755 ci/build-deb create mode 100755 ci/cargo-out-dir create mode 100644 ci/docker/README.md create mode 100644 ci/docker/arm-unknown-linux-gnueabihf/Dockerfile create mode 100755 ci/docker/arm-unknown-linux-gnueabihf/build create mode 100644 ci/docker/i686-unknown-linux-gnu/Dockerfile create mode 100755 ci/docker/i686-unknown-linux-gnu/build create mode 100644 ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile create mode 100755 ci/docker/mips64-unknown-linux-gnuabi64/build create mode 100644 ci/docker/x86_64-unknown-linux-musl/Dockerfile create mode 100755 ci/docker/x86_64-unknown-linux-musl/build create mode 100755 ci/macos-install-packages create mode 100755 ci/sha256-releases create mode 100755 ci/test-complete create mode 100755 ci/ubuntu-install-packages create mode 100644 ci/utils.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..eb76aa1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,186 @@ +name: ci +on: + pull_request: + push: + branches: + - master + schedule: + - cron: '00 01 * * *' +jobs: + test: + name: test + env: + # For some builds, we use cross to test on 32-bit and big-endian + # systems. + CARGO: cargo + # When CARGO is set to CROSS, this is set to `--target matrix.target`. + TARGET_FLAGS: + # When CARGO is set to CROSS, TARGET_DIR includes matrix.target. + TARGET_DIR: ./target + # Emit backtraces on panics. + RUST_BACKTRACE: 1 + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + build: + # We test lifter on a pinned version of Rust, along with the moving + # targets of 'stable' and 'beta' for good measure. + - pinned + - stable + - beta + # Our release builds are generated by a nightly compiler to take + # advantage of the latest optimizations/compile time improvements. So + # we test all of them here. (We don't do mips releases, but test on + # mips for big-endian coverage.) + - nightly + - nightly-musl + - nightly-32 + # - nightly-mips + - nightly-arm + - macos + - win-msvc + - win-gnu + include: + - build: pinned + os: ubuntu-18.04 + rust: 1.52.1 + - build: stable + os: ubuntu-18.04 + rust: stable + - build: beta + os: ubuntu-18.04 + rust: beta + - build: nightly + os: ubuntu-18.04 + rust: nightly + - build: nightly-musl + os: ubuntu-18.04 + rust: nightly + target: x86_64-unknown-linux-musl + - build: nightly-32 + os: ubuntu-18.04 + rust: nightly + target: i686-unknown-linux-gnu + # - build: nightly-mips + # os: ubuntu-18.04 + # rust: nightly + # target: mips64-unknown-linux-gnuabi64 + - build: nightly-arm + os: ubuntu-18.04 + rust: nightly + # For stripping release binaries: + # docker run --rm -v $PWD/target:/target:Z \ + # rustembedded/cross:arm-unknown-linux-gnueabihf \ + # arm-linux-gnueabihf-strip \ + # /target/arm-unknown-linux-gnueabihf/debug/rg + target: arm-unknown-linux-gnueabihf + - build: macos + os: macos-latest + rust: nightly + - build: win-msvc + os: windows-2019 + rust: nightly + - build: win-gnu + os: windows-2019 + rust: nightly-x86_64-gnu + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install packages (Ubuntu) + if: matrix.os == 'ubuntu-18.04' + run: | + ci/ubuntu-install-packages + - name: Install packages (macOS) + if: matrix.os == 'macos-latest' + run: | + ci/macos-install-packages + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: true + + - name: Use Cross + if: matrix.target != '' + run: | + cargo install cross + echo "CARGO=cross" >> $GITHUB_ENV + echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV + echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV + - name: Show command used for Cargo + run: | + echo "cargo command is: ${{ env.CARGO }}" + echo "target flag is: ${{ env.TARGET_FLAGS }}" + - name: Build lifter and all crates + run: ${{ env.CARGO }} build --verbose --workspace ${{ env.TARGET_FLAGS }} + + # This is useful for debugging problems when the expected build artifacts + # (like shell completions and man pages) aren't generated. + - name: Show build.rs stderr + shell: bash + run: | + set +x + stderr="$(find "${{ env.TARGET_DIR }}/debug" -name stderr -print0 | xargs -0 ls -t | head -n1)" + if [ -s "$stderr" ]; then + echo "===== $stderr ===== " + cat "$stderr" + echo "=====" + fi + set -x + - name: Run tests + if: matrix.target != '' + run: ${{ env.CARGO }} test --verbose --workspace ${{ env.TARGET_FLAGS }} + + # - name: Test for existence of build artifacts (Windows) + # if: matrix.os == 'windows-2019' + # shell: bash + # run: | + # outdir="$(ci/cargo-out-dir "${{ env.TARGET_DIR }}")" + # ls "$outdir/_rg.ps1" && file "$outdir/_rg.ps1" + # - name: Test for existence of build artifacts (Unix) + # if: matrix.os != 'windows-2019' + # shell: bash + # run: | + # outdir="$(ci/cargo-out-dir "${{ env.TARGET_DIR }}")" + # # TODO: Check for the man page generation here. For whatever reason, + # # it seems to be intermittently failing in CI. No idea why. + # # for f in rg.bash rg.fish rg.1; do + # for f in rg.bash rg.fish; do + # # We could use file -E here, but it isn't supported on macOS. + # ls "$outdir/$f" && file "$outdir/$f" + # done + rustfmt: + name: rustfmt + runs-on: ubuntu-18.04 + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + profile: minimal + components: rustfmt + - name: Check formatting + run: | + cargo fmt --all -- --check + docs: + name: Docs + runs-on: ubuntu-20.04 + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + - name: Check documentation + env: + RUSTDOCFLAGS: -D warnings + run: cargo doc --no-deps --document-private-items --workspace diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7081ed1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,176 @@ +# The way this works is the following: +# +# The create-release job runs purely to initialize the GitHub release itself +# and to output upload_url for the following job. +# +# The build-release job runs only once create-release is finished. It gets the +# release upload URL from create-release job outputs, then builds the release +# executables for each supported platform and attaches them as release assets +# to the previously created release. +# +# The key here is that we create the release only once. +# +# Reference: +# https://eugene-babichenko.github.io/blog/2020/05/09/github-actions-cross-platform-auto-releases/ + +name: release +on: + push: + # Enable when testing release infrastructure on a branch. + # branches: + # - ag/work + tags: + - "[0-9]+.[0-9]+.[0-9]+" +jobs: + create-release: + name: create-release + runs-on: ubuntu-latest + # env: + # Set to force version number, e.g., when no tag exists. + # RG_VERSION: TEST-0.0.0 + outputs: + upload_url: ${{ steps.release.outputs.upload_url }} + rg_version: ${{ env.RG_VERSION }} + steps: + - name: Get the release version from the tag + shell: bash + if: env.RG_VERSION == '' + run: | + # Apparently, this is the right way to get a tag name. Really? + # + # See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027 + echo "RG_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + echo "version is: ${{ env.RG_VERSION }}" + - name: Create GitHub release + id: release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.RG_VERSION }} + release_name: ${{ env.RG_VERSION }} + + build-release: + name: build-release + needs: ['create-release'] + runs-on: ${{ matrix.os }} + env: + # For some builds, we use cross to test on 32-bit and big-endian + # systems. + CARGO: cargo + # When CARGO is set to CROSS, this is set to `--target matrix.target`. + TARGET_FLAGS: "" + # When CARGO is set to CROSS, TARGET_DIR includes matrix.target. + TARGET_DIR: ./target + # Emit backtraces on panics. + RUST_BACKTRACE: 1 + # Build static releases with PCRE2. + PCRE2_SYS_STATIC: 1 + strategy: + matrix: + build: [linux, linux-arm, macos, win-msvc, win-gnu, win32-msvc] + include: + - build: linux + os: ubuntu-18.04 + rust: nightly + target: x86_64-unknown-linux-musl + - build: linux-arm + os: ubuntu-18.04 + rust: nightly + target: arm-unknown-linux-gnueabihf + - build: macos + os: macos-latest + rust: nightly + target: x86_64-apple-darwin + - build: win-msvc + os: windows-2019 + rust: nightly + target: x86_64-pc-windows-msvc + - build: win-gnu + os: windows-2019 + rust: nightly-x86_64-gnu + target: x86_64-pc-windows-gnu + - build: win32-msvc + os: windows-2019 + rust: nightly + target: i686-pc-windows-msvc + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Install packages (Ubuntu) + if: matrix.os == 'ubuntu-18.04' + run: | + ci/ubuntu-install-packages + - name: Install packages (macOS) + if: matrix.os == 'macos-latest' + run: | + ci/macos-install-packages + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: true + target: ${{ matrix.target }} + + - name: Use Cross + shell: bash + run: | + cargo install cross + echo "CARGO=cross" >> $GITHUB_ENV + echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV + echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV + - name: Show command used for Cargo + run: | + echo "cargo command is: ${{ env.CARGO }}" + echo "target flag is: ${{ env.TARGET_FLAGS }}" + echo "target dir is: ${{ env.TARGET_DIR }}" + - name: Build release binary + run: ${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }} + + - name: Strip release binary (linux and macos) + if: matrix.build == 'linux' || matrix.build == 'macos' + run: strip "target/${{ matrix.target }}/release/lifter" + + - name: Strip release binary (arm) + if: matrix.build == 'linux-arm' + run: | + docker run --rm -v \ + "$PWD/target:/target:Z" \ + rustembedded/cross:arm-unknown-linux-gnueabihf \ + arm-linux-gnueabihf-strip \ + /target/arm-unknown-linux-gnueabihf/release/lifter + - name: Build archive + shell: bash + run: | + outdir="$(ci/cargo-out-dir "${{ env.TARGET_DIR }}")" + staging="lifter-${{ needs.create-release.outputs.rg_version }}-${{ matrix.target }}" + mkdir -p "$staging"/{complete,doc} + cp {README.md,COPYING,UNLICENSE,LICENSE-MIT} "$staging/" + cp {CHANGELOG.md,FAQ.md,GUIDE.md} "$staging/doc/" + # cp "$outdir"/{rg.bash,rg.fish,_rg.ps1} "$staging/complete/" + # cp complete/_rg "$staging/complete/" + if [ "${{ matrix.os }}" = "windows-2019" ]; then + cp "target/${{ matrix.target }}/release/lifter.exe" "$staging/" + 7z a "$staging.zip" "$staging" + echo "ASSET=$staging.zip" >> $GITHUB_ENV + else + # The man page is only generated on Unix systems. ¯\_(ツ)_/¯ + # cp "$outdir"/rg.1 "$staging/doc/" + cp "target/${{ matrix.target }}/release/lifter" "$staging/" + tar czf "$staging.tar.gz" "$staging" + echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV + fi + - name: Upload release archive + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.create-release.outputs.upload_url }} + asset_path: ${{ env.ASSET }} + asset_name: ${{ env.ASSET }} + asset_content_type: application/octet-stream diff --git a/Cargo.lock b/Cargo.lock index 5abe965..e67acdb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "adler" version = "0.2.3" @@ -165,22 +167,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "core-foundation" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" - [[package]] name = "crc32fast" version = "1.2.1" @@ -341,21 +327,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.0.1" @@ -397,6 +368,18 @@ version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71c2c65c57704c32f5241c1223167c2c3294fd34ac020c807ddbe6db287ba59" +[[package]] +name = "futures-macro" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea405816a5139fb39af82c2beb921d52143f556038378d6db21183a5c37fbfb7" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "futures-sink" version = "0.3.13" @@ -417,10 +400,13 @@ checksum = "1812c7ab8aedf8d6f2701a43e1243acdbcc2b36ab26e2ad421eb99ac963d96d1" dependencies = [ "futures-core", "futures-io", + "futures-macro", "futures-task", "memchr", "pin-project-lite", "pin-utils", + "proc-macro-hack", + "proc-macro-nested", "slab", ] @@ -463,18 +449,7 @@ checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ "cfg-if", "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - -[[package]] -name = "getrandom" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -593,16 +568,18 @@ dependencies = [ ] [[package]] -name = "hyper-tls" -version = "0.5.0" +name = "hyper-rustls" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64" dependencies = [ - "bytes", + "futures-util", "hyper", - "native-tls", + "log", + "rustls", "tokio", - "tokio-native-tls", + "tokio-rustls", + "webpki", ] [[package]] @@ -819,24 +796,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "native-tls" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.4" @@ -888,37 +847,10 @@ dependencies = [ ] [[package]] -name = "openssl" -version = "0.10.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038d43985d1ddca7a9900630d8cd031b56e4794eecc2e9ea39dd17aa04399a70" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "lazy_static", - "libc", - "openssl-sys", -] - -[[package]] -name = "openssl-probe" -version = "0.1.2" +name = "once_cell" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" - -[[package]] -name = "openssl-sys" -version = "0.9.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "921fc71883267538946025deffb622905ecad223c28efbfdef9bb59a0175f3e6" -dependencies = [ - "autocfg", - "cc", - "libc", - "pkg-config", - "vcpkg", -] +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "paw" @@ -981,7 +913,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526" dependencies = [ "phf_shared", - "rand 0.7.3", + "rand", ] [[package]] @@ -1087,6 +1019,12 @@ version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" +[[package]] +name = "proc-macro-nested" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" + [[package]] name = "proc-macro2" version = "1.0.24" @@ -1111,26 +1049,14 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom 0.1.16", + "getrandom", "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc 0.2.0", + "rand_chacha", + "rand_core", + "rand_hc", "rand_pcg", ] -[[package]] -name = "rand" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" -dependencies = [ - "libc", - "rand_chacha 0.3.0", - "rand_core 0.6.2", - "rand_hc 0.3.0", -] - [[package]] name = "rand_chacha" version = "0.2.2" @@ -1138,17 +1064,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core 0.5.1", -] - -[[package]] -name = "rand_chacha" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" -dependencies = [ - "ppv-lite86", - "rand_core 0.6.2", + "rand_core", ] [[package]] @@ -1157,16 +1073,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom 0.1.16", -] - -[[package]] -name = "rand_core" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" -dependencies = [ - "getrandom 0.2.2", + "getrandom", ] [[package]] @@ -1175,16 +1082,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core 0.5.1", -] - -[[package]] -name = "rand_hc" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" -dependencies = [ - "rand_core 0.6.2", + "rand_core", ] [[package]] @@ -1193,7 +1091,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" dependencies = [ - "rand_core 0.5.1", + "rand_core", ] [[package]] @@ -1247,15 +1145,6 @@ version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] - [[package]] name = "reqwest" version = "0.11.4" @@ -1270,26 +1159,55 @@ dependencies = [ "http", "http-body", "hyper", - "hyper-tls", + "hyper-rustls", "ipnet", "js-sys", "lazy_static", "log", "mime", - "native-tls", "percent-encoding", "pin-project-lite", + "rustls", "serde", "serde_urlencoded", "tokio", - "tokio-native-tls", + "tokio-rustls", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "winreg", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] + +[[package]] +name = "rustls" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" +dependencies = [ + "base64", + "log", + "ring", + "sct", + "webpki", +] + [[package]] name = "rustversion" version = "1.0.4" @@ -1302,16 +1220,6 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" -[[package]] -name = "schannel" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" -dependencies = [ - "lazy_static", - "winapi", -] - [[package]] name = "scoped-tls" version = "1.0.0" @@ -1341,26 +1249,13 @@ dependencies = [ ] [[package]] -name = "security-framework" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1759c2e3c8580017a484a7ac56d3abc5a6c1feadf88db2f3633f12ae4268c69" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.0.0" +name = "sct" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f99b9d5e26d2a71633cc4f2ebae7cc9f874044e0c351a27e17892d76dce5678b" +checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" dependencies = [ - "core-foundation-sys", - "libc", + "ring", + "untrusted", ] [[package]] @@ -1473,6 +1368,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -1576,20 +1477,6 @@ dependencies = [ "xattr", ] -[[package]] -name = "tempfile" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" -dependencies = [ - "cfg-if", - "libc", - "rand 0.8.3", - "redox_syscall", - "remove_dir_all", - "winapi", -] - [[package]] name = "tendril" version = "0.4.2" @@ -1701,13 +1588,14 @@ dependencies = [ ] [[package]] -name = "tokio-native-tls" -version = "0.3.0" +name = "tokio-rustls" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" dependencies = [ - "native-tls", + "rustls", "tokio", + "webpki", ] [[package]] @@ -1811,6 +1699,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "url" version = "2.2.1" @@ -1829,12 +1723,6 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" -[[package]] -name = "vcpkg" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" - [[package]] name = "vec_map" version = "0.8.2" @@ -1863,12 +1751,6 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" -[[package]] -name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" - [[package]] name = "wasm-bindgen" version = "0.2.70" @@ -1947,6 +1829,25 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki" +version = "0.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" +dependencies = [ + "webpki", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 3f69536..bb9d231 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ panic = "abort" opt-level = 'z' [dependencies] -reqwest = { version = "0.11.4", features = ["blocking"] } +# reqwest = { version = "0.11.4", features = ["blocking"] } scraper = "0.12.0" select = "0.5.0" regex = "1.4.6" @@ -31,3 +31,9 @@ anyhow = "1.0.40" xz2 = "0.1.6" rayon = "1.5.1" strfmt = "0.1.6" + +[dependencies.reqwest] +version = "0.11.4" +default-features = false +features = ["blocking", "rustls-tls"] + diff --git a/ci/build-deb b/ci/build-deb new file mode 100755 index 0000000..18d72b3 --- /dev/null +++ b/ci/build-deb @@ -0,0 +1,42 @@ +#!/bin/bash + +set -e +D="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" + +# This script builds a binary dpkg for Debian based distros. It does not +# currently run in CI, and is instead run manually and the resulting dpkg is +# uploaded to GitHub via the web UI. +# +# Note that this requires 'cargo deb', which can be installed with +# 'cargo install cargo-deb'. +# +# This should be run from the root of the ripgrep repo. + +if ! command -V cargo-deb > /dev/null 2>&1; then + echo "cargo-deb command missing" >&2 + exit 1 +fi + +if ! command -V asciidoctor > /dev/null 2>&1; then + echo "asciidoctor command missing" >&2 + exit 1 +fi + +# 'cargo deb' does not seem to provide a way to specify an asset that is +# created at build time, such as ripgrep's man page. To work around this, +# we force a debug build, copy out the man page (and shell completions) +# produced from that build, put it into a predictable location and then build +# the deb, which knows where to look. +cargo build + +DEPLOY_DIR=deployment/deb +OUT_DIR="$("$D"/cargo-out-dir target/debug/)" +mkdir -p "$DEPLOY_DIR" + +# Copy man page and shell completions. +cp "$OUT_DIR"/{rg.1,rg.bash,rg.fish} "$DEPLOY_DIR/" +cp complete/_rg "$DEPLOY_DIR/" + +# Since we're distributing the dpkg, we don't know whether the user will have +# PCRE2 installed, so just do a static build. +PCRE2_SYS_STATIC=1 cargo deb --target x86_64-unknown-linux-musl diff --git a/ci/cargo-out-dir b/ci/cargo-out-dir new file mode 100755 index 0000000..99bec6f --- /dev/null +++ b/ci/cargo-out-dir @@ -0,0 +1,19 @@ +#!/bin/bash + +# Finds Cargo's `OUT_DIR` directory from the most recent build. +# +# This requires one parameter corresponding to the target directory +# to search for the build output. + +if [ $# != 1 ]; then + echo "Usage: $(basename "$0") " >&2 + exit 2 +fi + +# This works by finding the most recent stamp file, which is produced by +# every ripgrep build. +target_dir="$1" +find "$target_dir" -name lifter-stamp -print0 \ + | xargs -0 ls -t \ + | head -n1 \ + | xargs dirname diff --git a/ci/docker/README.md b/ci/docker/README.md new file mode 100644 index 0000000..89baa24 --- /dev/null +++ b/ci/docker/README.md @@ -0,0 +1,24 @@ +These are Docker images used for cross compilation in CI builds (or locally) +via the [Cross](https://github.com/rust-embedded/cross) tool. + +The Cross tool actually provides its own Docker images, and all Docker images +in this directory are derived from one of them. We provide our own in order +to customize the environment. For example, we need to install some things like +`asciidoctor` in order to generate man pages. We also install compression tools +like `xz` so that tests for the `-z/--search-zip` flag are run. + +If you make a change to a Docker image, then you can re-build it. `cd` into the +directory containing the `Dockerfile` and run: + + $ cd x86_64-unknown-linux-musl + $ ./build + +At this point, subsequent uses of `cross` will now use your built image since +Docker prefers local images over remote images. In order to make these changes +stick, they need to be pushed to Docker Hub: + + $ docker push burntsushi/cross:x86_64-unknown-linux-musl + +Of course, only I (BurntSushi) can push to that location. To make `cross` use +a different location, then edit `Cross.toml` in the root of this repo to use +a different image name for the desired target. diff --git a/ci/docker/arm-unknown-linux-gnueabihf/Dockerfile b/ci/docker/arm-unknown-linux-gnueabihf/Dockerfile new file mode 100644 index 0000000..59901cb --- /dev/null +++ b/ci/docker/arm-unknown-linux-gnueabihf/Dockerfile @@ -0,0 +1,4 @@ +FROM rustembedded/cross:arm-unknown-linux-gnueabihf + +COPY stage/ubuntu-install-packages / +RUN /ubuntu-install-packages diff --git a/ci/docker/arm-unknown-linux-gnueabihf/build b/ci/docker/arm-unknown-linux-gnueabihf/build new file mode 100755 index 0000000..107b836 --- /dev/null +++ b/ci/docker/arm-unknown-linux-gnueabihf/build @@ -0,0 +1,5 @@ +#!/bin/sh + +mkdir -p stage +cp ../../ubuntu-install-packages ./stage/ +docker build -t burntsushi/cross:arm-unknown-linux-gnueabihf . diff --git a/ci/docker/i686-unknown-linux-gnu/Dockerfile b/ci/docker/i686-unknown-linux-gnu/Dockerfile new file mode 100644 index 0000000..9c9107e --- /dev/null +++ b/ci/docker/i686-unknown-linux-gnu/Dockerfile @@ -0,0 +1,4 @@ +FROM rustembedded/cross:i686-unknown-linux-gnu + +COPY stage/ubuntu-install-packages / +RUN /ubuntu-install-packages diff --git a/ci/docker/i686-unknown-linux-gnu/build b/ci/docker/i686-unknown-linux-gnu/build new file mode 100755 index 0000000..5837c82 --- /dev/null +++ b/ci/docker/i686-unknown-linux-gnu/build @@ -0,0 +1,5 @@ +#!/bin/sh + +mkdir -p stage +cp ../../ubuntu-install-packages ./stage/ +docker build -t burntsushi/cross:i686-unknown-linux-gnu . diff --git a/ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile b/ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile new file mode 100644 index 0000000..4b14616 --- /dev/null +++ b/ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile @@ -0,0 +1,4 @@ +FROM rustembedded/cross:mips64-unknown-linux-gnuabi64 + +COPY stage/ubuntu-install-packages / +RUN /ubuntu-install-packages diff --git a/ci/docker/mips64-unknown-linux-gnuabi64/build b/ci/docker/mips64-unknown-linux-gnuabi64/build new file mode 100755 index 0000000..a15ca35 --- /dev/null +++ b/ci/docker/mips64-unknown-linux-gnuabi64/build @@ -0,0 +1,5 @@ +#!/bin/sh + +mkdir -p stage +cp ../../ubuntu-install-packages ./stage/ +docker build -t burntsushi/cross:mips64-unknown-linux-gnuabi64 . diff --git a/ci/docker/x86_64-unknown-linux-musl/Dockerfile b/ci/docker/x86_64-unknown-linux-musl/Dockerfile new file mode 100644 index 0000000..8818b60 --- /dev/null +++ b/ci/docker/x86_64-unknown-linux-musl/Dockerfile @@ -0,0 +1,4 @@ +FROM rustembedded/cross:x86_64-unknown-linux-musl + +COPY stage/ubuntu-install-packages / +RUN /ubuntu-install-packages diff --git a/ci/docker/x86_64-unknown-linux-musl/build b/ci/docker/x86_64-unknown-linux-musl/build new file mode 100755 index 0000000..7fce7c2 --- /dev/null +++ b/ci/docker/x86_64-unknown-linux-musl/build @@ -0,0 +1,5 @@ +#!/bin/sh + +mkdir -p stage +cp ../../ubuntu-install-packages ./stage/ +docker build -t burntsushi/cross:x86_64-unknown-linux-musl . diff --git a/ci/macos-install-packages b/ci/macos-install-packages new file mode 100755 index 0000000..dc0955c --- /dev/null +++ b/ci/macos-install-packages @@ -0,0 +1,3 @@ +#!/bin/sh + +brew install asciidoctor diff --git a/ci/sha256-releases b/ci/sha256-releases new file mode 100755 index 0000000..41aa2b1 --- /dev/null +++ b/ci/sha256-releases @@ -0,0 +1,25 @@ +#!/bin/sh + +set -e + +if [ $# != 1 ]; then + echo "Usage: $(basename $0) version" >&2 + exit 1 +fi +version="$1" + +# Linux and Darwin builds. +for arch in i686 x86_64; do + for target in apple-darwin unknown-linux-musl; do + url="https://github.com/cjrh/lifter/releases/download/$version/lifter-$version-$arch-$target.tar.gz" + sha=$(curl -sfSL "$url" | sha256sum) + echo "$version-$arch-$target $sha" + done +done + +# Source. +for ext in zip tar.gz; do + url="https://github.com/cjrh/lifter/archive/$version.$ext" + sha=$(curl -sfSL "$url" | sha256sum) + echo "source.$ext $sha" +done diff --git a/ci/test-complete b/ci/test-complete new file mode 100755 index 0000000..3143cc4 --- /dev/null +++ b/ci/test-complete @@ -0,0 +1,97 @@ +#!/usr/bin/env zsh + +emulate zsh -o extended_glob -o no_function_argzero -o no_unset + +## +# Compares options in `rg --help` output to options in zsh completion function + +get_comp_args() { + # Technically there are many options that the completion system sets that + # our function may rely on, but we'll trust that we've got it mostly right + setopt local_options unset + + # Our completion function recognises a special variable which tells it to + # dump the _arguments specs and then just return. But do this in a sub-shell + # anyway to avoid any weirdness + ( _RG_COMPLETE_LIST_ARGS=1 source $1 ) +} + +main() { + local diff + local rg="${0:a:h}/../${TARGET_DIR:-target}/release/rg" + local _rg="${0:a:h}/../complete/_rg" + local -a help_args comp_args + + [[ -e $rg ]] || rg=${rg/%\/release\/rg/\/debug\/rg} + + rg=${rg:a} + _rg=${_rg:a} + + [[ -e $rg ]] || { + print -r >&2 "File not found: $rg" + return 1 + } + [[ -e $_rg ]] || { + print -r >&2 "File not found: $_rg" + return 1 + } + + print -rl - 'Comparing options:' "-$rg" "+$_rg" + + # 'Parse' options out of the `--help` output. To prevent false positives we + # only look at lines where the first non-white-space character is `-`, or + # where a long option starting with certain letters (see `_rg`) is found. + # Occasionally we may have to handle some manually, however + help_args=( ${(f)"$( + $rg --help | + $rg -i -- '^\s+--?[a-z0-9.]|--[a-z]' | + $rg -ior '$1' -- $'[\t /\"\'`.,](-[a-z0-9.]|--[a-z0-9-]+)(,|\\b)' | + $rg -v -- --print0 | # False positives + sort -u + )"} ) + + # 'Parse' options out of the completion function + comp_args=( ${(f)"$( get_comp_args $_rg )"} ) + + # Note that we currently exclude hidden (!...) options; matching these + # properly against the `--help` output could be irritating + comp_args=( ${comp_args#\(*\)} ) # Strip excluded options + comp_args=( ${comp_args#\*} ) # Strip repetition indicator + comp_args=( ${comp_args%%-[:[]*} ) # Strip everything after -optname- + comp_args=( ${comp_args%%[:+=[]*} ) # Strip everything after other optspecs + comp_args=( ${comp_args##[^-]*} ) # Remove non-options + comp_args=( ${(f)"$( print -rl - $comp_args | sort -u )"} ) + + (( $#help_args )) || { + print -r >&2 'Failed to get help_args' + return 1 + } + (( $#comp_args )) || { + print -r >&2 'Failed to get comp_args' + return 1 + } + + diff="$( + if diff --help 2>&1 | grep -qF -- '--label'; then + diff -U2 \ + --label '`rg --help`' \ + --label '`_rg`' \ + =( print -rl - $help_args ) =( print -rl - $comp_args ) + else + diff -U2 \ + -L '`rg --help`' \ + -L '`_rg`' \ + =( print -rl - $help_args ) =( print -rl - $comp_args ) + fi + )" + + (( $#diff )) && { + printf >&2 '%s\n' 'zsh completion options differ from `--help` options:' + printf >&2 '%s\n' $diff + return 1 + } + printf 'OK\n' + return 0 +} + +main "$@" diff --git a/ci/ubuntu-install-packages b/ci/ubuntu-install-packages new file mode 100755 index 0000000..b372e0e --- /dev/null +++ b/ci/ubuntu-install-packages @@ -0,0 +1,6 @@ +#!/bin/sh + +sudo apt-get update +sudo apt-get install -y --no-install-recommends \ + asciidoctor \ + zsh xz-utils liblz4-tool musl-tools diff --git a/ci/utils.sh b/ci/utils.sh new file mode 100644 index 0000000..f3dc96d --- /dev/null +++ b/ci/utils.sh @@ -0,0 +1,107 @@ +#!/bin/bash + +# Various utility functions used through CI. + +# Finds Cargo's `OUT_DIR` directory from the most recent build. +# +# This requires one parameter corresponding to the target directory +# to search for the build output. +cargo_out_dir() { + # This works by finding the most recent stamp file, which is produced by + # every ripgrep build. + target_dir="$1" + find "$target_dir" -name ripgrep-stamp -print0 \ + | xargs -0 ls -t \ + | head -n1 \ + | xargs dirname +} + +host() { + case "$TRAVIS_OS_NAME" in + linux) + echo x86_64-unknown-linux-gnu + ;; + osx) + echo x86_64-apple-darwin + ;; + esac +} + +architecture() { + case "$TARGET" in + x86_64-*) + echo amd64 + ;; + i686-*|i586-*|i386-*) + echo i386 + ;; + arm*-unknown-linux-gnueabihf) + echo armhf + ;; + *) + die "architecture: unexpected target $TARGET" + ;; + esac +} + +gcc_prefix() { + case "$(architecture)" in + armhf) + echo arm-linux-gnueabihf- + ;; + *) + return + ;; + esac +} + +is_musl() { + case "$TARGET" in + *-musl) return 0 ;; + *) return 1 ;; + esac +} + +is_x86() { + case "$(architecture)" in + amd64|i386) return 0 ;; + *) return 1 ;; + esac +} + +is_x86_64() { + case "$(architecture)" in + amd64) return 0 ;; + *) return 1 ;; + esac +} + +is_arm() { + case "$(architecture)" in + armhf) return 0 ;; + *) return 1 ;; + esac +} + +is_linux() { + case "$TRAVIS_OS_NAME" in + linux) return 0 ;; + *) return 1 ;; + esac +} + +is_osx() { + case "$TRAVIS_OS_NAME" in + osx) return 0 ;; + *) return 1 ;; + esac +} + +builder() { + if is_musl && is_x86_64; then + cargo install cross + echo "cross" + else + echo "cargo" + fi +} diff --git a/src/lib.rs b/src/lib.rs index 31b0aa2..74e0e21 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,12 +2,12 @@ use std::io::{Read, Write}; #[cfg(target_family = "unix")] use std::os::unix::fs::PermissionsExt; -use anyhow::{Result, anyhow}; +use anyhow::{anyhow, Result}; use itertools::Itertools; use log::*; use scraper::{Html, Selector}; -use std::path::Path; use std::collections::HashMap; +use std::path::Path; use strfmt::strfmt; /// This pattern matches the format of how filenames of binaries are @@ -63,10 +63,9 @@ struct Hit { fn read_section_into_map(conf: &tini::Ini, section: &str) -> HashMap { let mut tmp = HashMap::new(); - conf.section_iter(§ion) - .for_each(|(k, v)| { - tmp.insert(k.clone(), v.clone()); - }); + conf.section_iter(§ion).for_each(|(k, v)| { + tmp.insert(k.clone(), v.clone()); + }); tmp } @@ -75,7 +74,7 @@ type Templates = HashMap>; /// Mutate the config to replace a template with the template values. /// /// If `template` is specified in a section, we must use it! Look up -/// the fields that are defined in a template with that name, and +/// the fields that are defined in a template with that name, and /// insert those fields into the `Config` object that represents /// that section. /// @@ -84,20 +83,21 @@ type Templates = HashMap>; /// format. Any fields defined in the *section* can be substituted /// into each template item if the `{name}` of that item is used. fn insert_fields_from_template( - cf: &mut Config, + cf: &mut Config, templates: &Templates, - values: &HashMap) -> Result<()> { - + values: &HashMap, +) -> Result<()> { if let Some(t) = values.get("template") { debug!("Config has a template: {:?}", &values); cf.template = t.clone(); - let template_fields = templates - .get(&cf.template) - .ok_or_else(|| anyhow!( - "The specified template '{}' was not found in the \ + let template_fields = templates.get(&cf.template).ok_or_else(|| { + anyhow!( + "The specified template '{}' was not found in the \ list of available templates: {:?}", - &t, templates.keys().collect::>() - ))?; + &t, + templates.keys().collect::>() + ) + })?; if let Some(value) = template_fields.get("page_url") { cf.page_url = strfmt(value, values)?; @@ -114,17 +114,16 @@ fn insert_fields_from_template( Ok(()) } - pub fn run_section( section: &str, - templates: &Templates, + templates: &Templates, conf: &tini::Ini, filename: &str, output_dir: &Path, ) -> Result<()> { let tmp = read_section_into_map(conf, section); let mut cf = Config::new(); - insert_fields_from_template(&mut cf, templates, &tmp)?; + insert_fields_from_template(&mut cf, templates, &tmp)?; // First get the project - required match tmp.get("page_url") { @@ -134,11 +133,12 @@ pub fn run_section( return { warn!( "[{}] Section {} is missing required field \ - \"page_url\"", section, section); + \"page_url\"", + section, section + ); Ok(()) }; } - } }; debug!("[{}] Processing: {}", section, &cf.page_url); @@ -155,11 +155,12 @@ pub fn run_section( cf.version_tag = Some(strfmt(value, &tmp)?); }; - cf.target_filename_to_extract_from_archive = if let Some(value) = tmp.get("target_filename_to_extract_from_archive") { - Some(strfmt(value, &tmp)?) - } else { - Some(section.to_owned()) - }; + cf.target_filename_to_extract_from_archive = + if let Some(value) = tmp.get("target_filename_to_extract_from_archive") { + Some(strfmt(value, &tmp)?) + } else { + Some(section.to_owned()) + }; if let Some(value) = tmp.get("version") { cf.version = Some(strfmt(value, &tmp)?); @@ -189,7 +190,10 @@ pub fn run_section( debug!("[{}] Updated config file.", section); } } else { - info!("[{}] Target {} exists, skipping.", section, &cf.target_filename); + info!( + "[{}] Target {} exists, skipping.", + section, &cf.target_filename + ); } Ok(()) } @@ -218,7 +222,7 @@ fn process(section: &str, conf: &mut Config, output_dir: &Path) -> Result