I need to extract a deb file that is available inside an archive - in bazel
new_artifactory_archive(
name = "extract",
build_file = "//path_to_build_file:my_file.BUILD",
path = "archive.tar.gz",
repo = "https://repository_where_archive_is/",
sha256 = "xxxxx",
)
By default, Bazel extracted the archive, but I don't know how can I extract the deb file then.
archive.tar.gz contains: deb_file1.deb and deb_file2.deb.
I have to extract those deb_file*.deb files.
I tried to create a rule and I used something like
cmd = "cd to_path_where_debs_are_available && ar -x deb_file1.deb && tar -xf data.tar.xz"
But I don't think this is the best approach.
Thank you!
Related
I have different modules in my project which are generating config files as a JSON which are part of java_libarary. I need to copy this generated JSON files to a new module using bazel build. I am thinking algorithm to do that as :
Read all dependency from bazel (assumption all modules which
generate json will be added as dependency).
Extract JAR files once by one in dependency
Copy json to new location
Package copied json to new tar as output
I am not sure, how i can do this in bazel, let me know if any one has similar example available.
Thanks in Advance...
I am using genrule to achieve same as :
In java_library BUILD file
genrule(
name = "core-search-registry-gen-rule",
srcs = [
":core-alarm",
],
outs = ["search-registry.zip"],
cmd = """
mkdir -p $(#D)/search_registry && \
$(JAVABASE)/bin/jar xf $(location :core-alarm) && \
for x in `find . -type f -name "*_registry.json"`; \
do cp $$x $(#D)/search_registry/; done && \
(cd $(#D) && zip -rq search-registry.zip search_registry/)
""",
message = "Concatenation of all json files one zip file",
toolchains = [
"#bazel_tools//tools/jdk:current_java_runtime",
],
visibility = ["//mp:__subpackages__"],
)
In packaging BUILD file :
pkg_tar(
name = "etc-search-registry",
files = [
"//mp/alarms/core:core-search-registry-gen-rule",
],
mode = "0644",
package_dir = "/etc/conf",
)
Thanks
Does Bazel offer a variable substitution for a temp directory in genrules?
Sometimes I need a staging area before creating the final output artefact.
I am imagining something like this:
genrule(
name = "example",
srcs = [ "a.txt" ],
cmd = "cp $< $(TMP)/b.txt && cp $(TMP)/b.txt $#",
)
$(TMP) would be a folder generated for me by Bazel on each rule execution.
No it doesn't. (As of Bazel 0.23.1)
It does set $TMPDIR though (even with --incompatible_strict_action_env), so mktemp should work. But $TMPDIR is by no means a dedicated temp directory (it's often just /tmp), so be careful what you clobber.
I migrated my genrule to a full Starlark rule. There I can do
tmp = ctx.actions.declare_directory("TMP_" + ctx.label.name)
and just use that directory as my temp in further actions.
It is similar to what the Starlark tutorial shows, in https://docs.bazel.build/versions/2.0.0/skylark/rules-tutorial.html#creating-a-file. The difference is that I do not register that directory as an output. That is, I don't do something like
return [DefaultInfo(files = depset([tmp]))]
You can make your own inside the bash code:
export TMP=$(mktemp -d || mktemp -d -t bazel-tmp)
trap "rm -rf $TMP" EXIT # Delete on exit
# Do things...
I have a library that depends on graphics files that are generated by a shell script.
I would like the library, when it is compiled, to use the shell script to generate the graphics files, which should be copied as if it were a 'data' statement, but whenever I try to make the library depend on the genrule, I get
in deps attribute of cc_library rule //graphics_assets
genrule rule '//graphics_assets:assets_gen_rule' is misplaced here
(expected cc_inc_library, cc_library, objc_library or
cc_proto_library)
# This is the correct format.
# Here we want to run all the shader .glsl files through the program
# file_utils:archive_tool (which we also build elsewhere) and copy the
# output .arc file to the data.
# 1. List the source files
filegroup(
name = "shader_source",
srcs = glob([
"shaders/*.glsl",
]),
)
# 2. invoke file_utils::archive_tool on the shaders
genrule(
name = "shaders_gen_rule",
srcs = [":shader_source"],
outs = ["shaders.arc"],
cmd = "echo $(locations shader_source) > temp.txt ; \
$(location //common/file_utils:archive_tool) \
--create_from_list=temp.txt \
--archive $(OUTS) ; \
$(location //common/file_utils:archive_tool) \
--ls --archive $(OUTS) ",
tools = ["//common/file_utils:archive_tool"],
)
# 3. when a a binary depends on this tool the arc file will be copied.
# This is the thing I had trouble with
cc_library(
name = "shaders",
srcs = [], # Something
data = [":shaders_gen_rule"],
linkstatic = 1,
)
Everyone who searched how to include a static library in SDK, surely read this thread from 2014. I tried what they suggested, but that didn't work.
Reading the yocto mega manual version 2.1 (yocto morty), I found in chapter 5.9.12. (Poky Reference Distribution Changes), that they added DISABLE_STATIC variable, to disable generation of static libraries. I tried adding this to my recipe, and it didn't enable adding static library to SDK:
DISABLE_STATIC = ""
I can see the library in the sysroot when building the image. But it is not getting in the SDK.
So, what exactly do I need to do to get a static library and the headers in SDK?
What worked is adding the staticdev package to ´IMAGE_INSTALL´ in local.conf, but I don't want to have to do that.
I created an example recipe, which demonstrates my problem. The directory structure is like this:
example-staticlib/
example-staticlib/example-staticlib_0.1.bb
example-staticlib/files/
example-staticlib/files/lib.c
example-staticlib/files/lib.h
example-staticlib/files/Makefile
example-staticlib_0.1.bb :
DESCRIPTION = "example stared library"
LICENSE = "LGPLv2"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/LGPL-2.0;md5=9427b8ccf5cf3df47c29110424c9641a"
SRC_URI = "file://lib.c \
file://lib.h \
file://Makefile"
PR = "r0"
S = "${WORKDIR}"
ALLOW_EMPTY_${PN} = "1"
do_install () {
oe_runmake install DEST=${D}
}
TOOLCHAIN_TARGET_TASK += "example-staticlib-dev"
TOOLCHAIN_TARGET_TASK += "example-staticlib-staticdev"
lib.c:
int foo()
{
return 42;
}
lib.h:
int foo();
Makefile:
TARGET=libexample.a
all:$(TARGET)
install :
#install -d $(DEST)/usr/lib/
#install -m 0644 $(TARGET) $(DEST)/usr/lib/
#install -d $(DEST)/usr/include/
#install -m 0644 lib.h $(DEST)/usr/include/
$(TARGET) : lib.c
$(CC) -c lib.c -o lib.o
$(AR) rcs $# lib.o
clean:
rm -rf lib.o $(TARGET)
How exactly to modify the recipe, in order to get the static library in the SDK?
Following your added example.
Adding the following line to your image recipe (or to an .bbappend, eg core-image-minimal.bbappend)
TOOLCHAIN_TARGET_TASK += "example-staticlib-staticdev"
should work for you. That will give you the .a file in the SDK, after running bitbake core-image-minimal -c populate_sdk. (Again assuming that the image used is core-image-minimal).
That your experiment to add the .a file to ${PN}-dev didn't work, is duet to the order of how files are put into packages. The order is ${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}. Thus, the .a file will, regardless, be put into ${PN}-staticdev, as that packages is handled prior to {PN}-dev.
Note, you add this line, TOOLCHAIN_TARGET_TASK += "example-staticlib-staticdev" to your image recipe, thus, you need to write the package name instead of PN.
I tried a way which doesn't require editing the image recipe.
example-staticlib_0.1.bb :
After do_install. I didn't use TOOLCHAIN_TARGET_TASK
FILES_${PN}-staticdev += "${libdir}/libexample.a"
RDEPENDS_${PN}-dev += "${PN}-staticdev"
BBCLASSEXTEND = "native nativesdk"
I have a file dagens_130325.tar.gz containing the folder dagens. In one folder I have hundreds of these daily info. I would like to unpack dagens_130325.tar.gz/dagens to 130325 with all the files inside. Then 130326 etc.
Is there a way to do it?
Not sure this is the right stack where to ask this kind of question, however try with
tar -zxvf dagens_130325.tar.gz -C /tmp/130325 dagens
This way, the folder dagens for the archive dagens_130325.tar.gz is going to be extracted into /tmp/130325. However, note that the target folder must exist, otherwise the command will fail
So, supposedly you have 4 archives in the form dagens_1.tar.gz, dagens_2.tar.gz, ..., you can write an extract.sh file containing
#!/bin/bash
for i in {1..4}
do
mkdir /tmp/$i
FILE="dagens_$i.tar.gz"
tar -zxvf $FILE -C /tmp/$i dagens
done
Having this file the execute permission, being in the same folder as your archives and executing it should produced the result you asked.
This was the solution I came up with in the end
#!/bin/bash
search_dir=/yourdir/with/tar.gz
for entry in "$search_dir"/*.tar.gz
do
substring=$(basename "$entry")
echo $substring
sub2=${substring:7:6}
tar -xvzf $substring
rm -rf $sub2
mv dagens $sub2
done
use
#!/bin/bash
for file in dagens_*.tar.gz
do
from=${file%_*} #removes chars after _
to=${file#*_} #removes chars before _
to=${to%.t*} #removes chars after .t (.tar.gz)
tar -zxf $file --show-transformed --transform "s/$from/$to/"
done