有没有办法看到正在运行的Bazel动作的助记符?

时间:2017-06-12 07:55:14

标签: bazel

(来自https://groups.google.com/d/msg/bazel-discuss/XrtKLhH1bgI/B9xZn_aVAAAJ

在我们使用Bazel进行构建的项目中,我使用了远程缓存(--spawn_strategy=remote),我们不得不进行一些微调以关闭某些操作的缓存。例如,当我们生成tar文件时,我们不想使用远程缓存,因为(a)在本地构建tar文件与下载它们一样快,并且(b)我们的一些tar文件可能真的如此巨大的。

所以我想让我们的.bazelrc文件为某些操作指定不同的策略,例如--strategy=PackageTar=standalone

这里有一个棘手的部分:为了覆盖策略,你需要知道助记符。例如。对于pkg_tar规则,相关操作具有助记符PackageTar。我发现在bazel来源。要弄明白其他一些人相当棘手。

有什么办法可以让bazel告诉我它正在执行的动作的助记符吗?我查看了各种选项,例如--profile--explain--verbose_explanations--subcommands,但无法找到方法。

2 个答案:

答案 0 :(得分:1)

不幸的是,Bazel似乎没有在任何地方报告助记符。

您可以通过在源代码中为它们进行grepping来找到可用助记符列表。

在Skylark规则中:

(function() {
'use strict';

function reviewDeletionService($uibModal, $state, $rootScope, RecordLockService, $q, Restangular) {

    return {
        openDeletionModal:  openDeletionModal
    };


    function  openDeletionModal(reviewDetails, reviewImpacts, unlock) {
        var reviewDeletionModalInstance = $uibModal.open({
            animation: true,
            size: 'md',
            templateUrl: "src/app/common/modals/delete-review/deleteReviewImpacts.modal.view.html",
            backdrop: 'static',
            controller: 'DeleteReviewImpactsModalController as drivm',
            resolve: {
                reviewType: function () {
                    return reviewDetails.reviewType;
                },
                reviewTitle: function () {
                    return reviewDetails.reviewTitle;
                },
                reviewImpacts: function () {
                    return reviewImpacts;
                }
            }
        });

        reviewDeletionModalInstance.result.then(function (data) {
            openReviewReasonModal(reviewDetails, reviewImpacts, data.noImpacts, unlock);
        }, function () {
        if(unlock){
            RecordLockService.unlockReview(reviewDetails.reviewId);
        }                         
        })
    }
}

angular.module('common')
    .factory('ReviewDeletionService', reviewDeletionService);

})();

在原生规则中:

(function() {
'use strict';

describe("Service: ReviewDeletionService", function() {
    var reviewDeletionService, $httpBackend, restangular, successHandler, errorHandler, mockAuthenticationService, q, configParams ;
    var mockCurrentUser = {id: 1782, name: "One, Coordinator", roleId: [3, 10], eauthId: "coodinator1"};
    var recordLockService, modal, actualOptions;
    var fakeModal = {
        result: {
            then: function(confirmCallback, cancelCallback) {
                //Store the callbacks for later when the user clicks on the OK button of the dialog
                this.confirmCallBack = confirmCallback;
                this.cancelCallback = cancelCallback;
            }
        },
        close: function( item ) {
            //The user clicked OK on the modal dialog, call the stored confirm callback with the selected item
            this.result.confirmCallBack(item);
        },
        dismiss: function( type ) {
            //The user clicked cancel on the modal dialog, call the stored cancel callback
            this.result.cancelCallback( type );
        }

    };

    beforeEach(module('app'));
    beforeEach(module('common'));
    beforeEach(inject(function(_ReviewDeletionService_, _RecordLockService_, _$httpBackend_, _Restangular_, _AuthenticationService_, $q, _configParams_, _$uibModal_) {
        reviewDeletionService = _ReviewDeletionService_;
        recordLockService = _RecordLockService_;
        restangular = _Restangular_;
        q = $q;
        $httpBackend = _$httpBackend_;
        modal = _$uibModal_;
        mockAuthenticationService = _AuthenticationService_;
        configParams = _configParams_;

        spyOn(mockAuthenticationService , 'getLoggedUser').and.callFake(function() {
            var deferred = q.defer();
            deferred.resolve(mockCurrentUser);
            return deferred.promise;

        });

        successHandler = jasmine.createSpy('success');
        errorHandler = jasmine.createSpy('error');
    }));
    afterEach(function() {
        $httpBackend.verifyNoOutstandingExpectation();
        $httpBackend.verifyNoOutstandingRequest();
    });

    describe('call openDeletionModal function',function(){
        beforeEach(function () {
           spyOn(modal, 'open').and.callFake(function(options){
                actualOptions = options;
                return fakeModal;
            });
        }); 
        it('should call openDeletionModal', function() {
            reviewDeletionService.openDeletionModal(review, impacts, false);

         // Here I want to test.then part, I want my test to go inside .then part. 
         // If this was controller I would have just add
         //scope.lockedReviewModalInstance.close(data);
         // or. controller.lockedReviewModalInstance.close(data);

        });
    });

});
})();

答案 1 :(得分:1)

您可以使用bazel aquery进行此操作:

$ cat BUILD
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")

pkg_tar(
    name = "my_archive",
    srcs = ["hello.txt"],
)
$ bazel aquery :my_archive 2>/dev/null
action 'Writing file my_archive.args'
  Mnemonic: FileWrite
  Target: //:my_archive
  Configuration: k8-fastbuild
  ActionKey: 3dafce6be7ba0023b7eaae485085f977
  Inputs: []
  Outputs: [bazel-out/k8-fastbuild/bin/my_archive.args]

action 'PackageTar my_archive.tar'
  Mnemonic: PackageTar
  Target: //:my_archive
  Configuration: k8-fastbuild
  ActionKey: 86bd5d0e112232cf0224fd0e3534f553
  Inputs: [<snip>]
  Outputs: [bazel-out/k8-fastbuild/bin/my_archive.tar]
  Command Line: (exec bazel-out/host/bin/external/bazel_tools/tools/build_defs/pkg/build_tar \
    --flagfile \
    bazel-out/k8-fastbuild/bin/my_archive.args)

请注意第二步中的Mnemonic: PackageTar行。

您可以使用--output=textproto optionbazel aquery来 获取机器可读的输出。

您还可以使用诸如bazel aquery 'outputs(".*\.tar", //...)'之类的查询 缩小动作图;有关更多信息,请查阅aquery文档 详细信息。