VirtualBox

Changeset 3194 in kBuild


Ignore:
Timestamp:
Mar 27, 2018 2:05:17 PM (7 years ago)
Author:
bird
Message:

kmk/win: Windows kmk now defaults to --output-sync=target. Fixed output sync on windows in nested make processes that got busted by winchildren and it's no inheritance policy.

Location:
trunk/src/kmk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/job.h

    r3156 r3194  
    6868/* Public functions emulated/provided in posixfcn.c.  */
    6969int fcntl (intptr_t fd, int cmd, ...);
     70#  ifdef CONFIG_NEW_WIN_CHILDREN
     71intptr_t create_mutex (char *mtxname, size_t size);
     72#  else
    7073intptr_t create_mutex (void);
     74#  endif
    7175int same_stream (FILE *f1, FILE *f2);
    7276
    7377#  define RECORD_SYNC_MUTEX(m) record_sync_mutex(m)
    7478void record_sync_mutex (const char *str);
     79#  ifdef CONFIG_NEW_WIN_CHILDREN
     80void prepare_mutex_handle_string (const char *mtxname);
     81#  else
    7582void prepare_mutex_handle_string (intptr_t hdl);
     83#  endif
    7684# else  /* !WINDOWS32 */
    7785
  • trunk/src/kmk/kmkbuiltin/kSubmit.c

    r3192 r3194  
    14921492        if (pWorker)
    14931493        {
    1494             if (!pszExecutable)
    1495                 pszExecutable = argv[iArg];
     1494            /* Before we send off the job, we should dump pending output, since
     1495               the kWorker process currently does not coordinate its output with
     1496               the output.c mechanics. */
     1497            if (pCtx->pOut)
     1498                output_dump(pCtx->pOut);
    14961499
    14971500            rcExit = kSubmitSendJobMessage(pCtx, pWorker, pvMsg, cbMsg, 0 /*fNoRespawning*/, cVerbosity);
  • trunk/src/kmk/main.c

    r3186 r3194  
    478478  -O[TYPE], --output-sync[=TYPE]\n\
    479479                              Synchronize output of parallel jobs by TYPE.\n"),
     480#elif defined(KBUILD_OS_WINDOWS)
     481    N_("\
     482  -O[TYPE], --output-sync[=TYPE]\n\
     483                              Synchronize output of parallel jobs by TYPE:\n\
     484                                none    = no synchronization.\n\
     485                                line    = receip line output\n\
     486                                target  = entire receip output (default)\n\
     487                                recurse = entire recursive invocation\n"),
    480488#else
    481489    N_("\
     
    730738   of each job stay together.  */
    731739
     740#if defined(KMK) && defined(KBUILD_OS_WINDOWS)
     741int output_sync = OUTPUT_SYNC_TARGET;
     742#else
    732743int output_sync = OUTPUT_SYNC_NONE;
     744#endif
    733745
    734746/* Nonzero if the "--trace" option was given.  */
     
    11121124   command-line argument.  */
    11131125void
     1126# ifdef CONFIG_NEW_WIN_CHILDREN
     1127prepare_mutex_handle_string (const char *mtxname)
     1128{
     1129  if (!sync_mutex)
     1130    {
     1131      sync_mutex = xstrdup(mtxname);
     1132      define_makeflags (1, 0);
     1133    }
     1134}
     1135# else
    11141136prepare_mutex_handle_string (sync_handle_t handle)
    11151137{
     
    11231145    }
    11241146}
     1147# endif
    11251148
    11261149#endif  /* NO_OUTPUT_SYNC */
  • trunk/src/kmk/output.c

    r3193 r3194  
    9494      void *sem = acquire_semaphore ();
    9595
     96# ifndef KMK /* this drives me bananas. */
    9697      /* Log the working directory for this dump.  */
    9798      if (print_directory_flag && output_sync != OUTPUT_SYNC_RECURSE)
    9899        traced = log_working_directory (1);
     100# endif
    99101
    100102      /* Work the out and err sequences in parallel. */
     
    124126            fflush(prevdst);
    125127          prevdst = dst;
    126 #ifdef KBUILD_OS_WINDOWS
     128# ifdef KBUILD_OS_WINDOWS
    127129          maybe_con_fwrite (src, len, 1, dst);
    128 #else
     130# else
    129131          fwrite (src, len, 1, dst);
    130 #endif
     132# endif
    131133        }
    132134      if (prevdst)
    133135        fflush (prevdst);
    134136
     137# ifndef KMK /* this drives me bananas. */
    135138      if (traced)
    136139        log_working_directory (0);
     140# endif
    137141
    138142      /* Exit the critical section.  */
     
    599603
    600604#ifdef WINDOWS32
     605# ifdef CONFIG_NEW_WIN_CHILDREN
     606  if (STREAM_OK (stdout))
     607    {
     608      if (STREAM_OK (stderr))
     609        {
     610          char mtxname[256];
     611          sync_handle = create_mutex (mtxname, sizeof (mtxname));
     612          if (sync_handle != -1)
     613            {
     614              prepare_mutex_handle_string (mtxname);
     615              return same_stream (stdout, stderr);
     616            }
     617          perror_with_name ("output-sync suppressed: ", "create_mutex");
     618        }
     619      else
     620        perror_with_name ("output-sync suppressed: ", "stderr");
     621    }
     622  else
     623    perror_with_name ("output-sync suppressed: ", "stdout");
     624  output_sync = OUTPUT_SYNC_NONE;
     625
     626# else  /* !CONFIG_NEW_WIN_CHILDREN */
    601627  if ((!STREAM_OK (stdout) && !STREAM_OK (stderr))
    602628      || (sync_handle = create_mutex ()) == -1)
     
    610636      prepare_mutex_handle_string (sync_handle);
    611637    }
     638# endif /* !CONFIG_NEW_WIN_CHILDREN */
    612639
    613640#else
     
    10321059#endif
    10331060
     1061#ifndef KMK
    10341062  /* If we're not syncing this output per-line or per-target, make sure we emit
    10351063     the "Entering..." message where appropriate.  */
    10361064  if (output_sync == OUTPUT_SYNC_NONE || output_sync == OUTPUT_SYNC_RECURSE)
     1065#else
     1066  /* Indiscriminately output "Entering..." and "Leaving..." message for each
     1067     command line or target is plain annoying!  And when there is no recursion
     1068     it's actually inappropriate.   Haven't got a simple way of detecting that,
     1069     so back to the old behavior for now.  [bird] */
     1070#endif
    10371071    if (! stdio_traced && print_directory_flag)
    10381072      stdio_traced = log_working_directory (1);
  • trunk/src/kmk/w32/compat/posixfcn.c

    r3140 r3194  
    154154record_sync_mutex (const char *str)
    155155{
     156#ifdef CONFIG_NEW_WIN_CHILDREN
     157  HANDLE hmtx = OpenMutexA(SYNCHRONIZE, FALSE /*fInheritable*/, str);
     158  if (hmtx)
     159    mutex_handle = (intptr_t)hmtx;
     160  else
     161    {
     162      mutex_handle = -1;
     163      errno = ENOENT;
     164    }
     165#else
    156166  char *endp;
    157167  intptr_t hmutex = strtol (str, &endp, 16);
     
    164174      errno = EINVAL;
    165175    }
     176#endif
    166177}
    167178
    168179/* Create a new mutex or reuse one created by our parent.  */
    169180intptr_t
     181#ifdef CONFIG_NEW_WIN_CHILDREN
     182create_mutex (char *mtxname, size_t size)
     183#else
    170184create_mutex (void)
    171 {
     185#endif
     186{
     187#ifndef CONFIG_NEW_WIN_CHILDREN
    172188  SECURITY_ATTRIBUTES secattr;
     189#endif
    173190  intptr_t hmutex = -1;
    174191
     
    176193     that.  */
    177194  if (mutex_handle > 0)
    178     return mutex_handle;
    179 
     195    {
     196#ifdef CONFIG_NEW_WIN_CHILDREN
     197      mtxname[0] = '\0';
     198#endif
     199      return mutex_handle;
     200    }
     201
     202#ifdef CONFIG_NEW_WIN_CHILDREN
     203  /* We're the top-level Make. Child Make processes will open our mutex, since
     204     children does not inherit any handles other than the three standard ones. */
     205  snprintf(mtxname, size, "Make-output-%u-%u-%u", GetCurrentProcessId(),
     206           GetCurrentThreadId(), GetTickCount());
     207  hmutex = (intptr_t)CreateMutexA (NULL, FALSE /*Locked*/, mtxname);
     208#else
    180209  /* We are the top-level Make, and we want the handle to be inherited
    181210     by our child processes.  */
     
    185214
    186215  hmutex = (intptr_t)CreateMutex (&secattr, FALSE, NULL);
     216#endif
    187217  if (!hmutex)
    188218    {
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