当项目具有内部依赖性时,bazel golang构建失败

时间:2018-03-25 15:06:26

标签: go build bazel

我在MacOS 10.13.2上。 去1.10。 bazel 0.11.1

我需要编译一个包含2个项目的repo(project1和project2)。 project1有2个subpacakges。 p1lib和dep1 p1lib使用dep1。

我用瞪羚生成BUILD文件,文件看起来不错。

  @{
        ViewBag.Title = "Chat";
    }
    <fieldset>
        <legend style="color:orangered">Welcome To  Satya's signalR MVC Group Chat Club</legend>
    </fieldset>
    <div class="form-group col-xl-12">
        <label style="color: blue; font-style: oblique;font-size: medium" id="label1">Write Your Message Here!</label><br />
        <textarea class="form-control" rows="4" cols="40" id="message" placeholder="Share what's in your mind..."></textarea>
        <br />
        <input type="button" class="btn btn-primary" id="sendmessage" value="Send" />
        <br />
        <br />
        <label style="color: blue;font-style:oblique;font-size:medium" id="label2">Group Chat Conversations History</label>
        <div class="container chatArea">
            <input type="hidden" id="displayname" />
            <ul id="discussion"></ul>
        </div>
    </div>
    @section scripts {
        <script src="~/Scripts/jquery.signalR-2.2.3.min.js"></script>
        <script src="http://52.236.38.106:4848/signalr/hubs"></script>
        <script>

            $(function () {
                $.connection.hub.url = "http://52.236.38.106:4848/signalr";
                var chat = $.connection.myHub;
                chat.client.AddMessage = function (name, message) {
                    $('#discussion').append('<ul style="list-style-type:square"><li><strong style="color:red;font-style:normal;font-size:medium;text-transform:uppercase">' + htmlEncode(name) + '  ' + '<strong style="color:black;font-style:normal;font-size:medium;text-transform:lowercase">said</strong>'
                        + '</strong>: ' + '<strong style="color:blue;font-style:oblique;font-size:medium">' + htmlEncode(message) + '</strong>' + '</li></ul>');
                };
                $('#displayname').val(prompt('Your Good Name Please:', ''));
                $('#message').focus();
                $.connection.hub.start().done(function () {
                    $('#sendmessage').click(function () {
                        chat.server.send($('#displayname').val(), $('#message').val());
                        $('#message').val('').focus();
                    });
                });
            });
            function htmlEncode(value) {
                var encodedValue = $('<div />').text(value).html();
                return encodedValue;
            }
        </script>
    }

但是当我运行构建时,我得到一个错误,表明我缺少直接依赖。

gazelle -go_prefix=github.com/BazelBuildForGo

我的项目可以在这里找到 https://github.com/wix-playground/BazelBuildForGo

1 个答案:

答案 0 :(得分:1)

我认为问题在于您在命令行(github.com/BazelBuildForGo)上传递给Gazelle的导入前缀与.go文件(github.com/wix-private/BazelBuildForGo)中的导入不同。当Gazelle看到超出当前前缀的导入时,它将为这些导入生成外部依赖项,并且这些依赖项将会丢失:

go_library(
    name = "go_default_library",
    srcs = ["p1lib.go"],
    importpath = "github.com/BazelBuildForGo/project1/p1lib",
    visibility = ["//visibility:public"],
    deps = ["@com_github_wix_private_bazelbuildforgo//project1/dep1:go_default_library"],
)

尽管如此,修复此问题非常简单。只需使用前缀github.com/wix-private/BazelBuildForGo运行Gazelle。实际上你已经在//:gazelle中有了这个,所以只需运行它,然后重建。

$ bazel run //:gazelle
$ bazel build //...

这会将上面的go_library规则更改为:

go_library(
    name = "go_default_library",
    srcs = ["p1lib.go"],
    importpath = "github.com/wix-private/BazelBuildForGo/project1/p1lib",
    visibility = ["//visibility:public"],
    deps = ["//project1/dep1:go_default_library"],
)