Make import paths work right
This commit is contained in:
parent
2dfb2ca574
commit
f1ea2cb645
1 changed files with 25 additions and 7 deletions
|
@ -33,12 +33,12 @@ https://github.com/dart-lang/rules_dart).
|
|||
SassInfo = provider(
|
||||
doc = "Collects files from sass_library for use in downstream sass_binary",
|
||||
fields = {
|
||||
"transitive_includes": "Directories to be treated as @use/@import search paths",
|
||||
"transitive_sources": "Sass sources for this target and its dependencies",
|
||||
},
|
||||
)
|
||||
|
||||
def _collect_transitive_sources(srcs, deps):
|
||||
"Sass compilation requires all transitive .sass source files"
|
||||
return depset(
|
||||
srcs,
|
||||
transitive = [dep[SassInfo].transitive_sources for dep in deps],
|
||||
|
@ -46,6 +46,13 @@ def _collect_transitive_sources(srcs, deps):
|
|||
order = "postorder",
|
||||
)
|
||||
|
||||
def _collect_transitive_imports(imports, deps):
|
||||
return depset(
|
||||
imports,
|
||||
transitive = [dep[SassInfo].transitive_includes for dep in deps],
|
||||
order = "postorder",
|
||||
)
|
||||
|
||||
def _sass_library_impl(ctx):
|
||||
"""sass_library collects all transitive sources for given srcs and deps.
|
||||
|
||||
|
@ -61,8 +68,16 @@ def _sass_library_impl(ctx):
|
|||
ctx.files.srcs,
|
||||
ctx.attr.deps,
|
||||
)
|
||||
transitive_includes = _collect_transitive_imports(
|
||||
[ctx.label.package] + ctx.attr.imports,
|
||||
ctx.attr.deps,
|
||||
)
|
||||
|
||||
return [
|
||||
SassInfo(transitive_sources = transitive_sources),
|
||||
SassInfo(
|
||||
transitive_sources = transitive_sources,
|
||||
transitive_includes = transitive_includes,
|
||||
),
|
||||
DefaultInfo(
|
||||
files = transitive_sources,
|
||||
runfiles = ctx.runfiles(transitive_files = transitive_sources),
|
||||
|
@ -84,11 +99,8 @@ def _run_sass(ctx, input, css_output, map_output = None):
|
|||
if ctx.attr.sourcemap_embed_sources:
|
||||
args.add("--sourcemap-contents")
|
||||
|
||||
# Sources for compilation may exist in the source tree, in bazel-bin, or bazel-genfiles.
|
||||
for prefix in [".", ctx.var["BINDIR"], ctx.var["GENDIR"]]:
|
||||
args.add("--include-path=%s/" % prefix)
|
||||
for include_path in ctx.attr.include_paths:
|
||||
args.add("--include-path=%s/%s" % (prefix, include_path))
|
||||
for include_path in _collect_transitive_imports([ctx.label.package], ctx.attr.deps).to_list():
|
||||
args.add("--include-path=%s/" % include_path)
|
||||
|
||||
# Last arguments are input and output paths
|
||||
# Note that the sourcemap is implicitly written to a path the same as the
|
||||
|
@ -163,6 +175,9 @@ _sass_library_attrs = {
|
|||
allow_empty = False,
|
||||
mandatory = True,
|
||||
),
|
||||
"imports": attr.string_list(
|
||||
doc = "Import prefixes",
|
||||
),
|
||||
"deps": sass_deps_attr,
|
||||
}
|
||||
|
||||
|
@ -179,6 +194,9 @@ _sass_binary_attrs = {
|
|||
mandatory = True,
|
||||
allow_single_file = _ALLOWED_SRC_FILE_EXTENSIONS,
|
||||
),
|
||||
"imports": attr.string_list(
|
||||
doc = "Import prefixes",
|
||||
),
|
||||
"sourcemap": attr.bool(
|
||||
default = True,
|
||||
doc = "Whether source maps should be emitted.",
|
||||
|
|
Loading…
Reference in a new issue