private static StringCollection GetCompilersOnPath()
        {
            PathScanner scanner = new PathScanner();

            scanner.Add("cl.exe");
            return(scanner.Scan("PATH"));
        }
        /// <summary>
        /// Routine which checks if the resource compiler is present.
        /// </summary>
        /// <returns>
        /// <see langword="true" /> if the resource compiler is present;
        /// otherwise, <see langword="false" />.
        /// </returns>
        private static bool CheckResourceCompilerPresent()
        {
            PathScanner scanner = new PathScanner();

            scanner.Add("rc.exe");
            return(scanner.Scan("PATH").Count > 0);
        }
 /// <summary>
 /// Routine which checks if the header files are present.
 /// </summary>
 /// <returns>
 /// <see langword="true" /> if the header files are present; otherwise,
 /// <see langword="false" />.
 /// </returns>
 private static bool CheckHeaderFilesPresent()
 {
     foreach (string headerFile in ExpectedHeaderFiles)
     {
         PathScanner scanner = new PathScanner();
         scanner.Add(headerFile);
         if (scanner.Scan("INCLUDE").Count == 0)
         {
             return(false);
         }
     }
     return(true);
 }
 /// <summary>
 /// Routine which checks if the libs are present.
 /// </summary>
 /// <returns>
 /// <see langword="true" /> if the libs are present; otherwise,
 /// <see langword="false" />.
 /// </returns>
 private static bool CheckLibsPresent()
 {
     foreach (string lib in ExpectedLibs)
     {
         PathScanner scanner = new PathScanner();
         scanner.Add(lib);
         if (scanner.Scan("LIB").Count == 0)
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #5
0
        private void AddChange(FsChange fsChange, bool notifyHasWork = true, bool withSubdirectories = false)
        {
            lock (_changes)
            {
                if (_changes.TryGetValue(fsChange.Path, out var oldFsChange))
                {
                    oldFsChange.Expired = true;
                }
                _changes[fsChange.Path] = fsChange;
            }

            if (withSubdirectories)
            {
                _pathScanner.Add(fsChange.Path);
            }

            if (notifyHasWork)
            {
                UpdateHasWork();
            }
        }
Exemple #6
0
        private void AddChange(FsSenderChange fsSenderChange, bool notifyHasWork = true, bool withSubdirectories = false)
        {
            // ignore empty path
            if (string.IsNullOrEmpty(fsSenderChange.Path))
            {
                return;
            }

            lock (_changes)
            {
                if (_changes.TryGetValue(fsSenderChange.Path, out var oldFsChange))
                {
                    oldFsChange.Expired = true;
                }

                if (fsSenderChange.ChangeType == FsChangeType.Rename &&
                    _changes.TryGetValue(fsSenderChange.OldPath, out var oldPathFsChange))
                {
                    // rename -> delete old, create new
                    oldPathFsChange.Expired          = true;
                    _changes[fsSenderChange.OldPath] = FsSenderChange.CreateRemove(fsSenderChange.OldPath);
                    fsSenderChange = FsSenderChange.CreateChange(fsSenderChange.Path);
                }

                _changes[fsSenderChange.Path] = fsSenderChange;
            }

            if (withSubdirectories)
            {
                _pathScanner.Add(fsSenderChange.Path);
            }

            if (notifyHasWork)
            {
                UpdateHasWork();
            }
        }
Exemple #7
0
        protected string MKSExecute(string command)
        {
            // locate Source Integrity client on PATH
            PathScanner pathScanner = new PathScanner();

            pathScanner.Add("si.exe");
            StringCollection files = pathScanner.Scan();

            if (files.Count == 0)
            {
                throw new BuildException("Could not find MKS Integrity Client on the system path.",
                                         Location);
            }

            // set up process
            Process proc = new Process();

            proc.StartInfo.UseShellExecute        = false;
            proc.StartInfo.CreateNoWindow         = true;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError  = true;
            proc.StartInfo.FileName  = files[0];
            proc.StartInfo.Arguments = command;
            proc.Start();
            proc.WaitForExit();

            if (proc.ExitCode != 0)
            {
                throw new BuildException(proc.ExitCode.ToString(), Location,
                                         new Exception(proc.StandardError.ReadToEnd()));
            }
            else
            {
                return(proc.StandardOutput.ReadToEnd());
            }
        }
Exemple #8
0
        /// <summary>
        /// Determines whether any file that are includes in the specified
        /// source file has been updated after the obj was compiled.
        /// </summary>
        /// <param name="srcFileName">The source file to check.</param>
        /// <param name="objLastWriteTime">The last write time of the compiled obj.</param>
        /// <returns>
        /// The full path to the include file that was modified after the obj
        /// was compiled, or <see langword="null" /> if no include files were
        /// modified since the obj was compiled.
        /// </returns>
        /// <remarks>
        ///   <para>
        ///   To determine what includes are defined in a source file, conditional
        ///   directives are not honored.
        ///   </para>
        ///   <para>
        ///   If a given include cannot be resolved to an existing file, then
        ///   it will be considered stable.
        ///   </para>
        /// </remarks>
        private string FindUpdatedInclude(string srcFileName, DateTime objLastWriteTime) {
            // quick and dirty code to check whether includes have been modified
            // after the source was last modified

            // TODO: recursively check includes

            Log(Level.Debug, "Checking whether includes of \"{0}\" have been"
                + " updated.", srcFileName);

            // holds the line we're parsing
            string line;

            // locate include directives in source file
            using (StreamReader sr = new StreamReader(srcFileName, true)) {
                while ((line = sr.ReadLine()) != null) {
                    Match match = _includeRegex.Match(line);
                    if (match.Groups.Count != 2) {
                        continue;
                    }

                    string includeFile = match.Groups["includefile"].Value;

                    Log(Level.Debug, "Checking include \"{0}\"...", includeFile);

                    string resolvedInclude = _resolvedIncludes[includeFile] as string;
                    if (resolvedInclude == null) {
                        foreach (string includeDir in IncludeDirs.DirectoryNames) {
                            string foundIncludeFile = FileUtils.CombinePaths(includeDir, includeFile);
                            if (File.Exists(foundIncludeFile)) {
                                Log(Level.Debug, "Found include \"{0}\" in"
                                    + " includedirs.", includeFile);
                                resolvedInclude = foundIncludeFile;
                                break;
                            }
                        }

                        // if we could not locate include in include dirs and
                        // source dir, then try to locate include in INCLUDE 
                        // env var
                        if (resolvedInclude == null) {
                            PathScanner pathScanner = new PathScanner();
                            pathScanner.Add(includeFile);
                            StringCollection includes = pathScanner.Scan("INCLUDE");
                            if (includes.Count > 0) {
                                Log(Level.Debug, "Found include \"{0}\" in"
                                    + " INCLUDE.", includeFile);
                                resolvedInclude = includes[0];
                            }
                        }

                        // if we could not locate include in include dirs
                        // and INCLUDE env var then check for include in base
                        // directory (which is used as working dir)
                        if (resolvedInclude == null) {
                            string foundIncludeFile = FileUtils.CombinePaths(
                                BaseDirectory.FullName, includeFile);
                            if (File.Exists(foundIncludeFile)) {
                                Log(Level.Debug, "Found include \"{0}\" in"
                                    + " working directory.", includeFile);
                                resolvedInclude = foundIncludeFile;
                            }
                        }

                        if (resolvedInclude != null) {
                            _resolvedIncludes.Add(includeFile, resolvedInclude);
                        }
                    }

                    if (resolvedInclude != null) {
                        if (File.GetLastWriteTime(resolvedInclude) > objLastWriteTime) {
                            return resolvedInclude;
                        }
                    } else {
                        // TODO: what do we do if the include cannot be located ?
                        //
                        // for now we'll consider the obj file to be up-to-date
                        Log(Level.Debug, "Include \"{0}\" could not be located.", 
                            includeFile);
                    }
                }
            }

            return null;
        }
Exemple #9
0
        private void AddChange(FsSenderChange fsSenderChange, bool notifyHasWork = true, bool withSubdirectories = false)
        {
            if (_logger.IsDebug)
            {
                _logger.Log($"AddChange {fsSenderChange}", LogLevel.Debug);
            }

            // ignore empty path
            if (string.IsNullOrEmpty(fsSenderChange.Path))
            {
                return;
            }

            lock (_changes)
            {
                if (_changes.TryGetValue(fsSenderChange.Path, out var oldFsChange))
                {
                    oldFsChange.Expired = true;
                    _changes.Remove(oldFsChange.Path);
                    // Rename + Change -> Combine
                    if (fsSenderChange.IsChange && oldFsChange.IsRename)
                    {
                        fsSenderChange.Combine(oldFsChange);
                    }
                }

                _changes.Add(fsSenderChange.Path, fsSenderChange);

                if (fsSenderChange.IsRename)
                {
                    // replace changes inside OldPath to Path
                    var oldPathPrefix          = fsSenderChange.OldPath + "/";
                    var insideOldPathFsChanges = _changes.Values
                                                 .Where(fsChange => !fsChange.Opened &&
                                                        (((fsChange.IsChange || fsChange.IsRename) && fsChange.Path.StartsWith(oldPathPrefix)) ||
                                                         (fsChange.IsRename && fsChange.OldPath.StartsWith(oldPathPrefix)))
                                                        )
                                                 .ToList();

                    var index = oldPathPrefix.Length - 1;
                    foreach (var insideOldPathFsChange in insideOldPathFsChanges)
                    {
                        insideOldPathFsChange.Expired = true;
                        _changes.Remove(insideOldPathFsChange.Path);

                        // update Path
                        var newPath = insideOldPathFsChange.Path.StartsWith(oldPathPrefix)
                            ? string.Concat(fsSenderChange.Path, insideOldPathFsChange.Path.AsSpan(index))
                            : insideOldPathFsChange.Path;

                        var newChange = FsSenderChange.CreateWithPath(insideOldPathFsChange, newPath);
                        // update OldPath
                        if (newChange.IsRename && newChange.OldPath.StartsWith(oldPathPrefix))
                        {
                            newChange.OldPath = string.Concat(fsSenderChange.Path, newChange.OldPath.AsSpan(index));
                        }
                        AddChange(newChange);
                    }

                    // expire and combine change with OldPath
                    if (_changes.TryGetValue(fsSenderChange.OldPath, out var oldPathFsChange) &&
                        !oldPathFsChange.Opened && oldPathFsChange.IsChange)
                    {
                        oldPathFsChange.Expired = true;
                        // Change + Rename -> Combine
                        fsSenderChange.Combine(oldPathFsChange);
                    }
                }
            }

            if (withSubdirectories)
            {
                _pathScanner.Add(fsSenderChange.Path);
            }

            if (notifyHasWork)
            {
                UpdateHasWork();
            }
        }