diff options
author | 2017-07-12 23:50:23 +0200 | |
---|---|---|
committer | 2017-07-13 09:56:55 +0200 | |
commit | f626144b6fd245fcf0f793e18dda513b2263a7a7 (patch) | |
tree | ac7b11e7ada2e33522f479fcd481692305395d7d /src/test/java/com/google/devtools/build/lib/rules/platform | |
parent | 669534514a51f1bd66d2426c0c57924e758fd124 (diff) |
Add skyfunction to return all registered toolchain labels.
Part of #2219.
Change-Id: I7293fd13bd8e0931f92afd051e18a9e7ce63762d
PiperOrigin-RevId: 161721445
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/rules/platform')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/platform/BUILD | 20 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java | 87 |
2 files changed, 106 insertions, 1 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/platform/BUILD b/src/test/java/com/google/devtools/build/lib/rules/platform/BUILD index 781420d5f7..9c34048c0d 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/platform/BUILD +++ b/src/test/java/com/google/devtools/build/lib/rules/platform/BUILD @@ -4,9 +4,14 @@ filegroup( visibility = ["//src/test/java/com/google/devtools/build/lib:__pkg__"], ) +TESTUTIL_SRCS = ["ToolchainTestCase.java"] + java_test( name = "PlatformRulesTests", - srcs = glob(["*.java"]), + srcs = glob( + ["*.java"], + exclude = TESTUTIL_SRCS, + ), test_class = "com.google.devtools.build.lib.AllTests", deps = [ "//src/main/java/com/google/devtools/build/lib:build-base", @@ -26,3 +31,16 @@ java_test( "//third_party:truth", ], ) + +java_library( + name = "testutil", + srcs = TESTUTIL_SRCS, + visibility = ["//src/test/java/com/google/devtools/build/lib:__subpackages__"], + deps = [ + "//src/main/java/com/google/devtools/build/lib/analysis/platform", + "//src/main/java/com/google/devtools/build/lib/cmdline", + "//src/test/java/com/google/devtools/build/lib/skylark:testutil", + "//third_party:junit4", + "//third_party:truth", + ], +) diff --git a/src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java new file mode 100644 index 0000000000..87bce409db --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java @@ -0,0 +1,87 @@ +// Copyright 2017 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. + +package com.google.devtools.build.lib.rules.platform; + +import com.google.devtools.build.lib.analysis.platform.ConstraintSettingInfo; +import com.google.devtools.build.lib.analysis.platform.ConstraintValueInfo; +import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.skylark.util.SkylarkTestCase; +import org.junit.Before; + +/** Utility methods for setting up platform and toolchain related tests. */ +public abstract class ToolchainTestCase extends SkylarkTestCase { + + public Label testToolchainType; + public ConstraintSettingInfo setting; + public ConstraintValueInfo linuxConstraint; + public ConstraintValueInfo macConstraint; + + @Before + public void createConstraints() throws Exception { + scratch.file( + "constraint/BUILD", + "constraint_setting(name = 'os')", + "constraint_value(name = 'linux',", + " constraint_setting = ':os')", + "constraint_value(name = 'mac',", + " constraint_setting = ':os')"); + + setting = ConstraintSettingInfo.create(makeLabel("//constraint:os")); + linuxConstraint = ConstraintValueInfo.create(setting, makeLabel("//constraint:linux")); + macConstraint = ConstraintValueInfo.create(setting, makeLabel("//constraint:mac")); + } + + @Before + public void createToolchains() throws Exception { + rewriteWorkspace( + "register_toolchains(", " '//toolchain:toolchain_1',", " '//toolchain:toolchain_2')"); + + scratch.file( + "toolchain/BUILD", + "load(':toolchain_def.bzl', 'test_toolchain')", + "toolchain_type(name = 'test_toolchain')", + "toolchain(", + " name = 'toolchain_1',", + " toolchain_type = ':test_toolchain',", + " exec_compatible_with = ['//constraint:linux'],", + " target_compatible_with = ['//constraint:mac'],", + " toolchain = ':test_toolchain_1')", + "toolchain(", + " name = 'toolchain_2',", + " toolchain_type = ':test_toolchain',", + " exec_compatible_with = ['//constraint:mac'],", + " target_compatible_with = ['//constraint:linux'],", + " toolchain = ':test_toolchain_2')", + "test_toolchain(", + " name='test_toolchain_1',", + " data = 'foo')", + "test_toolchain(", + " name='test_toolchain_2',", + " data = 'bar')"); + scratch.file( + "toolchain/toolchain_def.bzl", + "def _impl(ctx):", + " toolchain = platform_common.ToolchainInfo(", + " type = Label('//toolchain:test_toolchain'),", + " data = ctx.attr.data)", + " return [toolchain]", + "test_toolchain = rule(", + " implementation = _impl,", + " attrs = {", + " 'data': attr.string()})"); + + testToolchainType = makeLabel("//toolchain:test_toolchain"); + } +} |