Skip to content
This repository has been archived by the owner on Aug 18, 2022. It is now read-only.

(maint) Pay down tech debt #349

Merged
52 changes: 3 additions & 49 deletions build/dsc.rake
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ eod
update_versions = args[:update_versions] || false
is_custom_resource = (dsc_resources_path != default_dsc_resources_path)

m = Dsc::Manager.new
m = Dsc::TypeImporter.new
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of single letter variables, but may be outside the scope of this?


if !is_custom_resource
puts "Downloading and Importing #{item_name}"
Expand Down Expand Up @@ -87,57 +87,11 @@ eod
puts "Copying vendored resources from #{dsc_resources_path_tmp} to #{vendor_dsc_resources_path}"

# remove destination path, copy everything in from the filtered list
valid_files.each do |f|
if f.start_with?("#{community_dsc_resources_root}/")
dscresource_name = f.split(community_dsc_resources_root)[1].split("/")[1]
if f.include?("/#{dscresource_name}/Modules/#{dscresource_name}")
d = f.sub("#{dscresource_name}/Modules/#{dscresource_name}", "#{dscresource_name}")
dest = Pathname.new(d.sub(community_dsc_resources_root, vendor_dsc_resources_path))
else
dest = Pathname.new(f.sub(community_dsc_resources_root, vendor_dsc_resources_path))
end

FileUtils.mkdir_p(dest.dirname)
FileUtils.cp(f, dest)
end
if f.start_with?("#{official_dsc_resources_root}/")
dscresource_name = f.split(official_dsc_resources_root)[1].split("/")[1]
if f.include?("/#{dscresource_name}/Modules/#{dscresource_name}")
d = f.sub("#{dscresource_name}/Modules/#{dscresource_name}", "#{dscresource_name}")
dest = Pathname.new(d.sub(official_dsc_resources_root, vendor_dsc_resources_path))
else
dest = Pathname.new(f.sub(official_dsc_resources_root, vendor_dsc_resources_path))
end

FileUtils.mkdir_p(dest.dirname)
FileUtils.cp(f, dest)
end
end

# and duplicate the vendored files
FileUtils.cp_r vendor_dsc_resources_path, dsc_resources_path

puts "Copying vendored resources from #{default_dsc_module_path}/build/vendor/wmf_dsc_resources to #{dsc_resources_path}"
FileUtils.cp_r "#{default_dsc_module_path}/build/vendor/wmf_dsc_resources/.", "#{dsc_resources_path}/"
m.move_valid_files(valid_files, community_dsc_resources_root, official_dsc_resources_root, dsc_resources_path, vendor_dsc_resources_path, default_dsc_module_path)
else
puts "Importing custom types from '#{dsc_resources_path}'"
# filter out unwanted files
valid_files = m.find_valid_files("#{dsc_resources_path}/**/*")

puts "Copying vendored resources from #{dsc_resources_path} to #{vendor_dsc_resources_path}"
valid_files.each do |f|
dest = Pathname.new(f.sub(dsc_resources_path, vendor_dsc_resources_path))
FileUtils.mkdir_p(dest.dirname)
FileUtils.cp(f, dest)
end

puts "Adding custom types to '#{default_dsc_resources_path}'"
FileUtils.mkdir_p(default_dsc_resources_path) unless Dir.exist? default_dsc_resources_path
valid_files.each do |f|
dest = Pathname.new(f.sub(dsc_resources_path, default_dsc_resources_path))
FileUtils.mkdir_p(dest.dirname)
FileUtils.cp(f, dest)
end
m.move_valid_custom_files(valid_files, dsc_resources_path, vendor_dsc_resources_path, default_dsc_resources_path)
end
end

Expand Down
1 change: 1 addition & 0 deletions build/dsc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
require "#{LIB_PATH}/dsc/manager"
require "#{LIB_PATH}/dsc/typebuilder"
require "#{LIB_PATH}/dsc/typecleaner"
require "#{LIB_PATH}/dsc/typeimporter"
require "#{LIB_PATH}/dsc/documentbuilder"

module Dsc
Expand Down
19 changes: 0 additions & 19 deletions build/dsc/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,6 @@ def import_dmtf_mofs
Dsc::Import.download(@dmtf_cim_mof_zip_url, @dmtf_cim_mof_zip_path)
Dsc::Import.unzip(@dmtf_cim_mof_zip_path, @dmtf_mof_folder)
end

def find_valid_files(directory)
valid_files = Dir.glob("#{directory}/**/*").reject do |f|
# reject the .git folder or special git files
f =~ /\/\.(git|gitattributes|gitignore|gitmodules)/ ||
# reject binary and other file extensions
f =~ /\.(pptx|docx|sln|cmd|xml|pssproj|pfx|html|txt|xlsm|csv|png|git|yml|md|js|json)$/i ||
# reject test / sample / example code
f =~ /\/.*([Ss]ample|[Ee]xample|[Tt]est).*/ ||
# reject stuff that is a Composite DSC Resource
f =~ /(xChrome|xDSCResourceDesigner|xDscDiagnostics|xFirefox|xSafeHarbor|xSystemSecurity).*/ ||
# reject duplicated resources
f =~ /(xSharePoint|PSDscResources).*/ ||
# and don't keep track of dirs
Dir.exists?(f)
end

valid_files
end

private

Expand Down
73 changes: 73 additions & 0 deletions build/dsc/typeimporter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module Dsc
class TypeImporter

def find_valid_files(directory)
valid_files = Dir.glob("#{directory}/**/*").reject do |f|
# reject the .git folder or special git files
f =~ /\/\.(git|gitattributes|gitignore|gitmodules)/ ||
# reject binary and other file extensions
f =~ /\.(pptx|docx|sln|cmd|xml|pssproj|pfx|html|txt|xlsm|csv|png|git|yml|md|js|json)$/i ||
# reject test / sample / example code
f =~ /\/.*([Ss]ample|[Ee]xample|[Tt]est).*/ ||
# reject stuff that is a Composite DSC Resource
f =~ /(xChrome|xDSCResourceDesigner|xDscDiagnostics|xFirefox|xSafeHarbor|xSystemSecurity).*/ ||
# reject duplicated resources
f =~ /(xSharePoint|PSDscResources).*/ ||
# and don't keep track of dirs
Dir.exists?(f)
end

valid_files
end

def move_valid_files(valid_files, community_dsc_resources_root, official_dsc_resources_root, dsc_resources_path, vendor_dsc_resources_path, default_dsc_module_path)
valid_files.each do |f|
if f.start_with?("#{community_dsc_resources_root}/")
move_file(f, community_dsc_resources_root, vendor_dsc_resources_path)
end
if f.start_with?("#{official_dsc_resources_root}/")
move_file(f, official_dsc_resources_root, vendor_dsc_resources_path)
end
end

# and duplicate the vendored files
FileUtils.cp_r vendor_dsc_resources_path, dsc_resources_path

puts "Copying vendored resources from #{default_dsc_module_path}/build/vendor/wmf_dsc_resources to #{dsc_resources_path}"
FileUtils.cp_r "#{default_dsc_module_path}/build/vendor/wmf_dsc_resources/.", "#{dsc_resources_path}/"
end

def move_valid_custom_files(valid_files, dsc_resources_path, vendor_dsc_resources_path, default_dsc_resources_path)
puts "Importing custom types from '#{dsc_resources_path}'"

puts "Copying vendored resources from #{dsc_resources_path} to #{vendor_dsc_resources_path}"
valid_files.each do |f|
dest = Pathname.new(f.sub(dsc_resources_path, vendor_dsc_resources_path))
FileUtils.mkdir_p(dest.dirname)
FileUtils.cp(f, dest)
end

puts "Adding custom types to '#{default_dsc_resources_path}'"
FileUtils.mkdir_p(default_dsc_resources_path) unless Dir.exist? default_dsc_resources_path
valid_files.each do |f|
dest = Pathname.new(f.sub(dsc_resources_path, default_dsc_resources_path))
FileUtils.mkdir_p(dest.dirname)
FileUtils.cp(f, dest)
end
end

def move_file(f, dsc_resources_root, vendor_dsc_resources_path)
dscresource_name = f.split(dsc_resources_root)[1].split("/")[1]
if f.include?("/#{dscresource_name}/Modules/#{dscresource_name}")
d = f.sub("#{dscresource_name}/Modules/#{dscresource_name}", "#{dscresource_name}")
dest = Pathname.new(d.sub(dsc_resources_root, vendor_dsc_resources_path))
else
dest = Pathname.new(f.sub(dsc_resources_root, vendor_dsc_resources_path))
end

FileUtils.mkdir_p(dest.dirname)
FileUtils.cp(f, dest)
end

end
end