module Autoproj
Constants
- ENV_FILENAME
- GIT_SERVER_ACCESS_METHODS
- GIT_SERVER_CONFIG_VARS
- Query
Match class for the query system.
This class allows to create a query object based on a textual representation, and then match packages using this query object.
The queries are of the form
FIELD=VALUE:FIELD~VALUE:FIELD=VALUE
The F=V form requires an exact match while F~V allows partial matches. The different matches are combined with AND (i.e. only packages matching all criterias will be returned)
The following fields are allowed:
* autobuild.name: the package name * autobuild.srcdir: the package source directory * autobuild.class.name: the package class * vcs.type: the VCS type (as used in the source.yml files) * vcs.url: the URL from the VCS. The exact semantic of it depends on the VCS type * package_set.name: the name of the package set that defines the package
Some fields have shortcuts:
* 'name' can be used instead of 'autobuild.name' * 'class' can be used instead of 'autobuild.class.name' * 'vcs' can be used instead of 'vcs.url' * 'package_set' can be used instead of 'package_set.name'
- VERSION
- YAML_LOAD_ERROR
Attributes
Public Class Methods
# File lib/autoproj/manifest.rb, line 1247 def self.add_osdeps_overrides(*args, **kw, &block) manifest.add_osdeps_overrides(*args, **kw, &block) end
Add a custom source handler named name
Custom source handlers are shortcuts that can be used to represent VCS information. For instance, the {Autoproj.git_server_configuration} helper defines a source handler that allows to easily add new github packages:
Autoproj.git_server_configuration('GITHUB', 'github.com', http_url: 'https://github.com', default: 'http,ssh')
Defines a ‘github’ custom handler that expands into the full VCS configuration to access github
version_control: - tools/orocos.rb: github: rock-core/base-types branch: test
@yieldparam [String] url the url given to the handler @yieldparam [Hash] the rest of the VCS hash @return [Hash] a VCS hash with the information expanded
# File lib/autoproj/vcs_definition.rb, line 351 def self.add_source_handler(name, &handler) @custom_source_handlers[name.to_s] = handler end
@deprecated use workspace.prefix_dir instead
# File lib/autoproj/system.rb, line 88 def self.build_dir Autoproj.warn_deprecated(__method__, "workspace.prefix_dir") workspace.prefix_dir end
Shim for a smooth upgrade path to bundler 2.1+
# File lib/autoproj/base.rb, line 61 def self.bundler_unbundled_system(*args, **options) if Bundler.respond_to?(:unbundled_system) Bundler.unbundled_system(*args, **options) else Bundler.clean_system(*args, **options) end end
Shim for a smooth upgrade path to bundler 2.1+
# File lib/autoproj/base.rb, line 70 def self.bundler_with_unbundled_env(&block) if Bundler.respond_to?(:with_unbundled_env) Bundler.with_unbundled_env(&block) else Bundler.with_clean_env(&block) end end
Returns the source handlers associated with vcs
Source handlers are added by Autoproj.add_source_handler
. The returned value is an object that responds to call(url, options) and return a VCS definition as a hash
# File lib/autoproj/vcs_definition.rb, line 321 def self.call_source_handler(vcs, url, options) handler = @custom_source_handlers[vcs.to_s] if handler handler.call(url, **options) else raise ArgumentError, "there is no source handler for #{vcs}" end end
@deprecated use config.set(key, value, user_validated) instead
# File lib/autoproj/options.rb, line 15 def self.change_option(key, value, user_validated = false) Autoproj.warn_deprecated __method__, "use the API on Autoproj.config (from Autoproj::Configuration) instead" config.set(key, value, user_validated) end
# File lib/autoproj/reporter.rb, line 32 def self.color(*args) Autobuild.color(*args) end
# File lib/autoproj/manifest.rb, line 1243 def self.config workspace.config end
@deprecated use workspace.config_dir instead
# File lib/autoproj/system.rb, line 48 def self.config_dir Autoproj.warn "#{__method__} is deprecated, use workspace.config_dir instead" caller.each { |l| Autoproj.warn " #{l}" } workspace.config_dir end
@deprecated compute the full path with File.join(config_dir
, file)
directly instead
# File lib/autoproj/system.rb, line 95 def self.config_file(file) Autoproj.warn_deprecated(__method__, "compute the full path with File.join(config_dir, ...) instead") File.join(config_dir, file) end
@deprecated use config.declare(name, type, options, &validator) instead
# File lib/autoproj/options.rb, line 33 def self.configuration_option(name, type, options, &validator) Autoproj.warn_deprecated __method__, "use the API on Autoproj.config (from Autoproj::Configuration) instead" config.declare(name, type, options, &validator) end
@deprecated use config.configure(option_name) instead
# File lib/autoproj/options.rb, line 45 def self.configure(option_name) Autoproj.warn_deprecated __method__, "use the API on Autoproj.config (from Autoproj::Configuration) instead" config.configure(option_name) end
True if the given string contains expansions
# File lib/autoproj/variable_expansion.rb, line 82 def self.contains_expansion?(string) string.respond_to?(:to_str) && string.to_str =~ /\$/ end
OS-independent creation of symbolic links. Note that on windows, it only works for directories
# File lib/autoproj/system.rb, line 4 def self.create_symlink(from, to) if Autobuild.windows? Dir.create_junction(to, from) else FileUtils.ln_sf from, to end end
@deprecated use Autoproj.workspace
.current_file or add a proper Loader
object to your class
# File lib/autoproj/autobuild_extensions/dsl.rb, line 69 def self.current_file Autoproj.warn_deprecated( __method__, "use AUtoproj.workspace.current_file instead" ) Autoproj.workspace.current_file end
@deprecated use Autoproj.workspace
.current_package_set or add a proper
Loader object to your class
# File lib/autoproj/autobuild_extensions/dsl.rb, line 79 def self.current_package_set Autoproj.warn_deprecated( __method__, "use Autoproj.workspace.current_package_set instead" ) Autoproj.workspace.current_package_set end
Registers a block that will be called to determine a package handler for the package in full_path.
# File lib/autoproj/autobuild_extensions/dsl.rb, line 41 def self.custom_package_handler(&block) custom_package_handlers << block end
# File lib/autoproj/autobuild_extensions/dsl.rb, line 26 def custom_package_handlers @custom_package_handlers ||= [] end
@deprecated use config.declared?(name, type, options, &validator) instead
# File lib/autoproj/options.rb, line 39 def self.declared_option?(name) Autoproj.warn_deprecated __method__, "use the API on Autoproj.config (from Autoproj::Configuration) instead" config.declared?(name) end
The base path from which we search for workspaces
# File lib/autoproj/find_workspace.rb, line 6 def self.default_find_base_dir ENV["AUTOPROJ_CURRENT_ROOT"] || Dir.pwd end
@deprecated use {Workspace#define_package} directly instead.
Beware that the return value changed from Autobuild::Package to Autoproj::PackageDefinition
# File lib/autoproj/autobuild_extensions/dsl.rb, line 90 def self.define(package_type, spec, &block) Autoproj.warn_deprecated( __method__, "use Autoproj.workspace.define_package "\ "instead (and beware that the return value changed from "\ "Autobuild::Package to Autoproj::PackageDefinition)" ) workspace.define_package(package_type, spec, block, *current_file) .autobuild end
# File lib/autoproj/autobuild_extensions/dsl.rb, line 31 def self.each_custom_package_handler(&block) return enum_for(__method__) unless block_given? custom_package_handlers.each do |handler| block.call(handler) end end
Enumerate the post-import blocks registered for the given package
@param [PackageDefinition] pkg @see post_import
# File lib/autoproj/base.rb, line 34 def self.each_post_import_block(pkg, &block) # We use Autobuild packages as keys pkg = pkg.autobuild if pkg.respond_to?(:autobuild) @post_import_blocks[nil].each(&block) @post_import_blocks[pkg]&.each(&block) end
# File lib/autoproj/workspace.rb, line 947 def self.env workspace.env end
@deprecated call Autoproj.env
.add instead
# File lib/autoproj/environment.rb, line 93 def self.env_add(name, *value) env.add(name, *value) end
@deprecated call Autoproj.env
.add_path instead
# File lib/autoproj/environment.rb, line 103 def self.env_add_path(name, *value) env.add_path(name, *value) end
@deprecated call Autoproj.env
.inherit instead
# File lib/autoproj/environment.rb, line 123 def self.env_inherit(*names) env.inherit(*names) end
@deprecated call Autoproj.env
.set instead
# File lib/autoproj/environment.rb, line 88 def self.env_set(name, *value) env.set(name, *value) end
@deprecated call Autoproj.env
.set_path instead
# File lib/autoproj/environment.rb, line 98 def self.env_set_path(name, *value) env.set_path(name, *value) end
@deprecated call Autoproj.env
.source_after instead
# File lib/autoproj/environment.rb, line 113 def self.env_source_after(file, shell: "sh") env.source_after(file, shell: shell) end
@deprecated call Autoproj.env
.source_before instead
# File lib/autoproj/environment.rb, line 118 def self.env_source_before(file, shell: "sh") env.source_before(file, shell: shell) end
@deprecated call Autoproj.env
.source_after instead
# File lib/autoproj/environment.rb, line 108 def self.env_source_file(file, shell: "sh") env.source_after(file, shell: shell) end
Displays an error message
# File lib/autoproj/reporter.rb, line 37 def self.error(message) Autobuild.error(message) end
Expand constants within value
The list of constants is given in definitions
. It raises ConfigError
if some values are not found
# File lib/autoproj/variable_expansion.rb, line 63 def self.expand(value, definitions = Hash.new) if value.respond_to?(:to_hash) value.dup.each do |name, definition| value[name] = expand(definition, definitions) end value elsif value.respond_to?(:to_ary) value.map { |val| expand(val, definitions) } else value = single_expansion(value, definitions) if contains_expansion?(value) raise ConfigError.new, "some expansions are not defined in #{value.inspect}" end value end end
@deprecated use Autoproj.env
.export_env_sh instead
# File lib/autoproj/environment.rb, line 143 def self.export_env_sh(subdir = nil) env.export_env_sh(subdir) end
Filters in the given list of paths the paths that are within a workspace
# File lib/autoproj/find_workspace.rb, line 74 def self.filter_out_paths_in_workspace(paths) known_workspace_dirs = Array.new paths.find_all do |p| if !File.directory?(p) true elsif known_workspace_dirs.any? { |ws_root| "#{p}/".start_with?(ws_root) } false else ws_path, ws_config = find_v2_workspace_config(p) if ws_path known_workspace_dirs << "#{ws_path}/" if (ws_dir = ws_config["workspace"]) known_workspace_dirs << "#{ws_dir}/" end false else true end end end end
@deprecated use Autobuild.find_in_path instead
Warning: the autobuild method returns nil (instead of raising) if the argument cannot be found
# File lib/autoproj/system.rb, line 65 def self.find_in_path(name) Autoproj.warn "#{__method__} is deprecated, use Autobuild.find_in_path instead" caller.each { |l| Autoproj.warn " #{l}" } unless (path = Autobuild.find_in_path(name)) raise ArgumentError, "cannot find #{name} in PATH (#{ENV['PATH']})" end path end
Looks for the autoproj prefix that contains a given directory
@return [String,nil]
# File lib/autoproj/find_workspace.rb, line 20 def self.find_prefix_dir(base_dir = default_find_base_dir) find_v2_prefix_dir(base_dir) end
# File lib/autoproj/autobuild_extensions/dsl.rb, line 115 def self.find_topmost_directory_containing(dir, glob_pattern = nil) result = nil while dir != "/" match = false if glob_pattern match = true unless Dir.glob(File.join(dir, glob_pattern)).empty? end match = true if !match && block_given? && yield(dir) if !match && result return result elsif match result = dir end dir = File.dirname(dir) end end
{#find_workspace_dir} for v1 workspaces
Note that for v1 workspaces {#find_prefix_dir} cannot be implemented
# File lib/autoproj/find_workspace.rb, line 109 def self.find_v1_workspace_dir(base_dir = default_find_base_dir) path = Pathname.new(base_dir) until path.root? if path.join("autoproj").exist? return path.to_s unless path.join(".autoproj").exist? end path = path.parent end nil end
{#find_prefix_dir} for v2 workspaces
# File lib/autoproj/find_workspace.rb, line 102 def self.find_v2_prefix_dir(base_dir = default_find_base_dir) find_v2_root_dir(base_dir, "prefix") end
@private
Finds an autoproj “root directory” that contains a given directory. It can either be the root of a workspace or the root of an install directory
@param [String] base_dir the start of the search @param [String] config_field_name the name of a field in the root’s
configuration file, that should be returned instead of the root itself
@return [String,nil] the root of the workspace directory, or nil if
there's none
# File lib/autoproj/find_workspace.rb, line 56 def self.find_v2_root_dir(base_dir, config_field_name) path, config = find_v2_workspace_config(base_dir) return unless path result = config[config_field_name] || path.to_s result = File.expand_path(result, path.to_s) return result if result == path.to_s resolved = find_v2_root_dir(result, config_field_name) if !resolved || (resolved != result) raise ArgumentError, "found #{path} as possible workspace root for #{base_dir}, but it contains a configuration file that points to #{result} and #{result} is not an autoproj workspace root" end resolved end
Find a workspace configuration file in the parent tree of a given directory
@param [String] base_dir the directory to start from @return [(String,Hash),nil] the root path, and the configuration, or nil
if base_dir is not part of a workspace
# File lib/autoproj/find_workspace.rb, line 30 def self.find_v2_workspace_config(base_dir) path = Pathname.new(base_dir).expand_path until path.root? break if path.join(".autoproj", "config.yml").exist? path = path.parent end return if path.root? config_path = path.join(".autoproj", "config.yml") [path.to_s, (YAML.load(config_path.read) || Hash.new)] end
{#find_workspace_dir} for v2 workspaces
# File lib/autoproj/find_workspace.rb, line 97 def self.find_v2_workspace_dir(base_dir = default_find_base_dir) find_v2_root_dir(base_dir, "workspace") end
Looks for the autoproj workspace that is related to a given directory
@return [String,nil]
# File lib/autoproj/find_workspace.rb, line 13 def self.find_workspace_dir(base_dir = default_find_base_dir) find_v2_workspace_dir(base_dir) end
Flattens a hash whose keys are strings and values are either plain values, arrays or hashes
The keys in the flattened hash are made hierarchical by appending “.”. Array values are ignored.
@example
h = Hash['test' => 10, 'h' => Hash['value' => '20']] options_to_flat_hash(h) # Hash['test' => '10', # 'h.value' => 20]
@param [{[String,Symbol]=>}] @return [{String=>String}]
# File lib/autoproj/variable_expansion.rb, line 17 def self.flatten_recursive_hash(hash, prefix = "") result = Hash.new hash.each do |k, v| if v.kind_of?(Hash) result.merge!(flatten_recursive_hash(v, "#{prefix}#{k}.")) elsif !v.respond_to?(:to_ary) result["#{prefix}#{k}"] = v.to_s end end result end
Adds the relevant options to handle a gitorious server What this does is ask the user how he would like to access the gitorious server. Then, it sets
#{name}_ROOT to be the base URL for pulling #{name}_PUSH_ROOT to be the corresponding ssh-based URL for pushing
For instance, with
git_server_configuration "GITHUB", "github.com"
One would use the following shortcut in its source.yml:
- my/package: github: account/package
which would be expanded to the expected URLs for pull and push.
# File lib/autoproj/git_server_configuration.rb, line 68 def self.git_server_configuration(name, base_url, git_url: "git://#{base_url}", http_url: "https://git.#{base_url}", ssh_url: "git@#{base_url}:", default: "http,ssh", disabled_methods: [], config: Autoproj.config, fallback_to_http: nil, lazy: false) disabled_methods = Array(disabled_methods) long_doc = [ "How should I interact with #{base_url} (#{(GIT_SERVER_ACCESS_METHODS.keys - disabled_methods).sort.join(', ')})", "If you give one value, it's going to be the method used for all access", "If you give multiple values, comma-separated, the first one will be", "used for pulling and the second one for pushing. An optional third value", "will be used to pull from private repositories (the same than pushing is", "used by default)" ] config.declare name, "string", default: default, doc: long_doc do |value| git_server_validate_config_value(base_url, value, disabled_methods: disabled_methods) end unless lazy pull, push, private_pull = git_server_resolve_master_config(name, config, base_url: base_url, git_url: git_url, http_url: http_url, ssh_url: ssh_url, disabled_methods: disabled_methods) end Autoproj.add_source_handler name.downcase do |url, private: false, **vcs_options| url += ".git" if url !~ /\.git$/ url = "/#{url}" if url !~ /^\// unless GIT_SERVER_CONFIG_VARS.all? { |v| config.has_value_for?("#{name}#{v}") } pull, push, private_pull = git_server_resolve_master_config(name, config, base_url: base_url, git_url: git_url, http_url: http_url, ssh_url: ssh_url, disabled_methods: disabled_methods) end pull_base_url = if private config.get("#{name}_PRIVATE_ROOT") else config.get("#{name}_ROOT") end push_base_url = config.get("#{name}_PUSH_ROOT") Hash[type: "git", url: "#{pull_base_url}#{url}", push_to: "#{push_base_url}#{url}", interactive: (private && private_pull == "http"), retry_count: 10, repository_id: "#{name.downcase}:#{url}"].merge(vcs_options) end end
@api private
Helper for {.git_server_configuration}
# File lib/autoproj/git_server_configuration.rb, line 27 def self.git_server_resolve_master_config(name, config, base_url:, git_url:, http_url:, ssh_url:, disabled_methods:) access_mode = config.get(name) begin git_server_validate_config_value(base_url, access_mode, disabled_methods: disabled_methods) rescue Autoproj::InputError => e Autoproj.warn e.message config.reset(name) access_mode = config.get(name) end access_mode = GIT_SERVER_ACCESS_METHODS[access_mode] || access_mode pull, push, private_pull = access_mode.split(",") private_pull ||= push [[pull, "_ROOT"], [push, "_PUSH_ROOT"], [private_pull, "_PRIVATE_ROOT"]].each do |method, var_suffix| url = if method == "git" then git_url elsif method == "http" then http_url elsif method == "ssh" then ssh_url end config.set("#{name}#{var_suffix}", url) end [pull, push, private_pull] end
@api private
Helper for {.git_server_configuration}
# File lib/autoproj/git_server_configuration.rb, line 12 def self.git_server_validate_config_value(base_url, value, disabled_methods:) values = (GIT_SERVER_ACCESS_METHODS[value] || value).split(",") values.each do |access_method| if !GIT_SERVER_ACCESS_METHODS.has_key?(access_method) raise Autoproj::InputError, "#{access_method} is not a known access method" elsif disabled_methods.include?(access_method) raise Autoproj::InputError, "#{access_method} is disabled on #{base_url}" end end value end
# File lib/autoproj/git_server_configuration.rb, line 130 def self.gitorious_server_configuration(name, base_url, **options) Autoproj.warn_deprecated "gitorious_server_configuration", "use require 'git_server_configuration' and Autoproj.git_server_configuration instead. note that the method call interface has not changed, you just have to change the name(s)" git_server_configuration(name, base_url, **options) end
@deprecated use config.has_value_for?(name)
# File lib/autoproj/options.rb, line 51 def self.has_config_key?(name) Autoproj.warn_deprecated __method__, "use the API on Autoproj.config (from Autoproj::Configuration) instead" config.has_value_for?(name) end
Returns true if vcs
refers to a source handler name added by add_source_handler
# File lib/autoproj/vcs_definition.rb, line 312 def self.has_source_handler?(vcs) @custom_source_handlers.has_key?(vcs.to_s) end
# File lib/autoproj/autobuild_extensions/dsl.rb, line 107 def self.import_autobuild_file(package_set, path) Autoproj.warn_deprecated( __method__, "use Autoproj.workspace.import_autobuild_file" ) Autoproj.workspace.import_autobuild_file(package_set, path) end
Returns true if path
is part of an autoproj installation
# File lib/autoproj/system.rb, line 13 def self.in_autoproj_installation?(path) !!find_workspace_dir(path, "workspace") end
Yields, and if the given block raises a ConfigError
with no file assigned, add that file to both the object and the exception message
# File lib/autoproj/base.rb, line 12 def self.in_file(file, exception_t = ConfigError) yield rescue exception_t => e if exception_t != ConfigError raise ConfigError.new(file), "in #{file}: #{e.message}", e.backtrace elsif !e.file e.file = file raise e, "in #{file}: #{e.message}", e.backtrace else raise e end end
@deprecated use Autoproj.workspace
.in_package_set or add a proper Loader
object to your class
# File lib/autoproj/autobuild_extensions/dsl.rb, line 59 def self.in_package_set(package_set, path, &block) Autoproj.warn_deprecated( __method__, "use Autoproj.workspace.in_package_set instead" ) Autoproj.workspace.in_package_set(package_set, path, &block) end
@deprecated use Autoproj.env
.isolate instead
# File lib/autoproj/environment.rb, line 133 def self.isolate_environment env.isolate end
@deprecated use workspace.load or add a separate Loader object to your class
# File lib/autoproj/system.rb, line 107 def self.load(package_set, *path) Autoproj.warn_deprecated( __method__, "use workspace.load or add a separate Loader object to your class" ) workspace.load(package_set, *path) end
# File lib/autoproj/options.rb, line 73 def self.load_config workspace.load_config end
@deprecated use workspace.load_if_present or add a separate Loader object to your class
# File lib/autoproj/system.rb, line 116 def self.load_if_present(package_set, *path) Autoproj.warn_deprecated( __method__, "use workspace.load_if_present or add a separate Loader object to your class" ) workspace.load_if_present(package_set, *path) end
# File lib/autoproj/autobuild_extensions/dsl.rb, line 100 def self.loaded_autobuild_files Autoproj.warn_deprecated( __method__, "use Autoproj.workspace.loaded_autobuild_files" ) Autoproj.workspace.loaded_autobuild_files end
# File lib/autoproj/manifest.rb, line 1227 def self.manifest Autoproj.warn_deprecated( __method__, "use workspace.manifest instead" ) workspace.manifest end
# File lib/autoproj/reporter.rb, line 28 def self.message(*args) Autobuild.message(*args) end
# File lib/autoproj/reporter.rb, line 20 def self.not_silent silent = Autobuild.silent? Autobuild.silent = false yield ensure Autobuild.silent = silent end
@deprecated use config.validated_values instead
# File lib/autoproj/options.rb, line 21 def self.option_set Autoproj.warn_deprecated __method__, "use the API on Autoproj.config (from Autoproj::Configuration) instead" config.validated_values end
# File lib/autoproj/manifest.rb, line 1235 def self.osdeps Autoproj.warn_deprecated( __method__, "use workspace.os_package_resolver or workspace.os_package_installer instead" ) workspace.os_package_resolver end
@deprecated use config.override instead
# File lib/autoproj/options.rb, line 3 def self.override_option(option_name, value) Autoproj.warn_deprecated __method__, "use the API on Autoproj.config (from Autoproj::Configuration) instead" config.override(option_name, value) end
@deprecated use workspace.overrides_dir instead
# File lib/autoproj/system.rb, line 55 def self.overrides_dir Autoproj.warn "#{__method__} is deprecated, use workspace.overrides_dir instead" caller.each { |l| Autoproj.warn " #{l}" } workspace.overrides_dir end
Tries to find a handler automatically for ‘full_path’
# File lib/autoproj/autobuild_extensions/dsl.rb, line 136 def self.package_handler_for(full_path) each_custom_package_handler do |handler| pair = handler.call(full_path) return pair if pair end pyglob = File.join(File.basename(full_path), "*.py") if !Dir.enum_for(:glob, File.join(full_path, "*.orogen")).to_a.empty? ["orogen_package", full_path] elsif File.file?(File.join(full_path, "Makefile.am")) toplevel_dir = find_topmost_directory_containing(full_path) do |dir| configure_ac = File.join(dir, "configure.ac") configure_in = File.join(dir, "configure.in") File.file?(configure_ac) || File.file?(configure_in) end ["autotools_package", toplevel_dir] if toplevel_dir elsif File.file?(File.join(full_path, "configure.ac")) || File.file?(File.join(full_path, "configure.in")) ["autotools_package", full_path] elsif File.file?(File.join(full_path, "CMakeLists.txt")) toplevel_dir = find_topmost_directory_containing(full_path) do |dir| cmakelists = File.join(dir, "CMakeLists.txt") File.file?(cmakelists) && (File.read(cmakelists) =~ /PROJECT/i) end toplevel_dir ||= find_topmost_directory_containing( full_path, "CMakeLists.txt" ) manifest_xml = File.join(toplevel_dir, "manifest.xml") package_xml = File.join(toplevel_dir, "package.xml") if File.file?(package_xml) && !File.file?(manifest_xml) return "catkin_package", toplevel_dir end ["cmake_package", toplevel_dir] elsif (dir = (find_topmost_directory_containing(full_path, "Rakefile") || find_topmost_directory_containing(full_path, "lib/*.rb"))) ["ruby_package", dir] elsif (dir = (find_topmost_directory_containing(full_path, "setup.py") || find_topmost_directory_containing(full_path, pyglob))) ["python_package", dir] end end
@api private
Helper method that extracts the package name from a Rake-style package definition (e.g. package_name => package_deps)
# File lib/autoproj/autobuild_extensions/dsl.rb, line 49 def self.package_name_from_options(spec) if spec.kind_of?(Hash) spec.to_a.first.first.to_str else spec.to_str end end
Register a block that should be called after a set of package(s) have been imported
@overload post_import
(&block) register the block for all packages @overload post_import
(*packages, &block)
@param [Array<Autobuild::Package,PackageDefinition>] packages
# File lib/autoproj/base.rb, line 48 def self.post_import(*packages, &block) if packages.empty? @post_import_blocks[nil] << block else packages.each do |pkg| # We use Autobuild packages as keys pkg = pkg.autobuild if pkg.respond_to?(:autobuild) @post_import_blocks[pkg] << block end end end
@deprecated use workspace.prefix_dir instead
# File lib/autoproj/system.rb, line 76 def self.prefix Autoproj.warn_deprecated(__method__, "workspace.prefix_dir") workspace.prefix_dir end
@deprecated use workspace.prefix_dir= instead
# File lib/autoproj/system.rb, line 82 def self.prefix=(path) Autoproj.warn_deprecated(__method__, "workspace.prefix_dir=") workspace.prefix_dir = path end
@deprecated call Autoproj.env
.prepare directly
# File lib/autoproj/environment.rb, line 138 def self.prepare_environment(env = Autoproj.env, manifest = Autoproj.manifest) env.prepare(manifest) end
# File lib/autoproj/options.rb, line 80 def self.reconfigure? @reconfigure end
@deprecated use workspace.remotes_dir instead
# File lib/autoproj/system.rb, line 101 def self.remotes_dir Autoproj.warn_deprecated(__method__, "use workspace.remotes_dir instead") workspace.remotes_dir end
Deregister a source handler defined with {.add_source_handler}
# File lib/autoproj/vcs_definition.rb, line 356 def self.remove_source_handler(name) @custom_source_handlers.delete(name) end
# File lib/autoproj/reporter.rb, line 95 def self.report(root_dir: nil, silent: nil, debug: Autobuild.debug, on_package_success: :report, on_package_failures: Autobuild::Reporting .default_report_on_package_failures) reporter = Autoproj::Reporter.new Autobuild::Reporting << reporter interrupted = nil unless silent.nil? on_package_success = silent ? :silent : :report end silent_errors = %I[report_silent exit_silent].include?(on_package_failures) package_failures = Autobuild::Reporting.report(on_package_failures: :report_silent) do reporter.reset_timer yield rescue Interrupt => e interrupted = e end if package_failures.empty? raise interrupted if interrupted Autobuild::Reporting.success if on_package_success == :report [] else Autobuild::Reporting.report_finish_on_error( package_failures, on_package_failures: on_package_failures, interrupted_by: interrupted ) end rescue CLI::CLIException, InvalidWorkspace, ConfigError => e if silent_errors [e] elsif on_package_failures == :raise raise e elsif on_package_failures == :report Autoproj.not_silent do Autoproj.error e.message end [e] elsif on_package_failures == :exit Autoproj.not_silent do Autoproj.error e.message end exit 1 end rescue SystemExit raise ensure report_interrupt if !silent_errors && interrupted Autobuild::Reporting.remove(reporter) if reporter end
# File lib/autoproj/reporter.rb, line 46 def self.report_interrupt(io = STDERR) io.puts io.puts color("Interrupted by user", :red, :bold) end
@deprecated use config.reset instead
# File lib/autoproj/options.rb, line 9 def self.reset_option(key) Autoproj.warn_deprecated __method__, "use the API on Autoproj.config (from Autoproj::Configuration) instead" config.reset(key) end
Resolves all possible variable references from constants
I.e. replaces variables by their values, so that no value in constants
refers to variables defined in constants
# File lib/autoproj/variable_expansion.rb, line 97 def self.resolve_constant_definitions(constants, definitions = Hash.new) definitions = definitions.merge(constants) all_resolutions = Hash.new resolution_cache = Hash.new constants.each do |key, value| all_resolutions[key] = resolve_one_constant(key, value, resolution_cache, definitions) end all_resolutions end
# File lib/autoproj/variable_expansion.rb, line 86 def self.resolve_one_constant(name, value, result, definitions) result[name] ||= single_expansion(value, result) do |missing_name| result[missing_name] = resolve_one_constant(missing_name, definitions[missing_name], result, definitions) end end
Returns the root directory of the current autoproj installation.
If the current directory is not in an autoproj installation, raises UserError
.
# File lib/autoproj/system.rb, line 33 def self.root_dir(dir = Dir.pwd) if @root_dir return @root_dir elsif !dir @root_dir = ni return end path = Autoproj.find_workspace_dir(dir) raise UserError, "not in a Autoproj installation" unless path path end
Forcefully sets the root directory
This is mostly useful during bootstrapping (i.e. when the search would fail)
# File lib/autoproj/system.rb, line 21 def self.root_dir=(dir) if @workspace && dir != @workspace.root_dir raise WorkspaceAlreadyCreated, "cannot switch global root directory after a workspace object got created" end @root_dir = dir end
@deprecated use Workspace.config
.ruby_executable instead, or
Autoproj.config.ruby_executable if you don't have a workspace context object
# File lib/autoproj/autobuild_extensions/dsl.rb, line 10 def self.ruby_executable config.ruby_executable end
Run the provided command as root, using sudo to gain root access
# File lib/autoproj/system.rb, line 130 def self.run_as_root(*args, env: workspace.env) unless system(Autobuild.tool_in_path("sudo", env: env), *args) raise "failed to run #{args.join(' ')} as root" end end
Run the provided command as user
# File lib/autoproj/system.rb, line 125 def self.run_as_user(*args) raise "failed to run #{args.join(' ')}" unless system(*args) end
# File lib/autoproj/options.rb, line 68 def self.save_config Autoproj.warn_deprecated __method__, "use the API on Autoproj.config (from Autoproj::Configuration) instead" config.save end
@deprecated use Autoproj.env
.isolate instead
# File lib/autoproj/environment.rb, line 128 def self.set_initial_env isolate_environment end
@deprecated use config.shell_helpers= instead
# File lib/autoproj/options.rb, line 63 def self.shell_helpers=(flag) Autoproj.warn_deprecated __method__, "use the API on Autoproj.config (from Autoproj::Configuration) instead" config.shell_helpers = flag end
@deprecated use config.shell_helpers? instead
# File lib/autoproj/options.rb, line 57 def self.shell_helpers? Autoproj.warn_deprecated __method__, "use the API on Autoproj.config (from Autoproj::Configuration) instead" config.shell_helpers? end
# File lib/autoproj/reporter.rb, line 16 def self.silent(&block) Autobuild.silent(&block) end
# File lib/autoproj/reporter.rb, line 10 def silent=(value) Autobuild.silent = value end
# File lib/autoproj/reporter.rb, line 6 def silent? Autobuild.silent? end
Does a non-recursive expansion in data
of configuration variables ($VAR_NAME) listed in definitions
If the values listed in definitions
also contain configuration variables, they do not get expanded
# File lib/autoproj/variable_expansion.rb, line 34 def self.single_expansion(data, definitions) return data unless data.respond_to?(:to_str) data = data.gsub(/(.|^)\$(\w+)/) do |constant_name| prefix = constant_name[0, 1] next(constant_name[1..-1]) if prefix == "\\" if prefix == "$" prefix = "" constant_name = constant_name[1..-1] else constant_name = constant_name[2..-1] end value = definitions[constant_name] if value.nil? if !block_given? || !(value = yield(constant_name)) raise ArgumentError, "cannot find a definition for $#{constant_name}" end end "#{prefix}#{value}" end data end
@deprecated use config.get(key) instead
# File lib/autoproj/options.rb, line 27 def self.user_config(key) Autoproj.warn_deprecated __method__, "use the API on Autoproj.config (from Autoproj::Configuration) instead" config.get(key) end
Look into dir
, searching for shared libraries. For each library, display a warning message if this library has undefined symbols.
# File lib/autoproj/system.rb, line 138 def self.validate_solib_dependencies(dir, exclude_paths = []) Find.find(File.expand_path(dir)) do |name| next unless name =~ /\.so$/ next if exclude_paths.find { |p| name =~ p } output = `ldd -r #{name} 2>&1` if output =~ /undefined symbol/ Autoproj.message(" WARN: #{name} has undefined symbols", :magenta) end end end
Displays a warning message
# File lib/autoproj/reporter.rb, line 42 def self.warn(message, *style) Autobuild.warn(message, *style) end
# File lib/autoproj.rb, line 82 def self.warn_deprecated(method, msg = nil, level = 0) if level >= @warn_deprecated_level if msg Autoproj.warn "#{method} is deprecated, #{msg}" else Autoproj.warn msg end caller.each { |l| Autoproj.warn " #{l}" } end end
# File lib/autoproj.rb, line 73 def self.warn_deprecated_level @warn_deprecated_level end
# File lib/autoproj.rb, line 77 def self.warn_deprecated_level=(level) @warn_deprecated_level = level end
# File lib/autoproj/workspace.rb, line 938 def self.workspace @workspace ||= Workspace.new(root_dir) end
# File lib/autoproj/workspace.rb, line 942 def self.workspace=(ws) @workspace = ws self.root_dir = ws&.root_dir end