Skip to content

Commit 61d0572

Browse files
authored
Merge pull request #238 from chef/nikhil/hab-path-changes
CHEF-14475-Hab path changes for chef-cli
2 parents cd601aa + d9959f3 commit 61d0572

File tree

6 files changed

+41
-117
lines changed

6 files changed

+41
-117
lines changed

chef-cli.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,4 @@ Gem::Specification.new do |gem|
5050
gem.add_dependency "diff-lcs", ">= 1.0", "< 1.4" # 1.4 changes the output
5151
gem.add_dependency "pastel", "~> 0.7" # used for policyfile differ
5252
gem.add_dependency "license-acceptance", ">= 1.0.11", "< 3"
53-
gem.add_dependency "chef-licensing", "~> 1.0"
5453
end

habitat/plan.ps1

Lines changed: 0 additions & 92 deletions
This file was deleted.

habitat/plan.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
_chef_client_ruby="core/ruby31"
22
pkg_name="chef-cli"
3-
pkg_origin="chef"
3+
pkg_origin="ngupta26"
44
pkg_maintainer="The Chef Maintainers <[email protected]>"
55
pkg_description="The Chef CLI"
66
pkg_license=('Apache-2.0')

lib/chef-cli/command/env.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,19 @@ def ruby_info
7373

7474
def gem_environment
7575
h = {}
76-
h["GEM ROOT"] = omnibus_env["GEM_ROOT"]
77-
h["GEM HOME"] = omnibus_env["GEM_HOME"]
78-
h["GEM PATHS"] = omnibus_env["GEM_PATH"].split(File::PATH_SEPARATOR)
79-
rescue OmnibusInstallNotFound
76+
# h["GEM ROOT"] = omnibus_env["GEM_ROOT"]
77+
# h["GEM HOME"] = omnibus_env["GEM_HOME"]
78+
# h["GEM PATHS"] = omnibus_env["GEM_PATH"].split(File::PATH_SEPARATOR)
79+
# rescue OmnibusInstallNotFound
8080
h["GEM_ROOT"] = ENV["GEM_ROOT"] if ENV.key?("GEM_ROOT")
8181
h["GEM_HOME"] = ENV["GEM_HOME"] if ENV.key?("GEM_HOME")
8282
h["GEM PATHS"] = ENV["GEM_PATH"].split(File::PATH_SEPARATOR) if ENV.key?("GEM_PATH") && !ENV.key?("GEM_PATH").nil?
83-
ensure
84-
h
83+
# ensure
84+
# h
8585
end
8686

8787
def paths
88-
omnibus_env["PATH"].split(File::PATH_SEPARATOR)
88+
habitat_env["PATH"].split(File::PATH_SEPARATOR)
8989
rescue OmnibusInstallNotFound
9090
ENV["PATH"].split(File::PATH_SEPARATOR)
9191
end

lib/chef-cli/command/exec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Exec < ChefCLI::Command::Base
3030
def run(params)
3131
# Set ENV directly on the "parent" process (us) before running #exec to
3232
# ensure the custom PATH is honored when finding the command to exec
33-
omnibus_env.each { |var, value| ENV[var] = value }
33+
habitat_env.each { |var, value| ENV[var] = value }
3434
exec(*params)
3535
raise "Exec failed without an exception, your ruby is buggy" # should never get here
3636
end

lib/chef-cli/helpers.rb

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,39 @@ def git_windows_bin_dir
111111
end
112112

113113
#
114-
# environment vars for omnibus
114+
# environment vars for habitat
115115
#
116-
def omnibus_env
117-
@omnibus_env ||=
118-
begin
119-
user_bin_dir = File.expand_path(File.join(Gem.user_dir, "bin"))
120-
path = [ omnibus_bin_dir, user_bin_dir, omnibus_embedded_bin_dir, ENV["PATH"].split(File::PATH_SEPARATOR) ]
121-
path << git_bin_dir if Dir.exist?(git_bin_dir)
122-
path << git_windows_bin_dir if Dir.exist?(git_windows_bin_dir)
123-
{
124-
"PATH" => path.flatten.uniq.join(File::PATH_SEPARATOR),
125-
"GEM_ROOT" => Gem.default_dir,
126-
"GEM_HOME" => Gem.user_dir,
127-
"GEM_PATH" => Gem.path.join(File::PATH_SEPARATOR),
128-
}
129-
end
116+
def habitat_env
117+
@habitat_env ||=
118+
begin
119+
# Define the necessary paths for the Habitat environment
120+
# Custom GEM_HOME within Habitat
121+
pkg_prefix = get_pkg_prefix
122+
vendor_dir = File.join(pkg_prefix, "vendor")
123+
path = [
124+
File.join(pkg_prefix, "bin"),
125+
ENV["PATH"].split(File::PATH_SEPARATOR) # Preserve existing PATH
126+
].flatten.uniq
127+
128+
{
129+
"PATH" => path.join(File::PATH_SEPARATOR),
130+
"GEM_ROOT" => Gem.default_dir, # Default directory for gems
131+
"GEM_HOME" => vendor_dir, # GEM_HOME pointing to the vendor directory
132+
"GEM_PATH" => vendor_dir, # GEM_PATH also pointing to the vendor directory
133+
}
134+
end
135+
end
136+
137+
def get_pkg_prefix
138+
pkg_origin = "ngupta26"
139+
pkg_name = "#{pkg_origin}/chef-cli" # Your origin and package name
140+
path = `hab pkg path #{pkg_name}`.strip
141+
142+
if $?.success? && !path.empty?
143+
path
144+
else
145+
raise "Failed to get pkg_prefix for #{pkg_name}: #{path}"
146+
end
130147
end
131148

132149
def omnibus_expand_path(*paths)

0 commit comments

Comments
 (0)