add multiple target capability. for now names are read, and task version has been adapted
This commit is contained in:
parent
b5a6f73251
commit
4690936c91
|
@ -4,26 +4,34 @@ require 'rake/clean'
|
|||
# project variables
|
||||
# =================
|
||||
|
||||
# main name used if filename
|
||||
target = IO.read("name").split("\n")[0]
|
||||
raise "define project name in 'name' file" unless target
|
||||
# schema
|
||||
sch = "#{target}.sch"
|
||||
# pcb layout
|
||||
pcb = "#{target}.pcb"
|
||||
# main names used for filenames
|
||||
names = IO.read("name").split("\n").select {|target| !target.empty?}
|
||||
raise "define project name(s) in 'name' file" if names.empty?
|
||||
|
||||
# project version, read from "version" file
|
||||
version = IO.read("version").split("\n")[0]
|
||||
raise "define project version in 'version' file" unless version
|
||||
# current date for stamping output
|
||||
date = Time.now.strftime("%Y-%m-%d")
|
||||
# schematic revision, based on the number of schematic commits)
|
||||
sch_rev = `git log --pretty=oneline "#{sch}" | wc -l`.chomp.to_i
|
||||
# pcb layout revision, based on the number of pcb commits)
|
||||
pcb_rev = `git log --pretty=oneline "#{pcb}" | wc -l`.chomp.to_i
|
||||
# schema name with version and revition
|
||||
vsch = "#{target}_v#{version}.#{sch_rev.to_s.rjust(3,'0')}.sch"
|
||||
# pcb layout name with version and revition
|
||||
vpcb = "#{target}_v#{version}.#{pcb_rev.to_s.rjust(3,'0')}.pcb"
|
||||
|
||||
# create targets for each name
|
||||
targets = []
|
||||
names.each do |name|
|
||||
# schema
|
||||
sch = "#{name}.sch"
|
||||
# pcb layout
|
||||
pcb = "#{name}.pcb"
|
||||
# schematic revision, based on the number of schematic commits
|
||||
sch_rev = `git log --pretty=oneline "#{sch}" | wc -l`.chomp.to_i
|
||||
# pcb layout revision, based on the number of pcb commits
|
||||
pcb_rev = pcbs.collect {|pcb| `git log --pretty=oneline "#{pcb}" | wc -l`.chomp.to_i}
|
||||
# schema name with version and revition
|
||||
vsch = "#{name}_v#{version}.#{sch_rev.to_s.rjust(3,'0')}.sch"
|
||||
# pcb layout name with version and revition
|
||||
vpcb = "#{name}_v#{version}.#{pcb_rev.to_s.rjust(3,'0')}.pcb"
|
||||
# add to targets
|
||||
targets << { name: name, sch: sch, pcb: pcb, sch_rev: sch_rev, pcb_rev: pcb_rev, vsch: vsch, vpcb: vpcb }
|
||||
end
|
||||
|
||||
# ==========
|
||||
# main tasks
|
||||
|
@ -37,11 +45,13 @@ task :release => "hardware-release_v#{version}.tar.gz"
|
|||
CLOBBER.include("hardware-release_v#{version}.tar.gz")
|
||||
|
||||
desc "set version in schematic and layout"
|
||||
task :version => [vsch,vpcb]
|
||||
CLEAN.include(vsch)
|
||||
CLEAN.include(vpcb)
|
||||
CLOBBER.include("#{target}_*.sch")
|
||||
CLOBBER.include("#{target}_*.pcb")
|
||||
task :version => targets.collect{|target| [target[:vsch],target[:vpcb]}.flatten
|
||||
targets.each do |target|
|
||||
CLEAN.include(target[:vsch])
|
||||
CLEAN.include(target[:vpcb])
|
||||
CLOBBER.include("#{target[:name]}_*.sch")
|
||||
CLOBBER.include("#{target[:name]}_*.pcb")
|
||||
end
|
||||
|
||||
desc "print schematic and layout (as pdf)"
|
||||
task :print => ["#{target}_schematic.pdf","#{target}_layout.pdf"]
|
||||
|
@ -142,29 +152,33 @@ CLEAN.include("attribs")
|
|||
# ===============
|
||||
|
||||
desc "copy schematic to version it: include version, revision, and date"
|
||||
file vsch => sch do |t|
|
||||
sh "cp #{t.prerequisites.join(' ')} #{t.name}"
|
||||
# on \ is to prevent ruby interpreting it, th other is for sed
|
||||
# the version
|
||||
sh "sed -i 's/\\(version=\\)\\$Version\\$/\\1#{version}/' #{t.name}"
|
||||
# the date
|
||||
sh "sed -i 's/\\(date=\\)\\$Date\\$/\\1#{date}/' #{t.name}"
|
||||
# the revision
|
||||
sh "sed -i 's/\\(revision=\\)\\$Revision\\$/\\1#{sch_rev}/' #{t.name}"
|
||||
tagerts.each do |target|
|
||||
file tagert[:vsch] => target[:sch] do |t|
|
||||
sh "cp #{t.prerequisites.join(' ')} #{t.name}"
|
||||
# on \ is to prevent ruby interpreting it, th other is for sed
|
||||
# the version
|
||||
sh "sed -i 's/\\(version=\\)\\$Version\\$/\\1#{version}/' #{t.name}"
|
||||
# the date
|
||||
sh "sed -i 's/\\(date=\\)\\$Date\\$/\\1#{date}/' #{t.name}"
|
||||
# the revision
|
||||
sh "sed -i 's/\\(revision=\\)\\$Revision\\$/\\1#{sch_rev}/' #{t.name}"
|
||||
end
|
||||
end
|
||||
|
||||
desc "copy layout to version it: include version, date, and run teardrops when available"
|
||||
file vpcb => pcb do |t|
|
||||
sh "cp #{t.prerequisites.join(' ')} #{t.name}"
|
||||
# on \ is to prevent ruby interpreting it, th other is for sed
|
||||
# the version and revision
|
||||
version_revision = "v#{version}.#{pcb_rev.to_s.rjust(3,'0')}"
|
||||
sh "sed -i 's/\\$version\\$/#{version_revision}/' #{t.name}"
|
||||
# the date
|
||||
sh "sed -i 's/\\$date\\$/#{date}/' #{t.name}"
|
||||
# run teardrop for vias and pins
|
||||
if File.exist? "#{Dir.home}/.pcb/plugins/teardrops.so" then
|
||||
sh "pcb --action-string \"djopt(splitlines) Teardrops() s() q()\" #{t.name}"
|
||||
tagerts.each do |target|
|
||||
file tagert[:vpcb] => target[:pcb] do |t|
|
||||
sh "cp #{t.prerequisites.join(' ')} #{t.name}"
|
||||
# on \ is to prevent ruby interpreting it, th other is for sed
|
||||
# the version and revision
|
||||
version_revision = "v#{version}.#{pcb_rev.to_s.rjust(3,'0')}"
|
||||
sh "sed -i 's/\\$version\\$/#{version_revision}/' #{t.name}"
|
||||
# the date
|
||||
sh "sed -i 's/\\$date\\$/#{date}/' #{t.name}"
|
||||
# run teardrop for vias and pins
|
||||
if File.exist? "#{Dir.home}/.pcb/plugins/teardrops.so" then
|
||||
sh "pcb --action-string \"djopt(splitlines) Teardrops() s() q()\" #{t.name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue