I have a structure like this
target_files/
├──target1/
├──target2/
└──target3/
And I want to include only "target2" for example and exclude the other targets. How I write the spec.exclude_files?
I found this example for excluding files, but I can't understand how to write it for whole folders.
spec.exclude_files = '_private/**/*.{h,m}'
spec.source_files = [ 'target_files/**' ]
spec.exclude_files = [ 'target_files/target1/**', 'target_files/target3/**' ]
or for the case you ask about, more simply:
spec.source_files = [ 'target_files/target2/**' ]
Reference
CocoaPods exclude_files
[CocoaPods]
Pattern: ** - Matches directories recursively.
s.exclude_files = 'target_files/target1/', 'target_files/target3/'
The opposite is source_files[About]
Related
I'd like to do something like:
srcs = glob(["*.proto"]) - ["some.proto"],
That particular syntax isn't valid in Skylark. How do I go about accomplishing a list diff in Skylark?
glob provides a exclude attribute, e.g.:
glob(
[
".editorconfig",
".gitattributes",
"third_party/eigen-*/**",
],
exclude = ["devertexwahn/flatland/copy.bara.sky"],
),
I have a genrule that looks like the below. It basically runs a simple go template tool that gets a resource name, a json file and template and outputs the rendered file. I have a bunch of resources that all need to be in separate files and ultimately packaged into a container.
resources = ["foo", "bar"]
[genrule(
name = "generate_" + resource + "_config",
srcs = [
"//some:tool:config.tmpl",
"//some:json",
],
outs = [resource + ".hcl"],
cmd = "$(location //some/tool:template) -resource " + resource + " -json_path=$(location //some:json) -template=$(location //some/tool:config.tmpl) -out=$#",
tools = [
"/some/tool:template",
],
) for resource in resources]
The above will generate a few rules named generate_foo_config and generate_bar_config and the files output correctly. I however cannot figure out how to use each one without specifying them directly in a filegroup or pkg_tar rule without enumerating each one. I would like to be able to add a new thing to the resources variable, and have it automatically included in the filegroup or tar for use in a build rule later. Is this possible?
Use a list comprehension, like you've got creating the genrules. Something like this:
pkg_tar(
name = "all_resources",
srcs = [":generate_" + resource + "_config" for resource in resources],
)
You can also put the list in a variable in the BUILD file to use it multiple times:
all_resources = [":generate_" + resource + "_config" for resource in resources]
pkg_tar(
name = "all_resources",
srcs = all_resources,
)
filegroup(
name = "resources_filegroup",
srcs = all_resources,
)
The documentation (https://docs.bazel.build/configurable-attributes.html) offers the following example, which sadly doesn't work:
cc_library(
name = "my_lib",
deps = select(
{
"//tools/cc_target_os:android": [":android_deps"],
"//tools/cc_target_os:windows": [":windows_deps"],
},
no_match_error = "Please build with an Android or Windows toolchain",
),
)
Matchers such as "#platforms//os:macos" and "#platforms//os:windows" sadly only detect HOST platform but not TARGET platform. This breaks when cross-compiling on a different architecture.
I came up with an "android" matcher that works:
config_setting(
name = "android",
values = {"crosstool_top": "//external:android/crosstool"},
)
But cannot figure out a way to match windows, macos or linux TARGET toolchains.
Thanks!
I think that you are looking for platforms: https://docs.bazel.build/versions/master/platforms.html and the target_compatible_with attribute on cc_library.
I would suggest you want something like:
cc_library(
name = "my_lib_android",
deps = [":android_deps"],
target_compatible_with = [
"#platforms//os:android",
],
)
cc_library(
name = "my_lib_windows",
deps = [":windows_deps"],
target_compatible_with = [
"#platforms//os:windows",
],
)
The user of my_lib would then have to depend on either my_lib_android or my_lib_windows as appropriate.
My android project contains some aar modules, which have their own AndroidManifest.xml. What should I do to have the aar's manifest to be merged into the final AndroidManifest.xml?
Thanks very much for any help!
My android_binary rule:
android_binary(
name="apk",
custom_package = "com.xtbc",
manifest_merger = "android",
manifest = "AndroidManifest.xml",
resource_files = glob(["res/**"], exclude=["res/.DS_Store"]),
assets = glob(["assets/**"], exclude=["assets/.DS_Store"]),
assets_dir = "assets",
multidex = "manual_main_dex",
main_dex_list = "mainDexList.txt",
dexopts = [
"--force-jumbo"
],
deps = [
":lib",
":base_lib",
":jni"
]
)
The :base_lib is a module (ie, an android_library rule):
android_library(
name = "base_lib",
srcs = glob(["base/src/**/*.java"]),
custom_package = "com.xtbc.base",
manifest = "base/AndroidManifest.xml",
resource_files = glob(["base/res/**"], exclude=["base/res/.DS_Store"]),
assets = glob(["base/assets/**"], exclude=["base/assets/.DS_Store"]),
assets_dir = "base/assets",
deps = [
"#androidsdk//com.android.support:support-annotations-23.0.1"
]
)
It has its own base/AndoridManifest.xml, what I want is that the :base_lib's AndroidManifest.xml will be merged into the final AndroidManifest.xml(ie, the :apk's AndroidManifest.xml).
I do not have enough stackoverflow reputation to respond to the comment chain, but it sounds like what you are after is the exports_manifest attribute of android_library.
The documentation at https://bazel.build/versions/master/docs/be/android.html#android_library.exports_manifest says that the default is 1, however, that documentation is based on source code changes that have not made it into a Bazel release yet. For now you will need to add exports_manifest = 1 onto your android_library. In the next Bazel release, this will no longer be necessary.
Also, regarding "AAR modules": If these are prebuilt .aar files, you will want to use the aar_import rule. It does not have an exports_manifest attribute, because it will always export by default. If these are Gradle Android library modules, then you can just use the android_library rule. If you were referring to the support libraries, #androidsdk//com.android.support:support-annotations-23.0.1 is actually a JAR, not an AAR.
I am creating a Yeoman generator app. I want to create a set of parent directories and each parent directory has the same set of child templates.
Right now I am using the below commands repeatedly to achieve this. Is there a better way to loop over an array and achieve the same?
this.mkdir('app/scss/modules/tables');
this.mkdir('app/scss/modules/navigation');
this.mkdir('app/scss/modules/pagination');
this.copy('_extends.scss', 'app/scss/modules/navigation/_extends.scss');
this.copy('_mixins.scss', 'app/scss/modules/navigation/_mixins.scss');
this.copy('_variables.scss', 'app/scss/modules/navigation/_variables.scss');
this.copy('_extends.scss', 'app/scss/modules/pagination/_extends.scss');
this.copy('_mixins.scss', 'app/scss/modules/pagination/_mixins.scss');
this.copy('_variables.scss', 'app/scss/modules/pagination/_variables.scss');
this.copy('_extends.scss', 'app/scss/modules/tables/_extends.scss');
this.copy('_mixins.scss', 'app/scss/modules/tables/_mixins.scss');
this.copy('_variables.scss', 'app/scss/modules/tables/_variables.scss');
I reckon you'd need two arrays, and at least two loops.
In pseudocode:
dirs = [ ... directories ... ];
files = [ ... files ... ];
for (directory in dirs) {
mkdir (d);
for (file in files) {
copy(file, directory + file);
}
}
If you ever need another directory with all files, or another file to go in all directories you'd just add it to the corresponding array.
Hope you find this useful!
You could also do something like this:
dirs = [ "folder1", "folder2", "etc" ];
files = [ "file1", "file2", "etc" ];
dirs.forEach(function(directory){
this.mkdir(directory);
files.forEach(function(file){
this.copy(file, directory + file);
}.bind(this));
}.bind(this));
...if you want to avoid using a 'for-in' loop, since they're somewhat error-prone.