-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinternal.bzl
57 lines (50 loc) · 2.79 KB
/
internal.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Copyright (c) 2016-2017 Dustin Doloff
# Licensed under Apache License v2.0
load(
"@bazel_toolbox//collections:collections.bzl",
"merge_dicts",
)
# Returns |value| if it is not None, otherwise returns |default|.
def _default_none(value, default):
return value if value != None else default
# Helper function for adding optional flags to action inputs
# flag - str - The flag for the argument. E.g. "--arg-name"
# val - bool or list or * - A boolean to indicate if the flag should appear or not or a list, which if
# non-empty will result in a list with the flag followed by the contents.
# list - Returns a list that will either be empty, contain just the flag, or contain the flag and
# the contents of val.
def optional_arg_(flag, val):
val_type = type(val)
if val_type == "bool":
if val:
return [flag]
elif val_type == "list":
if len(val) > 0:
return [flag] + [str(v) for v in val]
elif val != None:
return [flag, str(val)]
return []
# Adds all the transitive dependencies of resource to orig_struct and returns the new struct
# orig_struct - struct - The base struct
# resource - dict like object - The dict to get properties from
# opt_ignore_types - list of str - An optional list of types to leave out of the returned struct
# A merged struct with all the resources in resource on top of orig_struct's resources
def transitive_resources_(orig_struct, resource, opt_ignore_types = []):
if type(orig_struct) != "struct":
fail("orig_struct is not a struct")
if type(opt_ignore_types) != "list":
fail("opt_ignore_types is not a list")
return struct(
source_map = merge_dicts(
getattr(orig_struct, "source_map", {}),
getattr(resource, "source_map", {}) if "source_map" not in opt_ignore_types else {},
),
resources = depset(getattr(orig_struct, "resources", depset()).to_list() +
(getattr(resource, "resources", depset()).to_list() if "resources" not in opt_ignore_types else list())),
css_resources = depset(getattr(orig_struct, "css_resources", depset()).to_list() +
(getattr(resource, "css_resources", depset()).to_list() if "css_resources" not in opt_ignore_types else list())),
deferred_js_resources = depset(getattr(orig_struct, "deferred_js_resources", depset()).to_list() +
(getattr(resource, "deferred_js_resources", depset()).to_list() if "deferred_js_resources" not in opt_ignore_types else list())),
js_resources = depset(getattr(orig_struct, "js_resources", depset()).to_list() +
(getattr(resource, "js_resources", depset()).to_list() if "js_resources" not in opt_ignore_types else list())),
)