VirtualBox

Changeset 69467 in vbox for trunk/src/bldprogs


Ignore:
Timestamp:
Oct 28, 2017 12:30:09 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
118802
Message:

scm: detect hash bang scripts. fixed binary config entry.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bldprogs/scm.cpp

    r69464 r69467  
    664664    SCM_CFG_ENTRY("def",        g_apRewritersFor_DEF,              false, "*.def" ),
    665665    SCM_CFG_ENTRY("iasl",       g_apRewritersFor_DSL,              false, "*.dsl" ),
    666     SCM_CFG_ENTRY("sh",         g_apRewritersFor_ShellScripts,     false, "*.sh|configure" ),
     666    SCM_CFG_ENTRY("shell",      g_apRewritersFor_ShellScripts,     false, "*.sh|configure" ),
    667667    SCM_CFG_ENTRY("bat",        g_apRewritersFor_BatchFiles,       false, "*.bat|*.cmd|*.btm" ),
    668668    SCM_CFG_ENTRY("vbs",        g_apRewritersFor_BasicScripts,     false, "*.vbs|*.vb" ),
     
    671671    SCM_CFG_ENTRY("perl",       g_apRewritersFor_Perl,             false, "*.pl|*.pm" ),
    672672    SCM_CFG_ENTRY("drvinf",     g_apRewritersFor_DriverInfFiles,   false, "*.inf" ),
    673     SCM_CFG_ENTRY("nsis",       g_apRewritersFor_NsisFiles,        false, "*.nsh|*.nsi" ),
     673    SCM_CFG_ENTRY("nsis",       g_apRewritersFor_NsisFiles,        false, "*.nsh|*.nsi|*.nsis" ),
    674674    SCM_CFG_ENTRY("java",       g_apRewritersFor_Java,             false, "*.java" ),
    675675    SCM_CFG_ENTRY("scm",        g_apRewritersFor_ScmSettings,      false, "*.scm-settings" ),
     
    685685    SCM_CFG_ENTRY("sql",        g_apRewritersFor_SqlFiles,         false, "*.pgsql|*.sql" ),
    686686    SCM_CFG_ENTRY("gas",        g_apRewritersFor_GnuAsm,           false, "*.S" ),
    687     SCM_CFG_ENTRY("binary",     g_apRewritersFor_BinaryFiles,      false, "*.bin|*.pdf" ),
     687    SCM_CFG_ENTRY("binary",     g_apRewritersFor_BinaryFiles,      true,  "*.bin|*.pdf|*.zip|*.bz2|*.gz" ),
    688688    /* These should be be last: */
    689     SCM_CFG_ENTRY("make",       g_apRewritersFor_OtherMakefiles,   false, "Makefile|makefile|GNUmakefile|SMakefile" ),
     689    SCM_CFG_ENTRY("make",       g_apRewritersFor_OtherMakefiles,   false, "Makefile|makefile|GNUmakefile|SMakefile|Makefile.am|Makefile.in|*.cmake" ),
    690690    SCM_CFG_ENTRY("text",       g_apRewritersFor_TextFiles,        false, "*.txt|README*|readme*|ReadMe*|NOTE*|TODO*" ),
    691     SCM_CFG_ENTRY("plaintext",  g_apRewritersFor_PlainTextFiles,   false, "LICENSE" ),
     691    SCM_CFG_ENTRY("plaintext",  g_apRewritersFor_PlainTextFiles,   false, "LICENSE|ChangeLog|FAQ|AUTHORS|INSTALL|NEWS" ),
    692692    SCM_CFG_ENTRY("file-list",  g_apRewritersFor_FileLists,        false, "files_*" ),
    693693};
     
    19051905
    19061906    /*
    1907      * Try find a matching rewrite config for this filename.
    1908      */
    1909     PCSCMCFGENTRY pCfg = pBaseSettings->pTreatAs;
    1910     if (!pCfg)
    1911     {
    1912         for (size_t iCfg = 0; iCfg < RT_ELEMENTS(g_aConfigs); iCfg++)
    1913             if (RTStrSimplePatternMultiMatch(g_aConfigs[iCfg].pszFilePattern, RTSTR_MAX, pszBasename, cchBasename, NULL))
    1914             {
    1915                 pCfg = &g_aConfigs[iCfg];
    1916                 break;
    1917             }
    1918         if (!pCfg)
    1919         {
    1920             ScmVerbose(NULL, 2, "skipping '%s': no rewriters configured\n", pszFilename);
    1921             g_cFilesNoRewriters++;
    1922             return VINF_SUCCESS;
    1923         }
    1924         ScmVerbose(pState, 4, "matched \"%s\" (%s)\n", pCfg->pszFilePattern, pCfg->pszName);
    1925     }
    1926     else
    1927         ScmVerbose(pState, 4, "treat-as \"%s\"\n", pCfg->pszName);
    1928 
    1929     /*
    19301907     * Create an input stream from the file and check that it's text.
    19311908     */
     
    19371914        return rc;
    19381915    }
    1939     if (ScmStreamIsText(&Stream1) || pCfg->fBinary)
     1916    bool const fIsText = ScmStreamIsText(&Stream1);
     1917
     1918    /*
     1919     * Try find a matching rewrite config for this filename.
     1920     */
     1921    PCSCMCFGENTRY pCfg = pBaseSettings->pTreatAs;
     1922    if (!pCfg)
     1923    {
     1924        for (size_t iCfg = 0; iCfg < RT_ELEMENTS(g_aConfigs); iCfg++)
     1925            if (RTStrSimplePatternMultiMatch(g_aConfigs[iCfg].pszFilePattern, RTSTR_MAX, pszBasename, cchBasename, NULL))
     1926            {
     1927                pCfg = &g_aConfigs[iCfg];
     1928                break;
     1929            }
     1930        if (!pCfg)
     1931        {
     1932            /* On failure try check for hash-bang stuff before giving up. */
     1933            if (fIsText)
     1934            {
     1935                SCMEOL      enmIgn;
     1936                size_t      cchFirst;
     1937                const char *pchFirst = ScmStreamGetLine(&Stream1, &cchFirst, &enmIgn);
     1938                if (cchFirst >= 9 && *pchFirst == '#')
     1939                {
     1940                    do
     1941                    {
     1942                        pchFirst++;
     1943                        cchFirst--;
     1944                    } while (cchFirst > 0 && RT_C_IS_BLANK(*pchFirst));
     1945                    if (*pchFirst == '!')
     1946                    {
     1947                        do
     1948                        {
     1949                            pchFirst++;
     1950                            cchFirst--;
     1951                        } while (cchFirst > 0 && RT_C_IS_BLANK(*pchFirst));
     1952                        const char *pszTreatAs = NULL;
     1953                        if (   (cchFirst >= 7 && strncmp(pchFirst, "/bin/sh", 7) == 0)
     1954                            || (cchFirst >= 9 && strncmp(pchFirst, "/bin/bash", 9) == 0)
     1955                            || (cchFirst >= 4+9 && strncmp(pchFirst, "/usr/bin/bash", 4+9) == 0) )
     1956                            pszTreatAs = "shell";
     1957                        else if (   (cchFirst >= 15 && strncmp(pchFirst, "/usr/bin/python", 15) == 0)
     1958                                 || (cchFirst >= 19 && strncmp(pchFirst, "/usr/bin/env python", 19) == 0) )
     1959                            pszTreatAs = "python";
     1960                        else if (   (cchFirst >= 13 && strncmp(pchFirst, "/usr/bin/perl", 13) == 0)
     1961                                 || (cchFirst >= 17 && strncmp(pchFirst, "/usr/bin/env perl", 17) == 0) )
     1962                            pszTreatAs = "python";
     1963                        if (pszTreatAs)
     1964                        {
     1965                            for (size_t iCfg = 0; iCfg < RT_ELEMENTS(g_aConfigs); iCfg++)
     1966                                if (strcmp(pszTreatAs, g_aConfigs[iCfg].pszName) == 0)
     1967                                {
     1968                                    pCfg = &g_aConfigs[iCfg];
     1969                                    break;
     1970                                }
     1971                            Assert(pCfg);
     1972                        }
     1973                    }
     1974                }
     1975                ScmStreamRewindForReading(&Stream1);
     1976            }
     1977            if (!pCfg)
     1978            {
     1979                ScmVerbose(NULL, 2, "skipping '%s': no rewriters configured\n", pszFilename);
     1980                g_cFilesNoRewriters++;
     1981                ScmStreamDelete(&Stream1);
     1982                return VINF_SUCCESS;
     1983            }
     1984        }
     1985        ScmVerbose(pState, 4, "matched \"%s\" (%s)\n", pCfg->pszFilePattern, pCfg->pszName);
     1986    }
     1987    else
     1988        ScmVerbose(pState, 4, "treat-as \"%s\"\n", pCfg->pszName);
     1989
     1990    if (fIsText || pCfg->fBinary)
    19401991    {
    19411992        ScmVerboseBanner(pState, 3);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette