Skip to content

Commit e361e1d

Browse files
authored
Merge branch 'bazelbuild:master' into 5716-java-baseline-coverage
2 parents dc0b753 + 387ed02 commit e361e1d

File tree

8 files changed

+157
-50
lines changed

8 files changed

+157
-50
lines changed

src/main/java/com/google/devtools/build/lib/actions/ImportantOutputHandler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@
2222
import com.google.devtools.build.lib.util.DetailedExitCode;
2323
import com.google.devtools.build.lib.vfs.Path;
2424
import com.google.devtools.build.lib.vfs.PathFragment;
25+
import java.time.Duration;
2526
import java.util.Collection;
2627
import java.util.Map;
2728
import java.util.Optional;
2829

2930
/** Context to be informed of top-level outputs and their runfiles. */
3031
public interface ImportantOutputHandler extends ActionContext {
3132

33+
/**
34+
* A threshold to pass to {@link com.google.devtools.build.lib.profiler.GoogleAutoProfilerUtils}
35+
* for profiling {@link ImportantOutputHandler} operations.
36+
*/
37+
Duration LOG_THRESHOLD = Duration.ofMillis(100);
38+
3239
/**
3340
* Informs this handler that top-level outputs have been built.
3441
*

src/main/java/com/google/devtools/build/lib/bazel/coverage/CoverageReportActionBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ private void informImportantOutputHandler(ActionExecutionContext ctx)
154154
Path coverageReportOutput = ctx.getPathResolver().toPath(getPrimaryOutput());
155155
try (var ignored =
156156
GoogleAutoProfilerUtils.profiledAndLogged(
157-
"Informing important output handler of coverage report", ProfilerTask.INFO)) {
157+
"Informing important output handler of coverage report",
158+
ProfilerTask.INFO,
159+
ImportantOutputHandler.LOG_THRESHOLD)) {
158160
importantOutputHandler.processTestOutputs(ImmutableList.of(coverageReportOutput));
159161
} catch (ImportantOutputException e) {
160162
throw new EnvironmentalExecException(e, e.getFailureDetail());

src/main/java/com/google/devtools/build/lib/profiler/GoogleAutoProfilerUtils.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,17 @@ public static AutoProfiler logged(String description, Duration minTimeForLogging
3939
}
4040

4141
public static AutoProfiler logged(String description) {
42-
return AutoProfiler.create(createSimpleLogger(description));
42+
return AutoProfiler.create(
43+
createSimpleLogger(description, /* minTimeForLogging= */ Duration.ZERO));
4344
}
4445

45-
private static ElapsedTimeReceiver createSimpleLogger(String description) {
46-
return elapsedTimeNanos -> log(selfLogger, elapsedTimeNanos, description);
46+
private static ElapsedTimeReceiver createSimpleLogger(
47+
String description, Duration minTimeForLogging) {
48+
return elapsedTimeNanos -> {
49+
if (elapsedTimeNanos >= minTimeForLogging.toNanos()) {
50+
log(selfLogger, elapsedTimeNanos, description);
51+
}
52+
};
4753
}
4854

4955
/**
@@ -54,10 +60,24 @@ private static ElapsedTimeReceiver createSimpleLogger(String description) {
5460
*/
5561
public static AutoProfiler profiledAndLogged(
5662
String taskDescription, ProfilerTask profilerTaskType) {
63+
return profiledAndLogged(
64+
taskDescription, profilerTaskType, /* minTimeForLogging= */ Duration.ZERO);
65+
}
66+
67+
/**
68+
* Like {@link #profiledAndLogged(String, ProfilerTask)} but only logs if the task takes at least
69+
* {@code minTimeForLogging}.
70+
*
71+
* <p>The elapsed time is recorded using {@link Profiler} even if it is less than {@code
72+
* minTimeForLogging}.
73+
*/
74+
public static AutoProfiler profiledAndLogged(
75+
String taskDescription, ProfilerTask profilerTaskType, Duration minTimeForLogging) {
5776
ElapsedTimeReceiver profilingReceiver =
5877
new AutoProfiler.ProfilingElapsedTimeReceiver(taskDescription, profilerTaskType);
5978
return AutoProfiler.create(
60-
new SequencedElapsedTimeReceiver(profilingReceiver, createSimpleLogger(taskDescription)));
79+
new SequencedElapsedTimeReceiver(
80+
profilingReceiver, createSimpleLogger(taskDescription, minTimeForLogging)));
6181
}
6282

6383
/**

src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ private RewindPlanResult informImportantOutputHandler(
422422
try (var ignored =
423423
GoogleAutoProfilerUtils.profiledAndLogged(
424424
"Informing important output handler of top-level outputs for " + label,
425-
ProfilerTask.INFO)) {
425+
ProfilerTask.INFO,
426+
ImportantOutputHandler.LOG_THRESHOLD)) {
426427
lostOutputs =
427428
importantOutputHandler.processOutputsAndGetLostArtifacts(
428429
key.topLevelArtifactContext().expandFilesets()

src/main/java/com/google/devtools/build/lib/skyframe/config/FlagSetFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private static ImmutableSet<String> getSclConfig(
107107
EnforcementPolicy enforcementPolicy = sclContent.getEnforcementPolicy();
108108

109109
ImmutableMap<String, ProjectValue.BuildableUnit> configs = sclContent.getBuildableUnits();
110-
if (configs == null) {
110+
if (configs == null || configs.isEmpty()) {
111111
// This project file doesn't define configs, so it must not be used for canonical configs.
112112
return ImmutableSet.of();
113113
}

src/test/java/com/google/devtools/build/lib/analysis/producers/BuildConfigurationKeyProducerTest.java

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ public final void initializeSkyframExecutor() throws Exception {
7575
.build());
7676
}
7777

78+
@Before
79+
public void iniitalizeProjectScl() throws Exception {
80+
setBuildLanguageOptions("--experimental_enable_scl_dialect=true");
81+
writeProjectSclDefinition("test/project_proto.scl");
82+
scratch.file("test/BUILD");
83+
}
84+
7885
/** Extra options for this test. */
7986
public static class DummyTestOptions extends FragmentOptions {
8087
public DummyTestOptions() {}
@@ -488,13 +495,10 @@ public void createKey_withScopedBuildOptions_outOfScopeFlag_flagNotSetInTheBasel
488495
scratch.file(
489496
"flag/PROJECT.scl",
490497
"""
491-
project = {
492-
"active_directories": {
493-
"default": [
494-
"//my_project"
495-
]
496-
}
497-
}
498+
load("//test:project_proto.scl", "project_pb2")
499+
project = project_pb2.Project.create(
500+
project_directories = ["//my_project"],
501+
)
498502
""");
499503

500504
scratch.file(
@@ -510,13 +514,10 @@ public void createKey_withScopedBuildOptions_outOfScopeFlag_flagNotSetInTheBasel
510514
scratch.file(
511515
"out_of_scope_flag/PROJECT.scl",
512516
"""
513-
project = {
514-
"active_directories": {
515-
"default": [
516-
"//out_side_of_my_project"
517-
]
518-
}
519-
}
517+
load("//test:project_proto.scl", "project_pb2")
518+
project = project_pb2.Project.create(
519+
project_directories = ["//out_side_of_my_project"],
520+
)
520521
""");
521522

522523
invalidatePackages(false);
@@ -601,13 +602,10 @@ public void createKey_withScopedBuildOptions_outOfScopeFlag_flagSetInTheBaseline
601602
scratch.file(
602603
"flag/PROJECT.scl",
603604
"""
604-
project = {
605-
"active_directories": {
606-
"default": [
607-
"//my_project"
608-
]
609-
}
610-
}
605+
load("//test:project_proto.scl", "project_pb2")
606+
project = project_pb2.Project.create(
607+
project_directories = ["//my_project"],
608+
)
611609
""");
612610

613611
scratch.file(
@@ -623,13 +621,10 @@ public void createKey_withScopedBuildOptions_outOfScopeFlag_flagSetInTheBaseline
623621
scratch.file(
624622
"out_of_scope_flag/PROJECT.scl",
625623
"""
626-
project = {
627-
"active_directories": {
628-
"default": [
629-
"//out_side_of_my_project"
630-
]
631-
}
632-
}
624+
load("//test:project_proto.scl", "project_pb2")
625+
project = project_pb2.Project.create(
626+
project_directories = ["//out_side_of_my_project"],
627+
)
633628
""");
634629

635630
invalidatePackages(false);

src/test/java/com/google/devtools/build/lib/buildtool/ProjectResolutionTest.java

Lines changed: 92 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.devtools.build.lib.analysis.ProjectResolutionException;
2323
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
2424
import com.google.devtools.build.lib.cmdline.Label;
25+
import org.junit.Before;
2526
import org.junit.Test;
2627
import org.junit.runner.RunWith;
2728
import org.junit.runners.JUnit4;
@@ -35,6 +36,13 @@
3536
*/
3637
@RunWith(JUnit4.class)
3738
public class ProjectResolutionTest extends BuildViewTestCase {
39+
@Before
40+
public void setUp() throws Exception {
41+
setBuildLanguageOptions("--experimental_enable_scl_dialect=true");
42+
writeProjectSclDefinition("test/project_proto.scl");
43+
scratch.file("test/BUILD");
44+
}
45+
3846
@Test
3947
public void buildWithNoProjectFiles() throws Exception {
4048
scratch.file("pkg/BUILD", "genrule(name='f', cmd = '', srcs=[], outs=['a.out'])");
@@ -51,7 +59,12 @@ public void buildWithNoProjectFiles() throws Exception {
5159
@Test
5260
public void buildWithOneProjectFile() throws Exception {
5361
scratch.file("pkg/BUILD", "genrule(name='f', cmd = '', srcs=[], outs=['a.out'])");
54-
scratch.file("pkg/" + PROJECT_FILE_NAME, "project = {}");
62+
scratch.file(
63+
"pkg/" + PROJECT_FILE_NAME,
64+
"""
65+
load("//test:project_proto.scl", "project_pb2")
66+
project = project_pb2.Project.create()
67+
""");
5568

5669
var projectFiles =
5770
Project.getProjectFiles(
@@ -64,8 +77,18 @@ public void buildWithOneProjectFile() throws Exception {
6477
public void buildWithTwoProjectFiles() throws Exception {
6578
scratch.file("foo/bar/BUILD", "genrule(name='f', cmd = '', srcs=[], outs=['a.out'])");
6679
scratch.file("foo/BUILD");
67-
scratch.file("foo/" + PROJECT_FILE_NAME, "project = {}");
68-
scratch.file("foo/bar/" + PROJECT_FILE_NAME, "project = {}");
80+
scratch.file(
81+
"foo/" + PROJECT_FILE_NAME,
82+
"""
83+
load("//test:project_proto.scl", "project_pb2")
84+
project = project_pb2.Project.create()
85+
""");
86+
scratch.file(
87+
"foo/bar/" + PROJECT_FILE_NAME,
88+
"""
89+
load("//test:project_proto.scl", "project_pb2")
90+
project = project_pb2.Project.create()
91+
""");
6992

7093
var projectFiles =
7194
Project.getProjectFiles(
@@ -79,7 +102,12 @@ public void buildWithTwoProjectFiles() throws Exception {
79102
public void twoTargetsSameProjectFile() throws Exception {
80103
scratch.file("foo/bar/BUILD", "genrule(name='child', cmd = '', srcs=[], outs=['c.out'])");
81104
scratch.file("foo/BUILD", "genrule(name='parent', cmd = '', srcs=[], outs=['p.out'])");
82-
scratch.file("foo/" + PROJECT_FILE_NAME, "project = {}");
105+
scratch.file(
106+
"foo/" + PROJECT_FILE_NAME,
107+
"""
108+
load("//test:project_proto.scl", "project_pb2")
109+
project = project_pb2.Project.create()
110+
""");
83111

84112
var projectFiles =
85113
Project.getProjectFiles(
@@ -95,8 +123,18 @@ public void twoTargetsSameProjectFile() throws Exception {
95123
public void twoTargetsDifferentProjectFiles() throws Exception {
96124
scratch.file("foo/BUILD", "genrule(name='f', cmd = '', srcs=[], outs=['f.out'])");
97125
scratch.file("bar/BUILD", "genrule(name='g', cmd = '', srcs=[], outs=['g.out'])");
98-
scratch.file("foo/" + PROJECT_FILE_NAME, "project = {}");
99-
scratch.file("bar/" + PROJECT_FILE_NAME, "project = {}");
126+
scratch.file(
127+
"foo/" + PROJECT_FILE_NAME,
128+
"""
129+
load("//test:project_proto.scl", "project_pb2")
130+
project = project_pb2.Project.create()
131+
""");
132+
scratch.file(
133+
"bar/" + PROJECT_FILE_NAME,
134+
"""
135+
load("//test:project_proto.scl", "project_pb2")
136+
project = project_pb2.Project.create()
137+
""");
100138

101139
var projectFiles =
102140
Project.getProjectFiles(
@@ -120,7 +158,12 @@ public void twoTargetsDifferentProjectFiles() throws Exception {
120158
public void twoTargetsOnlyOneHasProjectFile() throws Exception {
121159
scratch.file("foo/BUILD", "genrule(name='f', cmd = '', srcs=[], outs=['f.out'])");
122160
scratch.file("bar/BUILD", "genrule(name='g', cmd = '', srcs=[], outs=['g.out'])");
123-
scratch.file("foo/" + PROJECT_FILE_NAME, "project = {}");
161+
scratch.file(
162+
"foo/" + PROJECT_FILE_NAME,
163+
"""
164+
load("//test:project_proto.scl", "project_pb2")
165+
project = project_pb2.Project.create()
166+
""");
124167

125168
var projectFiles =
126169
Project.getProjectFiles(
@@ -141,10 +184,20 @@ public void twoTargetsOnlyOneHasProjectFile() throws Exception {
141184
@Test
142185
public void innermostPackageIsAParentDirectory() throws Exception {
143186
scratch.file("pkg/BUILD", "genrule(name='f', cmd = '', srcs=[], outs=['a.out'])");
144-
scratch.file("pkg/" + PROJECT_FILE_NAME, "project = {}");
187+
scratch.file(
188+
"pkg/" + PROJECT_FILE_NAME,
189+
"""
190+
load("//test:project_proto.scl", "project_pb2")
191+
project = project_pb2.Project.create()
192+
""");
145193
scratch.file("pkg/subdir/not_a_build_file");
146194
// Doesn't count because it's not colocated with a BUILD file:
147-
scratch.file("pkg/subdir" + PROJECT_FILE_NAME, "project = {}");
195+
scratch.file(
196+
"pkg/subdir/" + PROJECT_FILE_NAME,
197+
"""
198+
load("//test:project_proto.scl", "project_pb2")
199+
project = project_pb2.Project.create()
200+
""");
148201

149202
var projectFiles =
150203
Project.getProjectFiles(
@@ -166,7 +219,12 @@ public void aliasProjectFile() throws Exception {
166219
}
167220
""");
168221
scratch.file("canonical/BUILD");
169-
scratch.file("canonical/PROJECT.scl", "project = {}");
222+
scratch.file(
223+
"canonical/" + PROJECT_FILE_NAME,
224+
"""
225+
load("//test:project_proto.scl", "project_pb2")
226+
project = project_pb2.Project.create()
227+
""");
170228

171229
var projectFiles =
172230
Project.getProjectFiles(
@@ -299,7 +357,12 @@ public void aliasToAlias() throws Exception {
299357
}
300358
""");
301359
scratch.file("canonical/BUILD");
302-
scratch.file("canonical/PROJECT.scl", "project = {}");
360+
scratch.file(
361+
"canonical/" + PROJECT_FILE_NAME,
362+
"""
363+
load("//test:project_proto.scl", "project_pb2")
364+
project = project_pb2.Project.create()
365+
""");
303366

304367
var projectFiles =
305368
Project.getProjectFiles(
@@ -327,7 +390,12 @@ public void sameProjectFileAfterAliasResolution() throws Exception {
327390
}
328391
""");
329392
scratch.file("canonical/BUILD");
330-
scratch.file("canonical/PROJECT.scl", "project = {}");
393+
scratch.file(
394+
"canonical/" + PROJECT_FILE_NAME,
395+
"""
396+
load("//test:project_proto.scl", "project_pb2")
397+
project = project_pb2.Project.create()
398+
""");
331399

332400
var projectFiles =
333401
Project.getProjectFiles(
@@ -357,9 +425,19 @@ public void differentProjectFilesAfterAliasResolution() throws Exception {
357425
}
358426
""");
359427
scratch.file("canonical1/BUILD");
360-
scratch.file("canonical1/PROJECT.scl", "project = {}");
428+
scratch.file(
429+
"canonical1/" + PROJECT_FILE_NAME,
430+
"""
431+
load("//test:project_proto.scl", "project_pb2")
432+
project = project_pb2.Project.create()
433+
""");
361434
scratch.file("canonical2/BUILD");
362-
scratch.file("canonical2/PROJECT.scl", "project = {}");
435+
scratch.file(
436+
"canonical2/" + PROJECT_FILE_NAME,
437+
"""
438+
load("//test:project_proto.scl", "project_pb2")
439+
project = project_pb2.Project.create()
440+
""");
363441

364442
var projectFiles =
365443
Project.getProjectFiles(

src/test/shell/bazel/cc_integration_test.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,11 @@ int main() {
18231823
EOF
18241824

18251825
bazel run //pkg:example &> "$TEST_log" && fail "Should have failed due to $feature" || true
1826-
expect_log "WARNING: ThreadSanitizer: data race"
1826+
# TODO: we used to expect "WARNING: ThreadSanitizer: data race" here, but that
1827+
# has suddenly started failing on Ubuntu on Bazel CI (see
1828+
# https://buildkite.com/bazel/google-bazel-presubmit/builds/92979). We should
1829+
# figure out what's going on and fix this check eventually.
1830+
expect_log "ThreadSanitizer: "
18271831
}
18281832

18291833
function test_cc_toolchain_ubsan_feature() {

0 commit comments

Comments
 (0)