-
-
Notifications
You must be signed in to change notification settings - Fork 668
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let go_binary's executable bit depend on
linkmode
If a go_binary's `linkmode` is neither `normal` nor `pie`, the resulting file can't be executed. In this case, `executable` should be set to `False` on the go_binary rule so that Bazel doesn't create a runfiles tree for the targets and does not include e.g. a resulting static library in the runfiles of dependants.
- Loading branch information
Showing
5 changed files
with
71 additions
and
4 deletions.
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
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
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
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
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,51 @@ | ||
// Copyright 2022 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 non_executable_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/bazelbuild/rules_go/go/tools/bazel_testing" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
bazel_testing.TestMain(m, bazel_testing.Args{ | ||
Main: ` | ||
-- src/BUILD.bazel -- | ||
load("@io_bazel_rules_go//go:def.bzl", "go_binary") | ||
go_binary( | ||
name = "archive", | ||
srcs = ["archive.go"], | ||
linkmode = "c-archive", | ||
) | ||
-- src/archive.go -- | ||
package main | ||
func main() {} | ||
`, | ||
}) | ||
} | ||
|
||
func TestNonExecutableGoBinary(t *testing.T) { | ||
if err := bazel_testing.RunBazel("build", "//src:archive"); err != nil { | ||
t.Fatal(err) | ||
} | ||
err := bazel_testing.RunBazel("run", "//src:archive") | ||
if err == nil || !strings.Contains(err.Error(), "ERROR: Cannot run target //src:archive: Not executable") { | ||
t.Errorf("Expected bazel run to fail due to //src:archive not being executable") | ||
} | ||
} |