[Notes] [Git][BuildGrid/buildgrid][mablanch/71-buildstream-support] buildbox.py: Manually forge a Tree message



Title: GitLab

Martin Blanchard pushed to branch mablanch/71-buildstream-support at BuildGrid / buildgrid

Commits:

1 changed file:

Changes:

  • buildgrid/_app/bots/buildbox.py
    ... ... @@ -19,10 +19,10 @@ import tempfile
    19 19
     
    
    20 20
     from google.protobuf import any_pb2
    
    21 21
     
    
    22
    +from buildgrid.client.cas import upload
    
    22 23
     from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
    
    23 24
     from buildgrid._protos.google.bytestream import bytestream_pb2_grpc
    
    24
    -from buildgrid.utils import parse_to_pb2_from_fetch
    
    25
    -from buildgrid.utils import read_file, write_file
    
    25
    +from buildgrid.utils import read_file, write_file, parse_to_pb2_from_fetch
    
    26 26
     
    
    27 27
     
    
    28 28
     def work_buildbox(context, lease):
    
    ... ... @@ -91,15 +91,24 @@ def work_buildbox(context, lease):
    91 91
                 # TODO: Should return the stdout and stderr to the user.
    
    92 92
                 command_line.communicate()
    
    93 93
     
    
    94
    -            output_root_digest = remote_execution_pb2.Digest()
    
    95
    -            output_root_digest.ParseFromString(read_file(output_digest_file.name))
    
    94
    +            output_digest = remote_execution_pb2.Digest()
    
    95
    +            output_digest.ParseFromString(read_file(output_digest_file.name))
    
    96 96
     
    
    97
    -            logger.debug("Output root digest: {}".format(output_root_digest))
    
    97
    +            logger.debug("Output root digest: {}".format(output_digest))
    
    98 98
     
    
    99
    -            if len(output_root_digest.hash) < 64:
    
    99
    +            if len(output_digest.hash) < 64:
    
    100 100
                     logger.warning("Buildbox command failed - no output root digest present.")
    
    101 101
     
    
    102
    -            output_directory = remote_execution_pb2.OutputDirectory(tree_digest=output_root_digest)
    
    102
    +            # TODO: Have BuildBox helping us creating the Tree instance here
    
    103
    +            # See https://gitlab.com/BuildStream/buildbox/issues/7 for details
    
    104
    +            output_tree = _cas_tree_maker(stub_bytestream, output_digest)
    
    105
    +
    
    106
    +            with upload(context.cas_channel) as cas:
    
    107
    +                output_tree_digest = cas.send_message(output_tree)
    
    108
    +
    
    109
    +            output_directory = remote_execution_pb2.OutputDirectory()
    
    110
    +            output_directory.tree_digest.CopyFrom(output_tree_digest)
    
    111
    +            output_directory.path = os.path.relpath(working_directory, start='/')
    
    103 112
     
    
    104 113
                 action_result = remote_execution_pb2.ActionResult()
    
    105 114
                 action_result.output_directories.extend([output_directory])
    
    ... ... @@ -110,3 +119,26 @@ def work_buildbox(context, lease):
    110 119
                 lease.result.CopyFrom(action_result_any)
    
    111 120
     
    
    112 121
         return lease
    
    122
    +
    
    123
    +
    
    124
    +def _cas_tree_maker(stub_bytestream, directory_digest):
    
    125
    +    # Generates and stores a Tree for a given Directory. This is very inefficient
    
    126
    +    # and only temporary. See https://gitlab.com/BuildStream/buildbox/issues/7.
    
    127
    +    output_tree = remote_execution_pb2.Tree()
    
    128
    +
    
    129
    +    def list_directories(parent_directory):
    
    130
    +        directory_list = list()
    
    131
    +        for directory_node in parent_directory.directories:
    
    132
    +            directory = parse_to_pb2_from_fetch(remote_execution_pb2.Directory(),
    
    133
    +                                                stub_bytestream, directory_node.digest)
    
    134
    +            directory_list.extend(list_directories(directory))
    
    135
    +            directory_list.append(directory)
    
    136
    +
    
    137
    +        return directory_list
    
    138
    +
    
    139
    +    root_directory = parse_to_pb2_from_fetch(remote_execution_pb2.Directory(),
    
    140
    +                                             stub_bytestream, directory_digest)
    
    141
    +    output_tree.children.extend(list_directories(root_directory))
    
    142
    +    output_tree.root.CopyFrom(root_directory)
    
    143
    +
    
    144
    +    return output_tree



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]