Skip to content

Commit

Permalink
minimum go version support 1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
jonabc committed Jan 2, 2023
1 parent 5429f28 commit 57ca385
Showing 1 changed file with 1 addition and 36 deletions.
37 changes: 1 addition & 36 deletions lib/licensed/sources/go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,13 @@ def enumerate_dependencies

# Returns an array of dependency package import paths
def packages
dependency_packages =
if go_version < Gem::Version.new("1.11.0")
root_package_deps
else
go_list_deps
end

# don't include go std packages
# don't include packages under the root project that aren't vendored
dependency_packages
go_list_deps
.reject { |pkg| go_std_package?(pkg) }
.reject { |pkg| local_package?(pkg) }
end

# Returns non-ignored packages found from the root packages "Deps" property
def root_package_deps
# check for ignored packages to avoid raising errors calling `go list`
# when ignored package is not found
Parallel.map(Array(root_package["Deps"])) { |name| package_info(name) }
end

# Returns the list of dependencies as returned by "go list -json -deps"
# available in go 1.11
def go_list_deps
Expand Down Expand Up @@ -188,25 +174,13 @@ def non_vendored_import_path(package)
package["ImportPath"]
end

# Returns a hash of information about the package with a given import path
#
# import_path - Go package import path
def package_info(import_path)
JSON.parse(package_info_command(import_path))
end

# Returns package information as a JSON string
#
# args - additional arguments to `go list`, e.g. Go package import path
def package_info_command(*args)
Licensed::Shell.execute("go", "list", "-e", "-json", *Array(args)).strip
end

# Returns the info for the package under test
def root_package
@root_package ||= package_info(".")
end

# Returns whether go source is found
def go_source?
with_configured_gopath { Licensed::Shell.success?("go", "doc") }
Expand All @@ -230,15 +204,6 @@ def gopath
end
end

# Returns the current version of go available, as a Gem::Version
def go_version
@go_version ||= begin
full_version = Licensed::Shell.execute("go", "version").strip
version_string = full_version.gsub(%r{.*go(\d+\.\d+(\.\d+)?).*}, "\\1")
Gem::Version.new(version_string)
end
end

private

# Execute a block with ENV["GOPATH"] set to the value of #gopath.
Expand Down

0 comments on commit 57ca385

Please sign in to comment.