How to use a static library created by a custom task? - waf

I want use waf to trigger a makefile to build an other library. For this I created the following task:
def build(bld):
def run(self):
bld_dir = self.generator.bld.path.get_bld()
src_dir = self.inputs[0].parent
tgt = self.outputs[0]
tgt_dir = bld_dir.make_node(os.path.splitext(tgt.name)[0])
cmd = 'BUILDDIR="{tgt_dir}" make config gdb=1 debug=1 cc={cc} && BUILDDIR=" {tgt_dir}" make'.format(
tgt_dir = tgt_dir.abspath(),
cc = self.env.get_flat("CC"))
self.exec_command(cmd, cwd=src_dir.abspath())
return self.exec_command(['cp', lib.abspath(), tgt.abspath()],
cwd=tgt_dir.abspath())
bld(
rule = run,
source = "Makefile",
target = 'metis',
)
How can I tell waf that the task created a static library, so that I can use "metis" in a use keyword:
bld(
features = "cxx cxxprogramm"
source = "main.cpp",
target = 'main',
use = 'metis'
)

To finally solve the problem I created a on link_task, that basicly does notthing (similar to the fake_lib in ccroot.py):
from waflib.TaskGen import feature, after_method
from waflib.Tools.ccroot import stlink_task
class custom_stlib(stlink_task):
""" Dummy link task """
pass
#feature("custom_stlib")
def custom_lib(self):
self.env['custom_stlib_PATTERN'] = 'lib%s.a'
self.link_task = self.create_task('custom_stlib', [])
self.link_task.add_target(self.target)
def build(bld):
# ...
bld(
features = "cxx custom_stlib",
target = 'metis',
after = "metis_bld",
)

Related

How to spllit laserscan data from lidar into sections and view them on rviz

I was trying to split the laser scan range data into subcategories and like to publish each category into different laser topics.
to specify more, the script should get one topic as an input - /scan and the script should publish three topics as follow = scan1, scan2, scan3
is there a way to split the laser scan and publish back and look them on rviz
I tried the following
def callback(laser):
current_time = rospy.Time.now()
regions["l_f_fork"] = laser.ranges[0:288]
regions["l_f_s"] = laser.ranges[289:576]
regions["stand"] = laser.ranges[576:864]
l.header.stamp = current_time
l.header.frame_id = 'laser'
l.angle_min = 0
l.angle_max = 1.57
l.angle_increment =0
l.time_increment = 0
l.range_min = 0.0
l.range_max = 100.0
l.ranges = regions["l_f_fork"]
l.intensities = [0]
left_fork.publish(l)
# l.ranges = regions["l_f_s"]
# left_side.publish(l)
# l.ranges = regions["stand"]
# left_side.publish(l)
rospy.loginfo("publishing new info")
I can see the different topics on rviz, but they are lies on the same line,
Tutorial
The following code splits the LaserScan data into three equal sections:
#! /usr/bin/env python3
"""
Program to split LaserScan into three parts.
"""
import rospy
from sensor_msgs.msg import LaserScan
class LaserScanSplit():
"""
Class for splitting LaserScan into three parts.
"""
def __init__(self):
self.update_rate = 50
self.freq = 1./self.update_rate
# Initialize variables
self.scan_data = []
# Subscribers
rospy.Subscriber("/scan", LaserScan, self.lidar_callback)
# Publishers
self.pub1 = rospy.Publisher('/scan1', LaserScan, queue_size=10)
self.pub2 = rospy.Publisher('/scan2', LaserScan, queue_size=10)
self.pub3 = rospy.Publisher('/scan3', LaserScan, queue_size=10)
# Timers
rospy.Timer(rospy.Duration(self.freq), self.laserscan_split_update)
def lidar_callback(self, msg):
"""
Callback function for the Scan topic
"""
self.scan_data = msg
def laserscan_split_update(self, event):
"""
Function to update the split scan topics
"""
scan1 = LaserScan()
scan2 = LaserScan()
scan3 = LaserScan()
scan1.header = self.scan_data.header
scan2.header = self.scan_data.header
scan3.header = self.scan_data.header
scan1.angle_min = self.scan_data.angle_min
scan2.angle_min = self.scan_data.angle_min
scan3.angle_min = self.scan_data.angle_min
scan1.angle_max = self.scan_data.angle_max
scan2.angle_max = self.scan_data.angle_max
scan3.angle_max = self.scan_data.angle_max
scan1.angle_increment = self.scan_data.angle_increment
scan2.angle_increment = self.scan_data.angle_increment
scan3.angle_increment = self.scan_data.angle_increment
scan1.time_increment = self.scan_data.time_increment
scan2.time_increment = self.scan_data.time_increment
scan3.time_increment = self.scan_data.time_increment
scan1.scan_time = self.scan_data.scan_time
scan2.scan_time = self.scan_data.scan_time
scan3.scan_time = self.scan_data.scan_time
scan1.range_min = self.scan_data.range_min
scan2.range_min = self.scan_data.range_min
scan3.range_min = self.scan_data.range_min
scan1.range_max = self.scan_data.range_max
scan2.range_max = self.scan_data.range_max
scan3.range_max = self.scan_data.range_max
# LiDAR Range
n = len(self.scan_data.ranges)
scan1.ranges = [float('inf')] * n
scan2.ranges = [float('inf')] * n
scan3.ranges = [float('inf')] * n
# Splitting Block [three equal parts]
scan1.ranges[0 : n//3] = self.scan_data.ranges[0 : n//3]
scan2.ranges[n//3 : 2*n//3] = self.scan_data.ranges[n//3 : 2*n//3]
scan3.ranges[2*n//3 : n] = self.scan_data.ranges[2*n//3 : n]
# Publish the LaserScan
self.pub1.publish(scan1)
self.pub2.publish(scan2)
self.pub3.publish(scan3)
def kill_node(self):
"""
Function to kill the ROS node
"""
rospy.signal_shutdown("Done")
if __name__ == '__main__':
rospy.init_node('laserscan_split_node')
LaserScanSplit()
rospy.spin()
The following are screenshots of the robot and obstacles in the environment in Gazebo and RViz:
References:
ROS1 Python Boilerplate
atreus

Is there a way to change private attribute of an Aspect progammatically?

Say I have something like the following.
def _foo_aspect_impl(target, ctx):
# operations
return FooInfo(...)
foo_aspect = aspect(implementation = _foo_aspect_impl,
attr_aspects = ['deps'],
attrs = dict(
_tool = attr.Label(
# defs
),
)
)
def _foo_rule_impl(ctx):
for dep in ctx.attr.deps:
# do something with `dep[FooInfo]`
return DefaultInfo(...)
foo_rule = rule(
implementation = _foo_rule_impl,
attrs = dict(
"deps": attr.label_list(
aspects = [foo_aspect],
)
)
)
Is there a way to change the value of foo_aspect.attr._tool, either in WORKSPACE, or at the invocation of foo_rule? Former is much preferable.
The use case being that version and repository origin of _tool might change from project to project. When aspect resides in a repository shared by two projects, it does not make sense to create two branches for these two projects just for versioning of _tool.
After a lot of head scratching I found a rather complicated way of doing it.
Since the only thing that seems to be configuarable in WORKSPACE.bazel during loading phase is other workspaces / repositories, one could actually use target aliasing together with repository loading to mutiplex configuarable targets.
Here is how it works.
First, define a new repository rule new_virtual_repository, which creates repositories that does nothing but loading the BUILD.bazel and WORKSPACE.bazel files.
# repo.bzl
load("#bazel_tools//tools/build_defs/repo:utils.bzl", "workspace_and_buildfile")
def _new_virtual_repo_impl(ctx):
# Create build file
workspace_and_buildfile(ctx)
return ctx.attr
new_virtual_repository = repository_rule(
implementation = _new_virtual_repo_impl,
attrs = dict(
build_file = attr.label(allow_single_file = True),
build_file_content = attr.string(),
workspace_file = attr.label(allow_single_file = True),
workspace_file_content = attr.string(),
),
local = True,
)
Then, create an extension file config.bzl which implements a function that generates the BUILD.bazel file and load the virtual repository:
# config.bzl
load(":repo.bzl", "new_virtual_repository")
def config(tool):
build_file_content = """
alias(
name = "tool",
actual = "%s",
""" % (tool)
new_virtual_repository(
name = "config_repo",
build_file_content = build_file_content,
)
Now in the aspect specification:
# aspect.bzl
foo_aspect = aspect(
...
attrs = dict(
_tool = attr.Label("#config_repo//:tool"),
)
)
Finally, configure the actual tool in WORKSPACE.bazel:
# WORKSPACE.bazel
load("//:config.bzl", "config")
config(tool="<actual_tool_label>")

Waf Task should use variant directory

I am creating files in a Task, the example code looks as follows:
from waflib import Task, TaskGen
def build(bld):
bld(features='write_file')
class xyz(Task.Task):
def run(self):
self.generator.path.get_bld().make_node(self.outputs[0].relpath())
#TaskGen.feature('write_file')
def make_tasks(self):
for x in range(20):
src = bld.path.find_node('wscript')
tgt = src.change_ext('.'+str(x))
tsk = self.create_task('xyz', src=src, tgt=tgt)
Now all files get placed inside the build directory, but I want them to be placed in build\abc. How do I do that? For normal builds, I can use a BuildContext and specify a variant:
from waflib.Build import BuildContext
class abc(BuildContext):
variant = 'abc'
But I can't get the BuildContext working on that example, and setting variant on a Task.Task does not work.
Update
I update the example based on neuros answer:
A minimal working example with this code looks like this:
from waflib import Task, TaskGen, Configure
Configure.autoconfig = True
def configure(cnf):
cnf.path.get_src().make_node('a/wscript').write('')
def build(bld):
bld(features='write_file')
class xyz(Task.Task):
def run(self):
self.generator.path.get_bld().find_or_declare(self.outputs[0].abspath()).write('')
#TaskGen.feature('write_file')
def make_tasks(self):
srcs = bld.path.ant_glob('**/wscript', excl='build')
for src in srcs:
build_dir_of_src = src.get_bld().parent
my_sub_node = build_dir_of_src.make_node('xyz')
my_sub_node.mkdir()
tgt_basename = src.name
tgt = my_sub_node.make_node(tgt_basename)
tsk = self.create_task('xyz', src=src, tgt=tgt)
The problem is that this creates the following:
build\xyz\wscript
build\a\xyz\wscript
But I want this:
build\xyz\wscript
build\xyz\a\wscript
So I just to create the folder xyz between build and what ever the tgt is. So exactly the behavior of variant in a BuildContext.
When tasks execute, you are already in a variant build dir. To control the outputs of a task you have to use the waflib.Node class API. In your example, change_ext get the source build directory equivalent and change the extension. To insert a subdir:
# [...]
build_dir_of_src = src.get_bld().parent
my_sub_node = build_dir_of_src.make_node("my_sub_dir")
my_sub_node.mkdir()
tgt_basename = src.change_ext('.' + str(x)).name
tgt = my_sub_node.make_node(tgt_basename)
# [...]
If you want to insert a "variant style" directory, you can use bld.bldnode (untested but you see the point, use bld.bldnode):
def get_my_bld(bld, src_node):
variant_like_dirname = "xyz"
my_bld_node = bld.bldnode.make_node(variant_like_dirname)
my_bld_node.mkdir()
rp = src_node.get_bld().relpath(bld.bldnode)
my_bld_target = my_bld_node.make_node(rp)
return my_bld_tgt
# [...]
tgt = get_my_bld(bld, src)
# [...]

Getting a second parameter based on the first parameter in Jenkins

I have a task where my Jenkins job needs two parameters for build. The first specifies the application name and can be either QA, Dev, Prod etc and the second is a server which is dependent on the first one.
Example: If I chose the app name as QA, the second parameter should display values like QAServer1, QAServer2, QAServer3.
I'm using Active Choices Plugin (https://wiki.jenkins.io/display/JENKINS/Active+Choices+Plugin) to get this done but facing an problem in fetching the second parameter contents.
Snapshots:
For obtaining the second parameter, I've written a Groovy code which reads the respective files of the selected first parameter and gets the details.
code:
#!/usr/bin/env groovy
import hudson.model.*
def Appliname = System.getenv("APPNAME")
//println Appliname
def list1 = []
def directoryName = "C:/Users/Dev/Desktop/JSONSTest"
def fileSubStr = Appliname
def filePattern = ~/${fileSubStr}/
def directory = new File(directoryName)
def findFilenameClosure =
{
if (filePattern.matcher(it.name).find())
{
def jsoname = it.name
def jsoname1 = jsoname.reverse().take(9).reverse()
list1.add(jsoname1.substring(1,4))
String listAsString = "[\'${list1.join("', '")}\']"
println "return"+listAsString
}
}
directory.eachFileRecurse(findFilenameClosure)
The above code will print the output as return['QAServer1', 'QAServer2'] which i want to use it as input for the second parameter.
Snapshot of Second parameter:
Somehow the Groovy script is not being executed and second parameter value remains empty. How can i get this done dynamically. Am i following the right away to it. Kindly help me figure out. TIA
Would you like to try below change
From:
def findFilenameClosure =
{
if (filePattern.matcher(it.name).find())
{
def jsoname = it.name
def jsoname1 = jsoname.reverse().take(9).reverse()
list1.add(jsoname1.substring(1,4))
String listAsString = "[\'${list1.join("', '")}\']"
println "return"+listAsString
}
}
directory.eachFileRecurse(findFilenameClosure)
To:
directory.eachFileRecurse {
if (filePattern.matcher(it.name).find()) {
def jsoname = it.name
def jsoname1 = jsoname.reverse().take(9).reverse()
list1.add(jsoname1.substring(1,4))
}
}
return list1

Duplicate iOS application target, rename it, add new icon and build app from command line (without using Xcode GUI)

I would like to automate the process of adding a new target to my iOS application and write a script which would speed up the whole process. Is there any way to duplicate Xcode iOS application target, then rename it, add new icon specific for this target, change bundle id, app name etc. and finally build the app? I've tried using AppleScript to achieve this, but with no luck.
The workaround I am using now is to create one additional target (using Xcode GUI) and customize it during the build time (every time I want to build the app). The biggest downside of this approach is that targets' configurations are not saved anywhere and the parameters of the target have to be specified for every build of the app. This can lead to unrepeatable builds and other undebuggable issues. That's why I am looking for a method or a tool which would allow me to duplicate and configure new target from command line script
You can use this ruby script to duplicate any target, but you need to install github.com/CocoaPods/Xcodeproj first :
#!/usr/bin/env ruby
require 'rubygems'
require 'xcodeproj'
puts "Project path:"
proj_path = gets
puts "New target name:"
name = gets
puts "New target bundle identifer"
bundleIdentifier = gets
puts "Witch target to clone?"
srcTargetName = gets
name = name.chomp
bundleIdentifier = bundleIdentifier.chomp
proj_path = proj_path.chomp
srcTargetName = srcTargetName.chomp
proj = Xcodeproj::Project.open(proj_path)
src_target = proj.targets.find { |item| item.to_s == srcTargetName }
#proj_path = "/testingTest.xcodeproj"
# create target
target = proj.new_target(src_target.symbol_type, name, src_target.platform_name, src_target.deployment_target)
target.product_name = name
# create scheme
scheme = Xcodeproj::XCScheme.new
scheme.add_build_target(target)
scheme.set_launch_target(target)
scheme.save_as(proj_path, name, shared = true)
# copy build_configurations
target.build_configurations.map do |item|
item.build_settings.update(src_target.build_settings(item.name))
end
target.build_configurations.each do |config|
config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = bundleIdentifier
config.build_settings['PRODUCT_NAME'] = "$(TARGET_NAME)"
end
# copy build_phases
phases = src_target.build_phases.reject { |x| x.instance_of? Xcodeproj::Project::Object::PBXShellScriptBuildPhase }.collect(&:class)
phases.each do |klass|
src = src_target.build_phases.find { |x| x.instance_of? klass }
dst = target.build_phases.find { |x| x.instance_of? klass }
unless dst
dst ||= proj.new(klass)
target.build_phases << dst
end
dst.files.map { |x| x.remove_from_project }
src.files.each do |f|
file_ref = proj.new(Xcodeproj::Project::Object::PBXFileReference)
file_ref.name = f.file_ref.name
file_ref.path = f.file_ref.path
file_ref.source_tree = f.file_ref.source_tree
file_ref.last_known_file_type = f.file_ref.last_known_file_type
#file_ref.fileEncoding = f.file_ref.fileEncoding
begin
file_ref.move(f.file_ref.parent)
rescue
end
build_file = proj.new(Xcodeproj::Project::Object::PBXBuildFile)
build_file.file_ref = f.file_ref
dst.files << build_file
end
end
# add files
#classes = proj.main_group.groups.find { |x| x.to_s == 'Group' }.groups.find { |x| x.name == 'Classes' }
#sources = target.build_phases.find { |x| x.instance_of? Xcodeproj::Project::Object::PBXSourcesBuildPhase }
#file_ref = classes.new_file('test.m')
#build_file = proj.new(Xcodeproj::Project::Object::PBXBuildFile)
#build_file.file_ref = file_ref
#sources.files << build_file
proj.save

Resources