Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve detection of unsupported cargo toolchains #8181

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion cargo/lib/dependabot/cargo/file_updater/lockfile_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def run_shell_command(command, fingerprint:)
# returns a non-zero status
return if process.success?

if stdout.include?("usage of sparse registries requires `-Z sparse-registry`")
if using_old_toolchain?(stdout)
raise Dependabot::DependencyFileNotEvaluatable, "Dependabot only supports toolchain 1.68 and up."
end

Expand All @@ -170,6 +170,15 @@ def run_shell_command(command, fingerprint:)
)
end

def using_old_toolchain?(message)
return true if message.include?("usage of sparse registries requires `-Z sparse-registry`")

version_log = /rust version (?<version>\d.\d+)/.match(message)
return false unless version_log

version_class.new(version_log[:version]) < version_class.new("1.68")
end

def write_temporary_dependency_files
write_temporary_manifest_files
write_temporary_path_dependency_files
Expand Down Expand Up @@ -386,6 +395,10 @@ def toolchain
def virtual_manifest?(file)
!file.content.include?("[package]")
end

def version_class
dependency.version_class
end
end
end
end
Expand Down
35 changes: 25 additions & 10 deletions cargo/lib/dependabot/cargo/update_checker/version_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,26 @@ def handle_cargo_errors(error)
return nil
end

if error.message.include?("usage of sparse registries requires `-Z sparse-registry`")
if using_old_toolchain?(error.message)
raise Dependabot::DependencyFileNotEvaluatable, "Dependabot only supports toolchain 1.68 and up."
end

raise Dependabot::DependencyFileNotResolvable, error.message if resolvability_error?(error.message)

raise error
raise
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/PerceivedComplexity

def using_old_toolchain?(message)
return true if message.include?("usage of sparse registries requires `-Z sparse-registry`")

version_log = /rust version (?<version>\d.\d+)/.match(message)
return false unless version_log

version_class.new(version_log[:version]) < version_class.new("1.68")
end

def unreachable_git_urls
return @unreachable_git_urls if defined?(@unreachable_git_urls)

Expand Down Expand Up @@ -295,7 +304,11 @@ def resolvability_error?(message)
return true if message.match?(/feature `[^\`]+` is required/)
return true if message.include?("unexpected end of input while parsing major version number")

!original_requirements_resolvable?
original_requirements_resolvable = original_requirements_resolvable?

return false if original_requirements_resolvable == :unknown

!original_requirements_resolvable
end

def original_requirements_resolvable?
Expand All @@ -310,13 +323,15 @@ def original_requirements_resolvable?

true
rescue SharedHelpers::HelperSubprocessFailed => e
raise unless e.message.include?("no matching version") ||
e.message.include?("failed to select a version") ||
e.message.include?("no matching package named") ||
e.message.include?("failed to parse manifest") ||
e.message.include?("failed to update submodule")

false
if e.message.include?("no matching version") ||
e.message.include?("failed to select a version") ||
e.message.include?("no matching package named") ||
e.message.include?("failed to parse manifest") ||
e.message.include?("failed to update submodule")
false
else
:unknown
end
end

def workspace_native_library_update_error?(message)
Expand Down