Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix genrule autostamping #21407

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package com.google.devtools.build.lib.bazel.rules.genrule;

import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.TriState;
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.rules.genrule.GenRuleBase;

Expand All @@ -25,9 +27,11 @@ public class BazelGenRule extends GenRuleBase {

@Override
protected boolean isStampingEnabled(RuleContext ruleContext) {
if (!ruleContext.attributes().has("stamp", Type.BOOLEAN)) {
if (!ruleContext.attributes().has("stamp", BuildType.TRISTATE)) {
return false;
}
return ruleContext.attributes().get("stamp", Type.BOOLEAN);
TriState stamp = ruleContext.attributes().get("stamp", BuildType.TRISTATE);
return stamp.equals(TriState.YES) ||
(stamp.equals(TriState.AUTO) && ruleContext.getConfiguration().stampBinaries());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@

import static com.google.devtools.build.lib.packages.Attribute.attr;
import static com.google.devtools.build.lib.packages.BuildType.LABEL;
import static com.google.devtools.build.lib.packages.BuildType.TRISTATE;
import static com.google.devtools.build.lib.packages.Type.BOOLEAN;

import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.TriState;
import com.google.devtools.build.lib.rules.genrule.GenRuleBaseRule;

/**
Expand All @@ -43,9 +45,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
attr("$genrule_setup", LABEL)
.cfg(ExecutionTransitionFactory.createFactory())
.value(env.getToolsLabel(GENRULE_SETUP_LABEL)))

// TODO(bazel-team): stamping doesn't seem to work. Fix it or remove attribute.
.add(attr("stamp", BOOLEAN).value(false))
.add(attr("stamp", TRISTATE).value(TriState.NO))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ private void createStampingTargets() throws Exception {
"u/BUILD",
"genrule(name='foo_stamp', srcs=[], outs=['uu'], stamp=1, cmd='')",
"genrule(name='foo_nostamp', srcs=[], outs=['vv'], stamp=0, cmd='')",
"genrule(name='foo_autostamp', srcs=[], outs=['aa'], stamp=-1, cmd='')",
"genrule(name='foo_default', srcs=[], outs=['xx'], cmd='')");
}

Expand Down Expand Up @@ -562,6 +563,8 @@ public void testStampingWithNoStamp() throws Exception {
assertStamped(getExecConfiguredTarget("//u:foo_stamp"));
assertNotStamped("//u:foo_nostamp");
assertNotStamped(getExecConfiguredTarget("//u:foo_nostamp"));
assertNotStamped("//u:foo_autostamp");
assertNotStamped(getExecConfiguredTarget("//u:foo_autostamp"));
assertNotStamped("//u:foo_default");
}

Expand All @@ -571,8 +574,10 @@ public void testStampingWithStamp() throws Exception {
createStampingTargets();
assertStamped("//u:foo_stamp");
assertStamped(getExecConfiguredTarget("//u:foo_stamp"));
// assertStamped("//u:foo_nostamp");
assertNotStamped("//u:foo_nostamp");
assertNotStamped(getExecConfiguredTarget("//u:foo_nostamp"));
assertStamped("//u:foo_autostamp");
assertNotStamped(getExecConfiguredTarget("//u:foo_autostamp"));
assertNotStamped("//u:foo_default");
}

Expand Down
Loading