summaryrefslogtreecommitdiff
path: root/lib/license
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-08-04 14:51:49 -0600
committermo khan <mo.khan@gmail.com>2020-08-07 12:44:29 -0600
commitca3e93e2f67707a016b28e58f8374522a1fb68f0 (patch)
tree63f5341b5b2ef4732cd0ec3717f9bb01378eb507 /lib/license
parent71e548e24191f9afe53f5679906d464b24c5c985 (diff)
Add limited network support for Cargo projects
* Add test to scan cargo project with packages from a private registry * Synchronize mono cert store * Wipe nuget package cache before specs * Compress /usr/local/share * Exclude development dependencies * Add CHANGELOG entry
Diffstat (limited to 'lib/license')
-rw-r--r--lib/license/finder/ext.rb1
-rw-r--r--lib/license/finder/ext/cargo.rb84
-rw-r--r--lib/license/management/version.rb2
3 files changed, 86 insertions, 1 deletions
diff --git a/lib/license/finder/ext.rb b/lib/license/finder/ext.rb
index e524771..fb593cc 100644
--- a/lib/license/finder/ext.rb
+++ b/lib/license/finder/ext.rb
@@ -2,6 +2,7 @@
require 'license/finder/ext/bower'
require 'license/finder/ext/bundler'
+require 'license/finder/ext/cargo'
require 'license/finder/ext/composer'
require 'license/finder/ext/conan'
require 'license/finder/ext/dependency'
diff --git a/lib/license/finder/ext/cargo.rb b/lib/license/finder/ext/cargo.rb
new file mode 100644
index 0000000..20b1b03
--- /dev/null
+++ b/lib/license/finder/ext/cargo.rb
@@ -0,0 +1,84 @@
+# frozen_string_literal: true
+
+module LicenseFinder
+ class Cargo < PackageManager
+ SENTINEL = ' -|- '
+
+ def installed?(*)
+ true
+ end
+
+ def prepare
+ create_vendor_path
+
+ within_project_path do
+ shell.execute([:dpkg, '-i', '/opt/toolcache/rust*.deb'])
+ shell.execute([:asdf, :reshim])
+ shell.execute([:env, '|', :sort, '&&', :asdf, :exec, :cargo, :fetch, '-vv'], env: default_env)
+ end
+ end
+
+ def current_packages
+ within_project_path do
+ stdout, _stderr, status = shell.execute(scan_command)
+ status.success? ? parse(stdout) : []
+ end
+ end
+
+ def possible_package_paths
+ [
+ project_path.join('Cargo.lock'),
+ project_path.join('Cargo.toml')
+ ]
+ end
+
+ private
+
+ def parse(stdout)
+ stdout.each_line.map do |line|
+ next if line.include?(project_path.to_s)
+
+ map_from(line.chomp)
+ end.compact
+ end
+
+ def scan_command
+ [
+ :asdf, :exec,
+ :cargo, :tree, '--edges=no-dev',
+ "--color=never",
+ "--offline",
+ "--prefix=none",
+ "-f='{p}#{SENTINEL}{l}'"
+ ]
+ end
+
+ def default_env
+ @default_env ||= {
+ 'CARGO_HOME' => vendor_path.to_s,
+ 'CARGO_TARGET_DIR' => vendor_path.to_s,
+ 'HTTP_TIMEOUT' => '10',
+ 'HTTP_CAINFO' => shell.default_certificate_path.to_s,
+ 'TERM' => 'dumb'
+ }
+ end
+
+ def map_from(line)
+ name_version, license = line.split(SENTINEL, 2)
+ name, version = name_version.split(' ', 2)
+
+ Dependency.new(
+ 'Cargo',
+ name,
+ version,
+ detection_path: detected_package_path,
+ install_path: path_to(name, version),
+ spec_licenses: license ? license.split('/') : []
+ )
+ end
+
+ def path_to(name, version)
+ Dir.glob("/opt/asdf/installs/rust/**/registry/src/**/#{name}-#{version}")[0]
+ end
+ end
+end
diff --git a/lib/license/management/version.rb b/lib/license/management/version.rb
index 9e5f556..e3de501 100644
--- a/lib/license/management/version.rb
+++ b/lib/license/management/version.rb
@@ -2,6 +2,6 @@
module License
module Management
- VERSION = '3.20.1'
+ VERSION = '3.21.0'
end
end