mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 16:26:40 -04:00
merge separate vendor rules into single rule
Rather than creating a separate rule for each package, we can just create a generic one and reuse it. Also switch to keyword arguments in the resulting macros, as it's easier to read.
This commit is contained in:
parent
13994973cb
commit
5ec5a47708
8 changed files with 106 additions and 172 deletions
32
qt/aqt/data/web/js/vendor/BUILD.bazel
vendored
32
qt/aqt/data/web/js/vendor/BUILD.bazel
vendored
|
@ -1,28 +1,12 @@
|
||||||
load("//ts:jquery.bzl", "copy_jquery")
|
load("//ts:vendor.bzl", "copy_css_browser_selector", "copy_jquery", "copy_jquery_ui", "copy_protobufjs")
|
||||||
load("//ts:jquery-ui.bzl", "copy_jquery_ui")
|
|
||||||
load("//ts:protobufjs.bzl", "copy_protobufjs")
|
|
||||||
load("//ts:css-browser-selector.bzl", "copy_css_browser_selector")
|
|
||||||
|
|
||||||
copy_jquery(
|
copy_jquery(name = "jquery")
|
||||||
name = "jquery",
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
||||||
|
|
||||||
copy_jquery_ui(
|
copy_jquery_ui(name = "jquery-ui")
|
||||||
name = "jquery-ui",
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
||||||
|
|
||||||
copy_protobufjs(
|
copy_protobufjs(name = "protobufjs")
|
||||||
name = "protobufjs",
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
||||||
|
|
||||||
copy_css_browser_selector(
|
|
||||||
name = "css-browser-selector",
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
copy_css_browser_selector(name = "css-browser-selector")
|
||||||
|
|
||||||
files = [
|
files = [
|
||||||
"jquery",
|
"jquery",
|
||||||
|
@ -37,8 +21,8 @@ directories = [
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
name = "vendor",
|
name = "vendor",
|
||||||
srcs = glob(["*.js"])
|
srcs = glob(["*.js"]) +
|
||||||
+ ["//qt/aqt/data/web/js/vendor:{}".format(file) for file in files]
|
["//qt/aqt/data/web/js/vendor:{}".format(file) for file in files] +
|
||||||
+ ["//qt/aqt/data/web/js/vendor/{}".format(dir) for dir in directories],
|
["//qt/aqt/data/web/js/vendor/{}".format(dir) for dir in directories],
|
||||||
visibility = ["//qt:__subpackages__"],
|
visibility = ["//qt:__subpackages__"],
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
load("//ts:mathjax.bzl", "copy_mathjax")
|
load("//ts:vendor.bzl", "copy_mathjax")
|
||||||
|
|
||||||
copy_mathjax(
|
copy_mathjax(name = "mathjax")
|
||||||
name = "mathjax",
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
load("//ts:copy.bzl", "copy_select_files")
|
|
||||||
|
|
||||||
"Rule to copy css-browser-selector subset from node_modules to vendor folder."
|
|
||||||
|
|
||||||
_include = [
|
|
||||||
"css_browser_selector.min.js",
|
|
||||||
]
|
|
||||||
|
|
||||||
_base = "external/npm/node_modules/css-browser-selector/"
|
|
||||||
_unwanted_prefix = ""
|
|
||||||
|
|
||||||
def _copy_css_browser_selector_impl(ctx):
|
|
||||||
return copy_select_files(
|
|
||||||
ctx,
|
|
||||||
ctx.attr.css_browser_selector.files,
|
|
||||||
_include,
|
|
||||||
[],
|
|
||||||
_base,
|
|
||||||
_unwanted_prefix,
|
|
||||||
)
|
|
||||||
|
|
||||||
copy_css_browser_selector = rule(
|
|
||||||
implementation = _copy_css_browser_selector_impl,
|
|
||||||
attrs = {
|
|
||||||
"css_browser_selector": attr.label(default = "@npm//css-browser-selector:css-browser-selector__files"),
|
|
||||||
},
|
|
||||||
)
|
|
|
@ -1,27 +0,0 @@
|
||||||
load("//ts:copy.bzl", "copy_select_files")
|
|
||||||
|
|
||||||
"Rule to copy jquery-ui subset from node_modules to vendor folder."
|
|
||||||
|
|
||||||
_include = [
|
|
||||||
"jquery-ui.min.js",
|
|
||||||
]
|
|
||||||
|
|
||||||
_base = "external/npm/node_modules/jquery-ui-dist/"
|
|
||||||
_unwanted_prefix = ""
|
|
||||||
|
|
||||||
def _copy_jquery_ui_impl(ctx):
|
|
||||||
return copy_select_files(
|
|
||||||
ctx,
|
|
||||||
ctx.attr.jquery_ui.files,
|
|
||||||
_include,
|
|
||||||
[],
|
|
||||||
_base,
|
|
||||||
_unwanted_prefix,
|
|
||||||
)
|
|
||||||
|
|
||||||
copy_jquery_ui = rule(
|
|
||||||
implementation = _copy_jquery_ui_impl,
|
|
||||||
attrs = {
|
|
||||||
"jquery_ui": attr.label(default = "@npm//jquery-ui-dist:jquery-ui-dist__files"),
|
|
||||||
},
|
|
||||||
)
|
|
|
@ -1,27 +0,0 @@
|
||||||
load("//ts:copy.bzl", "copy_select_files")
|
|
||||||
|
|
||||||
"Rule to copy jquery subset from node_modules to vendor folder."
|
|
||||||
|
|
||||||
_include = [
|
|
||||||
"dist/jquery.min.js"
|
|
||||||
]
|
|
||||||
|
|
||||||
_base = "external/npm/node_modules/jquery/"
|
|
||||||
_unwanted_prefix = "dist/"
|
|
||||||
|
|
||||||
def _copy_jquery_impl(ctx):
|
|
||||||
return copy_select_files(
|
|
||||||
ctx,
|
|
||||||
ctx.attr.jquery.files,
|
|
||||||
_include,
|
|
||||||
[],
|
|
||||||
_base,
|
|
||||||
_unwanted_prefix,
|
|
||||||
)
|
|
||||||
|
|
||||||
copy_jquery = rule(
|
|
||||||
implementation = _copy_jquery_impl,
|
|
||||||
attrs = {
|
|
||||||
"jquery": attr.label(default = "@npm//jquery:jquery__files"),
|
|
||||||
},
|
|
||||||
)
|
|
|
@ -1,35 +0,0 @@
|
||||||
load("//ts:copy.bzl", "copy_select_files")
|
|
||||||
|
|
||||||
"Rule to copy mathjax subset from node_modules to vendor folder."
|
|
||||||
|
|
||||||
_include = [
|
|
||||||
"es5/tex-chtml.js",
|
|
||||||
"es5/input/tex/extensions",
|
|
||||||
"es5/output/chtml/fonts/woff-v2",
|
|
||||||
"es5/a11y",
|
|
||||||
"es5/sre",
|
|
||||||
]
|
|
||||||
|
|
||||||
_exclude = [
|
|
||||||
"es5/sre/mathmaps/mathmaps_ie.js",
|
|
||||||
]
|
|
||||||
|
|
||||||
_base = "external/npm/node_modules/mathjax/"
|
|
||||||
_unwanted_prefix = "es5/"
|
|
||||||
|
|
||||||
def _copy_mathjax_impl(ctx):
|
|
||||||
return copy_select_files(
|
|
||||||
ctx,
|
|
||||||
ctx.attr.mathjax.files,
|
|
||||||
_include,
|
|
||||||
_exclude,
|
|
||||||
_base,
|
|
||||||
_unwanted_prefix,
|
|
||||||
)
|
|
||||||
|
|
||||||
copy_mathjax = rule(
|
|
||||||
implementation = _copy_mathjax_impl,
|
|
||||||
attrs = {
|
|
||||||
"mathjax": attr.label(default = "@npm//mathjax:mathjax__files"),
|
|
||||||
},
|
|
||||||
)
|
|
|
@ -1,27 +0,0 @@
|
||||||
load("//ts:copy.bzl", "copy_select_files")
|
|
||||||
|
|
||||||
"Rule to copy protobufjs subset from node_modules to vendor folder."
|
|
||||||
|
|
||||||
_include = [
|
|
||||||
"dist/protobuf.min.js",
|
|
||||||
]
|
|
||||||
|
|
||||||
_base = "external/npm/node_modules/protobufjs/"
|
|
||||||
_unwanted_prefix = "dist/"
|
|
||||||
|
|
||||||
def _copy_protobufjs_impl(ctx):
|
|
||||||
return copy_select_files(
|
|
||||||
ctx,
|
|
||||||
ctx.attr.protobufjs.files,
|
|
||||||
_include,
|
|
||||||
[],
|
|
||||||
_base,
|
|
||||||
_unwanted_prefix,
|
|
||||||
)
|
|
||||||
|
|
||||||
copy_protobufjs = rule(
|
|
||||||
implementation = _copy_protobufjs_impl,
|
|
||||||
attrs = {
|
|
||||||
"protobufjs": attr.label(default = "@npm//protobufjs:protobufjs__files"),
|
|
||||||
},
|
|
||||||
)
|
|
96
ts/vendor.bzl
Normal file
96
ts/vendor.bzl
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
"""
|
||||||
|
Helpers to copy runtime dependencies from node_modules.
|
||||||
|
"""
|
||||||
|
|
||||||
|
load("//ts:copy.bzl", "copy_select_files")
|
||||||
|
|
||||||
|
def _vendor_js_lib_impl(ctx):
|
||||||
|
base = ctx.attr.base or "external/npm/node_modules/{}/".format(ctx.attr.name)
|
||||||
|
return copy_select_files(
|
||||||
|
ctx = ctx,
|
||||||
|
files = ctx.attr.pkg.files,
|
||||||
|
include = ctx.attr.include,
|
||||||
|
exclude = ctx.attr.exclude,
|
||||||
|
base = base,
|
||||||
|
unwanted_prefix = ctx.attr.strip_prefix,
|
||||||
|
)
|
||||||
|
|
||||||
|
vendor_js_lib = rule(
|
||||||
|
implementation = _vendor_js_lib_impl,
|
||||||
|
attrs = {
|
||||||
|
"pkg": attr.label(),
|
||||||
|
"include": attr.string_list(),
|
||||||
|
"exclude": attr.string_list(default = []),
|
||||||
|
"base": attr.string(default = ""),
|
||||||
|
"strip_prefix": attr.string(default = ""),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
def _pkg_from_name(name):
|
||||||
|
return "@npm//{0}:{0}__files".format(name)
|
||||||
|
|
||||||
|
#
|
||||||
|
# These could be defined directly in BUILD files, but defining them as
|
||||||
|
# macros allows downstream projects to reuse them.
|
||||||
|
#
|
||||||
|
|
||||||
|
def copy_jquery(name = "jquery", visibility = ["//visibility:public"]):
|
||||||
|
vendor_js_lib(
|
||||||
|
name = name,
|
||||||
|
pkg = _pkg_from_name(name),
|
||||||
|
include = [
|
||||||
|
"dist/jquery.min.js",
|
||||||
|
],
|
||||||
|
strip_prefix = "dist/",
|
||||||
|
visibility = visibility,
|
||||||
|
)
|
||||||
|
|
||||||
|
def copy_jquery_ui(name = "jquery-ui", visibility = ["//visibility:public"]):
|
||||||
|
vendor_js_lib(
|
||||||
|
name = name,
|
||||||
|
pkg = _pkg_from_name("jquery-ui-dist"),
|
||||||
|
base = "external/npm/node_modules/jquery-ui-dist/",
|
||||||
|
include = [
|
||||||
|
"jquery-ui.min.js",
|
||||||
|
],
|
||||||
|
visibility = visibility,
|
||||||
|
)
|
||||||
|
|
||||||
|
def copy_protobufjs(name = "protobufjs", visibility = ["//visibility:public"]):
|
||||||
|
vendor_js_lib(
|
||||||
|
name = name,
|
||||||
|
pkg = _pkg_from_name(name),
|
||||||
|
include = [
|
||||||
|
"dist/protobuf.min.js",
|
||||||
|
],
|
||||||
|
strip_prefix = "dist/",
|
||||||
|
visibility = visibility,
|
||||||
|
)
|
||||||
|
|
||||||
|
def copy_mathjax(name = "mathjax", visibility = ["//visibility:public"]):
|
||||||
|
vendor_js_lib(
|
||||||
|
name = name,
|
||||||
|
pkg = _pkg_from_name(name),
|
||||||
|
include = [
|
||||||
|
"es5/tex-chtml.js",
|
||||||
|
"es5/input/tex/extensions",
|
||||||
|
"es5/output/chtml/fonts/woff-v2",
|
||||||
|
"es5/a11y",
|
||||||
|
"es5/sre",
|
||||||
|
],
|
||||||
|
exclude = [
|
||||||
|
"es5/sre/mathmaps/mathmaps_ie.js",
|
||||||
|
],
|
||||||
|
strip_prefix = "es5/",
|
||||||
|
visibility = visibility,
|
||||||
|
)
|
||||||
|
|
||||||
|
def copy_css_browser_selector(name = "css-browser-selector", visibility = ["//visibility:public"]):
|
||||||
|
vendor_js_lib(
|
||||||
|
name = name,
|
||||||
|
pkg = _pkg_from_name(name),
|
||||||
|
include = [
|
||||||
|
"css_browser_selector.min.js",
|
||||||
|
],
|
||||||
|
visibility = visibility,
|
||||||
|
)
|
Loading…
Reference in a new issue