Skip to content

Commit

Permalink
Add use_os and use_arch to module extension
Browse files Browse the repository at this point in the history
Will be followed by using these two attributes in the lockfile to store platform dependent extensions

related issue: #19154

PiperOrigin-RevId: 559392081
Change-Id: Ib0cfa2df648effe785068fa4d03da02c39d1fdd8
  • Loading branch information
SalmaSamy committed Sep 12, 2023
1 parent 5e1ceaf commit 15c442c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public abstract class ModuleExtension implements StarlarkValue {

public abstract ImmutableList<String> getEnvVariables();

public abstract boolean getUseOs();

public abstract boolean getUseArch();

public static Builder builder() {
return new AutoValue_ModuleExtension.Builder();
}
Expand All @@ -54,6 +58,10 @@ public abstract static class Builder {

public abstract Builder setEnvVariables(ImmutableList<String> value);

public abstract Builder setUseOs(boolean useOs);

public abstract Builder setUseArch(boolean useArch);

public abstract ModuleExtension build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ public ModuleExtension moduleExtension(
Dict<?, ?> tagClasses, // Dict<String, TagClass>
String doc,
Sequence<?> environ, // <String>
Boolean useOs,
Boolean useArch,
StarlarkThread thread)
throws EvalException {
return ModuleExtension.builder()
Expand All @@ -277,6 +279,8 @@ public ModuleExtension moduleExtension(
.setDoc(doc)
.setEnvVariables(ImmutableList.copyOf(Sequence.cast(environ, String.class, "environ")))
.setLocation(thread.getCallerLocation())
.setUseOs(useOs)
.setUseArch(useArch)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,27 @@ StarlarkCallable repositoryRule(
+ "re-evaluated.",
named = true,
positional = false),
@Param(
name = "use_os",
defaultValue = "False",
doc = "Indicates whether this extension is OS-dependent or not",
named = true,
positional = false),
@Param(
name = "use_arch",
defaultValue = "False",
doc = "Indicates whether this extension is architecture-dependent or not",
named = true,
positional = false)
},
useStarlarkThread = true)
Object moduleExtension(
StarlarkCallable implementation,
Dict<?, ?> tagClasses, // Dict<String, TagClassApi>
String doc,
Sequence<?> environ, // <String>
Boolean useOs,
Boolean useArch,
StarlarkThread thread)
throws EvalException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public Object moduleExtension(
Dict<?, ?> tagClasses,
String doc,
Sequence<?> environ,
Boolean useOs,
Boolean useArch,
StarlarkThread thread)
throws EvalException {
return new Object();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ public void simpleExtension() throws Exception {
" for mod in ctx.modules:",
" for tag in mod.tags.tag:",
" data_repo(name=tag.name,data=tag.data)",
"ext = module_extension(implementation=_ext_impl, tag_classes={'tag':tag})");
"ext = module_extension(implementation=_ext_impl, tag_classes={'tag':tag}, "
+ "use_os=True, use_arch=True)");
scratch.file(workspaceRoot.getRelative("BUILD").getPathString());
scratch.file(
workspaceRoot.getRelative("data.bzl").getPathString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ private static ModuleExtension.Builder getBaseExtensionBuilder() {
.setDoc("")
.setLocation(Location.BUILTIN)
.setImplementation(() -> "maven")
.setEnvVariables(ImmutableList.of());
.setEnvVariables(ImmutableList.of())
.setUseOs(false)
.setUseArch(false);
}

@Test
Expand Down

0 comments on commit 15c442c

Please sign in to comment.