diff --git a/.github/actions/odbc-mac/action.yml b/.github/actions/odbc-mac/action.yml new file mode 100644 index 000000000000..42bf95656924 --- /dev/null +++ b/.github/actions/odbc-mac/action.yml @@ -0,0 +1,94 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +name: ODBC macOS Reusable +description: Install dependencies and build the Flight SQL ODBC driver on macOS +inputs: + architecture: + description: 'Architecture to build for (AMD64 or ARM64)' + required: true + generate-installer: + description: 'Whether to run cpack to generate the .pkg installer after the build' + required: false + default: 'false' +runs: + using: "composite" + steps: + - name: Install Dependencies + shell: bash + run: | + brew bundle --file=cpp/Brewfile + + # We want to use bundled RE2 for static linking. If + # Homebrew's RE2 is installed, its header file may be used. + # We uninstall Homebrew's RE2 to ensure using bundled RE2. + brew uninstall grpc || : # gRPC depends on RE2 + brew uninstall grpc@1.54 || : # gRPC 1.54 may be installed too + brew uninstall re2 + + # We want to use bundled Protobuf for static linking. If + # Homebrew's Protobuf is installed, its library file may be + # used on test. We uninstall Homebrew's Protobuf to ensure using + # bundled Protobuf. + brew uninstall protobuf + + # We want to use bundled Boost for static linking. + brew uninstall boost + - name: Setup ccache + shell: bash + run: | + ci/scripts/ccache_setup.sh + - name: ccache info + id: ccache-info + shell: bash + run: | + echo "cache-dir=$(ccache --get-config cache_dir)" >> $GITHUB_OUTPUT + - name: Restore ccache + uses: apache/infrastructure-actions/stash/restore@762a01f36a09ab9e0e4c8af8f4b0f2ed12683df5 + with: + path: ${{ steps.ccache-info.outputs.cache-dir }} + key: cpp-odbc-ccache-macos-${{ inputs.architecture }}-${{ env.ARROW_BUILD_TYPE }} + - name: Build + shell: bash + run: | + # Homebrew uses /usr/local as prefix. So packages + # installed by Homebrew also use /usr/local/include. We + # want to include headers for packages installed by + # Homebrew as system headers to ignore warnings in them. + # But "-isystem /usr/local/include" isn't used by CMake + # because /usr/local/include is marked as the default + # include path. So we disable -Werror to avoid build error + # by warnings from packages installed by Homebrew. + export BUILD_WARNING_LEVEL=PRODUCTION + LIBIODBC_DIR="$(brew --cellar libiodbc)/$(brew list --versions libiodbc | awk '{print $2}')" + ODBC_INCLUDE_DIR=$LIBIODBC_DIR/include + export ARROW_CMAKE_ARGS="-DODBC_INCLUDE_DIR=$ODBC_INCLUDE_DIR" + export CXXFLAGS="$CXXFLAGS -I$ODBC_INCLUDE_DIR" + ci/scripts/cpp_build.sh $(pwd) $(pwd)/build + - name: Save ccache + if: ${{ !cancelled() }} + continue-on-error: true + uses: apache/infrastructure-actions/stash/save@762a01f36a09ab9e0e4c8af8f4b0f2ed12683df5 + with: + path: ${{ steps.ccache-info.outputs.cache-dir }} + key: cpp-odbc-ccache-macos-${{ inputs.architecture }}-${{ env.ARROW_BUILD_TYPE }} + - name: Generate macOS Installer + if: inputs.generate-installer == 'true' + shell: bash + run: | + cd build/cpp + cpack diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 1acdf1e9cad8..d4f702e8c049 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -18,7 +18,9 @@ version: 2 updates: - package-ecosystem: "github-actions" - directory: "/" + directories: + - "/" + - "/.github/actions/*" schedule: interval: "weekly" commit-message: diff --git a/.github/workflows/cpp_extra.yml b/.github/workflows/cpp_extra.yml index 40ad84643231..2645932f469f 100644 --- a/.github/workflows/cpp_extra.yml +++ b/.github/workflows/cpp_extra.yml @@ -36,6 +36,7 @@ on: - 'ci/scripts/install_gcs_testbench.sh' - 'ci/scripts/install_minio.sh' - 'ci/scripts/msys2_*' + - 'ci/scripts/odbc_macos_universal_pkg.sh' - 'ci/scripts/util_*' - 'cpp/**' - 'compose.yaml' @@ -576,60 +577,10 @@ jobs: persist-credentials: false fetch-depth: 0 submodules: recursive - - name: Install Dependencies - run: | - brew bundle --file=cpp/Brewfile - - # We want to use bundled RE2 for static linking. If - # Homebrew's RE2 is installed, its header file may be used. - # We uninstall Homebrew's RE2 to ensure using bundled RE2. - brew uninstall grpc || : # gRPC depends on RE2 - brew uninstall grpc@1.54 || : # gRPC 1.54 may be installed too - brew uninstall re2 - - # We want to use bundled Protobuf for static linking. If - # Homebrew's Protobuf is installed, its library file may be - # used on test We uninstall Homebrew's Protobuf to ensure using - # bundled Protobuf. - brew uninstall protobuf - - # We want to use bundled Boost for static linking. - brew uninstall boost - - name: Setup ccache - run: | - ci/scripts/ccache_setup.sh - - name: ccache info - id: ccache-info - run: | - echo "cache-dir=$(ccache --get-config cache_dir)" >> $GITHUB_OUTPUT - - name: Restore ccache - uses: apache/infrastructure-actions/stash/restore@762a01f36a09ab9e0e4c8af8f4b0f2ed12683df5 + - name: Build ODBC macOS + uses: ./.github/actions/odbc-mac with: - path: ${{ steps.ccache-info.outputs.cache-dir }} - key: cpp-odbc-ccache-macos-${{ matrix.macos-version }}-${{ matrix.build-type }} - - name: Build - run: | - # Homebrew uses /usr/local as prefix. So packages - # installed by Homebrew also use /usr/local/include. We - # want to include headers for packages installed by - # Homebrew as system headers to ignore warnings in them. - # But "-isystem /usr/local/include" isn't used by CMake - # because /usr/local/include is marked as the default - # include path. So we disable -Werror to avoid build error - # by warnings from packages installed by Homebrew. - export BUILD_WARNING_LEVEL=PRODUCTION - LIBIODBC_DIR="$(brew --cellar libiodbc)/$(brew list --versions libiodbc | awk '{print $2}')" - ODBC_INCLUDE_DIR=$LIBIODBC_DIR/include - export ARROW_CMAKE_ARGS="-DODBC_INCLUDE_DIR=$ODBC_INCLUDE_DIR" - export CXXFLAGS="$CXXFLAGS -I$ODBC_INCLUDE_DIR" - ci/scripts/cpp_build.sh $(pwd) $(pwd)/build - - name: Save ccache - if: ${{ !cancelled() }} - continue-on-error: true - uses: apache/infrastructure-actions/stash/save@762a01f36a09ab9e0e4c8af8f4b0f2ed12683df5 - with: - path: ${{ steps.ccache-info.outputs.cache-dir }} - key: cpp-odbc-ccache-macos-${{ matrix.macos-version }}-${{ matrix.build-type }} + architecture: ${{ matrix.architecture }} - name: Setup Python uses: actions/setup-python@v7 with: @@ -661,12 +612,18 @@ jobs: name: flight-sql-odbc-pkg-installer-${{ matrix.architecture }} path: build/cpp/ArrowFlightSQLODBC-*.pkg if-no-files-found: error - - name: Upload AMD64 ODBC dylib to the job - if: matrix.build-type == 'release' && matrix.architecture == 'AMD64' + - name: Copy ODBC dylib + if: matrix.build-type == 'release' + run: | + mkdir ${{ matrix.architecture }}-dylib + cp "$(realpath build/cpp/${{ matrix.build-type }}/libarrow_flight_sql_odbc.dylib)" \ + ${{ matrix.architecture }}-dylib/ + - name: Upload ODBC dylib to the job + if: matrix.build-type == 'release' uses: actions/upload-artifact@v7 with: name: flight-sql-odbc-dylib-${{ matrix.architecture }} - path: build/cpp/${{ matrix.build-type }}/libarrow_flight_sql_odbc.dylib + path: ${{ matrix.architecture }}-dylib/libarrow_flight_sql_odbc.*.dylib if-no-files-found: error - name: Register Flight SQL ODBC Driver run: | @@ -688,53 +645,46 @@ jobs: runs-on: macos-26 timeout-minutes: 30 steps: + - name: Checkout Arrow + uses: actions/checkout@v7 + with: + persist-credentials: false - name: Download ARM64 PKG uses: actions/download-artifact@v8 with: name: flight-sql-odbc-pkg-installer-ARM64 path: arm64-pkg + - name: Download ARM64 dylib + uses: actions/download-artifact@v8 + with: + name: flight-sql-odbc-dylib-ARM64 + path: arm64-dylib - name: Download AMD64 dylib uses: actions/download-artifact@v8 with: name: flight-sql-odbc-dylib-AMD64 path: amd64-dylib + - name: Create universal dylib + run: | + set -euo pipefail + + arm64_dylib="$(ls arm64-dylib/libarrow_flight_sql_odbc.*.dylib)" + amd64_dylib="$(ls amd64-dylib/libarrow_flight_sql_odbc.*.dylib)" + mkdir universal-dylib + lipo -create "${arm64_dylib}" "${amd64_dylib}" \ + -output "universal-dylib/$(basename "${arm64_dylib}")" - name: Build universal macOS installer run: | set -euo pipefail pkg_path="$(ls arm64-pkg/ArrowFlightSQLODBC-*.pkg)" pkg_name="$(basename "${pkg_path}" .pkg)" + universal_dylib="$(ls universal-dylib/libarrow_flight_sql_odbc.*.dylib)" # Use the ARM64 .pkg and swap in a universal ODBC dylib # that works on ARM64 and AMD64. - pkgutil --expand-full "${pkg_path}" expanded - - # The unversioned name libarrow_flight_sql_odbc.dylib is a symlink - # to the versioned dylib that the - # install name (@rpath/libarrow_flight_sql_odbc..dylib) - # resolves to. Run lipo on the real file so the symlinks stay intact. - symlink_path="$(find expanded -name libarrow_flight_sql_odbc.dylib)" - lib_dir="$(dirname "${symlink_path}")" - dylib_path="$(realpath "${symlink_path}")" - echo "Merging into ${dylib_path} (via ${symlink_path})" - lipo -create "${dylib_path}" amd64-dylib/libarrow_flight_sql_odbc.dylib \ - -output "${dylib_path}" - - # Verify every dylib (including the symlinks) is universal before re-packaging. - # Check one architecture at a time with `lipo -archs`, - # as macOS 27 support only one architecture search at a time. - for lib in "${lib_dir}"/libarrow_flight_sql_odbc*.dylib; do - dylib_archs="$(lipo -archs "${lib}")" - echo "${lib}: ${dylib_archs}" - for arch in arm64 x86_64; do - if ! grep -qw "${arch}" <<< "${dylib_archs}"; then - echo "${lib} is missing '${arch}' (got: ${dylib_archs})" - exit 1 - fi - done - done - - pkgutil --flatten-full expanded "${pkg_name}.pkg" + ci/scripts/odbc_macos_universal_pkg.sh \ + "${pkg_path}" "${universal_dylib}" "${pkg_name}.pkg" - name: Upload universal ODBC PKG uses: actions/upload-artifact@v7 with: diff --git a/.github/workflows/package_odbc.yml b/.github/workflows/package_odbc.yml index 975ad05ce007..3a98da46c9d9 100644 --- a/.github/workflows/package_odbc.yml +++ b/.github/workflows/package_odbc.yml @@ -24,7 +24,7 @@ on: workflow_dispatch: inputs: odbc_release_step: - description: 'ODBC MSI release step' + description: 'ODBC MSI and macOS PKG release step' required: false default: false type: boolean @@ -179,3 +179,206 @@ jobs: gh release upload $env:GITHUB_REF_NAME ` --clobber ` Apache-Arrow-Flight-SQL-ODBC-*-win64.msi + + # Upload unsigned non-universal DYLIBs and the ARM64 base PKG + odbc-macos-upload-dylib: + name: ODBC macOS Upload Unsigned ${{ matrix.architecture }} DYLIB and ARM64 PKG + runs-on: macos-${{ matrix.macos-version }} + if: github.event_name == 'push' + timeout-minutes: 120 + strategy: + fail-fast: false + matrix: + include: + - { architecture: AMD64, macos-version: "26-intel" } + - { architecture: ARM64, macos-version: "26" } + env: + ARROW_BUILD_TESTS: OFF + ARROW_BUILD_TYPE: release + ARROW_DEPENDENCY_SOURCE: BUNDLED + ARROW_DEPENDENCY_USE_SHARED: OFF + ARROW_FLIGHT_SQL_ODBC: ON + ARROW_FLIGHT_SQL_ODBC_INSTALLER: ON + ARROW_HOME: /tmp/local + ARROW_MIMALLOC: OFF + MACOSX_DEPLOYMENT_TARGET: "14.0" + steps: + - name: Checkout Arrow + uses: actions/checkout@v7 + with: + persist-credentials: false + fetch-depth: 0 + submodules: recursive + - name: Build ODBC macOS + uses: ./.github/actions/odbc-mac + with: + architecture: ${{ matrix.architecture }} + generate-installer: ${{ matrix.architecture == 'ARM64' }} + - name: Copy Unsigned ODBC DYLIB + run: | + # The unversioned name libarrow_flight_sql_odbc.dylib is a symlink to + # libarrow_flight_sql_odbc..dylib. Copy the real file, keeping + # its versioned name, so the upload doesn't hit a dangling symlink. + mkdir ${{ matrix.architecture }}-dylib + cp "$(realpath build/cpp/${{ env.ARROW_BUILD_TYPE }}/libarrow_flight_sql_odbc.dylib)" \ + ${{ matrix.architecture }}-dylib/ + - name: Rename ARM64 base ODBC PKG + if: matrix.architecture == 'ARM64' + run: | + pkg_path="$(ls build/cpp/ArrowFlightSQLODBC-*.pkg)" + mv "${pkg_path}" "$(basename "${pkg_path}" .pkg)_ARM64_base.pkg" + - name: Upload ODBC DYLIB to the job + uses: actions/upload-artifact@v7 + with: + name: flight-sql-odbc-dylib-${{ matrix.architecture }} + path: ${{ matrix.architecture }}-dylib/libarrow_flight_sql_odbc.*.dylib + if-no-files-found: error + - name: Upload ARM64 base ODBC PKG to the job + if: matrix.architecture == 'ARM64' + uses: actions/upload-artifact@v7 + with: + name: flight-sql-odbc-pkg-base-ARM64 + path: ArrowFlightSQLODBC-*_ARM64_base.pkg + if-no-files-found: error + + # Upload unsigned universal DYLIB from ARM and AMD DYLIBs + odbc-macos-upload-universal-dylib: + needs: odbc-macos-upload-dylib + name: ODBC macOS Create Unsigned Universal DYLIB + runs-on: macos-26 + timeout-minutes: 30 + steps: + - name: Download ARM64 DYLIB + uses: actions/download-artifact@v8 + with: + name: flight-sql-odbc-dylib-ARM64 + path: arm64-dylib + - name: Download AMD64 DYLIB + uses: actions/download-artifact@v8 + with: + name: flight-sql-odbc-dylib-AMD64 + path: amd64-dylib + - name: Create universal DYLIB + run: | + set -euo pipefail + + arm64_dylib="$(ls arm64-dylib/libarrow_flight_sql_odbc.*.dylib)" + amd64_dylib="$(ls amd64-dylib/libarrow_flight_sql_odbc.*.dylib)" + dylib_name="$(basename "${arm64_dylib}")" + if [ "$(basename "${amd64_dylib}")" != "${dylib_name}" ]; then + echo "ARM64 and AMD64 DYLIB names differ: ${arm64_dylib} vs ${amd64_dylib}" + exit 1 + fi + + # Rename unsigned DYLIB + mkdir universal-dylib + unsigned_path="universal-dylib/libarrow_flight_sql_odbc_unsigned.${dylib_name#libarrow_flight_sql_odbc.}" + lipo -create "${arm64_dylib}" "${amd64_dylib}" -output "${unsigned_path}" + unsigned_archs="$(lipo -archs "${unsigned_path}")" + echo "${unsigned_path}: ${unsigned_archs}" + - name: Upload universal DYLIB to the job + uses: actions/upload-artifact@v7 + with: + name: flight-sql-odbc-dylib-universal + path: universal-dylib/libarrow_flight_sql_odbc_unsigned.*.dylib + if-no-files-found: error + + odbc-dylib-base-pkg-release: + needs: + - odbc-macos-upload-dylib + - odbc-macos-upload-universal-dylib + name: Upload Unsigned ODBC DYLIB and Base PKG to Release + runs-on: ubuntu-latest + permissions: + # Upload to GitHub Release + contents: write + steps: + - name: Checkout Arrow + uses: actions/checkout@v7 + with: + persist-credentials: false + - name: Download the universal DYLIB + uses: actions/download-artifact@v8 + with: + name: flight-sql-odbc-dylib-universal + - name: Download the ARM64 base PKG + uses: actions/download-artifact@v8 + with: + name: flight-sql-odbc-pkg-base-ARM64 + - name: Wait for creating GitHub Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + dev/release/utils-watch-gh-workflow.sh \ + ${GITHUB_REF_NAME} \ + release_candidate.yml + - name: Upload the artifacts to GitHub Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release upload ${GITHUB_REF_NAME} \ + --clobber \ + libarrow_flight_sql_odbc_unsigned.*.dylib \ + ArrowFlightSQLODBC-*_ARM64_base.pkg + + # Download and repackage the ARM64 base PKG and + # the signed universal dylib + odbc-macos-upload-pkg: + name: ODBC macOS Repackage & Upload Unsigned Universal PKG + runs-on: macos-26 + if: inputs.odbc_release_step + timeout-minutes: 30 + permissions: + # Upload to GitHub Release + contents: write + steps: + - name: Checkout Arrow + uses: actions/checkout@v7 + with: + persist-credentials: false + - name: Download ARM64 base PKG and signed universal ODBC DYLIB + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release download ${GITHUB_REF_NAME} \ + --repo ${{ github.repository }} \ + --pattern 'ArrowFlightSQLODBC-*_ARM64_base.pkg' \ + --pattern 'libarrow_flight_sql_odbc.*.dylib' \ + --clobber + - name: Build universal macOS installer + run: | + set -euo pipefail + + pkg_path="$(ls ArrowFlightSQLODBC-*_ARM64_base.pkg)" + pkg_name="$(basename "${pkg_path}" _ARM64_base.pkg)" + + signed_dylib="$(ls libarrow_flight_sql_odbc.*.dylib)" + + # Use the ARM64 .pkg and swap in the signed universal ODBC dylib. + ci/scripts/odbc_macos_universal_pkg.sh \ + "${pkg_path}" "${signed_dylib}" "universal/${pkg_name}.pkg" + - name: Verify universal macOS installer + run: | + set -euo pipefail + + pkg_path="$(ls universal/ArrowFlightSQLODBC-*.pkg)" + pkgutil --expand "${pkg_path}" verify + # Installed files must not be owned by the runner user. + runner_uid="$(id -u)" + for bom in verify/*.pkg/Bom; do + echo "${bom}:" + lsbom -p MugF "${bom}" + if lsbom -p u "${bom}" | grep -qx "${runner_uid}"; then + echo "${bom} contains files owned by the runner user (uid ${runner_uid})" + exit 1 + fi + done + grep installKBytes verify/Distribution + - name: Upload the artifacts to GitHub Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release upload ${GITHUB_REF_NAME} \ + --repo ${{ github.repository }} \ + --clobber \ + universal/ArrowFlightSQLODBC-*.pkg diff --git a/ci/scripts/odbc_macos_universal_pkg.sh b/ci/scripts/odbc_macos_universal_pkg.sh new file mode 100755 index 000000000000..829ac3e4e81b --- /dev/null +++ b/ci/scripts/odbc_macos_universal_pkg.sh @@ -0,0 +1,98 @@ +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Build a universal (ARM64 and AMD64) ODBC macOS installer PKG from an +# ARM64 base PKG by replacing its dylib with a universal dylib. +# +# Usage: odbc_macos_universal_pkg.sh BASE_PKG UNIVERSAL_DYLIB OUTPUT_PKG +# +# BASE_PKG: ARM64 installer PKG built by CPack +# UNIVERSAL_DYLIB: Universal libarrow_flight_sql_odbc..dylib. Its +# name must match the dylib in BASE_PKG. +# OUTPUT_PKG: Path of the flat PKG to create + +set -euo pipefail + +if [ $# -ne 3 ]; then + echo "Usage: $0 BASE_PKG UNIVERSAL_DYLIB OUTPUT_PKG" >&2 + exit 1 +fi + +base_pkg="${1}" +universal_dylib="${2}" +output_pkg="${3}" +work_dir="odbc_pkg_build_dir" +expanded_dir="${work_dir}/expanded" + +mkdir "${work_dir}" +trap 'sudo rm -rf "${work_dir}"' EXIT + +# Use sudo for every step that touches the expanded payload so the root-owned +# files in the PKG keep their ownership instead of being re-stamped with the +# runner user's uid/gid. +sudo pkgutil --expand-full "${base_pkg}" "${expanded_dir}" + +# The unversioned name libarrow_flight_sql_odbc.dylib is a symlink to the +# versioned dylib that the install name +# (@rpath/libarrow_flight_sql_odbc..dylib) resolves to. +# Replace the real file so the symlinks stay intact. +symlink_path="$(find "${expanded_dir}" -name libarrow_flight_sql_odbc.dylib)" +lib_dir="$(dirname "${symlink_path}")" +dylib_path="$(realpath "${symlink_path}")" +if [ "$(basename "${universal_dylib}")" != "$(basename "${dylib_path}")" ]; then + echo "DYLIB $(basename "${universal_dylib}") doesn't match PKG DYLIB $(basename "${dylib_path}")" + exit 1 +fi +echo "Replacing ${dylib_path} (via ${symlink_path}) with ${universal_dylib}" +# cp onto an existing file keeps its owner and mode. +sudo cp "${universal_dylib}" "${dylib_path}" + +# Verify every dylib (including the symlinks) is universal before re-packaging. +# Check architecture with `grep` on `lipo -archs` to be compatible on macOS 27. +for lib in "${lib_dir}"/libarrow_flight_sql_odbc*.dylib; do + dylib_archs="$(lipo -archs "${lib}")" + echo "${lib}: ${dylib_archs}" + for arch in arm64 x86_64; do + if ! grep -qw "${arch}" <<< "${dylib_archs}"; then + echo "${lib} is missing '${arch}' (got: ${dylib_archs})" + exit 1 + fi + done +done + +# --flatten-full regenerates each component's Bom and PackageInfo +# installKBytes, but leaves Distribution with outdated PKG's sizes. +# Workaround is to copy regenerated sizes into Distribution, +# then re-flatten without -full so the correct sizes stay in Distribution. +# +# Use sudo for every step that touches the expanded payload so the root-owned +# files in the PKG keep their ownership instead of being re-stamped with the +# runner user's uid/gid. +sudo pkgutil --flatten-full "${expanded_dir}" "${work_dir}/flattened.pkg" +sudo pkgutil --expand "${work_dir}/flattened.pkg" "${work_dir}/shallow" +for component in "${work_dir}"/shallow/*.pkg; do + component_name="$(basename "${component}")" + kbytes="$(sudo sed -n 's/.*installKBytes="\([0-9]*\)".*/\1/p' "${component}/PackageInfo")" + sudo sed -i '' \ + "/>#${component_name}<\/pkg-ref>/ s/installKBytes=\"[0-9]*\"/installKBytes=\"${kbytes}\"/" \ + "${work_dir}/shallow/Distribution" +done +mkdir -p "$(dirname "${output_pkg}")" +sudo pkgutil --flatten "${work_dir}/shallow" "${output_pkg}" +sudo chown "$(id -u):$(id -g)" "${output_pkg}"