msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.25k stars 1.21k forks source link

icu : some diagnostic/informational output from the pkgdata tool may be lost #17139

Closed dkrejsa closed 1 year ago

dkrejsa commented 1 year ago

Description / Steps to reproduce the issue

When building or using ICU, some output to stdout and stderr done by the pkgdata tool may be dropped, and not be visible in the build logs. This dropped output is confusing and can complicate debugging build problems when using pkgdata.

This can occur when the runCommand() function in pkgdata.cpp calls the system() function to run various commands. runCommand() calls printf() to display the command to be run immediately before calling system(), and will also write to stderr immediately afterwards if system() returns a nonzero result.

printf("pkgdata: %s\n", cmd);
int result = system(cmd);

Inserting calls to fflush() for stdout and stderr after the printf() and before the system() call, as suggested by Microsoft documentation for system()

You must explicitly flush, by using fflush or _flushall, or close any stream before you call system.

in the Remarks section, will prevent this useful diagnostic output from being lost. I suggest changing the above code to

printf("pkgdata: %s\n", cmd);
fflush(stdout);
fflush(stderr);
int result = system(cmd);

Expected behavior

Diagnostic or informational output from the pkgdata program should not be accidentally dropped.

Actual behavior

Currently, diagnostic output, such as the following bit added for U_PF_MINGW in pkg_generateLibraryFile(), may not be visible due to this issue:

#if U_PLATFORM == U_PF_MINGW
    fprintf(stderr, "genlib=%s targetdir=%s libfilenames=%s -o pkgdataflags=%s targetdir=%s libfilenames=%s objectfileandeverythingelse=%s %s%s %s %s",
            pkgDataFlags[GENLIB],
            targetDir,
            libFileNames[LIB_FILE_MINGW],
            pkgDataFlags[LDICUDTFLAGS],
            targetDir,
            libFileNames[LIB_FILE_VERSION_TMP],
            objectFile,
            pkgDataFlags[LD_SONAME],
            pkgDataFlags[LD_SONAME][0] == 0 ? "" : libFileNames[LIB_FILE_VERSION_MAJOR],
            pkgDataFlags[RPATH_FLAGS],
            pkgDataFlags[BIR_FLAGS]);

Verification

Windows Version

MINGW64_NT-10.0-19045

MINGW environments affected

Are you willing to submit a PR?

No response

Biswa96 commented 1 year ago

When building or using ICU, some output to stdout and stderr done by the pkgdata tool may be dropped

Could you provide the steps to reproduce the issue?

dkrejsa commented 1 year ago

Well, basically, build ICU from source using makepkg-mingw and examine the build logs, looking especially for the lines starting with 'pkgdata: bash -c ' such as

pkgdata: bash -c "cd ../lib/ && /usr/bin/install -c libicudt73.dll C:/msys64/...

that are output by the runCommand() function in pkgdata.cpp right before calling system(). (Or rather, that would be output if not for the lack of flushing.) I can probably provide more details and an example log if necessary, but not immediately.

Biswa96 commented 1 year ago

Thanks for the info. Could you provide the expected output and the actual output both?

dkrejsa commented 1 year ago

Apologies -- I cannot figure out how to reproduce this problem in a pure mingw environment. I could reproduce it in my own build environment, which was a weird cross build on Windows using a MINGW ICU build and its tools to package the ICU data in a cross build on Windows for VxWorks, using a suspect "bash" shell environment as part of the build, with the output being redirected to a file by a cmd.exe shell calling make; and adding the fflush() calls helped for that case. Anyhow, I'll close this bug since it is not be likely to affect common MINGW64 uses.