-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: refactor which and exec to optionally use an env cache
Moreover, we load as little files as possible to reduce the amount of time loading to a minimum.
- Loading branch information
Showing
15 changed files
with
421 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ pkg/ | |
/coverage/ | ||
/.yardoc/ | ||
test/gem_home | ||
tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require 'aruba/api' | ||
|
||
module Autoproj | ||
# Minitest-usable Aruba wrapper | ||
# | ||
# Aruba 0.14 is incompatible with Minitest because of their definition | ||
# of the #run method This change hacks around the problem, by moving | ||
# the Aruba API to a side stub object. | ||
# | ||
# The run methods are renamed as they have been renamed in Aruba 1.0 | ||
# alpha, run -> run_command and run_simple -> run_command_and_stop | ||
module ArubaMinitest | ||
class API | ||
include ::Aruba::Api | ||
end | ||
|
||
def setup | ||
super | ||
@aruba_api = API.new | ||
@aruba_api.setup_aruba | ||
end | ||
|
||
def teardown | ||
stop_all_commands | ||
super | ||
end | ||
|
||
def run_command_and_stop(*args, fail_on_error: true) | ||
cmd = run_command(*args) | ||
cmd.stop | ||
if fail_on_error | ||
assert_command_finished_successfully(cmd) | ||
end | ||
cmd | ||
end | ||
|
||
def run_command(*args) | ||
@aruba_api.run(*args) | ||
end | ||
|
||
def chmod(*args) # also defined by Rake | ||
@aruba_api.chmod(*args) | ||
end | ||
|
||
def method_missing(m, *args, &block) | ||
if @aruba_api.respond_to?(m) | ||
return @aruba_api.send(m, *args, &block) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def assert_command_stops(cmd, fail_on_error: true) | ||
cmd.stop | ||
if fail_on_error | ||
assert_command_finished_successfully(cmd) | ||
end | ||
end | ||
|
||
def assert_command_finished_successfully(cmd) | ||
refute cmd.timed_out?, "#{cmd} timed out on stop" | ||
assert_equal 0, cmd.exit_status, "#{cmd} finished with a non-zero exit status (#{cmd.exit_status})\n-- STDOUT\n#{cmd.stdout}\n-- STDERR\n#{cmd.stderr}" | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'autobuild/environment' | ||
|
||
module Autoproj | ||
module Ops | ||
def self.cached_env_path(root_dir) | ||
File.join(root_dir, '.autoproj', 'env.yml') | ||
end | ||
|
||
def self.load_cached_env(root_dir) | ||
path = cached_env_path(root_dir) | ||
if File.file?(path) | ||
env = YAML.load(File.read(path)) | ||
Autobuild::Environment::ExportedEnvironment.new( | ||
env['set'], env['unset'], env['update']) | ||
end | ||
end | ||
|
||
def self.save_cached_env(root_dir, env) | ||
env = env.exported_environment | ||
path = cached_env_path(root_dir) | ||
existing = | ||
begin | ||
YAML.load(File.read(path)) | ||
rescue Exception | ||
end | ||
|
||
env = Hash['set' => env.set, 'unset' => env.unset, 'update' => env.update] | ||
if env != existing | ||
Ops.atomic_write(path) do |io| | ||
YAML.dump(env, io) | ||
end | ||
true | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'pathname' | ||
require 'autoproj/exceptions' | ||
require 'autobuild/environment' | ||
|
||
module Autoproj | ||
module Ops | ||
# Find the given executable file in PATH | ||
# | ||
# If `cmd` is an absolute path, it will either return it or raise if | ||
# `cmd` is not executable. Otherwise, looks for an executable named | ||
# `cmd` in PATH and returns it, or raises if it cannot be found. The | ||
# exception contains a more detailed reason for failure | ||
# | ||
# | ||
# @param [String] cmd | ||
# @return [String] the resolved program | ||
# @raise [ExecutableNotFound] if an executable file named `cmd` cannot | ||
# be found | ||
def self.which(cmd, path_entries: nil) | ||
path = Pathname.new(cmd) | ||
if path.absolute? | ||
if path.file? && path.executable? | ||
return cmd | ||
elsif path.exist? | ||
raise ExecutableNotFound.new(cmd), "given command `#{cmd}` exists but is not an executable file" | ||
else | ||
raise ExecutableNotFound.new(cmd), "given command `#{cmd}` does not exist, an executable file was expected" | ||
end | ||
else | ||
if path_entries.respond_to?(:call) | ||
path_entries = path_entries.call | ||
end | ||
absolute = Autobuild::Environment.find_executable_in_path(cmd, path_entries) | ||
|
||
if absolute | ||
return absolute | ||
elsif file = Autobuild::Environment.find_in_path(cmd, path_entries) | ||
raise ExecutableNotFound.new(cmd), "`#{cmd}` resolves to #{file} which is not executable" | ||
else | ||
raise ExecutableNotFound.new(cmd), "cannot resolve `#{cmd}` to an executable in the workspace" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.