Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions habitat/aarch64-darwin/plan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
export HAB_BLDR_CHANNEL="base-2025"
export HAB_REFRESH_CHANNEL="base-2025"
pkg_name=fauxhai
pkg_origin=chef
ruby_pkg="core/ruby3_4"
pkg_description="Easily mock full ohai data"
pkg_deps=(${ruby_pkg} core/coreutils core/libarchive)
pkg_build_deps=(
core/make
core/sed
core/clang
core/cmake
)
pkg_bin_dirs=(bin)

do_setup_environment() {
push_runtime_env GEM_PATH "${pkg_prefix}/vendor"

set_runtime_env APPBUNDLER_ALLOW_RVM "true"
set_runtime_env LANG "en_US.UTF-8"
set_runtime_env LC_CTYPE "en_US.UTF-8"
}

do_prepare() {
build_line "Setting up build environment for native extensions"
export PATH="$(pkg_path_for core/cmake)/bin:$(pkg_path_for core/make)/bin:$(pkg_path_for core/clang)/bin:$PATH"
export CC="$(pkg_path_for core/clang)/bin/clang"
export CXX="$(pkg_path_for core/clang)/bin/clang++"
}

pkg_version() {
cat "$SRC_PATH/VERSION"
}

do_before() {
update_pkg_version
}

do_unpack() {
mkdir -pv "$HAB_CACHE_SRC_PATH/$pkg_dirname"
cp -RT "$PLAN_CONTEXT"/../.. "$HAB_CACHE_SRC_PATH/$pkg_dirname/"
}

do_build() {
cd "$HAB_CACHE_SRC_PATH/$pkg_dirname" || exit_with "unable to cd to source directory" 1

export GEM_HOME="$pkg_prefix/vendor"
export HOME="$HAB_CACHE_SRC_PATH/$pkg_dirname"
export GEM_SPEC_CACHE="$HAB_CACHE_SRC_PATH/$pkg_dirname/.gem/specs"
mkdir -p "$GEM_SPEC_CACHE"
export PATH="$(pkg_path_for core/cmake)/bin:$(pkg_path_for core/make)/bin:$(pkg_path_for core/clang)/bin:$PATH"
export CC="$(pkg_path_for core/clang)/bin/clang"
export CXX="$(pkg_path_for core/clang)/bin/clang++"

build_line "Setting GEM_PATH=$GEM_HOME"
export GEM_PATH="$GEM_HOME"
bundle config --local without integration deploy maintenance
bundle config --local jobs 4
bundle config --local retry 5
bundle config --local silence_root_warning 1
bundle install
gem build fauxhai-chef.gemspec
ruby ./cleanup_lint_roller.rb
}

do_install() {
cd "$HAB_CACHE_SRC_PATH/$pkg_dirname" || exit_with "unable to cd to source directory" 1

# Copy NOTICE to the package directory
if [[ -f "NOTICE" ]]; then
build_line "Copying NOTICE to package directory"
cp "NOTICE" "$pkg_prefix/"
else
build_line "Warning: NOTICE not found in source directory"
fi

export GEM_HOME="$pkg_prefix/vendor"
export HOME="$HAB_CACHE_SRC_PATH/$pkg_dirname"
export GEM_SPEC_CACHE="$HAB_CACHE_SRC_PATH/$pkg_dirname/.gem/specs"
mkdir -p "$GEM_SPEC_CACHE"

build_line "Setting GEM_PATH=$GEM_HOME"
export GEM_PATH="$GEM_HOME"
gem install --local fauxhai-*.gem --no-document --ignore-dependencies

build_line "** generating binstubs for fauxhai-chef with precise version pins"
"${pkg_prefix}/vendor/bin/appbundler" . "$pkg_prefix/bin" fauxhai-chef

build_line "** patching binstubs to allow running directly"
for binstub in ${pkg_prefix}/bin/*; do
sed -i "/require \"rubygems\"/r ${PLAN_CONTEXT}/../../binstub_patch.rb" "$binstub"
done

if ! grep -q 'APPBUNDLER_ALLOW_RVM' "${pkg_prefix}/bin/fauxhai"; then
build_line "ERROR: binstub patch injection failed for ${pkg_prefix}/bin/fauxhai"
return 1
fi

build_line "** creating wrapper for runtime environment"
mkdir -p "$pkg_prefix/libexec"
mv "$pkg_prefix/bin/fauxhai" "$pkg_prefix/libexec/fauxhai"
cat <<EOF > "$pkg_prefix/bin/fauxhai"
#!/bin/bash
set -e

export PATH="$(pkg_path_for ${ruby_pkg})/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:$pkg_prefix/vendor/bin:\$PATH"
export DYLD_LIBRARY_PATH="$(pkg_path_for core/libarchive)/lib:\$DYLD_LIBRARY_PATH"
export GEM_HOME="$pkg_prefix/vendor"
export GEM_PATH="$pkg_prefix/vendor"

exec $(pkg_path_for ${ruby_pkg})/bin/ruby $pkg_prefix/libexec/fauxhai "\$@"
EOF
chmod -v 755 "$pkg_prefix/bin/fauxhai"

fix_interpreter "${pkg_prefix}/vendor/bin/*" "$ruby_pkg" bin/ruby

rm -rf "$GEM_PATH/cache"
rm -rf "$GEM_PATH/bundler"
rm -rf "$GEM_PATH/doc"
}

do_after() {
build_line "Removing .github directories from vendored gems..."
find "$pkg_prefix/vendor/gems" -type d -name ".github" \
| while read github_dir; do rm -rf "$github_dir"; done

build_line "Removing stray Gemfile.lock files from vendored gems..."
find "$pkg_prefix/vendor/gems" -name "Gemfile.lock" -type f -delete
}

do_strip() {
return 0
}
Loading