Skip to content

Commit

Permalink
ship ignore IDE spam files. vendor:build also build dependences
Browse files Browse the repository at this point in the history
  • Loading branch information
jcangas committed Dec 8, 2015
1 parent c55acd2 commit 4c6d463
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 130 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -18,5 +18,5 @@ group :development do
gem "minitest"
gem "minitest-rg"
gem 'ocra', '1.3.6'
# gem 'ocra', '1.3.5', :git => 'https://github.com/jcangas/ocra.git', :ref => '9983f3113ed01f04087f600473f65885b223f577'
# gem 'ocra', :git => 'https://github.com/jcangas/ocra.git', :ref => '9983f3113ed01f04087f600473f65885b223f577'
end
2 changes: 1 addition & 1 deletion installer/delphivm.iss
@@ -1,4 +1,4 @@
# define VERSION "3.5.1"
# define VERSION "3.5.3+pre"
[Setup]
AppName=DelphiVM
AppVersion={#VERSION}
Expand Down
80 changes: 51 additions & 29 deletions lib/delphivm/dsl.rb
Expand Up @@ -2,26 +2,35 @@
class Delphivm
module DSL
def self.run_imports_dvm_script(path_to_file, options = {})
read_imports_dvm_script(path_to_file, options).foreach_do :proccess
load_dvm_script(path_to_file, options).foreach_do :proccess
end

def self.register_imports_dvm_script(path_to_file, options = {})
read_imports_dvm_script(path_to_file, options).foreach_do :proccess_ide_install
load_dvm_script(path_to_file, options).foreach_do :proccess_ide_install
end

def self.read_imports_dvm_script(path_to_file, options = {})
ImportScript.new(File.read(path_to_file), options)
def self.load_dvm_script(path_to_file, options = {})
if path_to_file.exist?
content = File.read(path_to_file)
else
content = nil
end
ImportScript.new(content, options)
end

class ImportScript < Object
attr_reader :idever
attr_reader :imports
attr_reader :options
attr_reader :loaded

def initialize(script = '', options = {})
def initialize(content = nil, options = {})
@imports = {}
@options = options
eval(script)
@loaded = (content != nil)
return unless @loaded
eval(content)
collect_dependences
end

def source(value = nil)
Expand All @@ -35,12 +44,24 @@ def uses(value, &block)

def import(libname, libver, liboptions = {}, &block)
key = "#{libname}-#{libver}".to_sym
unless @imports.has_key?(key)
@imports[key] = Importer.new(self, libname, libver, liboptions, &block)
return if @imports.key?(key)
@imports[key] = Importer.new(self, libname, libver, liboptions, &block)
end

def collect_dependences
ordered_imports = {}
imports.each do |lib_tag, importer|
importer.dependences_script.collect_dependences
importer.dependences_script.imports.each do |key, val|
ordered_imports[key] = val unless ordered_imports.key?(key)
end
ordered_imports[lib_tag] = importer unless ordered_imports.key?(lib_tag)
end
@imports = ordered_imports
end

def foreach_do(method)
return unless method
imports.values.each do |imp|
imp.send method
end
Expand All @@ -50,6 +71,8 @@ def foreach_do(method)
class Importer
include Delphivm::Talk
attr_reader :script
attr_reader :dependences_script
attr_reader :dependences_scriptname
attr_reader :source
attr_reader :source_uri
attr_reader :idever
Expand All @@ -67,6 +90,7 @@ def initialize(script, libname, libver, liboptions = {}, &block)
@libopts = liboptions
@source_uri = libopts[:uri] || Pathname(source) + lib_file
@ide_pkgs = []
@dependences_scriptname = Pathname(PRJ_IMPORTS + lib_tag + 'imports.dvm')
instance_eval(&block) if block
end

Expand All @@ -78,6 +102,21 @@ def lib_file
"#{lib_tag}-#{idever}.zip"
end

def ensure_dependences_script
# import.dvm file must exist in vendor
fname = dependences_scriptname
return if fname.exist?
fname.dirname.mkpath
fname.open('w')
end

def dependences_script
unless @dependences_script && @dependences_script.loaded
@dependences_script = DSL.load_dvm_script(dependences_scriptname, script.options)
end
@dependences_script
end

private

def ide_install(*packages)
Expand Down Expand Up @@ -129,35 +168,18 @@ def proccess
exist ||= zip_file
return unless exist
vendorize
proccess_dependences
ensure_dependences_script
dependences_script.foreach_do(:proccess)
proccess_ide_install
say_status :done, lib_file, :green
end

def proccess_dependences
dvm_file = Pathname(PRJ_IMPORTS + lib_tag + 'imports.dvm')
DSL.run_imports_dvm_script(dvm_file, script.options) if dvm_file.exist?
end

def get_vendor_files
Pathname.glob(DVM_IMPORTS + idever + lib_tag + '**/*')
end

def vendorized?
# check any src file is present
files = Pathname.glob(DVM_IMPORTS + idever + lib_tag + 'src/**/*.{dpr,dpk}')
return false if files.empty?
file = files.first
route = file.relative_path_from(DVM_IMPORTS + idever)
link = PRJ_IMPORTS + route
return true if link.exist?
# check any bin file is present
files = Pathname.glob(DVM_IMPORTS + idever + lib_tag + 'out/**/*.{exe,bpl,dll}')
return false if files.empty?
file = files.first
route = file.relative_path_from(DVM_IMPORTS + idever)
link = PRJ_ROOT + 'out' + idever + route
link.exist?
dependences_scriptname.exist?
end

def vendorize
Expand Down Expand Up @@ -197,7 +219,7 @@ def register(idever, pkg)
end

def download(source_uri, file_name)
# Esto solo es valido para ficheros, no uris en gral
# Esto solo es valido para ficheros, no uris en gral
# unless source_uri.exist?
# say_status :ERROR, "#{file_name} not found", :red
# return nil
Expand Down
2 changes: 1 addition & 1 deletion lib/delphivm/version.rb
@@ -1,5 +1,5 @@
class Delphivm
include VersionInfo
self.VERSION = "3.5.1"
self.VERSION = "3.5.3+pre"
self.VERSION.file_name = __FILE__
end
6 changes: 3 additions & 3 deletions lib/dvm/ship.thor
Expand Up @@ -10,10 +10,10 @@ class Ship < BuildTarget
desc "clean", "remove ship file #{APP_ID}-#{IDEServices.default_ide}.zip", :for => :clean
desc "make", "make ship file(s) #{APP_ID}-#{IDEServices.default_ide}.zip", :for => :make
desc "build", "build ship file(s) #{APP_ID}-#{IDEServices.default_ide}.zip", :for => :build

method_option :groups, type: :array, aliases: '-g', default: configuration.ship_groups, desc: "use groups: bin lib source doc samples test", for: :make
method_option :groups, type: :array, aliases: '-g', default: configuration.ship_groups, desc: "use groups: bin lib source doc samples test", for: :build

protected
def get_zip_name(idetag)
Pathname('ship') + spec.get_zip_name(idetag)
Expand Down Expand Up @@ -57,7 +57,7 @@ protected
@spec ||= ::Ship::Spec.new do |s|
s.name = Delphivm::APPMODULE.name
s.version = Delphivm::APPMODULE.VERSION.tag
s.ignore_files(['**/*.~*', '**/*.bak', '**/*.local', '**/*.identcache' ,'*.log', '.DS_Store'])
s.ignore_files(['**/*.~*', '**/*.{bak,local,dsk,tvsconfig,identcache}', '**/ModelSupport_*/**/*.*', '**/LibrarySupport/**/*.*', '**/__history/*.*', '*.log', '.DS_Store'])
s.bin_files("out/%{idetag}/*/*/bin/**{.*,}/*.*")
s.lib_files("out/%{idetag}/*/{Debug,Release}/lib/*.*")
s.source_files(["src/**/*.*", "*.*"])
Expand Down
183 changes: 90 additions & 93 deletions lib/dvm/ship/group.rb
@@ -1,93 +1,90 @@
class Ship
class Spec
attr_accessor :name
attr_accessor :version
def initialize
super()
@groups = []
@files = {}
yield self if block_given?
end

def ignore_files(patterns)
@ignore = [patterns].flatten
end

def bin_files(patterns)
@files[:bin] = [patterns].flatten
end

def lib_files(patterns)
@files[:lib] = [patterns].flatten
end

def source_files(patterns)
@files[:source] = [patterns].flatten
end

def doc_files(patterns)
@files[:doc] = [patterns].flatten
end

def sample_files(patterns)
@files[:samples] = [patterns].flatten
end

def test_files(patterns)
@files[:test] = [patterns].flatten
end

def get_zip_name(idever)
Pathname("#{name}-#{version}-#{idever}.zip")
end

def get_zip_root
Pathname("#{name}-#{version}")
end

def build(idever, groups, outdir: '.', start: nil, progress: nil, zipping: nil, done: nil)
self.vars = {idever: idever}
@groups = groups
reset_files
zip_fname = Pathname(outdir) + get_zip_name(idever)
zip_fname.dirname.mkpath
zip_root = get_zip_root
s = all_files.size
start.call(s) if start
Zip::File.open(zip_fname, Zip::File::CREATE) do |zipfile|
all_files.each do |file|
zip_entry = zip_root + file
zipfile.add(zip_entry, file)
progress.call(file) if progress
end
zipping.call if zipping
end
done.call if done
end

def vars
@vars
end

private

def reset_files
@all_files = nil
end

def vars=(value)
@vars = value
end

def all_files
return @all_files if @all_files
self.vars
ignore_files = @ignore.inject([]){|files, pattern| files + Pathname.glob(pattern % self.vars) }.uniq
use_files = @files.select { |key, value| @groups.empty? || @groups.include?(key.to_s)}
@all_files = use_files.values.inject([]) do |collect_files, patterns|
collect_files + patterns.inject([]){|files, pattern| files + Pathname.glob(pattern % self.vars) - ignore_files }.uniq
end.uniq
end
end

end
# Ship
class Ship
# Spec
class Spec
attr_accessor :name
attr_accessor :version
def initialize
super()
@groups = []
@files = {}
yield self if block_given?
end

def ignore_files(patterns)
@ignore = [patterns].flatten
end

def bin_files(patterns)
@files[:bin] = [patterns].flatten
end

def lib_files(patterns)
@files[:lib] = [patterns].flatten
end

def source_files(patterns)
@files[:source] = [patterns].flatten
end

def doc_files(patterns)
@files[:doc] = [patterns].flatten
end

def sample_files(patterns)
@files[:samples] = [patterns].flatten
end

def test_files(patterns)
@files[:test] = [patterns].flatten
end

def get_zip_name(idever)
Pathname("#{name}-#{version}-#{idever}.zip")
end

def get_zip_root
Pathname("#{name}-#{version}")
end

def build(idever, groups, outdir: '.', start: nil, progress: nil, zipping: nil, done: nil)
self.vars = { idever: idever }
@groups = groups
reset_files
zip_fname = Pathname(outdir) + get_zip_name(idever)
zip_fname.dirname.mkpath
zip_root = get_zip_root
s = all_files.size
all_files
start.call(s) if start
Zip::File.open(zip_fname, Zip::File::CREATE) do |zipfile|
all_files.each do |file|
zip_entry = zip_root + file
zipfile.add(zip_entry, file)
progress.call(file) if progress
end
zipping.call if zipping
end
done.call if done
end

attr_reader :vars

private

def reset_files
@all_files = nil
end

attr_writer :vars

def all_files
return @all_files if @all_files
ignore_files = @ignore.inject([]) { |files, pattern| files + Pathname.glob(pattern % vars) }.uniq
use_files = @files.select { |key, _value| @groups.empty? || @groups.include?(key.to_s) }
@all_files = use_files.values.inject([]) do |collect_files, patterns|
collect_files + patterns.inject([]) { |files, pattern| files + Pathname.glob(pattern % vars) - ignore_files }.uniq
end.uniq
end
end
end
4 changes: 2 additions & 2 deletions lib/dvm/vendor.thor
Expand Up @@ -102,10 +102,10 @@
def do_build_action(idetag, cfg, action)
cfg = {} unless cfg
cfg['BuildGroup'] = options[:group] if options.group?
script = DSL.read_imports_dvm_script(PRJ_IMPORTS_FILE, options)
script = DSL.load_dvm_script(PRJ_IMPORTS_FILE, options)
ide = IDEServices.new(idetag)
prj_paths = IDEServices.prj_paths
script.imports.map(&:lib_tag).each do |import|
script.imports.values.map(&:lib_tag).each do |import|
adjust_prj_paths(prj_paths, import)
ide.call_build_tool(action, cfg)
end
Expand Down

0 comments on commit 4c6d463

Please sign in to comment.