Skip to content

bazel: dev generate bazel trashes generated files if it fails before re-generating them #76503

@knz

Description

@knz

(This is a new issue / regression - did not fail in this way as late as one or two weeks ago)

Describe the problem

  1. I started with a working, building repository.

  2. I ran dev generate bazel.

  3. The command failed to complete due to some missing UI tool.

  4. As a result, all the previously-good generated files were removed, causing the following git diff:

 modified   pkg/gen/docs.bzl…
 modified   pkg/gen/excluded.bzl…
 modified   pkg/gen/execgen.bzl…
 modified   pkg/gen/gomock.bzl…
 modified   pkg/gen/misc.bzl…
 modified   pkg/gen/optgen.bzl…
 modified   pkg/gen/protobuf.bzl…
 modified   pkg/gen/stringer.bzl…

(all these files had empty contents)

It's important that generated files remain in-place even when a generate command fails.

The “traditional” algorithm for file generation is this:

file:
   generate >file.tmp || rm -f file.tmp
   mv -f file.tmp file

This way if the generate file fails, the tmp file gets deleted and the final file does not get altered.

It would be good if dev generate would use the same idea for all generated files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-build-systemC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions