OpenSSL Communities

Dealing with autogenerated files

Dmitry Belyavsky PublicSeen by 21

Dear colleagues,
I don't like the situation with autogenerated files.

Paul's efforts on dealing with parameters are much appreciated, but the result comes with a cost.

If we modify the autogenerated file by accident, we lose its content on `make clean` invocation (see https://github.com/openssl/openssl/discussions/28269). If we navigate to the autogenerated file by tag and don't know that it was expanded from the template,

The parameters are now not greppable until we make a real configure and generate the files. That is counter-intuitive and problematic for people who try to find smth by the constant corresponding to the param name (now we at least should have these constants in the generated code).

AFAIK, curl developers keep both the template file and generated file in the repo. Following this example and detecting the mismatch would save us both from losing our work by accident and problems with grep. However it will require implementing some mechanism to detect mismatch between the generated file and the template.

WDYT?

Tomas Mraz

We actually use similar approach for other generated files (i.e. ERR_ code related) and we already have a CI job that checks these. So I think it would be fairly trivial to switch to this approach with other C sources generated with perl. (I would not use this approach for perlasm though as that output is build configuration specific.)

Todd Short

Other repos I work in also have checked-in generated files. It's useful for the reasons you pointed out, especially being able to diff them to know what really changed prior to merge,

Shane Lontis

The downside is that conflicts are more frequent if the file is frequently changed.

Sasha Nedvedicky

I like the idea making the generated file read-only. error on save should raise level of awareness sufficiently. also having a comment at the beginning of the file saying it's been generated from path/to/template would help.

Dmitry Belyavsky

Yes - but the threat of losing the results of work should overweight it, I think

Richard Levitte (individual)

We should care, though, not to check in generated files that depend on configuration values.

Paul Dale

Honestly, I don't suffer from this problem. I never need to look at the generated code. The line number mismatch is annoying but searching for the errant line of code almost always gets to the right place.

I do think that if we modify the Perl wrapper to include #line directives many of the concerns would vanish.

All we need to do is to make it more difficult to edit the generated code than not. The current "generated code" warnings do not seem to be sufficient.

Richard Levitte (individual)

@Paul Dale 

I do think that if we modify the Perl wrapper to include #line directives many of the concerns would vanish.

You mean in the relevant template files that are used as input.

(we have template files that generate other than C source files, such as numerous .pod files)

Paul Dale

I had a thought overnight, we could use the Makefile to warn about the editing issue:

file.c.timestamp: file.c
        echo generated file.c modified
        exit 1

file.c: …
        …
        touch file.c.timestamp

Dmitry Belyavsky

If these timestamps are removed on make clean, I'm not sure it saves

Richard Levitte (individual)

Maybe this answers your concern, but kinda differently:

clean:
	...
	$(RM) $(GENERATED_MANDATORY) $(GENERATED)

Dmitry Belyavsky

@Richard Levitte sorry, I don't get.
My goal is
- not lose the changes introduced into generated files by accident
- make sure that a particular param can be found and it's possible to see how it used without build

The 1st is mine problem, the 2nd problem is the problem of a 3rd-party developer who tries to understand how the particular parameter is processed (and yes, I'm talking about real colleagues and real issue they meet)

Richard Levitte (individual)

@Dmitry Belyavsky, what I meant was that before worrying about timestamps being removed by 'make clean', we need to worry about the generated files themselves, which 'make clean' already removes.

Dmitry Belyavsky

That's my original point - I think we should stop doing this

Shane Lontis

On new files, I find myself looking at the .c file to figure out where any compiler error actually is. This is the point at which it is becomes hard to remember to switch to the .in file.