From b3eeb286b1611693cb0d1e99e61ce86756ec21bc Mon Sep 17 00:00:00 2001 From: Andrew Stepikov Date: Tue, 26 Mar 2019 16:12:20 -0700 Subject: [PATCH] fix(build): increase packing performance --- build.rb | 29 ++++++++++++++++++++++------- pack.rake | 12 ++++++++++-- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/build.rb b/build.rb index 8f7e30a..0592e1f 100755 --- a/build.rb +++ b/build.rb @@ -354,7 +354,6 @@ def update_files_based_on_timestamp(source_files, target_dir) def update_sources() puts "[INFO] Converting from gff to yml (this may take a while)..." - remove_deleted_files(GFF_CACHE_DIR, SOURCES.sub(/\.yml$/, '')) system "rake", "--rakefile", EXTRACT_RAKE.to_s, "flat=#{FLAT_LAYOUT}", "SRC_DIR=#{SRC_DIR}", "GFF_CACHE_DIR=#{GFF_CACHE_DIR}", "SCRIPTS_DIR=#{SCRIPTS_DIR}", "ENCODING=#{ENCODING}" update_files_based_on_timestamp(FileList[to_forward_slash GFF_CACHE_DIR.join("*.nss")], NSS_DIR) @@ -364,11 +363,20 @@ def update_gffs() puts "[INFO] Converting from yml to gff (this may take a while)..." gffs = FileList[to_forward_slash GFF_CACHE_DIR.join("*")].exclude(/\.ncs$/) - srcs = FileList[to_forward_slash SRC_DIR.join("**", "*.*")].sub(/\.yml$/, '') + gffs.each do |gff| - FileUtils.rm(gff) unless srcs.detect{|src| File.basename(gff) == File.basename(src)} + # extension is a name of the subfolder + type = File.extname(gff).delete('.') + # remove from gff cache if there is no associated file in src directory + # (taking into account subfolder with type and that nss files don't have an yml extension) + unless File.exist?(SRC_DIR.join(type, "#{File.basename(gff)}#{unless type == "nss" then ".yml" end }")) + puts "[INFO] %s removed from cache since it doesn't have a source" % File.basename(gff) + FileUtils.rm(gff) + end end + system "rake", "--rakefile", PACK_RAKE.to_s, "SRC_DIR=#{SRC_DIR}", "GFF_CACHE_DIR=#{GFF_CACHE_DIR}", "ENCODING=#{ENCODING}" + return update_files_based_on_timestamp(FileList[to_forward_slash NSS_DIR.join("*.nss")], GFF_CACHE_DIR) end @@ -449,10 +457,17 @@ def extract_all() def pack_all(skip_compile=false) verify_executables init_directories() - should_compile = update_gffs() && !skip_compile - puts "[INFO] No change in nss sources detected. Skipping compilation." unless should_compile && !skip_compile - puts "[INFO] Skipping compilation due to configuration" if skip_compile - compile_nss(MODULE_FILE) if should_compile + + if skip_compile + puts "[INFO] Skipping compilation due to configuration" + end + + should_compile = update_gffs() + if should_compile && !skip_compile + puts "[INFO] No change in nss sources detected. Skipping compilation." + end + + compile_nss(MODULE_FILE) unless skip_compile update_cache(GFF_CACHE_DIR, TMP_CACHE_DIR) pack_module(MODULE_FILE) diff --git a/pack.rake b/pack.rake index 119b4a4..d34e8bc 100644 --- a/pack.rake +++ b/pack.rake @@ -2,6 +2,7 @@ require 'nwn/all' require 'fileutils' require 'pathname' + def to_forward_slash(path=Pathname.getwd) return path.to_s.gsub(File::ALT_SEPARATOR || File::SEPARATOR, File::SEPARATOR) end @@ -22,11 +23,18 @@ task :gff => [GFF_CACHE_DIR.to_s, :yml2gff] multitask :yml2gff => GFF_TARGETS -rule( /\.(?!yml)[\w]+$/ => ->(f){ source_for_gff(f) }) do |t| +rule( /\.(?!yml)[\w]+$/ => ->(f){ + source_for_gff(f) + }) do |t| + puts "[INFO] packing changed file: %s" % File.basename(t.name) + # -i IN Input file [default: -] + # -o OUT Output file [default: -] + # -k OUTFORMAT Output format [default: autodetect] system "nwn-gff", "-i", "#{t.source}", "-o", "#{t.name}", "-kg", "--encoding", "#{ENCODING}" FileUtils.touch "#{t.name}", :mtime => File.mtime("#{t.source}") end def source_for_gff(gff) - YML_SOURCES.detect{|yml| File.basename(gff) == File.basename(yml, ".*")} + type = File.extname(gff).delete('.') + SRC_DIR.join(type, "#{File.basename(gff)}.yml") end