Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New option --copy COPYBOOK, to include a COPYBOOK #114

Closed

Conversation

lefessan
Copy link
Member

This option provides the same behavior as --include FILE for gcc and clang, i.e. including a file (or a group of files) before parsing the source.
It can be used typically to include REPLACE statements.

@codecov-commenter
Copy link

codecov-commenter commented Oct 11, 2023

Codecov Report

Merging #114 (993e3a4) into gcos4gnucobol-3.x (c0d64ad) will increase coverage by 0.02%.
The diff coverage is 86.53%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@                  Coverage Diff                  @@
##           gcos4gnucobol-3.x     #114      +/-   ##
=====================================================
+ Coverage              65.74%   65.76%   +0.02%     
=====================================================
  Files                     32       32              
  Lines                  59092    59133      +41     
  Branches               15575    15587      +12     
=====================================================
+ Hits                   38849    38890      +41     
+ Misses                 14262    14259       -3     
- Partials                5981     5984       +3     
Files Coverage Δ
cobc/flag.def 100.00% <100.00%> (ø)
cobc/help.c 100.00% <100.00%> (ø)
cobc/replace.c 96.20% <ø> (+0.94%) ⬆️
cobc/cobc.c 72.51% <91.66%> (+0.12%) ⬆️
cobc/codegen.c 75.98% <60.00%> (-0.02%) ⬇️
cobc/pplex.l 72.67% <85.00%> (+0.05%) ⬆️

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve the idea and the general approach (that could be an issue if we don't discuss it up-front).

This needs some more checks and documentation, then would be fine.

Can you please also add --include to actually include the specified header in every generated .c file after the default includes?
This would be the "command line" part of https://sourceforge.net/p/gnucobol/feature-requests/176/ and would work identical with all C compilers as backends - and is just so related to this PR...

tests/testsuite.src/syn_copy.at Outdated Show resolved Hide resolved
tests/testsuite.src/syn_copy.at Show resolved Hide resolved
cobc/cobc.c Outdated Show resolved Hide resolved
cobc/cobc.c Outdated Show resolved Hide resolved
@lefessan lefessan force-pushed the z-2023-10-11-copy-arg branch 5 times, most recently from e5f0129 to 49ec0d8 Compare October 13, 2023 12:11
Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only minor changes in the argument handling needed, otherwise good for SVN.

cobc/cobc.c Outdated
{
struct cb_text_list *l;
for (l = cb_copy_list; l; l=l->next){
char *name = cobc_strdup(l->text);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to duplicate the l->text? Why not using it directly?
If needed, then please use a local char name[COB_MINI_BUFF] here, this also removes the new failing under valgrind's memcheck when there is an error (because the err_exit leaves before we free the data).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that cb_copy_find_file() expects a non-const first argument (it modifies / into '\under Windows for example), whilecb_text_listcontains aconst char*` string.

I used the local array to remove the warning from valgrind.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the explanation, adding a note that the buffer name point to is modified in its function doc is likely good (its enough to do before the commit to svn).

The change is good, was there also a reason (other than the late hour) to not use strcpy?

cobc/cobc.c Outdated Show resolved Hide resolved
cobc/cobc.c Show resolved Hide resolved
@GitMensch
Copy link
Collaborator

As I've just recognized that: this could also serve for some people to gather compile options "the other way" using a file with directives, which are then included by this option.

It would also provide a "similar" option to MicroFocus -C DIRECTIVES "FILE" (take the old file, copy as ".cpy" go in there and add $SET in front of each line, then compile in cobc with --copy your.dir.cpy.

@GitMensch
Copy link
Collaborator

Hm, and another one - mostly a question @lefessan: how does this apply to -fformat=auto, or better to say: shouldn't the auto-format be "reset" after each of the included --copy elements?

@lefessan
Copy link
Member Author

It would also provide a "similar" option to MicroFocus -C DIRECTIVES "FILE" (take the old file, copy as ".cpy" go in there and add $SET in front of each line, then compile in cobc with --copy your.dir.cpy.

It should probably be part of a document of recipes to migrate from MicroFocus to GnuCOBOL. Unfortunately, the localisation of errors would make it difficult to debug in case of problem, it would be better to call a directive entry point in the parser for each directives in a list, juste before including the copies.

@GitMensch
Copy link
Collaborator

it would be better to call a directive entry point in the parser for each directives in a list, just before including the copies

That would be interesting, especially if it handles the different directive variants. Something to keep in mind for later.

@lefessan
Copy link
Member Author

Hm, and another one - mostly a question @lefessan: how does this apply to -fformat=auto, or better to say: shouldn't the auto-format be "reset" after each of the included --copy elements?

Good point. I just checked: if the format is auto, the detection is performed on the main target, the format is then set, and all copybooks are expected to be of the same format. I think it's a reasonable behavior.

@GitMensch
Copy link
Collaborator

I agree, that's a reasonable approach, possibly also to suggest users to use format-independent COBOL in those --copy included copybooks ;-)

@lefessan lefessan force-pushed the z-2023-10-11-copy-arg branch 2 times, most recently from 9d017b1 to 52c386a Compare October 13, 2023 21:46
@GitMensch
Copy link
Collaborator

As these are new options: please add them to the NEWS. I suggest to do that here already to not forget it on the later commit.

@lefessan
Copy link
Member Author

I just added the NEWS section.

I am still not comfortable with using absolute paths with --include. Recently, we discussed about using Docker to provide simpler multi-platform installations for GnuCOBOL: in my experience, it works pretty well, but only if all your paths are relative (the idea is to mount the local directory somewhere and run the program inside the container in that directory, so that it can access all local files). So, the --include "$PWD/FILE.h" will fail in such a context, since the absolute path is not the one in the Docker image.

If we cannot make a relative path the default, I added a commit to add a COBC_BUILD_INPLACE env variable that makes the C file to be generated and build in the local directory. It's not my preferred solution, but it would allow the Docker version to work correctly by setting it inside and outside the container.

@lefessan lefessan force-pushed the z-2023-10-11-copy-arg branch from 14f72d6 to 993e3a4 Compare October 28, 2023 08:52
@GitMensch
Copy link
Collaborator

GitMensch commented Oct 28, 2023

Can you please explain where you see the problem with something like --include "FILE.h" -I $PWD or --include "FILE.h" -g or --include "FILE.h" --save-temps?

@lefessan
Copy link
Member Author

I didn't notice that -g could be used for that.

For me, the behavior of --include FILE.h should not depend on whether it is used with or without another unrelated option. Indeed, --include FILE.h -g will probably be the set of options used by most users, so it will work without $PWD, but then, they will not understand why removing -g suddenly make their build fail.

For now, I only see scenarios where the option would only be used in development mode (so, with -g), but my experience is that one day or another, somebody will find a way to try to use this option in an unexpected way in release mode too (to replace some calls by macros ?), so we should let the door opened...

@GitMensch
Copy link
Collaborator

so we should let the door opened...

We do with --save-temps or -I $TMPDIR. You may consider checking gnucobol.tex if those three possibilities are mentioned there or should be mentioned.
I'm not sure we need that at all, because, as I've said, people most commonly use that option with including a file from the system include directories; for me a single half sentence about this "note that to find the file you may need to pass an appropriate -I" or alike would be enough.

@GitMensch
Copy link
Collaborator

What's the benefit of COBC_BUILD_INPLACE over --save-temps?
I guess the difference is it would place the intermediate files locally, but then deletes them afterwards, right?

@lefessan
Copy link
Member Author

Yes, it does not leave intermediate files in the local dir. (FWIW, my latency is high since last week as I am in a two-week vacation with my kids... and I didn't have as much time as I expected to hack on my spare time :-) )

Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please adjust the Changelog to reference FR #176 (and close that as soon as the change is committed to svn).
Please drop COBC_BUILD_INPLACE and replace as noted in the previous posts.

Afterwards this can go into svn (ideally after @ddeclerck's changes).

@lefessan
Copy link
Member Author

Please drop COBC_BUILD_INPLACE and replace as noted in the previous posts.

I am still not fond of using --save-temps to get this behavior, as it will pollute the local directory with unwanted intermediate files. Is it possible to keep it ?

@GitMensch
Copy link
Collaborator

Isn't it enough to have -I . if you want the local path?

In any case: #112 can be integrated upstream before.

@lefessan lefessan force-pushed the z-2023-10-11-copy-arg branch from 993e3a4 to 2f012f0 Compare January 22, 2024 15:53
NEWS Outdated Show resolved Hide resolved
cobc/cobc.c Outdated Show resolved Hide resolved
@lefessan lefessan force-pushed the z-2023-10-11-copy-arg branch from 2f012f0 to 9987137 Compare January 25, 2024 22:17
Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ready to me. One more solved :-)

tests/testsuite.src/used_binaries.at Outdated Show resolved Hide resolved
cobc/ChangeLog Show resolved Hide resolved
This option has two side-effect:
* the C file is compiled in the project directory (so that the included file
  can be found locally)
* no prototype is generated, so the new header file must contain a prototype
  for all statically called functions
@lefessan
Copy link
Member Author

Merged.

@lefessan lefessan closed this Jan 31, 2024
@GitMensch
Copy link
Collaborator

Thank you. I've just recognized that there's one missing part from FR # 176: Back in the discussions then the point was mot sources that call into C always need the same C header, and therefore a new directive was the goal.

Can you or @engboris have a look at adding the >>IMP INCLUDE directive and close the related FR by that?

@GitMensch
Copy link
Collaborator

reopen for the related missing part of the FR

@GitMensch GitMensch reopened this Mar 12, 2024
@GitMensch GitMensch added reopened (merged) already merged, but reopened and removed Merged in SVN labels Mar 12, 2024
@engboris
Copy link
Contributor

engboris commented Apr 25, 2024

Thank you. I've just recognized that there's one missing part from FR # 176: Back in the discussions then the point was mot sources that call into C always need the same C header, and therefore a new directive was the goal.

Can you or @engboris have a look at adding the >>IMP INCLUDE directive and close the related FR by that?

I'm currently working on it. What should happen if both the compiler option and the directive are defined? Should one be ignored? Both be considered?

I also plan to allow appending on text_list (probably restricted to cb_include_file_list) in cobc/cobc.h because it doesn't look like I'm able to do it from ppparse.y where the directive is parsed and defined.

EDIT : just noticed there are functions for that for the second paragraph of my answer

@GitMensch
Copy link
Collaborator

What should happen if both the compiler option and the directive are defined?

You may also have multiple >> IMP INCLUDE - each one (as well as the command line option) add to the list, the list is restored before the next input source file is handled (similar to source format).

@GitMensch
Copy link
Collaborator

ping @engboris

@engboris
Copy link
Contributor

Hello @GitMensch
Thank you for your reminder.

Maybe there is a misunderstanding? I have a PR here #143 (which I believe is almost completed) and I was waiting for your feedback.

Is there something you expected me to do that I didn't notice?

@ddeclerck
Copy link
Contributor

Shall we close this one again, since it is now superseded by #143 ?

@GitMensch GitMensch added Merged in SVN and removed reopened (merged) already merged, but reopened Ready for SVN labels Oct 2, 2024
@GitMensch
Copy link
Collaborator

Yes, it is fine to close that as only the directive is missing and this is what the related PR is about (not sure when I find the time to inspect the other current PRs though...).

@GitMensch GitMensch closed this Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants