Home > Blockchain >  Maximum depth of dependencies tree in Gemfile.lock
Maximum depth of dependencies tree in Gemfile.lock

Time:12-06

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!

CodePudding user response:

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.

  • Related