Class: Dependabot::Bazel::FileFetcher::IncludeExtractor
- Inherits:
-
Object
- Object
- Dependabot::Bazel::FileFetcher::IncludeExtractor
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/bazel/file_fetcher/include_extractor.rb
Overview
Extracts include() statements from MODULE.bazel files and fetches the included files. Bazel’s include() directive allows splitting MODULE.bazel content across multiple files. The include() statement uses Bazel label syntax: include(“//path:file.MODULE.bazel”) See bazel.build/rules/lib/globals/module#include
Instance Method Summary collapse
- #fetch_included_files ⇒ Object
-
#initialize(module_file:, fetcher:) ⇒ IncludeExtractor
constructor
A new instance of IncludeExtractor.
Constructor Details
#initialize(module_file:, fetcher:) ⇒ IncludeExtractor
Returns a new instance of IncludeExtractor.
24 25 26 27 28 |
# File 'lib/dependabot/bazel/file_fetcher/include_extractor.rb', line 24 def initialize(module_file:, fetcher:) @module_file = module_file @fetcher = fetcher @visited_files = T.let(Set.new, T::Set[String]) end |
Instance Method Details
#fetch_included_files ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dependabot/bazel/file_fetcher/include_extractor.rb', line 32 def fetch_included_files files = T.let([], T::Array[DependencyFile]) directories = T.let(Set.new, T::Set[String]) content = T.must(@module_file.content) include_paths = extract_include_paths(content) include_paths.each do |path| next if @visited_files.include?(path) @visited_files.add(path) fetched_file = @fetcher.send(:fetch_file_if_present, path) next unless fetched_file files << fetched_file dir = File.dirname(path) directories.add(dir) unless dir == "." nested_files, nested_dirs = fetch_nested_includes(fetched_file) files.concat(nested_files) nested_dirs.each { |d| directories.add(d) } end [files, directories] end |