/// ------------------------------------------------------------------------------------ /// <summary> /// Runs Nant. /// </summary> /// <param name="cmdLine">The CMD line.</param> /// ------------------------------------------------------------------------------------ public void RunNant(string cmdLine) { try { string buildFile = string.Empty; string fwroot = string.Empty; RetrieveBuildFile(DTE.Solution.FullName, out buildFile, out fwroot); cmdLine = string.Format("-nologo -e+ -buildfile:\"{0}\" {1}", buildFile, cmdLine); string workingDir = Path.GetFullPath(Path.GetDirectoryName(buildFile)); StartBuild(string.Format("------ Build started: {0} ------\n", cmdLine)); OutputBuild.Activate(); m_nantRunner = new NantRunner(NAnt, cmdLine, workingDir, new AddinLogListener(this, false), new NantRunner.BuildStatusHandler(BuildStatusChange)); m_nantRunner.Run(); } catch (ThreadAbortException) { throw; } catch (Exception e) { if (m_nantRunner != null && m_nantRunner.IsRunning) { m_nantRunner.Abort(); } OutputBuild.Write("\nINTERNAL ERROR\n\t"); OutputBuild.WriteLine(e.Message); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Start the build. This involves activating the output window, saving all files /// and printing a message. /// </summary> /// <param name="msg"></param> /// ------------------------------------------------------------------------------------ private void StartBuild(string msg) { OutputBuild.Clear(); DTE.Windows.Item(Constants.vsWindowKindOutput).Activate(); DTE.ExecuteCommand("File.SaveAll", string.Empty); OutputBuild.Write(msg); }
public static async Task OnRequest(Microsoft.AspNetCore.Http.HttpContext e, E_RPWS_User user, WebPebbleProject proj) { //Check if we're listing all, or one build. string[] split = e.Request.Path.ToString().Split('/'); bool showList = split.Length >= 5; if (showList) { showList = split[4].Length == 0; } if (showList) { //Print the build history. Remove the log data because it is expensive to bandwidth, and convert the time to a readable format. if (proj.builds == null) { proj.builds = new List <WebPebbleProjectBuild>(); proj.SaveProject(); } OutputBuild[] builds = new OutputBuild[proj.builds.Count]; //Go through each. for (int i = 0; i < proj.builds.Count; i++) { var b = proj.builds[i]; DateTime time = new DateTime(b.time); OutputBuild ob = new OutputBuild { id = b.id, passed = b.passed }; ob.api_log = "build_history/" + ob.id + "/"; ob.api_pbw = "/project/" + proj.projectId + "/pbw_media/" + ob.id + "/" + proj.projectId + "_build_" + b.id + ".pbw"; ob.time = time.ToShortDateString() + " at " + time.ToLongTimeString(); builds[i] = ob; } Array.Reverse(builds); await Program.QuickWriteJsonToDoc(e, builds); } else { //Show just one item. Check if it exists. string id = split[4]; var build = proj.builds.Find(x => x.id == id); if (build == null) { //Not found. await Program.QuickWriteToDoc(e, "Not Found", "text/plain", 404); } else { //Write this one file. await Program.QuickWriteJsonToDoc(e, build); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Finds the target. /// </summary> /// <param name="buildFile">The build file.</param> /// <param name="projectName">Name of the project.</param> /// <param name="fwroot">The fwroot.</param> /// <param name="projectPath">The project path.</param> /// ------------------------------------------------------------------------------------ private void FindTarget(ref string buildFile, ref string projectName, string fwroot, string projectPath) { lock (m_Targets) { string originalProjectName = projectName; bool fTargetExists = true; if (m_Targets.Contains(originalProjectName)) { TargetValue val = (TargetValue)m_Targets[originalProjectName]; if (val == null) { fTargetExists = false; } else { projectName = val.projectName; buildFile = val.buildfile; } } else { // If the target exists in the build file, we compile that. // If it doesn't exist, we look for a file '*.build' in the project's // directory and build with that. // If even that doesn't exist, we quit and let Visual Studio do the compile. // If the buildFile is the same as what we had before, we speed up things // and don't perform the check if ((buildFile == m_buildFile && Path.GetExtension(projectPath) == ".csproj") || TargetExists(buildFile, projectName, fwroot)) { // we already have the correct build file } else { if (projectPath != null && projectPath.Length > 0) { DirectoryInfo dirInfo = new DirectoryInfo(Path.GetDirectoryName(projectPath)); FileInfo[] buildfiles = dirInfo.GetFiles("*.build"); string tmpBuildfile = string.Empty; if (buildfiles != null) { if (buildfiles.Length == 1) { // there is exactly one *.build file tmpBuildfile = buildfiles[0].FullName; } else if (buildfiles.Length > 1) { foreach (FileInfo fileInfo in buildfiles) { if (fileInfo.Name == "build.build") { tmpBuildfile = fileInfo.FullName; } } } } if (tmpBuildfile != string.Empty) { OutputBuild.WriteLine(string.Format("Target \"{2}\" not found in {0}, using {1} instead", buildFile, tmpBuildfile, projectName)); fwroot = Path.GetDirectoryName(Path.GetFullPath(projectPath)); if (!TargetExists(tmpBuildfile, projectName, fwroot)) { projectName = "all"; } buildFile = tmpBuildfile; // projectName = string.Format("{0} -D:fwroot=\"{1}\"", projectName, fwroot); } else { fTargetExists = false; } } else { fTargetExists = false; } } } if (fTargetExists) { m_Targets[originalProjectName] = new TargetValue(buildFile, projectName); } else { m_Targets[originalProjectName] = null; System.Diagnostics.Debug.WriteLine("Target doesn't exist"); OutputBuild.WriteLine(string.Format("Target \"{1}\" not found in {0}, performing VS build", buildFile, projectName)); throw new TargetException("Target doesn't exist"); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Perform the build with NAnt /// </summary> /// <param name="projectName">Name(s) of the target</param> /// <param name="config">Configuration (Debug/Release...)</param> /// <param name="fRebuild"><c>true</c> to perform a rebuild</param> /// <param name="projectPath">Full path to the project</param> /// <param name="fWait"><c>true</c> to wait for the build to finish</param> /// <returns><c>true</c> if the build was successful</returns> /// <exception cref="TargetException">If target doesn't exist, so that a NAnt build /// can't be performed.</exception> /// ------------------------------------------------------------------------------------ private bool InternalBuildProject(Modifiers mods, string projectName, string config, bool fRebuild, string projectPath, bool fWait) { try { string buildFile = string.Empty; string fwroot = string.Empty; RetrieveBuildFile(projectPath, out buildFile, out fwroot); FindTarget(ref buildFile, ref projectName, fwroot, projectPath); m_buildFile = buildFile; //string cmdLine = string.Format("-buildfile:\"c:\\fwtexp\\bin\\FieldWorks.build\" VSCompile -D:sln=\"{0}\"", string action; if (mods.fClean) { action = "clean"; } else if (mods.fTest) { if (mods.fForceTests) { action = "forcetests test"; } else { action = "test"; } } else { action = "buildtest"; } string cmdLine = string.Format( "-e+ -nologo -buildfile:\"{0}\" {1} {2} {3}", buildFile, action, config, projectName); string workingDirectory = Path.GetFullPath(Path.GetDirectoryName(buildFile)); OutputBuild.Activate(); m_nantRunner = new NantRunner(NAnt, cmdLine, workingDirectory, new AddinLogListener(this, false), new NantRunner.BuildStatusHandler(BuildStatusChange)); if (fWait) { if (m_nantRunner.RunSync() != 0) { return(false); } } else { m_nantRunner.Run(); } } catch (TargetException) { throw; } catch (ThreadAbortException) { throw; } catch (Exception e) { if (m_nantRunner != null && m_nantRunner.IsRunning) { m_nantRunner.Abort(); } OutputBuild.Write("\nINTERNAL ERROR\n\t"); OutputBuild.WriteLine(e.Message); return(false); } return(true); }