mirror of
https://github.com/kp2pml30/ya-build.git
synced 2026-02-17 00:14:42 +04:00
various improvements
This commit is contained in:
parent
f86aff0986
commit
9a4e738f97
1 changed files with 49 additions and 6 deletions
55
ya-build
55
ya-build
|
|
@ -130,8 +130,9 @@ end
|
||||||
|
|
||||||
class CommandTarget < Target
|
class CommandTarget < Target
|
||||||
attr_reader :output_file
|
attr_reader :output_file
|
||||||
def initialize(output_file, dependencies, cwd, commands, depfile, pool)
|
def initialize(output_file, dependencies, cwd, commands, depfile, pool, env)
|
||||||
super(output_file, dependencies)
|
super(output_file, dependencies)
|
||||||
|
@env = env
|
||||||
@depfile = depfile
|
@depfile = depfile
|
||||||
@output_file = output_file
|
@output_file = output_file
|
||||||
@cwd = cwd
|
@cwd = cwd
|
||||||
|
|
@ -140,6 +141,13 @@ class CommandTarget < Target
|
||||||
end
|
end
|
||||||
|
|
||||||
protected def dump_rules_impl(buf)
|
protected def dump_rules_impl(buf)
|
||||||
|
if @env.size > 0
|
||||||
|
buf << " ENV = env"
|
||||||
|
@env.each { |k, v|
|
||||||
|
buf << ' ' << k << '=' << Shellwords.escape(v).gsub(/\\=/, '=')
|
||||||
|
}
|
||||||
|
buf << "\n"
|
||||||
|
end
|
||||||
if not @pool.nil?
|
if not @pool.nil?
|
||||||
buf << " pool = #{@pool}\n"
|
buf << " pool = #{@pool}\n"
|
||||||
end
|
end
|
||||||
|
|
@ -241,7 +249,7 @@ class CopyTarget < Target
|
||||||
end
|
end
|
||||||
|
|
||||||
class Configurator
|
class Configurator
|
||||||
attr_reader :root_src, :root_build, :config
|
attr_reader :root_src, :root_build, :config, :logger
|
||||||
|
|
||||||
private def get_tag_target(tag)
|
private def get_tag_target(tag)
|
||||||
ret = @tags[tag]
|
ret = @tags[tag]
|
||||||
|
|
@ -293,11 +301,21 @@ class Configurator
|
||||||
|
|
||||||
private def extend_config_impl(l, r)
|
private def extend_config_impl(l, r)
|
||||||
if l.kind_of? Hash
|
if l.kind_of? Hash
|
||||||
l.merge(r)
|
l.merge(r) { |k, ov, nv|
|
||||||
|
extend_config_impl ov, nv
|
||||||
|
}
|
||||||
elsif l.kind_of? OpenStruct
|
elsif l.kind_of? OpenStruct
|
||||||
OpenStruct.new(l.instance_eval { @table.merge(r) })
|
OpenStruct.new(l.instance_eval {
|
||||||
|
@table.merge(r) { |k, ov, nv|
|
||||||
|
extend_config_impl ov, nv
|
||||||
|
}.transform_values { |v|
|
||||||
|
if v.kind_of? Hash then v.to_ostruct else v end
|
||||||
|
}
|
||||||
|
})
|
||||||
elsif r.kind_of?(Proc)
|
elsif r.kind_of?(Proc)
|
||||||
r.call(l)
|
r.call(l)
|
||||||
|
elsif r.kind_of?(Hash)
|
||||||
|
r.to_ostruct
|
||||||
else
|
else
|
||||||
r
|
r
|
||||||
end
|
end
|
||||||
|
|
@ -366,7 +384,7 @@ rule HELP
|
||||||
description = All primary targets available
|
description = All primary targets available
|
||||||
|
|
||||||
rule CUSTOM_COMMAND
|
rule CUSTOM_COMMAND
|
||||||
command = cd $WD && $COMMAND
|
command = cd $WD && $ENV $COMMAND
|
||||||
description = $DESC
|
description = $DESC
|
||||||
|
|
||||||
rule COMPILE_C
|
rule COMPILE_C
|
||||||
|
|
@ -467,6 +485,30 @@ EOF
|
||||||
root_src.join(@stack[-1].path)
|
root_src.join(@stack[-1].path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_executable(name, critical: false)
|
||||||
|
paths = ENV['PATH'].split(':')
|
||||||
|
paths << '/usr/bin'
|
||||||
|
paths << '/bin'
|
||||||
|
paths << "#{ENV['HOME']}/.local/bin"
|
||||||
|
paths << "#{ENV['HOME']}/.cargo/bin"
|
||||||
|
paths.each { |p|
|
||||||
|
check = ['', '.elf', '.exe']
|
||||||
|
check.each { |c|
|
||||||
|
cur_p = Pathname.new(p).join("#{name}#{c}")
|
||||||
|
if cur_p.exist?()
|
||||||
|
logger.info("checking for #{name}... located at #{cur_p}")
|
||||||
|
return cur_p
|
||||||
|
end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if critical
|
||||||
|
logger.error("checking for #{name}... not found")
|
||||||
|
raise "#{name} not found in path"
|
||||||
|
end
|
||||||
|
logger.info("checking for #{name}... not found")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
def target_command(
|
def target_command(
|
||||||
output_file:,
|
output_file:,
|
||||||
dependencies:,
|
dependencies:,
|
||||||
|
|
@ -475,6 +517,7 @@ EOF
|
||||||
commands: nil,
|
commands: nil,
|
||||||
depfile: nil,
|
depfile: nil,
|
||||||
pool: nil,
|
pool: nil,
|
||||||
|
env: {},
|
||||||
**kwargs,
|
**kwargs,
|
||||||
&blk
|
&blk
|
||||||
)
|
)
|
||||||
|
|
@ -489,7 +532,7 @@ EOF
|
||||||
cwd = cur_src
|
cwd = cur_src
|
||||||
end
|
end
|
||||||
|
|
||||||
trg = CommandTarget.new(output_file, dependencies, cwd, commands, depfile, pool)
|
trg = CommandTarget.new(output_file, dependencies, cwd, commands, depfile, pool, env)
|
||||||
return_target(trg, **kwargs, &blk)
|
return_target(trg, **kwargs, &blk)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue