jeremyjh / dialyxir

Mix tasks to simplify use of Dialyzer in Elixir projects.
Apache License 2.0
1.69k stars 141 forks source link

PLT hash is inconsistent #395

Closed thomas9911 closed 4 years ago

thomas9911 commented 4 years ago

Environment

Elixir 1.9.1 OTP 20 Dialyxir 1.0.0

Current behavior

The current hash of the PLT is calculated based on a Mix.Dep.Lock.read() map, which is turned into a binary with :erlang.term_to_binary(). Only the ordering is sometimes different because of the way maps are implemented in Elixir. This means the hash is different even if the mix.lock file and its contents are the same.

Expected behavior

The hash should stay the same if the dependencies are not changed.

Possible solution

instead of a map of the contents of the mix.lock file just use the mix.lock file:

def dependency_hash do
  lock_file = Mix.Dep.Lock.read() |> :erlang.term_to_binary()
  apps = Project.cons_apps()
  apps |> inspect() |> info()
  # current method
  # hash = :crypto.hash(:sha, lock_file <> :erlang.term_to_binary(apps))
  hash = :crypto.hash(:sha, File.read!(Mix.Project.config()[:lockfile]) <> :erlang.term_to_binary(apps))
  {apps, hash}
end
jeremyjh commented 4 years ago

Thanks for finding and reporting this! A PR is welcome.

asummers commented 4 years ago

I'm in favor of the merged change, but just curious how the "upgrade path" here works. If I have an old hash file, does it update cleanly with the new version?

thomas9911 commented 4 years ago

Next time you run dialyzer it will check the plt and update the hash

jeremyjh commented 4 years ago

Closed by #396.