1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

B OpenNebula/one#5919: Add flow ruby dependencies for CLI (#2237)

This commit is contained in:
Daniel Clavijo Coca 2022-07-14 10:28:32 -05:00 committed by GitHub
parent 4d462de8da
commit 1e099dcc5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,15 +19,15 @@
require 'fileutils'
require 'tmpdir'
VERSION = "5.12.13"
VERSION = '5.12.13'
def version
v = VERSION
_, min, incr = v.split(".").collect{|e| e.to_i}
_, min, incr = v.split('.').collect {|e| e.to_i }
if min >= 80 || incr >= 80
v += ".pre"
v += '.pre'
end
v
@ -35,29 +35,29 @@ end
DEFAULTS={
:version => version,
:date => Time.now.strftime("%Y-%m-%d"),
:date => Time.now.strftime('%Y-%m-%d'),
:dependencies => []
}
TEMPLATE=<<EOT
# This file is automatically generated
TEMPLATE=<<~EOT
# This file is automatically generated
Gem::Specification.new do |s|
s.name = '$(NAME)'
s.version = '$(VERSION)'
s.date = '$(DATE)'
s.summary = "$(SUMMARY)"
s.description = "$(DESCRIPTION)"
s.authors = ["OpenNebula"]
s.email = 'contact@opennebula.io'
s.license = 'Apache-2.0'
s.files = [
$(FILES)
]
s.homepage = 'http://opennebula.io'
$(EXECUTABLES)
$(DEPENDENCIES)
end
Gem::Specification.new do |s|
s.name = '$(NAME)'
s.version = '$(VERSION)'
s.date = '$(DATE)'
s.summary = "$(SUMMARY)"
s.description = "$(DESCRIPTION)"
s.authors = ["OpenNebula"]
s.email = 'contact@opennebula.io'
s.license = 'Apache-2.0'
s.files = [
$(FILES)
]
s.homepage = 'http://opennebula.io'
$(EXECUTABLES)
$(DEPENDENCIES)
end
EOT
@ -77,6 +77,10 @@ GEM_DESCRIPTION={
['src/mad/ruby/ActionManager.rb', '/lib'],
['src/mad/ruby/DriverExecHelper.rb', '/lib'],
# other depenencies
['src/flow/lib/models.rb', '/lib'],
['src/flow/lib/models/*.rb', '/lib/models'],
['src/oca/ruby/opennebula/*.rb', '/lib/opennebula'],
['src/authm_mad/remotes/**/*.rb', '/lib/opennebula'],
['src/cloud/common/CloudClient.rb', '/lib/cloud'],
@ -88,7 +92,10 @@ GEM_DESCRIPTION={
:dependencies => [
'nokogiri',
'json',
'rbvmomi'
'rbvmomi',
'treetop', # oneflow
'ipaddress', # oneflow
'parse-cron' # oneflow
]
},
@ -114,18 +121,18 @@ def sane_prefix(prefix)
p=prefix
p.slice!(0) if p[0,1]=='/'
p<<'/' if p[-1,1]!='/'
p.slice!(0) if p[0, 1]=='/'
p<<'/' if p[-1, 1]!='/'
p
end
def file_list(description)
files=Array.new
files=[]
description[:files].each do |f, prefix, exclude|
Dir.glob(f).each do |source|
next if (! exclude.nil?) and (source.match(exclude))
next if !exclude.nil? and source.match(exclude)
files << [source, sane_prefix(prefix)+File.basename(source)]
end
@ -134,14 +141,14 @@ def file_list(description)
files
end
def copy_files(files, source_prefix='', destination_prefix='')
def copy_files(files, source_prefix = '', destination_prefix = '')
files.each do |file|
source=source_prefix+file[0]
destination=destination_prefix+file[1]
dir=File.dirname destination
FileUtils.mkdir_p(dir) if !File.exist?(dir)
FileUtils.mkdir_p(dir) unless File.exist?(dir)
FileUtils.cp(source, destination)
end
@ -154,10 +161,10 @@ def generate_gem_file_list(files)
end
def generate_gem_executable_list(files)
executables=files.
select {|f| f.last.match(/^bin\//) }.
map {|f| "'#{File.basename(f.last)}'" }.
join(", ")
executables=files
.select {|f| f.last.match(%r{^bin/}) }
.map {|f| "'#{File.basename(f.last)}'" }
.join(', ')
if !executables.empty?
" s.executables=[#{executables}]"
@ -168,9 +175,9 @@ end
def generate_dependencies(dependencies)
dependencies.map do |d|
line=" s.add_runtime_dependency "
if Array===d
line<<d.map {|part| "'#{part}'" }.join(", ")
line=' s.add_runtime_dependency '
if d.is_a?(Array)
line<<d.map {|part| "'#{part}'" }.join(', ')
else
line<<"'#{d}'"
end
@ -188,7 +195,8 @@ def populate_gem_template(description, files)
generate_gem_file_list(files)
elsif var==:dependencies
generate_dependencies(
description[:dependencies]||DEFAULTS[:dependencies])
description[:dependencies]||DEFAULTS[:dependencies]
)
elsif var==:executables
generate_gem_executable_list(files)
elsif description[var]
@ -200,7 +208,7 @@ def populate_gem_template(description, files)
end
def generate_gem_file(gem_file, description, files)
File.open(gem_file, "w") do |f|
File.open(gem_file, 'w') do |f|
f.write(populate_gem_template(description, files))
end
end
@ -208,22 +216,22 @@ end
def generate_gem(description)
Dir.mktmpdir do |tmp|
files=file_list(description)
copy_files(files, '', tmp+"/")
copy_files(files, '', tmp+'/')
gem_file=tmp+"/gem.gemspec"
gem_file=tmp+'/gem.gemspec'
generate_gem_file(gem_file, description, files)
pwd=Dir.pwd
Dir.chdir(tmp) do
system("gem build gem.gemspec")
system('gem build gem.gemspec')
if $?.exitstatus!=0
puts "Error generating gem"
puts 'Error generating gem'
exit(-1)
end
Dir.glob("*.gem").each do |f|
Dir.glob('*.gem').each do |f|
FileUtils.cp(f, pwd)
end
end
@ -232,8 +240,7 @@ end
# Go to source code root dir
root=Dir.pwd
root.gsub!(/\/share\/rubygems$/, '')
root.gsub!(%r{/share/rubygems$}, '')
Dir.chdir(root)
GEM_DESCRIPTION.each {|name, gem| generate_gem(gem) }
GEM_DESCRIPTION.each {|_name, gem| generate_gem(gem) }