Add base argument to copy_select_files
This commit is contained in:
parent
12dfb38609
commit
f97ad260bb
15
ts/copy.bzl
15
ts/copy.bzl
@ -27,22 +27,27 @@ def copy_files(ctx, files):
|
||||
|
||||
return [DefaultInfo(files = depset(outputs))]
|
||||
|
||||
def copy_select_files(ctx, files, include, exclude, unwanted_prefix):
|
||||
def remove_prefix(text, prefix):
|
||||
if text.startswith(prefix):
|
||||
return text[len(prefix):]
|
||||
return text
|
||||
|
||||
def copy_select_files(ctx, files, include, exclude, base, unwanted_prefix):
|
||||
wanted = []
|
||||
for f in files.to_list():
|
||||
path = f.path
|
||||
path = remove_prefix(f.path, base)
|
||||
want = True
|
||||
|
||||
for substr in exclude:
|
||||
if substr in path:
|
||||
if path.startswith(substr):
|
||||
want = False
|
||||
continue
|
||||
if not want:
|
||||
continue
|
||||
|
||||
for substr in include:
|
||||
if substr in path:
|
||||
output = path.replace(unwanted_prefix, "")
|
||||
if path.startswith(substr):
|
||||
output = remove_prefix(path, unwanted_prefix)
|
||||
wanted.append((f, output))
|
||||
|
||||
return copy_files(ctx, wanted)
|
||||
|
@ -6,7 +6,8 @@ _include = [
|
||||
"css_browser_selector.min.js",
|
||||
]
|
||||
|
||||
_unwanted_prefix = "external/npm/node_modules/css-browser-selector/"
|
||||
_base = "external/npm/node_modules/css-browser-selector/"
|
||||
_unwanted_prefix = ""
|
||||
|
||||
def _copy_css_browser_selector_impl(ctx):
|
||||
return copy_select_files(
|
||||
@ -14,6 +15,7 @@ def _copy_css_browser_selector_impl(ctx):
|
||||
ctx.attr.css_browser_selector.files,
|
||||
_include,
|
||||
[],
|
||||
_base,
|
||||
_unwanted_prefix,
|
||||
)
|
||||
|
||||
|
@ -6,7 +6,8 @@ _include = [
|
||||
"jquery-ui.min.js",
|
||||
]
|
||||
|
||||
_unwanted_prefix = "external/npm/node_modules/jquery-ui-dist/"
|
||||
_base = "external/npm/node_modules/jquery-ui-dist/"
|
||||
_unwanted_prefix = ""
|
||||
|
||||
def _copy_jquery_ui_impl(ctx):
|
||||
return copy_select_files(
|
||||
@ -14,6 +15,7 @@ def _copy_jquery_ui_impl(ctx):
|
||||
ctx.attr.jquery_ui.files,
|
||||
_include,
|
||||
[],
|
||||
_base,
|
||||
_unwanted_prefix,
|
||||
)
|
||||
|
||||
|
@ -6,7 +6,8 @@ _include = [
|
||||
"dist/jquery.min.js"
|
||||
]
|
||||
|
||||
_unwanted_prefix = "external/npm/node_modules/jquery/dist/"
|
||||
_base = "external/npm/node_modules/jquery/"
|
||||
_unwanted_prefix = "dist/"
|
||||
|
||||
def _copy_jquery_impl(ctx):
|
||||
return copy_select_files(
|
||||
@ -14,6 +15,7 @@ def _copy_jquery_impl(ctx):
|
||||
ctx.attr.jquery.files,
|
||||
_include,
|
||||
[],
|
||||
_base,
|
||||
_unwanted_prefix,
|
||||
)
|
||||
|
||||
|
@ -14,7 +14,8 @@ _exclude = [
|
||||
"es5/sre/mathmaps/mathmaps_ie.js",
|
||||
]
|
||||
|
||||
_unwanted_prefix = "external/npm/node_modules/mathjax/es5/"
|
||||
_base = "external/npm/node_modules/mathjax/"
|
||||
_unwanted_prefix = "es5/"
|
||||
|
||||
def _copy_mathjax_impl(ctx):
|
||||
return copy_select_files(
|
||||
@ -22,6 +23,7 @@ def _copy_mathjax_impl(ctx):
|
||||
ctx.attr.mathjax.files,
|
||||
_include,
|
||||
_exclude,
|
||||
_base,
|
||||
_unwanted_prefix,
|
||||
)
|
||||
|
||||
|
@ -6,7 +6,8 @@ _include = [
|
||||
"dist/protobuf.min.js",
|
||||
]
|
||||
|
||||
_unwanted_prefix = "external/npm/node_modules/protobufjs/dist/"
|
||||
_base = "external/npm/node_modules/protobufjs/"
|
||||
_unwanted_prefix = "dist/"
|
||||
|
||||
def _copy_protobufjs_impl(ctx):
|
||||
return copy_select_files(
|
||||
@ -14,6 +15,7 @@ def _copy_protobufjs_impl(ctx):
|
||||
ctx.attr.protobufjs.files,
|
||||
_include,
|
||||
[],
|
||||
_base,
|
||||
_unwanted_prefix,
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user