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

add dependencies options and -fcopybook-deps #109

Open
wants to merge 1 commit into
base: gcos4gnucobol-3.x
Choose a base branch
from

Conversation

lefessan
Copy link
Member

@lefessan lefessan commented Aug 15, 2023

  • Implements dependencies options similar to gcc
  • -fcopybook-deps outputs only copybook names instead of file paths. -fcopybook-deps also forces -E -foneline-deps -MT=copybooks, disables errors on missing copybooks and remove output on stdout.

@codecov-commenter
Copy link

codecov-commenter commented Aug 15, 2023

Codecov Report

Attention: Patch coverage is 85.46512% with 25 lines in your changes are missing coverage. Please review.

Project coverage is 65.90%. Comparing base (89c45a3) to head (75646da).

Files Patch % Lines
cobc/cobc.c 86.46% 6 Missing and 12 partials ⚠️
cobc/error.c 76.47% 2 Missing and 2 partials ⚠️
cobc/pplex.l 86.66% 1 Missing and 1 partial ⚠️
cobc/typeck.c 0.00% 0 Missing and 1 partial ⚠️

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

Additional details and impacted files
@@                  Coverage Diff                  @@
##           gcos4gnucobol-3.x     #109      +/-   ##
=====================================================
+ Coverage              65.87%   65.90%   +0.03%     
=====================================================
  Files                     32       32              
  Lines                  59483    59622     +139     
  Branches               15709    15747      +38     
=====================================================
+ Hits                   39182    39292     +110     
- Misses                 14282    14310      +28     
- Partials                6019     6020       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@GitMensch
Copy link
Collaborator

As testcases are missing I cannot get a grasp what this is about....

We definitely should provide a way to "only" calculate the dependencies and in this case the paths are not available so we can only output the names, which may be the idea behind that.

Not sure why we should have a "only on one line".

Adjustments to -MT and friends are useful and those were added back with an explicit note that there will be changes - but those should mimic what GCC does with them so please provide sample code and output of a C program with #include <something.h> and #include <else/something.h> and #include "other/something.h" along with some different -I and -M... options and add test cases that have the same scenario for cobc - making the later mimic the first is the way to go. Only when we have that we should inspect your scenario to check if that's what you need or what is missing.

And yes: if you could tackle the -M... options, that would be quite good (but those changes should mimic recent GCC, both from their options and from their results).

@lefessan lefessan force-pushed the z-2023-07-15-deps branch 2 times, most recently from b79b1e2 to e3c6cd9 Compare August 16, 2023 16:55
@lefessan
Copy link
Member Author

I added a test in used_binaries.at... and most arguments used by gcc that make sense for GnuCOBOL. I don't know which changes are being done in gcc, but I can import them accordingly.

For -fcopybook-deps, the idea is to output dependencies for other tools than make, in a very simple format and without file path resolution. For example, using this output, it is possible to create a tool that will use it to know the copybooks of a source file, and then search for them by scanning directories, and finally call cobc again with an automatically generated list of -I <dir>.

@lefessan lefessan force-pushed the z-2023-07-15-deps branch 4 times, most recently from 5cfc276 to 9aeb62c Compare August 16, 2023 17:20
@lefessan
Copy link
Member Author

lefessan commented Aug 16, 2023

@GitMensch I have a completely unrelated question ; I have a PR on the manual in OCamlPro/gnucobol-docs#2 . Is there another maintainer for that part, or are you also in charge ?

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.

Should -MM and -MMD be added, ignoring the copybooks in COB_COPY_DIR (currently extfh and screenio)?

Shouldn't the dependency options be included in gnucobol.texi, possibly copying GCCs docs verbatim? This would also allow to note in NEWS that we adjusted these options (referencing the 3.2 note about the future change) while pointing to the manual for the details on the dependency generation.

In any case this should be split to two commits for SVN - one that adjusts the "standard" dependency options and a second one for the new flags.
I'd like to review them separately, can you please split the PR into two (obviously the new flags would not base on the original target but on the deps branch)?

tests/testsuite.src/used_binaries.at Outdated Show resolved Hide resolved
AT_CHECK([$COMPILE -MD prog.cob])

AT_CHECK([cat prog.d], [0],
[prog.o: \
Copy link
Collaborator

Choose a reason for hiding this comment

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

that test would fail when COB_OBJECT_EXT != o

Copy link
Collaborator

Choose a reason for hiding this comment

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

That still fails with a compiler using ".obj" or else - no? Note: $COB_OBJECT_EXT is available in the testuite so a $SED operation should be possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should work now even with .obj, using $SED on compiler output...

tests/testsuite.src/used_binaries.at Outdated Show resolved Hide resolved
tests/testsuite.src/used_binaries.at Show resolved Hide resolved
tests/testsuite.src/used_binaries.at Show resolved Hide resolved
tests/testsuite.src/used_binaries.at Outdated Show resolved Hide resolved
tests/testsuite.src/used_binaries.at Outdated Show resolved Hide resolved
@GitMensch
Copy link
Collaborator

Should -MM and -MMD be added, ignoring the copybooks in COB_COPY_DIR (currently extfh and screenio)?

Shouldn't the dependency options be included in gnucobol.texi, possibly copying GCCs docs verbatim? This would also allow to note in NEWS that we adjusted these options (referencing the 3.2 note about the future change) while pointing to the manual for the details on the dependency generation.

In any case this should be split to two commits for SVN - one that adjusts the "standard" dependency options and a second one for the new flags. I'd like to review them separately, can you please split the PR into two (obviously the new flags would not base on the original target but on the deps branch)?

Friendly ping @lefessan

@GitMensch
Copy link
Collaborator

@lefessan I've did a quick browser-only merge, can you please review, adjust as needed and check the review comment above?

cobc/ChangeLog Outdated Show resolved Hide resolved
@GitMensch
Copy link
Collaborator

Thanks for the rebase. As guessed before, noted in the review and now seen in the CI: we have issues at least on Win32 as follows:

#                             -*- compilation -*-
28. used_binaries.at:1119: testing output dependencies ...
../../tests/used_binaries.at:1138: mkdir -p sub
../../tests/used_binaries.at:1144: $COMPILE_ONLY prog.cob
../../tests/used_binaries.at:1146: $COMPILE_ONLY -M prog.cob prog.cob
--- -	2024-03-12 14:25:51.094447400 +0000
+++ /d/a/gnucobol/gnucobol/_build/tests/testsuite.dir/at-groups/28/stdout	2024-03-12 14:25:51.042599800 +0000
@@ -2,12 +2,12 @@
  prog.cob \
  COPY1.CPY \
  COPY2.CPY \
- sub/COPY3.CPY
+ sub\COPY3.CPY
 
 prog.o: \
  prog.cob \
  COPY1.CPY \
  COPY2.CPY \
- sub/COPY3.CPY
+ sub\COPY3.CPY

I think all make implementations support / paths, in this case we may use these here; otherwise the test may get a conditional to change the expected result for Win32 to backslash or we go with adjusting the output of (.)\(.) to $1/$2.

@lefessan lefessan force-pushed the z-2023-07-15-deps branch 2 times, most recently from 136592b to 8dc9eed Compare March 15, 2024 09:22
@lefessan lefessan changed the title add new flags -foneline-deps and -fcopybook-deps to output dependencies add dependencies options and -fcopybook-deps to output dependencies Mar 15, 2024
@lefessan lefessan changed the title add dependencies options and -fcopybook-deps to output dependencies add dependencies options and -fcopybook-deps Mar 15, 2024
@lefessan
Copy link
Member Author

So, in this version, I am using the COB_IS_RUNNING_IN_TESTMODE variable to replace backslashes by slashes in the compiler output, so that tests have the same results on Unix and Windows.

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.

Nearly finished! Please see comments.

@@ -134,6 +134,9 @@ CB_FLAG (cb_flag_stack_extended, 1, "stack-extended",
CB_FLAG_ON (cb_flag_fast_compare, 0, "fast-compare",
_(" -fno-fast-compare disables inline comparisions"))

CB_FLAG (cb_flag_copybook_deps, 0, "copybook-deps",
_(" -fcopybook-deps output copybook names as dependencies"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

The M... options should already have some docs in gnucobol.texi and may should be extended (it is fine to reference GCC documentation for detail, it is also fine to copy its documentation over - both documents have the same license and copyright owner).
The option to getting a grasp how/why one should use them in the manual would be very useful.

The -fcopybook-deps is something new and "special", there definitely should be at least one sentence in the manual on which case/why to use that.

The currently missing NEWS entry can then also reference the manual for details. :-)

cobc/help.c Outdated Show resolved Hide resolved
cobc/flag.def Show resolved Hide resolved
cobc/error.c Show resolved Hide resolved
cobc/ChangeLog Show resolved Hide resolved
AT_CHECK([$GREP 'sub\\copy\\PROC.cpy:' prog.d], [0], [ignore])
AT_CHECK([$GREP 'sub\\PROCE.cpy:' prog.d], [0], [ignore])
], [
AT_CHECK([$GREP ' sub/copy/PROC.cpy \\' prog.d], [0], [ignore])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we still need that? I've thought the point of slashify is to not need that any more?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, it's probably not useful anymore, but without a Windows computer, it's painful to modify all these tests and then wait for Github CI for feedback...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see the pain, but please check that with either Github CI (that's still much faster than Appveyor) or otherwise, when adding the cob_slashify - which should be in a separate PR. Instead this PR should use the same approach that's used here or a simple tr of the test data for output.

AT_CHECK([$COMPILE -MD prog.cob])

AT_CHECK([cat prog.d], [0],
[prog.o: \
Copy link
Collaborator

Choose a reason for hiding this comment

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

That still fails with a compiler using ".obj" or else - no? Note: $COB_OBJECT_EXT is available in the testuite so a $SED operation should be possible.

Comment on lines 1105 to -1112
PROCEDURE DIVISION.
CALL "f" USING "Hello" BY VALUE long RETURNING NOTHING.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This has, by design a BY VALUE long in there and ignores the compiler output; is there a reason to change that?
What is that "rename" stuff about?

Copy link
Member Author

Choose a reason for hiding this comment

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

So, under Windows, the function has to be available. f was not a real function, so it was failing with an "undefined function 'f'". I solved it by calling an existing function (rename is part of stdio.h, which is not included by default in common.h). My understanding was that the test was mostly testing the arity of the function, not the exact types, so I chose a function with two char* because I couldn't find an existing function with the same prototype as former f.

Copy link
Collaborator

Choose a reason for hiding this comment

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

rechecking:

The first test is a simple non-static call, so no problem.
The second one does a static call, and that may need to be resolved to not raise an error, so yes, it would be reasonable to adjust this - but please put that to another (separate! PR) and leave this out here.

Comment on lines +1068 to +1075
AT_CHECK([echo "$PWD/prog.cob:7: error: CRUD.CPY: No such file or directory" > expected.output])
AT_CHECK([echo "$PWD/prog.cob:6: warning: numeric value is expected" >> expected.output])
AT_CHECK([echo "$PWD/prog.cob:14: warning: ignoring redundant ." >> expected.output])
AT_CAPTURE_FILE([expected.output])

AT_CHECK([[cat compiler.output | tr '[:upper:]' '[:lower:]' | tr -d ':/\\' > compiler.output2]])
AT_CHECK([[cat expected.output | tr '[:upper:]' '[:lower:]' | tr -d ':/\\' > expected.output2]])
AT_CHECK([diff compiler.output2 expected.output2])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use a HEREDOC here instead of AT_CHECK?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not familar with HEREDOC notations. This version is not the most elegant one, but it does the job :-)

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is all unrelated to the actual PR changes, please move this out to a separate PR for later review.

Comment on lines 399 to 396
AT_CHECK([TMPDIR="" TMP="notthere" TEMP="" $COMPILE prog.cob], [0], [],
[libcob: warning: Temporary directory TMP is invalid, adjust TMPDIR!
AT_CHECK([TMPDIR="" TMP="notthere" TEMP="" $COMPILE prog.cob 2> compiler.output], [0], [],
[],[
# On Windows, we get a failure from gcc, so the binary is not created, the stderr is mixed and exit code is 1.
AT_CHECK([grep libcob: compiler.output], [0], [libcob: warning: Temporary directory TMP is invalid, adjust TMPDIR!
])
AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [OK], [])
AT_CHECK([TMPDIR="" TMP="" TEMP="./prog.cob" $COMPILE prog.cob], [0], [],
[libcob: warning: Temporary directory TEMP is invalid, adjust TMPDIR!
],
[
AT_CHECK([cat compiler.output], [0], [libcob: warning: Temporary directory TMP is invalid, adjust TMPDIR!
])
AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [OK], [])
])

AT_CHECK([TMPDIR="" TMP="" TEMP="./prog.cob" $COMPILE prog.cob 2> compiler.output], [0], [],
[],[
AT_CHECK([grep libcob: compiler.output], [0], [libcob: warning: Temporary directory TEMP is invalid, adjust TMPDIR!
])
],
[
AT_CHECK([cat compiler.output], [0], [libcob: warning: Temporary directory TEMP is invalid, adjust TMPDIR!
])
])

Copy link
Collaborator

Choose a reason for hiding this comment

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

that's an ... interesting approach, but please move that out to a separate PR

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 problem with moving that elsewhere is that the test will keep failing under Windows, which means that I might make changes in this PR and not notice that the failures under Windows have changed. I would prefer to have a working CI under Windows and find another fix in another PR later...

@lefessan
Copy link
Member Author

Should -MM and -MMD be added, ignoring the copybooks in COB_COPY_DIR (currently extfh and screenio)?

I don't think it is worth it. Though they are easy to implement (by modifying the cb_copy_find_file in pplex.l to set a flag when using the COB_COPY_DIR entry of cb_include_list), I don't see any reason why the external tool that would use the dependencies would need to remove system dependencies, or wouldn't be able to do it by itself. Adding low value features makes the code harder to maintain for little benefit.

@lefessan
Copy link
Member Author

This version has a NEWS section and a new section in gnucobol.texi for dependency options.

@lefessan lefessan force-pushed the z-2023-07-15-deps branch 2 times, most recently from 7cf30b0 to 68c30e6 Compare March 17, 2024 15:54
Flags following gcc options: -M to output deps only, -MD to output
  deps while compiling (in .d files), -MP to output phony targets, -MG
  to keep missing copybooks, -MQ <target> to Makefile-quote target

Additional flags specific to GnuCOBOL: -fcopybook-deps outputs only
copybook names instead of file paths. -fcopybook-deps also forces -E.
@lefessan
Copy link
Member Author

@GitMensch I think I have replied and/or fixed all your points, is it for merge ?

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.

Nah, "review pending" - I haven't clicked on send.

But this let me recheck another time now and after thinking "what do we want to achieve" I concluded that it is not the Win32 test working fine afterwards.

I therefore added some review comments asking for moving those changes out to separate PR(s) to be reviewed separately (and definitely later), allowing to merge this R hopefully next week.

Thank you and Sorry for the postponed review!

Comment on lines -389 to +402
static char *cb_depend_target; /* -MT <target>... */

static char *cb_depend_target; /* -MT <target>... */
static const char *cb_depend_filename; /* -MF <file> */
Copy link
Collaborator

Choose a reason for hiding this comment

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

those are all pointer to chars, so the old space line after seems more reasonable (but it's enough to handle that on commit and no problem if you forget, other than people possibly stumbling over this later).

Actually, because they don't follow the "size" couple that the others have, I'd suggest to moving them up front with an extra space line after.

Comment on lines +3021 to +3025
static int string_is_dash (const char*s){
return ( strcmp (s, COB_DASH) == 0 );
}

static void add_depend_target (const char* s){
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor formatting:

  • first the type
  • next line the name and its arguments
  • next line the starting {

@@ -3001,6 +3018,74 @@ remove_trailing_slash (char *data)
}
}

static int string_is_dash (const char*s){
Copy link
Collaborator

Choose a reason for hiding this comment

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

please force-inline this function


AT_CLEANUP

AT_SETUP([output dependencies])
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add an extra empty line before that

AT_CHECK([$GREP 'sub\\copy\\PROC.cpy:' prog.d], [0], [ignore])
AT_CHECK([$GREP 'sub\\PROCE.cpy:' prog.d], [0], [ignore])
], [
AT_CHECK([$GREP ' sub/copy/PROC.cpy \\' prog.d], [0], [ignore])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see the pain, but please check that with either Github CI (that's still much faster than Appveyor) or otherwise, when adding the cob_slashify - which should be in a separate PR. Instead this PR should use the same approach that's used here or a simple tr of the test data for output.

Comment on lines 1105 to -1112
PROCEDURE DIVISION.
CALL "f" USING "Hello" BY VALUE long RETURNING NOTHING.
Copy link
Collaborator

Choose a reason for hiding this comment

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

rechecking:

The first test is a simple non-static call, so no problem.
The second one does a static call, and that may need to be resolved to not raise an error, so yes, it would be reasonable to adjust this - but please put that to another (separate! PR) and leave this out here.

Comment on lines +1068 to +1075
AT_CHECK([echo "$PWD/prog.cob:7: error: CRUD.CPY: No such file or directory" > expected.output])
AT_CHECK([echo "$PWD/prog.cob:6: warning: numeric value is expected" >> expected.output])
AT_CHECK([echo "$PWD/prog.cob:14: warning: ignoring redundant ." >> expected.output])
AT_CAPTURE_FILE([expected.output])

AT_CHECK([[cat compiler.output | tr '[:upper:]' '[:lower:]' | tr -d ':/\\' > compiler.output2]])
AT_CHECK([[cat expected.output | tr '[:upper:]' '[:lower:]' | tr -d ':/\\' > expected.output2]])
AT_CHECK([diff compiler.output2 expected.output2])
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is all unrelated to the actual PR changes, please move this out to a separate PR for later review.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's well done. Please add a ChangeLog entry for it.

the test of outputs, as they will be similar on Unix and Windows.
*/
char *
cobc_slashify (const char *src)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. But cob_slashify() and its related testsuite changes are far from the original PR. Please move that out to a separate one, then revert the related parts in this one.

Comment on lines 81 to -82
- name: check
continue-on-error: true
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about moving this to two separate steps? One "check" with continue-on-error and another test that should never fail? After all these run as separate checks for win32 in any case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants