Skip to content

Commit

Permalink
More mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed May 6, 2024
1 parent 05439c5 commit 5b5eda0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
29 changes: 14 additions & 15 deletions Library/Homebrew/sbom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class SBOM
# Instantiates a {SBOM} for a new installation of a formula.
sig { params(formula: Formula, compiler: T.nilable(String), stdlib: T.nilable(String)).returns(T.attached_class) }
def self.create(formula, compiler: nil, stdlib: nil)
build = formula.build
runtime_deps = formula.runtime_dependencies(undeclared: false)
runtime_deps = formula.runtime_formula_dependencies(undeclared: false)

attributes = {
name: formula.name,
homebrew_version: HOMEBREW_VERSION,
spdxfile: formula.prefix/FILENAME,
built_as_bottle: build.bottle?,
built_as_bottle: formula.build.bottle?,
installed_as_dependency: false,
installed_on_request: false,
poured_from_bottle: false,
Expand All @@ -38,7 +38,7 @@ def self.create(formula, compiler: nil, stdlib: nil)
compiler:,
stdlib:,
aliases: formula.aliases,
runtime_dependencies: SBOM.runtime_deps_hash(formula, runtime_deps),
runtime_dependencies: SBOM.runtime_deps_hash(runtime_deps),
arch: Hardware::CPU.arch,
license: SPDX.license_expression_to_string(formula.license),
built_on: DevelopmentTools.build_system_info,
Expand Down Expand Up @@ -294,19 +294,18 @@ def to_spdx_sbom
}
end

sig { params(formula: Formula, deps: T::Array[Dependency]).returns(T::Array[T::Hash[Symbol, String]]) }
def self.runtime_deps_hash(formula, deps)
sig { params(deps: T::Array[Formula]).returns(T::Array[T::Hash[Symbol, String]]) }
def self.runtime_deps_hash(deps)
deps.map do |dep|
f = dep.to_formula
{
full_name: f.full_name,
name: f.name,
version: f.version.to_s,
revision: f.revision,
pkg_version: f.pkg_version.to_s,
declared_directly: formula.deps.include?(dep),
license: SPDX.license_expression_to_string(f.license),
bottle: f.bottle_hash,
full_name: dep.full_name,
name: dep.name,
version: dep.version.to_s,
revision: dep.revision,
pkg_version: dep.pkg_version.to_s,
declared_directly: true,
license: SPDX.license_expression_to_string(dep.license),
bottle: dep.bottle_hash,
}
end
end
Expand Down
12 changes: 12 additions & 0 deletions Library/Homebrew/test/sbom_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
uses_from_macos "zlib"
end

beanstalkd = formula "beanstalkd" do
url "one-1.1"
end

zlib = formula "zlib" do
url "two-1.1"
end

allow(f).to receive_messages(
runtime_formula_dependencies: [beanstalkd, zlib],
)

sbom = described_class.create(f)
expect(sbom).to be_valid
end
Expand Down

0 comments on commit 5b5eda0

Please sign in to comment.