void UpdateVersionNumber()

in scbuild/scbuild.cs [494:592]


    void UpdateVersionNumber()
    {
        string versionFileName = @"inc\symcrypt_internal_shared.inc";

        string [] lines = File.ReadAllLines( versionFileName );
        if( lines.Length < 10 )
        {
            Fatal( "Could not read file '{0}'", versionFileName );
        }

        int vApi = -1;
        int nApi = 0;
        int vMinor = -1;
        int nMinor = 0;
        int newApi = -1;
        int newMinor = -1;
        for( int i=0; i<lines.Length; i++ )
        {
            string line = lines[i];
            if( line.Contains( "SYMCRYPT_CODE_VERSION_API" ) )
            {
                MatchCollection matches = Regex.Matches( line, @"\d+" );
                if( matches.Count != 1 )
                {
                    Fatal( "Did not find a single integer in a Release version line '{0}'", line );
                }
                Match m = matches[0];
                string digits = m.Value;
                int apiVersion = Convert.ToInt32( digits );

                if( vApi >= 0 && vApi != apiVersion )
                {
                    Fatal( "Inconsistent API versions in symcrypt_internal_shared.inc({0}) : {1} {2}", line, vApi, apiVersion );
                }
                vApi = apiVersion;
                newApi = vApi;
                //if( false  )        // never auto-increment API version #
                //{
                //    newApi++;
                //    line = line.Replace( digits, newApi.ToString() );
                //    lines[i] = line;
                //}
                nApi++;
            }

            if( line.Contains( "SYMCRYPT_CODE_VERSION_MINOR" ) )
            {
                MatchCollection matches = Regex.Matches( line, @"\d+" );
                if( matches.Count != 1 )
                {
                    Fatal( "Did not find a single integer in a minor version line '{0}'", line );
                }
                Match m = matches[0];
                string digits = m.Value;
                int minorVersion = Convert.ToInt32( digits );

                if( vMinor >= 0 && vMinor != minorVersion )
                {
                    Fatal( "Inconsistent minor versions in symcrypt_internal_shared.inc file" );
                }
                vMinor = minorVersion;

                newMinor = vMinor;
                if( m_option_inc_version )
                {
                    newMinor = vMinor + 1;
                    line = line.Replace( digits, newMinor.ToString() );
                    lines[i] = line;
                }

                nMinor++;
            }
        }

        if( nApi != 1 || nMinor != 1 )
        {
            Fatal( "symcrypt_internal_shared.inc file has unexpected number of API and minor version-containing lines" );
        }

        foreach( string l in lines )
        {
            //Print( l + "\n" );
        }

        m_apiVersion = newApi;
        m_minorVersion = newMinor;

        if( !m_option_inc_version )
        {
            Print( "...Not updating version number\n" );
            return;
        }

        Print( "New SymCrypt version number {0}.{1}\n", newApi, newMinor );

        File.WriteAllLines(versionFileName, lines);

        // We do not commit any data so that we can always build without touching the repo state.
    }