2

I have a Qt project setup with microsoft compiler (although I'm using QtCreator) and I noticed it seems to create a file named msvc_make.bat, current contents are

chcp 65001
"C:\Qt\Tools\QtCreator\bin\jom.exe" %*

What is the purpose of this?

KcFnMi
  • 5,516
  • 10
  • 62
  • 136
  • 2
    [Microsoft Doc.: **chcp**](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/chcp) - change code page. 65001 represents the code page for UTF-8. [Qt doc.: **jom**](https://wiki.qt.io/Jom): _jom is a clone of nmake_ (Sorry, this was easy to google.) – Scheff's Cat Feb 12 '21 at 06:47
  • _What is the purpose of this?_ I strongly assume the purpose is to ensure that the Windows console is set to UTF-8 before `jom` is called. – Scheff's Cat Feb 12 '21 at 06:48
  • [SO: Is codepage 65001 and utf-8 the same thing?](https://stackoverflow.com/a/1629454/7478597) – Scheff's Cat Feb 12 '21 at 06:50

1 Answers1

2

Prerequisite knowledge

while creating a makefile for your project using qmake,either nmake or jom is used to execute commands.

Where is it happening ?

In the source code of Qt creator, this file ( msvc.bat ) is created in the msvctoolchain.cpp file by the function wrappedMakeCommand() {on line 1091}

static QString wrappedMakeCommand(const QString &command)
{
    const QString wrapperPath = QDir::currentPath() + "/msvc_make.bat";
    QFile wrapper(wrapperPath);
    if (!wrapper.open(QIODevice::WriteOnly))
        return command;
    QTextStream stream(&wrapper);
    stream << "chcp 65001\n";
    stream << "\"" << QDir::toNativeSeparators(command) << "\" %*";

    return wrapperPath;
}

which is used by MsvcToolChain::makeCommand(){line 1104} function to create the make command to build the project.

FilePath MsvcToolChain::makeCommand(const Environment &environment) const
{
    bool useJom = ProjectExplorerPlugin::projectExplorerSettings().useJom;
    const QString jom("jom.exe");
    const QString nmake("nmake.exe");
    Utils::FilePath tmp;

    FilePath command;
    if (useJom) {
        tmp = environment.searchInPath(jom,
                                       {Utils::FilePath::fromString(
                                           QCoreApplication::applicationDirPath())});
        if (!tmp.isEmpty())
            command = tmp;
    }

    if (command.isEmpty()) {
        tmp = environment.searchInPath(nmake);
        if (!tmp.isEmpty())
            command = tmp;
    }

    if (command.isEmpty())
        command = FilePath::fromString(useJom ? jom : nmake);

    if (environment.hasKey("VSLANG"))
        return FilePath::fromString(wrappedMakeCommand(command.toString()));

    return command;
}

when you look closely in the source code of this function, you will notice that it is just searching for the the required executable (jom.exe or nmake.exe)

after that, wrappedMakeCommand() function is called when environment variable with key "VSLANG" is present ( contains information about the language of the VSCode )

in the function wrappedMakeCommand() , developers used a batch file ( MSVC_make.bat ) to add another command chcp 65001 before executing the make file which enables the UTF-8 encoding to understand symbols from different languages just in case the system is running in another language (say Japanese).

Disclaimer:

all this information is my interpretation of why this file exists (from the knowledge gained from the source code of qt creator) and I am not 100% sure if this is the correct reason or not, but it made sense to me so answered here.

in case of any correction then do let me know via comments.

Sources and useful links :-

  1. Source code of Qt creator ( via github )
  2. source code of msvctoolchains.cpp ( where the file is created )
  3. What is jom ?
  4. about chcp
  5. about qmake
Scheff's Cat
  • 19,528
  • 6
  • 28
  • 56
Arsenic
  • 727
  • 1
  • 8
  • 22