0

I want to parse a Gemfile.lock file as a dependencies tree. I've noticed that the indents indicates the structure of the dependencies tree like in this example below:

GEM
  remote: https://rubygems.org/
  specs:
    websocket-eventmachine-base (1.2.0)
      eventmachine (~> 1.0)

Meaning that the tree will be: websocket-eventmachine-base -> eventmachine

I've been trying to check what would be the maximum depth, but couldn't find any documentation about it. So far I saw the maximum is depth of 2 (dependencies and his sub-dependencies).

Can the depth be deeper than 2?

In case it can -

A root dependency has indent of 4 spaces, his sub-dependencies will have indent of 6, can I assume the next layer will be 8?

Thanks!

Tomer S
  • 900
  • 1
  • 10
  • 21
  • Does this help: https://stackoverflow.com/questions/44681231/how-to-list-ruby-production-only-dependencies-using-gemfile-lock-and-lockfilepar – engineersmnky Dec 05 '22 at 16:53
  • it is, but the below answer was directly referred to the source code so it was easier to understand :) thanks – Tomer S Dec 06 '22 at 06:37

1 Answers1

1

It will never go beyond gem -> dependency, because the dependencies aren't represented as deeply nested trees. Another approach is taken: if gem A depends on B and C, B depends on D with certain constraints and C depend on D with certain constraints, the structure of Gemfile.lock will the the following relatively flat one:

...
GEM
  remote: <...>
  specs:
    A (...)
      B (...)
      C (...)
    B (...)
      D (<constraint_1>)
    C (...)
      D (<constraint_2>)
    D (version)
...

where version will be the result of dependency resolution machinery (something, that satisfies both constraint_1 and constraint_2)

For the particular indentations you can always refer to the source, but beware of dragons - this is not part of the public contract, so the implementation can be changed by the maintainers without any prior deprecation warnings and things like that.

Konstantin Strukov
  • 2,899
  • 1
  • 10
  • 14