forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-- MOS_MIGRATED_REVID=108806251
- Loading branch information
Showing
8 changed files
with
876 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/test/java/com/google/devtools/build/lib/rules/cpp/CcCompileOnlyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2015 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.cpp; | ||
|
||
import com.google.devtools.build.lib.analysis.ConfiguredTarget; | ||
import com.google.devtools.build.lib.analysis.util.CompileOnlyTestCase; | ||
|
||
/** | ||
* Unit tests that validate --compile_only behavior. | ||
*/ | ||
public class CcCompileOnlyTest extends CompileOnlyTestCase { | ||
public void testCcCompileOnly() throws Exception { | ||
scratch.file("package/BUILD", | ||
"cc_binary(name='foo', srcs=['foo.cc', ':bar'], deps = [':foolib'])", | ||
"cc_library(name='foolib', srcs=['foolib.cc'])", | ||
"genrule(name='bar', outs=['bar.h', 'bar.cc'], cmd='touch $(OUTS)')"); | ||
scratch.file("package/foo.cc", | ||
"#include <stdio.h>", | ||
"int main() {", | ||
" printf(\"Hello, world!\\n\");", | ||
" return 0;", | ||
"}"); | ||
scratch.file("package/foolib.cc", | ||
"#include <stdio.h>", | ||
"int printHeader() {", | ||
" printf(\"Hello, library!\\n\");", | ||
" return 0;", | ||
"}"); | ||
|
||
ConfiguredTarget target = getConfiguredTarget("//package:foo"); | ||
|
||
assertNotNull(getArtifactByExecPathSuffix(target, "/foo.pic.o")); | ||
assertNotNull(getArtifactByExecPathSuffix(target, "/bar.pic.o")); | ||
// Check that deps are not built | ||
assertNull(getArtifactByExecPathSuffix(target, "/foolib.pic.o")); | ||
// Check that linking is not executed | ||
assertNull(getArtifactByExecPathSuffix(target, "/foo")); | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
src/test/java/com/google/devtools/build/lib/rules/cpp/CcSkylarkApiProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// Copyright 2015 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.cpp; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import com.google.devtools.build.lib.actions.util.ActionsTestUtil; | ||
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget; | ||
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; | ||
import com.google.devtools.build.lib.testutil.TestConstants; | ||
|
||
/** | ||
* Tests for Skylark providers for cpp rules. | ||
*/ | ||
public class CcSkylarkApiProviderTest extends BuildViewTestCase { | ||
private CcSkylarkApiProvider getApi(String label) throws Exception { | ||
RuleConfiguredTarget rule = (RuleConfiguredTarget) getConfiguredTarget(label); | ||
return (CcSkylarkApiProvider) rule.get(CcSkylarkApiProvider.NAME); | ||
} | ||
|
||
public void testTransitiveHeaders() throws Exception { | ||
scratch.file( | ||
"pkg/BUILD", | ||
"cc_binary(", | ||
" name = 'check',", | ||
" srcs = ['bin.cc', 'bin.h'],", | ||
" deps = [':check_lib'],", | ||
")", | ||
"cc_library(", | ||
" name = 'check_lib',", | ||
" srcs = ['lib.cc', 'lib.h'],", | ||
")"); | ||
assertThat(ActionsTestUtil.baseArtifactNames(getApi("//pkg:check").getTransitiveHeaders())) | ||
.containsAllOf("lib.h", "bin.h"); | ||
assertThat(ActionsTestUtil.baseArtifactNames(getApi("//pkg:check_lib").getTransitiveHeaders())) | ||
.contains("lib.h"); | ||
} | ||
|
||
public void testLinkFlags() throws Exception { | ||
scratch.file( | ||
"pkg/BUILD", | ||
"cc_binary(", | ||
" name = 'check',", | ||
" srcs = ['bin.cc', 'bin.h'],", | ||
" linkopts = ['-lm'],", | ||
" deps = [':dependent_lib'],", | ||
")", | ||
"cc_binary(", | ||
" name = 'check_no_srcs',", | ||
" linkopts = ['-lm'],", | ||
" deps = [':dependent_lib'],", | ||
")", | ||
"cc_library(", | ||
" name = 'dependent_lib',", | ||
" linkopts = ['-lz'],", | ||
" deps = [':check_lib'],", | ||
")", | ||
"cc_library(", | ||
" name = 'check_lib',", | ||
" defines = ['foo'],", | ||
" linkopts = ['-Wl,-M'],", | ||
")"); | ||
assertThat(getApi("//pkg:check_lib").getLinkopts()) | ||
.contains("-Wl,-M"); | ||
assertThat(getApi("//pkg:dependent_lib").getLinkopts()) | ||
.containsAllOf("-lz", "-Wl,-M") | ||
.inOrder(); | ||
assertThat(getApi("//pkg:check").getLinkopts()) | ||
.isEmpty(); | ||
assertThat(getApi("//pkg:check_no_srcs").getLinkopts()) | ||
.isEmpty(); | ||
} | ||
|
||
public void testLibraries() throws Exception { | ||
scratch.file( | ||
"pkg/BUILD", | ||
"cc_binary(", | ||
" name = 'check',", | ||
" srcs = ['bin.cc', 'bin.h'],", | ||
" deps = [':check_lib'],", | ||
")", | ||
"cc_binary(", | ||
" name = 'check_no_srcs',", | ||
" deps = [':check_lib'],", | ||
")", | ||
"cc_library(", | ||
" name = 'check_lib',", | ||
" srcs = ['lib.cc', 'lib.h'],", | ||
")"); | ||
assertThat(ActionsTestUtil.baseArtifactNames(getApi("//pkg:check_lib").getLibraries())) | ||
.containsExactly("libcheck_lib.a"); | ||
assertThat(ActionsTestUtil.baseArtifactNames(getApi("//pkg:check").getLibraries())) | ||
.isEmpty(); | ||
assertThat(ActionsTestUtil.baseArtifactNames(getApi("//pkg:check_no_srcs").getLibraries())) | ||
.isEmpty(); | ||
} | ||
|
||
public void testCcFlags() throws Exception { | ||
scratch.file( | ||
"pkg/BUILD", | ||
"cc_binary(", | ||
" name = 'check',", | ||
" srcs = ['bin.cc', 'bin.h'],", | ||
" deps = [':check_lib'],", | ||
")", | ||
"cc_library(", | ||
" name = 'check_lib',", | ||
" defines = ['foo'],", | ||
")"); | ||
// The particular values for include directories are slightly | ||
// fragile because the build system changes. But check for at | ||
// least one normal include, one system include, and one define. | ||
assertThat(getApi("//pkg:check").getCcFlags()) | ||
.containsAllOf("-iquote .", "-isystem " + TestConstants.GCC_INCLUDE_PATH, "-Dfoo"); | ||
} | ||
} |
Oops, something went wrong.