Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(RE-16095) Abandon fustigit in favor of build-uri. #840

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](https://semver.org).
This changelog adheres to [Keep a CHANGELOG](https://keepachangelog.com).

## [Unreleased]
### Changed
(RE-16095) Abandon fustigit in favor of build-uri. build-uri provides similar functionality
without the monkey-patching


## [0.45.0] - 2024-02-16
### Added
Expand Down
1 change: 0 additions & 1 deletion lib/vanagon/component/source.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'fustigit'
require 'vanagon/logger'
require 'vanagon/component/source/http'
require 'vanagon/component/source/git'
Expand Down
4 changes: 2 additions & 2 deletions lib/vanagon/component/source/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This stupid library requires a capital 'E' in its name
# but it provides a wealth of useful constants
require 'English'
require 'fustigit'
require 'build/uri'
require 'git/basic_submodules'
require 'logger'
require 'timeout'
Expand Down Expand Up @@ -98,7 +98,7 @@ def initialize(url, workdir:, **options) # rubocop:disable Metrics/AbcSize
opts = default_options.merge(options.reject { |k, v| v.nil? })

# Ensure that #url returns a URI object
@url = URI.parse(url.to_s)
@url = Build::URI.parse(url.to_s)
@log_url = @url.host + @url.path unless @url.host.nil? || @url.path.nil?
@ref = opts[:ref]
@dirname = opts[:dirname]
Expand Down
3 changes: 2 additions & 1 deletion lib/vanagon/component/source/rewrite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ def parse_and_rewrite(uri)
return uri if rewrite_rules.empty?
if !!uri.match(/^git:http/)
VanagonLogger.info <<-HERE.undent
`fustigit` parsing doesn't get along with how we specify the source
`build-uri` parsing doesn't get along with how we specify the source
type by prefixing `git`. As `rewrite_rules` are deprecated, we'll
replace `git:http` with `http` in your uri. At some point this will
break.
HERE
# build-uri does not support git:http://host/path
uri.sub!(/^git:http/, 'http')
end
url = URI.parse(uri)
Expand Down
130 changes: 74 additions & 56 deletions spec/lib/vanagon/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,57 @@
OpenStruct.new(:settings => {})
end

let(:project_block) {
let(:project_block) do
"project 'test-fixture' do |proj|
proj.component 'some-component'
end"
}
end

let(:upstream_project_block) {
let(:upstream_project_block) do
"project 'upstream-test' do |proj|
proj.setting(:test, 'upstream-test')
end"
}
end

let(:inheriting_project_block) {
let(:inheriting_project_block) do
"project 'inheritance-test' do |proj|
proj.inherit_settings 'upstream-test', 'git://some.url', 'master'
end"
}
end

let(:inheriting_project_block_with_settings) {
let(:inheriting_project_block_with_settings) do
"project 'inheritance-test' do |proj|
proj.setting(:merged, 'yup')
proj.inherit_settings 'upstream-test', 'git://some.url', 'master'
end"
}
end

let(:preset_inheriting_project_block) {
let(:preset_inheriting_project_block) do
"project 'inheritance-test' do |proj|
proj.setting(:test, 'inheritance-test')
proj.inherit_settings 'upstream-test', 'git://some.url', 'master'
end"
}
end

let(:postset_inheriting_project_block) {
let(:postset_inheriting_project_block) do
"project 'inheritance-test' do |proj|
proj.inherit_settings 'upstream-test', 'git://some.url', 'master'
proj.setting(:test, 'inheritance-test')
end"
}
end

let (:dummy_platform_settings) {
let (:dummy_platform_settings) do
plat = Vanagon::Platform::DSL.new('debian-6-i386')
plat.instance_eval("platform 'debian-6-i386' do |plat|
plat.servicetype 'sysv'
plat.servicedir '/etc/init.d'
plat.defaultdir '/etc/default'
settings[:platform_test] = 'debian'
end")
plat.instance_eval <<-END_EVAL, __FILE__, __LINE__ + 1
platform 'debian-6-i386' do |plat|
plat.servicetype 'sysv'
plat.servicedir '/etc/init.d'
plat.defaultdir '/etc/default'
settings[:platform_test] = 'debian'
end
END_EVAL
plat._platform
}
end


describe '#vendor=' do
Expand All @@ -71,7 +73,8 @@

it 'fails if vendor field does not include email address' do
project = Vanagon::Project.new('vendor-test', dummy_platform)
expect { project.vendor = bad_vendor }.to raise_error(Vanagon::Error, /Project vendor field must include email address/)
expect { project.vendor = bad_vendor }
.to raise_error(Vanagon::Error, /Project vendor field must include email address/)
end

it 'sets project vendor to the supplied value' do
Expand All @@ -98,7 +101,6 @@
end

describe '#get_root_directories' do

before do
allow_any_instance_of(Vanagon::Project::DSL).to receive(:puts)
allow(Vanagon::Driver).to receive(:configdir).and_return(configdir)
Expand All @@ -108,22 +110,25 @@
let(:test_sets) do
[
{
:directories => ["/opt/puppetlabs/bin", "/etc/puppetlabs", "/var/log/puppetlabs", "/etc/puppetlabs/puppet", "/opt/puppetlabs"],
:directories => ["/opt/puppetlabs/bin", "/etc/puppetlabs", "/var/log/puppetlabs",
"/etc/puppetlabs/puppet", "/opt/puppetlabs"],
:results => ["/opt/puppetlabs", "/etc/puppetlabs", "/var/log/puppetlabs"],
},
{
:directories => ["/opt/puppetlabs/bin", "/etc/puppetlabs", "/var/log/puppetlabs", "/etc/puppetlabs/puppet", "/opt/puppetlabs/lib"],
:results => ["/opt/puppetlabs/bin", "/etc/puppetlabs", "/var/log/puppetlabs", "/opt/puppetlabs/lib"],
:directories => ["/opt/puppetlabs/bin", "/etc/puppetlabs", "/var/log/puppetlabs",
"/etc/puppetlabs/puppet", "/opt/puppetlabs/lib"],
:results => ["/opt/puppetlabs/bin", "/etc/puppetlabs", "/var/log/puppetlabs",
"/opt/puppetlabs/lib"],
},
]
end

it 'returns only the highest level directories' do
test_sets.each do |set|
expect(component).to receive(:directories).and_return([])
allow(component).to receive(:directories).and_return([])
proj = Vanagon::Project::DSL.new('test-fixture', configdir, platform, [])
proj.instance_eval(project_block)
set[:directories].each {|dir| proj.directory dir }
set[:directories].each { |dir| proj.directory dir }
expect(proj._project.get_root_directories.sort).to eq(set[:results].sort)
end
end
Expand All @@ -132,16 +137,19 @@
describe "#load_upstream_settings" do
before(:each) do
# stub out all of the git methods so we don't actually clone
allow(Vanagon::Component::Source::Git).to receive(:valid_remote?).with(URI.parse('git://some.url')).and_return(true)
allow(Vanagon::Component::Source::Git)
.to receive(:valid_remote?)
.with(Build::URI.parse('git://some.url'))
.and_return(true)
git_source = Vanagon::Component::Source::Git.new('git://some.url', workdir: Dir.getwd)
allow(Vanagon::Component::Source::Git).to receive(:new).and_return(git_source)
expect(git_source).to receive(:fetch).and_return(true)
allow(git_source).to receive(:fetch).and_return(true)

# stubs for the upstream project
upstream_proj = Vanagon::Project::DSL.new('upstream-test', configdir, upstream_platform, [])
upstream_proj.instance_eval(upstream_project_block)
expect(Vanagon::Project).to receive(:load_project).and_return(upstream_proj._project)
expect(Vanagon::Platform).to receive(:load_platform).and_return(upstream_platform)
allow(Vanagon::Project).to receive(:load_project).and_return(upstream_proj._project)
allow(Vanagon::Platform).to receive(:load_platform).and_return(upstream_platform)

class Vanagon
class Project
Expand Down Expand Up @@ -182,8 +190,8 @@ class Project
before do
allow(Vanagon::Component)
.to receive(:load_component)
.with('some-component', any_args)
.and_return(component)
.with('some-component', any_args)
.and_return(component)
end

it 'loads settings set in platforms' do
Expand Down Expand Up @@ -232,16 +240,16 @@ class Project
it "fails if downloading over HTTP without a valid sha1sum URI" do
allow(Vanagon::Component::Source::Http)
.to receive(:valid_url?)
.with(http_yaml_uri)
.and_return(true)
.with(http_yaml_uri)
.and_return(true)
http_source = instance_double(Vanagon::Component::Source::Http)
allow(Vanagon::Component::Source).to receive(:source).and_return(http_source)
allow(http_source).to receive(:verify).and_return(true)

expect { project.load_yaml_settings(http_yaml_uri) }.to raise_error(Vanagon::Error)
end

context "given a valid source" do
context "with a valid source" do
before(:each) do
local_source = instance_double(Vanagon::Component::Source::Local)
allow(local_source).to receive(:fetch)
Expand Down Expand Up @@ -425,7 +433,7 @@ class Project
@proj = Vanagon::Project.new('test-project', platform)
end

it 'should generate a hash with the expected build metadata' do
it 'generates a hash with the expected build metadata' do
comp1 = Vanagon::Component.new('test-component1', {}, {})
comp1.version = '1.0.0'
@proj.components << comp1
Expand All @@ -439,7 +447,7 @@ class Project
})
end

it 'should call pretty-print when we want pretty json' do
it 'calls pretty-print when we want pretty json' do
comp1 = Vanagon::Component.new('test-component1', {}, {})
comp1.version = '1.0.0'
@proj.components << comp1
Expand All @@ -454,6 +462,7 @@ class Project
include FakeFS::SpecHelpers
let(:platform_name) { 'el-7-x86_64' }
let(:platform) { Vanagon::Platform.new(platform_name) }

before(:each) do
class Vanagon
class Project
Expand All @@ -465,7 +474,7 @@ class Project
@proj = Vanagon::Project.new('test-project', platform)
end

it 'should generate a file with the expected build metadata' do
it 'generates a file with the expected build metadata' do
correct_sample_metadata = {
'packaging_type' => { 'vanagon' => '0.0.0-rspec' },
'version' => '123abcde',
Expand Down Expand Up @@ -495,9 +504,6 @@ class Project


describe '#publish_yaml_settings' do
let(:platform_name) { 'aix-7.2-ppc' }
let(:platform) { Vanagon::Platform.new(platform_name) }

subject(:project) do
project = Vanagon::Project.new('test-project', platform)
project.settings = { key: 'value' }
Expand All @@ -506,8 +512,16 @@ class Project
project
end

let(:yaml_output_path) { File.expand_path("test-project-version.#{platform_name}.settings.yaml", "output") }
let(:sha1_output_path) { File.expand_path("test-project-version.#{platform_name}.settings.yaml.sha1", "output") }
let(:platform_name) { 'aix-7.2-ppc' }
let(:platform) { Vanagon::Platform.new(platform_name) }


let(:yaml_output_path) do
File.expand_path("test-project-version.#{platform_name}.settings.yaml", "output")
end
let(:sha1_output_path) do
File.expand_path("test-project-version.#{platform_name}.settings.yaml.sha1", "output")
end

let(:yaml_file) { double('yaml_file') }
let(:sha1_file) { double('sha1_file') }
Expand All @@ -516,10 +530,10 @@ class Project
let(:sha1_object) { instance_double(Digest::SHA1, hexdigest: sha1_content) }

it 'writes project settings as yaml and a sha1sum for the settings to the output directory' do
expect(File).to receive(:open).with(yaml_output_path, "w").and_yield(yaml_file)
expect(Digest::SHA1).to receive(:file).with(yaml_output_path).and_return(sha1_object)
expect(File).to receive(:open).with(sha1_output_path, "w").and_yield(sha1_file)
expect(yaml_file).to receive(:write).with({key: 'value'}.to_yaml)
allow(File).to receive(:open).with(yaml_output_path, "w").and_yield(yaml_file)
allow(Digest::SHA1).to receive(:file).with(yaml_output_path).and_return(sha1_object)
allow(File).to receive(:open).with(sha1_output_path, "w").and_yield(sha1_file)
expect(yaml_file).to receive(:write).with({ key: 'value' }.to_yaml)
expect(sha1_file).to receive(:puts).with(sha1_content)
expect { project.publish_yaml_settings(platform) }.not_to raise_error
end
Expand All @@ -545,35 +559,39 @@ class Project
describe '#generate_package' do
it "builds packages by default" do
platform = Vanagon::Platform::DSL.new('el-7-x86_64')
platform.instance_eval("platform 'el-7-x86_6' do |plat| end")
platform.instance_eval("platform 'el-7-x86_6' do |plat| end", __FILE__, __LINE__)
proj = Vanagon::Project::DSL.new('test-fixture', configdir, platform._platform, [])
expect(platform._platform).to receive(:generate_package) { ["# making a package"] }
allow(platform._platform).to receive(:generate_package).and_return(["# making a package"])
expect(proj._project.generate_package).to eq(["# making a package"])
end

it "builds packages and archives if configured for both" do
platform = Vanagon::Platform::DSL.new('el-7-x86_64')
platform.instance_eval("platform 'el-7-x86_6' do |plat| end")
platform.instance_eval("platform 'el-7-x86_6' do |plat| end", __FILE__, __LINE__)
proj = Vanagon::Project::DSL.new('test-fixture', configdir, platform._platform, [])
proj.generate_archives(true)
expect(platform._platform).to receive(:generate_package) { ["# making a package"] }
expect(platform._platform).to receive(:generate_compiled_archive) { ["# making an archive"] }
allow(platform._platform).to receive(:generate_package).and_return(["# making a package"])
allow(platform._platform)
.to receive(:generate_compiled_archive)
.and_return(["# making an archive"])
expect(proj._project.generate_package).to eq(["# making a package", "# making an archive"])
end

it "can build only archives" do
platform = Vanagon::Platform::DSL.new('el-7-x86_64')
platform.instance_eval("platform 'el-7-x86_6' do |plat| end")
platform.instance_eval("platform 'el-7-x86_6' do |plat| end", __FILE__, __LINE__)
proj = Vanagon::Project::DSL.new('test-fixture', configdir, platform._platform, [])
proj.generate_archives(true)
proj.generate_packages(false)
expect(platform._platform).to receive(:generate_compiled_archive) { ["# making an archive"] }
allow(platform._platform)
.to receive(:generate_compiled_archive)
.and_return(["# making an archive"])
expect(proj._project.generate_package).to eq(["# making an archive"])
end

it "builds nothing if that's what you really want" do
platform = Vanagon::Platform::DSL.new('el-7-x86_64')
platform.instance_eval("platform 'el-7-x86_6' do |plat| end")
platform.instance_eval("platform 'el-7-x86_6' do |plat| end", __FILE__, __LINE__)
proj = Vanagon::Project::DSL.new('test-fixture', configdir, platform._platform, [])
proj.generate_packages(false)
expect(proj._project.generate_package).to eq([])
Expand Down
4 changes: 2 additions & 2 deletions vanagon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Gem::Specification.new do |gem|
# - MIT licensed: https://rubygems.org/gems/git
gem.add_runtime_dependency('git', '~> 1.13.0')
# Parse scp-style triplets like URIs; used for Git source handling.
# - MIT licensed: https://rubygems.org/gems/fustigit
gem.add_runtime_dependency('fustigit', '~> 0.3.0')
# - MIT licensed: https://rubygems.org/gems/build-uri
gem.add_runtime_dependency('build-uri', '~> 1.0')
# Handle locking hardware resources
# - ASL v2 licensed: https://rubygems.org/gems/lock_manager
gem.add_runtime_dependency('lock_manager', '>= 0')
Expand Down
Loading