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

MSVC enhancement to add all remaining msvc batch file command-line options as SCons variables #4174

Merged
merged 111 commits into from
Jul 25, 2022

Conversation

jcbrill
Copy link
Contributor

@jcbrill jcbrill commented Jun 12, 2022

Add all remaining msvc batch file command-line options as SCons environment variables.

The intent of this PR is to enable all existing msvc batch arguments to be utilized with SCons auto-detection.

This PR modifies and/or adds the following SCons construction variables

  • MSVC_UWP_APP [modifies]
  • MSVC_SDK_VERSION [adds]
  • MSVC_TOOLSET_VERSION [adds]
  • MSVC_SPECTRE_LIBS [adds]
  • MSVC_SCRIPT_ARGS [adds]

With the exception of MSVC_SCRIPT_ARGS, all of the SCons variables have a one-to-one mapping with msvc batch file arguments.

Note: the implementation of MSVC_TOOLSET_VERSION does not affect the selection of the msvc instances (i.e., "auto-detection") in any way. Similar to the msvc batch files: given an msvc instance, a toolset version may be specified. This distinction is important as it makes the implementation reasonably straightforward.

All of the environment variables listed above are applied after the msvc instance is selected. This could be the default version of msvc if MSVC_VERSION is not specified.

The MSVC_SCRIPTERROR_POLICY construction variable was added as a mechanism to report msvc batch file errors which could prove useful when attempting to diagnose mysterious build failures.

Contributor Checklist:

  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt (and read the README.rst)
  • I have updated the appropriate documentation

Source Code Tasks

  • Move proposed code into appropriate locations
  • Rename and adjust some code added in recent PRs for consistency
  • Finalize handling of batch file errors

MSVC_UWP_APP

  • Base functionality complete
  • Argument validation complete
  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt (and read the README.rst)
  • I have updated the appropriate documentation

Known changes from the current main branch:

  • Boolean True is accepted in addition to string '1'
  • Attempting to use MSVC_UWP_APP in VS2013 and earlier results in an exception. Prior behavior was to silently ignore the UWP request.

MSVC_SDK_VERSION

  • Base functionality complete
  • Argument validation complete
  • Extended functionality complete
  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt (and read the README.rst)
  • I have updated the appropriate documentation

As currently implemented, the SDK version is passed to the msvc batch files without complete validation (i.e., that the SDK version is actually installed). This is planned.

MSVC_TOOLSET_VERSION

Addresses: #3265, #3664, #4149

  • Base functionality complete
  • Argument validation complete
  • Extended functionality complete
  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt (and read the README.rst)
  • I have updated the appropriate documentation

Known differences between the implementation and the msvc batch files:

  • The msvc batch files accept toolset versions specified in the form XX.Y, XX.YY, XX.YY.ZZZZZ.
    The implementation accepts toolset versions in the form XX.Y, XX.YY, XX.YY.Z, XX.YY.ZZ, XX.YY.ZZZ, XX.YY.ZZZZ, XX.YY.ZZZZZ.

The extended functionality consists of forcing the toolset version to be passed to the msvc batch files when not specified. Currently, there is an internal hard-coded value disabling this feature. By passing the toolset version to the batch files, the SCons cache would be impervious to toolset updates and would execute the batch files appropriately. This could be enabled via an internal-use only windows environment variable when running the test suite(s).

MSVC_SPECTRE_LIBS

  • Base functionality complete
  • Argument validation complete
  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt (and read the README.rst)
  • I have updated the appropriate documentation

MSVC_SCRIPT_ARGS

Closes: #4106

  • Base functionality complete
  • Argument validation complete (first-class arguments above and multiple declarations only)
  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt (and read the README.rst)
  • I have updated the appropriate documentation

MSVC_SCRIPTERROR_POLICY

The msvc batch file error detection was modified to process all of the lines of stdout instead of first line. VS2017 and later, display a banner which means that no msvc batch file errors are detected if only the first line is inspected.

If msvc batch file errors are detected, the msvc script error handler is called. The scons behavior is based on the construction variable value or the global policy setting if undefined or None.

The policy values are:

  • Ignore or Suppress: ignore script error messages when detected.
  • Warn or Warning: issue a warning when script error messages are detected.
  • Error or Exception: raise and exception when script error messages are detected.

The default policy is to ignore script error messages.

If script error messages are detected and cl.exe is not detected on the path, an internal exception is raised.

Prior behavior was when an error was detected to raise an internal exception. This was typically the case when querying host/target combinations.

There are errors messages possible that are non-fatal and solely due to the difference between the "command-line environment" and the "scons shell environment" in which the batch file is invoked. These messages would be annoying and there would be no way to easily rectify the situation.

For example, with VS2017 with Typescript installed and MSVC_SCRIPTERROR_POLICY='Warn', the following warning is produced:

    scons: warning: vc script errors detected:
    [ERROR:typescript.bat] TypeScript was not added to PATH since a valid installation was not found
    [ERROR:VsDevCmd.bat] *** VsDevCmd.bat encountered errors. Environment may be incomplete and/or incorrect. ***
    [ERROR:VsDevCmd.bat] In an uninitialized command prompt, please 'set VSCMD_DEBUG=[value]' and then re-run 
    [ERROR:VsDevCmd.bat] vsdevcmd.bat [args] for additional details.
    [ERROR:VsDevCmd.bat] Where [value] is:
    [ERROR:VsDevCmd.bat]    1 : basic debug logging
    [ERROR:VsDevCmd.bat]    2 : detailed debug logging
    [ERROR:VsDevCmd.bat]    3 : trace level logging. Redirection of output to a file when using this level is recommended.
    [ERROR:VsDevCmd.bat] Example: set VSCMD_DEBUG=3
    [ERROR:VsDevCmd.bat]          vsdevcmd.bat > vsdevcmd.trace.txt 2>&1

@jcbrill
Copy link
Contributor Author

jcbrill commented Jun 12, 2022

WIP PR for discussion purposes.

Test SConstruct for MSVC_TOOLSET_VERSION:

from SCons.Tool.MSCommon.vc import get_sdk_versions

env_list = []
def environment(**kwargs):
    global env_list
    build_n = len(env_list) + 1
    build = '_build{:03d}'.format(build_n)
    print('\nBuild:', build, kwargs)
    VariantDir(build, '.', duplicate=0)
    env=Environment(**kwargs)
    #print("CL.EXE", env.WhereIs('cl.exe'))
    #print(env.Dump())
    env.Program(build + '/hello', [build + '/hello.c'])
    env_list.append(env)
    return env

do_once = True
while do_once:
    do_once = False

    # SDK 10/8.1 Folders 
    # 10.0.22621.0 [Default]
    # 10.0.22000.0
    # 10.0.20348.0
    # 10.0.19041.0
    # 10.0.18362.0
    # 10.0.17763.0
    # 10.0.17134.0
    # 10.0.16299.0
    # 10.0.14393.0
    # 10.0.10586.0
    # 10.0.10240.0
    # 8.1
       
    # Default MSVC [VS2022 Community] toolsets installed

    # SxS toolsets
    # 14.32.17.2
    # 14.31.17.1
    # 14.30.17.0
    # 14.29.16.11

    # toolsets
    # 14.32.31326
    # 14.31.31103
    # 14.30.30705
    # 14.29.30133
    # 14.16.27023

    sdk_versions = [None] + get_sdk_versions(MSVC_UWP_APP=False)
    for sdk_version in sdk_versions:
        for spectre_libs in (True, False):

            environment(MSVC_TOOLSET_VERSION='14.32.17.2',  MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.31.17.1',  MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.30.17.0',  MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.29.16.11', MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.16',       MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)

            environment(MSVC_TOOLSET_VERSION=None,          MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.3',        MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.32',       MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.32.31326', MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.31',       MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.31.31103', MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.30',       MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.30.30705', MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.2',        MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.29',       MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.29.30133', MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.1',        MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.16',       MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.16.27023', MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_TOOLSET_VERSION='14.0',        MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)

    # VS2022 Community toolsets installed

    # SxS toolsets
    # 14.32.17.2
    # 14.31.17.1
    # 14.30.17.0
    # 14.29.16.11

    # toolsets
    # 14.32.31326
    # 14.31.31103
    # 14.30.30705
    # 14.29.30133
    # 14.16.27023

    sdk_versions = [None] + get_sdk_versions(MSVC_VERSION='14.3')
    for sdk_version in sdk_versions:
        for spectre_libs in (True, False):

            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.32.17.2',  MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.31.17.1',  MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.30.17.0',  MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.29.16.11', MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.16',       MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)

            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION=None,          MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.3',        MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.32',       MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.32.31326', MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.31',       MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.31.31103', MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.30',       MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.30.30705', MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.2',        MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.29',       MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.29.30133', MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.1',        MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.16',       MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.16.27023', MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)
            environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.0',        MSVC_SDK_VERSION=sdk_version, MSVC_SPECTRE_LIBS=spectre_libs)

    # VS2019 Community toolsets installed

    # SxS toolsets
    # 14.29.16.10
    # 14.28.16.9
    # 14.28.16.8

    # toolsets
    # 14.29.30133
    # 14.29.30037
    # 14.28.29910
    # 14.28.29333
    # 14.27.29110
    # 14.16.27023

    sdk_versions = [None] + get_sdk_versions(MSVC_VERSION='14.2')
    for sdk_version in sdk_versions:

        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.29.16.10',  MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.28.16.9',   MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.28.16.8',   MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.28',        MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.27',        MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.16',        MSVC_SDK_VERSION=sdk_version)

        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION=None,           MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.2',         MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.29',        MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.29.30133',  MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.29.30037',  MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.28',        MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.28.29910',  MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.28.29333',  MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.27.29110',  MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.1',         MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.16',        MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.16.27023',  MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.2', MSVC_TOOLSET_VERSION='14.0',         MSVC_SDK_VERSION=sdk_version)

    # VS2017 Community toolsets installed

    # toolsets
    # 14.16.27023
    # 14.15.26726

    sdk_versions = [None] + get_sdk_versions(MSVC_VERSION='14.1')
    for sdk_version in sdk_versions:

        environment(MSVC_VERSION='14.1', MSVC_TOOLSET_VERSION='14.15',        MSVC_SDK_VERSION=sdk_version)

        environment(MSVC_VERSION='14.1', MSVC_TOOLSET_VERSION=None,           MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.1', MSVC_TOOLSET_VERSION='14.1',         MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.1', MSVC_TOOLSET_VERSION='14.16',        MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.1', MSVC_TOOLSET_VERSION='14.16.27023',  MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.1', MSVC_TOOLSET_VERSION='14.15',        MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.1', MSVC_TOOLSET_VERSION='14.15.26726',  MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.1', MSVC_TOOLSET_VERSION='14.0',         MSVC_SDK_VERSION=sdk_version)

    # VS2017 Express toolsets installed

    # toolsets
    # 14.16.27023

    sdk_versions = [None] + get_sdk_versions(MSVC_VERSION='14.1Exp')
    #sdk_versions = []
    for sdk_version in sdk_versions:

        environment(MSVC_VERSION='14.1Exp', MSVC_TOOLSET_VERSION=None,          MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.1Exp', MSVC_TOOLSET_VERSION='14.1',        MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.1Exp', MSVC_TOOLSET_VERSION='14.16',       MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.1Exp', MSVC_TOOLSET_VERSION='14.16.27023', MSVC_SDK_VERSION=sdk_version)
        environment(MSVC_VERSION='14.1Exp', MSVC_TOOLSET_VERSION='14.0',        MSVC_SDK_VERSION=sdk_version)

    # VS2015 Community [No toolset support]

    sdk_versions = [None] + get_sdk_versions(MSVC_VERSION='14.0')
    for sdk_version in sdk_versions:

        environment(MSVC_VERSION='14.0', MSVC_SDK_VERSION=sdk_version)

@bdbaddog bdbaddog added this to In progress in msvc bug scrub 04-2022 via automation Jun 13, 2022
@bdbaddog bdbaddog added this to the 4.4 milestone Jun 13, 2022
@bdbaddog bdbaddog added the MSVC Microsoft Visual C++ Support label Jun 13, 2022
@jcbrill
Copy link
Contributor Author

jcbrill commented Jun 20, 2022

@bdbaddog and @mwichmann Guidance request at your conveniences.

The "code portion" is effectively complete for this PR. However, I need some guidance on the preferred code organization moving forward.

Some of the additions that I authored recently (e.g., setting up the default environment warning suppression primarily) used a large internal class with class attributes and classmethods. In the implementation of this PR, both the amount of code and the number of new internal classes expanded. While I am fond of this style, there is a drawback with the debug log as the class names are not written. I'm guessing that unit testing is a bit harder as well.

As an experiment, the current branch was re-worked to use a sub-module (SCons.Tool.MSCommon.MSVC) organization with the "class namespaces" moved to proper module files. There were a few quirks regarding a clean separation of the existing vc.py code and the new submodules. For instance, the base exception type was moved to the submodule and imported by vc.py rather than defined in vc.py. The recent msvc not found policy and default environment setup were moved into their own standalone modules. The default environment setup required a callback function to avoid circular dependencies/references.

This PR: https://github.com/jcbrill/scons/tree/jbrill-msvc-batchargs
This PR using modules: https://github.com/jcbrill/scons/tree/jbrill-msvc-batchargs-modules

When comparing vc.py in both branches, once the big chunks that moved to submodules are ignored there aren't that many changes. As of this morning, both branches should be functionally equivalent. I still need to do some of my own testing for the default environment warning suppression to make sure I didn't break anything.

The outstanding question is how to proceed? monolithic vc.py or smaller pieces via sub-modules?

There are advantages and disadvantages of each way forward.

Any and all feedback is appreciated.

@mwichmann
Copy link
Collaborator

Sadly, I agree with your comment that there are advantages either way. If I'm not dealing with a transition from earlier code, I strongly prefer dividing things out into smaller pieces, and implementing separation of responsibility. We're of course dealing with transition from a long-standing code arrangement, so the "If" part clearly applies...

There's nothing magical about the debug printing, if we need to add a class name or other information to how the logging setup is initialized, we can do so - but on the other hand, the msvc debug output is pretty "busy" already, at least for me it's already hard to pick out meaningful bits from lots of noise.

@bdbaddog
Copy link
Contributor

Would it work to name the module vc and then just have a __init__.py which would have the functionality/variables currently in vc.py?
That way anyone importing MSCommon/vc.py would not see any difference?

I like the submodule for when a file becomes way too large.. I did similar for ninja (if you noticed it moved from ninja.py to ninja/*).
Especially anything that refactors a nearly 3000 line source file.. ;)
(So thumbs up on that reorg)

Also are your complete checkboxes in the initial description at the top up to date?
Lastly, should probably update the README in MSCommon.

@jcbrill
Copy link
Contributor Author

jcbrill commented Jun 20, 2022

Also are your complete checkboxes in the initial description at the top up to date?
Lastly, should probably update the README in MSCommon.

Unfortunately, the checkboxes are up to date.
The two biggest remaining tasks are:

  • msvc.xml documentation of all new variables, and
  • unit tests

README and CHANGES should not be very difficult once the other two are complete.

Would it work to name the module vc and then just have a init.py which would have the functionality/variables currently in vc.py?
That way anyone importing MSCommon/vc.py would not see any difference?

Probably. I'm pretty sure that importing MSCommon/vc.py as it stands now would not be different.

@bdbaddog Would it be useful create a possible throwaway [WIP] PR with the modules branch so that the two of you can review the layout as it stands? If anyone likes the new layout, I can add it to this PR in one commit. If no one likes the other layout, then no harm done.

@bdbaddog
Copy link
Contributor

@jcbrill - Just thinking that since MSCommon/MSVC is effectively what was previously in vc.py, it might make sense to remove vc.py and make that the module name and move it's logic into vc/init.py ?

I'm ok with that refactor being in this PR.

@jcbrill
Copy link
Contributor Author

jcbrill commented Jun 20, 2022

Just thinking that since MSCommon/MSVC is effectively what was previously in vc.py, it might make sense to remove vc.py and make that the module name and move it's logic into vc/init.py ?

vc.py is still pretty large after the refactor: ~1350 loc.

At present, MSCommon/MSVC, only contains "recent/new components from vc.py":

  • msvc_notfound_policy support (parallel functions moved from vc.py to new module),
  • Suppress warning for default tools (_MSVCSetupEnvDefault class moved from vc.py to new module),
  • and this PR

None of the MSVS/MSVC tests have been affected yet.

I'm not arguing ... just feeling a little uneasy.

@bdbaddog
Copy link
Contributor

Ok. Let's not tie the vc.py -> module with this functionality.
I do like the moving logic to MSVC, so if you can push that into this PR.
I think that would be an improvement.

+-> MSCommon/vc.py:_check_cl_exists_in_vc_dir:
| Figure out host/target pair
| if version > 14.0 get specific version by looking in
| pdir + Auxiliary/Build/Microsoft/VCToolsVersion/default.txt
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Secret Scan] It may be dangerous to commit the AWS secret access key. (view)

AWS secret access key is an important credential that allows you to use AWS programmatically.
Once this leaks, an attacker can access and operate your AWS resources.

See also:

Rule Severity
sider.secrets.aws.secret_access_key warning

You can close this issue if no need to fix it. Learn more.

Sider got fooled, it thinks this might contain an AWS secret key.

The line it's flagging sure doesn't look like that to me:

          |    pdir + Auxiliary/Build/Microsoft/VCToolsVersion/default.txt

Copy link
Contributor

Choose a reason for hiding this comment

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

closed that one.. Weird.

@bdbaddog
Copy link
Contributor

I'll leave a "ruling" on that to @bdbaddog, but don't see where that should be a problem - it's a little riskier for code, where you might want to trace history backwards and have to remember git flags to track back across the rename (--follow), but that should be a non-factor for in-directory README files.

Yes. Rename is fine. use git mv old new should do the trick I think.

@jcbrill
Copy link
Contributor Author

jcbrill commented Jul 18, 2022

Mini-update: The only outstanding item is the request above to add content to MSCommon/README.rst.

Currently, there are no other planned code or documentation changes.

While there are a lot files, when broken down into logical groups it seems more manageable as the source files are really about 1/3 of the files and some are very small.

Note: due to moving the recent code to suppress warnings for msvc missing when there are no installations into MSVC/SetupEnvDefault.py, there appears to be a large difference with vc.py. Comparing the current PR with a state prior to that particular merge may be more illuminating.

Source Files [Total=15, New=11, Modified=4]:

  • SCons/Tool
    • MSCommon
      • MSVC
        • Config.py [New]
        • Dispatcher.py [New]
        • Exceptions.py [New]
        • Policy.py [New]
        • Registry.py [New]
        • ScriptArguments.py [New]
        • SetupEnvDefault.py [New]
        • Util.py [New]
        • Warnings.py [New]
        • WinSDK.py [New]
        • __init__.py [New]
      • __init__.py [Modified]
      • common.py [Bug Fix & Modified]
      • vc.py [Modified]
    • docbook
      • __init__.py [Bug Fix]

Documentation Files [Total=5, New=0, Modified=5]:

  • CHANGES.txt [Modified]
  • RELEASE.txt [Modified]
  • SCons/Tool
    • MSCommon
      • README [Renamed/Removed]
      • README.rst [Modified]
    • msvc.xml [Modified]

Tests [Total=21, New=16, Modified=5]:

  • SCons/Tool
    • MSCommon
      • MSVC
        • ConfigTests.py [New]
        • DispatcherTests.py [New]
        • PolicyTests.py [New]
        • RegistryTests.py [New]
        • ScriptArgumentsTests.py [New]
        • UtilTests.py [New]
        • WinSDKTests.py [New]
      • vcTests [Modified]
  • test
    • MSVC
      • MSVC_NOTFOUND_POLICY.py [New]
      • MSVC_SCRIPTERROR_POLICY.py [New]
      • MSVC_SDK_VERSION.py [New]
      • MSVC_SPECTRE_LIBS.py [New]
      • MSVC_TOOLSET_VERSION.py [New]
      • MSVC_USE_SCRIPT_ARGS-fixture
        • SConstruct [Modified]
      • MSVC_UWP_APP.py [Modified]
      • msvc_cache_force_defaults.py [New]
      • no_msvc.py [Modified]
  • fixture
    • no_msvc
      • no_msvcs_sconstruct_msvc_query_toolset_version.py[New]
      • no_msvcs_sconstruct_msvc_sdk_versions.py [New]
      • no_msvcs_sconstruct_msvc_toolset_versions.py [New]
      • no_msvcs_sconstruct_version.py [Modified]

Generated Documentation Files [Total=4, New=0, Modified=4]:

  • doc/genenerated
    • functions.gen [Modified]
    • tools.gen [Modified]
    • variabled.gen [Modified]
    • variables.mod [Modifed]

@bdbaddog
Copy link
Contributor

@jcbrill - is this done now?

@jcbrill
Copy link
Contributor Author

jcbrill commented Jul 19, 2022

@bdbaddog PR is complete!

The wherefore and the why of the PR implementation is likely easiest to comprehend by starting the review in the following sequence:

  • MSCommon/README.rst: For rendered version see https://github.com/jcbrill/scons/blob/jbrill-msvc-batchargs/SCons/Tool/MSCommon/README.rst [edit: link updated]
  • The generated html documentation for the man page: All of the new construction variables have been fully documented which may provide valuable context when reviewing the implementation.
  • MSCommon/MSVC/ScriptArguments.py: The primary source code implementing this PR. Lengthy due to validation considerations.
  • MSCommon/vc.py: large differences due to deletions for moved code (e.g., MSCommon/MSVC/SetupEnvDefault.py and MSCommon/MSVC/Policy.py), otherwise should be fairly straightforward.
  • MSCommon/common.py: largely uneventful.

Everything else is to support the above in one fashion or another.

@bdbaddog bdbaddog merged commit 41b0831 into SCons:master Jul 25, 2022
msvc bug scrub 04-2022 automation moved this from In progress to Done Jul 25, 2022
@bdbaddog
Copy link
Contributor

Merged.
Note. I'll likely have some follow on PR's to "clean up" a few things and perhaps some requests to @jcbrill to add some more inline code comment's documentation.
The new code is not simple, and so some more comments inline would probably be helpful for longer term maintanence.

Specifically.

  1. How do we add a new version of MSVC or the toolset to the existing code. I'm sure this is fairly simple, but an explicit HOWTO would prevent errors in doing so.
  2. I noticed there are some duplicates of utility functions already in SCons.Util and/or functions/code which would better live there than as a utility function inside MSVC.

None of these need hold up the release, but ideally would be addressed in the near term while the code is fresh in @jcbrill's wildly productive mind. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MSVC Microsoft Visual C++ Support
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

MSVC script enhancements including user-defined arguments
3 participants