Skip to content

Commit 67ddb44

Browse files
authored
Add support-path-mapping to mojo_library (#36)
The only changes here are making sure we let the args object handle path mapping. This is slightly complicated by using the dirname for import paths, but ignoring the value from our provider.
1 parent a60ffa0 commit 67ddb44

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

mojo/mojo_library.bzl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
load("//mojo:providers.bzl", "MojoInfo")
44
load("//mojo/private:utils.bzl", "MOJO_EXTENSIONS", "collect_mojoinfo")
55

6+
def _format_include(arg):
7+
return ["-I", arg.dirname]
8+
69
def _mojo_library_implementation(ctx):
710
mojo_toolchain = ctx.toolchains["//:toolchain_type"].mojo_toolchain_info
811

912
mojo_package = ctx.actions.declare_file(ctx.label.name + ".mojopkg")
1013
args = ctx.actions.args()
1114
args.add("package")
1215
args.add("-strip-file-prefix=.")
13-
args.add("-o", mojo_package.path)
16+
args.add("-o", mojo_package)
1417
args.add_all(ctx.attr.copts)
1518

1619
import_paths, transitive_mojopkgs = collect_mojoinfo(ctx.attr.deps + mojo_toolchain.implicit_deps)
@@ -19,9 +22,9 @@ def _mojo_library_implementation(ctx):
1922
file_args = ctx.actions.args()
2023
for file in ctx.files.srcs:
2124
if not file.dirname.startswith(root_directory):
22-
file_args.add("-I", file.dirname)
25+
args.add_all([file], map_each = _format_include)
2326

24-
file_args.add_all(import_paths, before_each = "-I")
27+
file_args.add_all(transitive_mojopkgs, map_each = _format_include)
2528
file_args.add(root_directory)
2629
ctx.actions.run(
2730
executable = mojo_toolchain.mojo,
@@ -37,6 +40,9 @@ def _mojo_library_implementation(ctx):
3740
},
3841
use_default_shell_env = True,
3942
toolchain = "//:toolchain_type",
43+
execution_requirements = {
44+
"supports-path-mapping": "1",
45+
},
4046
)
4147

4248
transitive_runfiles = []

0 commit comments

Comments
 (0)