Skip to content

Commit

Permalink
test-wrapper: add empty impl + Bazel flag
Browse files Browse the repository at this point in the history
This commit adds:

- the skeleton implementation of the Windows
  native test wrapper

- a depenency on the native test wrapper from test
  rules, through the new $test_wrapper rule
  attribute

- the --windows_native_test_wrapper Bazel flag,
  which is currently a no-op

See bazelbuild#5508

Change-Id: I8df95c8ce8bab53c51c257698ec95416065a836e
  • Loading branch information
laszlocsomor committed Aug 10, 2018
1 parent df16c77 commit 0627d22
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ public Object getDefault(AttributeMap rule) {
.nonconfigurable("policy decision: should be consistent across configurations"))
.add(attr("args", STRING_LIST))
// Input files for every test action
.add(
attr("$test_wrapper", LABEL)
.cfg(HostTransition.INSTANCE)
.singleArtifact()
.value(env.getToolsLabel("//tools/test:test_wrapper")))
.add(
attr("$test_runtime", LABEL_LIST)
.cfg(HostTransition.INSTANCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ public static final RuleClass getTestBaseRule(String toolsRepository) {
"policy decision: this should be consistent across configurations"))
.add(attr("args", STRING_LIST))
// Input files for every test action
.add(
attr("$test_wrapper", LABEL)
.cfg(HostTransition.INSTANCE)
.singleArtifact()
.value(
labelCache.getUnchecked(toolsRepository + "//tools/test:test_wrapper")))
.add(
attr("$test_runtime", LABEL_LIST)
.cfg(HostTransition.INSTANCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,24 @@ public static class TestOptions extends FragmentOptions {
)
public Label coverageReportGenerator;

@Option(
name = "windows_native_test_wrapper",
// Undocumented: this features is under development and not yet ready for production use.
// We define the flag only in order to be able to test the feature.
// Design:
// https://github.com/laszlocsomor/proposals/blob/win-test-runner/designs/2018-07-18-windows-native-test-runner.md
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
// Affects loading and analysis: this flag affects which target Bazel loads and creates test
// actions with on Windows.
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
defaultValue = "false",
help =
"Do not use yet, this flag's functionality is not yet implemented. "
+ "(On Windows: if true, uses the C++ test wrapper to run tests, otherwise uses "
+ "tools/test/test-setup.sh as on other platforms. On other platforms: no-op.)"
)
public boolean windowsNativeTestWrapper;

@Override
public Map<String, Set<Label>> getDefaultsLabels() {
return ImmutableMap.<String, Set<Label>>of(
Expand Down Expand Up @@ -298,6 +316,10 @@ public Label getCoverageReportGenerator(){
return options.coverageReportGenerator;
}

public boolean isUsingWindowsNativeTestWrapper() {
return options.windowsNativeTestWrapper;
}

/**
* @return number of times the given test should run. If the test doesn't match any of the
* filters, runs it once.
Expand Down
16 changes: 15 additions & 1 deletion tools/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ filegroup(
srcs = ["@bazel_tools//tools/test/LcovMerger/java/com/google/devtools/lcovmerger:Main"],
)

cc_binary(
name = "test_wrapper",
srcs = select({
"@bazel_tools//src/conditions:windows": ["windows/test_wrapper.cc"],
# Dummy source file, so this rule can be built on non-Windows platforms
# (when building all targets in this package).
"//conditions:default": ["windows/dummy.cc"],
}),
visibility = ["//visibility:private"],
)

filegroup(
name = "srcs",
srcs = glob(["**"]),
Expand All @@ -45,7 +56,10 @@ filegroup(
"test-setup.sh",
"generate-xml.sh",
"collect_coverage.sh",
] + glob(["LcovMerger/**"]),
] + glob(["LcovMerger/**"]) + select({
"@bazel_tools//src/conditions:windows": ["test_wrapper"],
"//conditions:default": [],
}),
visibility = ["//tools:__pkg__"],
)

Expand Down
8 changes: 8 additions & 0 deletions tools/test/BUILD.tools
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ filegroup(
name = "coverage_report_generator",
srcs = ["@bazel_tools//tools/test/LcovMerger/java/com/google/devtools/lcovmerger:Main"],
)

filegroup(
name = "test_wrapper",
srcs = select({
"@bazel_tools//src/conditions:windows": ["test_wrapper.exe"],
"//conditions:default": ["test_wrapper"],
}),
)
27 changes: 27 additions & 0 deletions tools/test/windows/dummy.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2018 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Empty implementation of the test wrapper.
//
// As of 2018-08-06, every platform uses //tools/test:test-setup.sh as the test
// wrapper, and we are working on introducing a C++ test wrapper for Windows.
// See https://github.com/laszlocsomor/proposals/blob/win-test-runner/designs/2018-07-18-windows-native-test-runner.md

#include <stdio.h>

int main(int, char**) {
fprintf(stderr,
__FILE__ ": The C++ test wrapper is not used on this platform.\n");
return 1;
}
22 changes: 22 additions & 0 deletions tools/test/windows/test_wrapper.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2018 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Test wrapper implementation for Windows.
// Design: https://github.com/laszlocsomor/proposals/blob/win-test-runner/designs/2018-07-18-windows-native-test-runner.md

int main(int argc, char** argv) {
// TODO(laszlocsomor): Implement the functionality described in
// https://github.com/laszlocsomor/proposals/blob/win-test-runner/designs/2018-07-18-windows-native-test-runner.md
return 0;
}

0 comments on commit 0627d22

Please # to comment.