Skip to content

Commit

Permalink
Skylark: Package environment extensions can register functions with t…
Browse files Browse the repository at this point in the history
…he native module.

--
MOS_MIGRATED_REVID=89309511
  • Loading branch information
Googler authored and hanwen committed Mar 24, 2015
1 parent 0ddcba2 commit 6db223d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ public interface EnvironmentExtension {
void update(Environment environment, MakeEnvironment.Builder pkgMakeEnv,
Label buildFileLabel);

/**
* Returns the extra functions needed to be added to the Skylark native module.
*/
ImmutableList<Function> nativeModuleFunctions();

Iterable<PackageArgument<?>> getPackageArguments();
}

Expand Down Expand Up @@ -821,7 +826,7 @@ private static RuleClass getBuiltInRuleClass(String ruleClassName, RuleFactory r
/**
* Get the PackageContext by looking up in the environment.
*/
private static PackageContext getContext(Environment env, FuncallExpression ast)
public static PackageContext getContext(Environment env, FuncallExpression ast)
throws EvalException {
try {
return (PackageContext) env.lookup(PKG_CONTEXT);
Expand Down Expand Up @@ -1069,6 +1074,13 @@ public PackageContext(Package.LegacyBuilder pkgBuilder, Globber globber,
this.eventHandler = eventHandler;
this.globber = globber;
}

/**
* Returns the Label of this Package.
*/
public Label getLabel() {
return pkgBuilder.getBuildFileLabel();
}
}

/**
Expand All @@ -1081,6 +1093,9 @@ public ImmutableList<Function> collectNativeRuleFunctions() {
builder.add(newRuleFunction(ruleFactory, ruleClass));
}
builder.add(newPackageFunction(packageArguments));
for (EnvironmentExtension extension : environmentExtensions) {
builder.addAll(extension.nativeModuleFunctions());
}
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.google.devtools.build.lib.skyframe.SkyframeExecutor;
import com.google.devtools.build.lib.skyframe.SkyframeExecutorFactory;
import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.syntax.Function;
import com.google.devtools.build.lib.syntax.Label;
import com.google.devtools.build.lib.util.AbruptExitException;
import com.google.devtools.build.lib.util.Clock;
Expand Down Expand Up @@ -359,6 +360,11 @@ public void update(
public Iterable<PackageArgument<?>> getPackageArguments() {
return ImmutableList.of();
}

@Override
public ImmutableList<Function> nativeModuleFunctions() {
return ImmutableList.<Function>of();
}
};
}

Expand Down

0 comments on commit 6db223d

Please sign in to comment.