Skip to content

Commit 4070f0d

Browse files
committed
Formatting pass.
1 parent 5746cba commit 4070f0d

File tree

1 file changed

+62
-61
lines changed

1 file changed

+62
-61
lines changed

FASTBuild.cs

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public override string Name
4848

4949
public static bool IsAvailable()
5050
{
51-
if(FBuildExePathOverride != "")
51+
if (FBuildExePathOverride != "")
5252
{
5353
return File.Exists(FBuildExePathOverride);
54-
}
54+
}
5555

5656
// Get the name of the FASTBuild executable.
5757
string fbuild = "fbuild";
@@ -93,7 +93,7 @@ private enum FBBuildType
9393

9494
private void DetectBuildType(List<Action> Actions)
9595
{
96-
foreach(Action action in Actions)
96+
foreach (Action action in Actions)
9797
{
9898
if (action.ActionType != ActionType.Compile && action.ActionType != ActionType.Link)
9999
continue;
@@ -151,7 +151,7 @@ private void AddText(string StringToWrite)
151151

152152
private Dictionary<string, string> ParseCommandLineOptions(string CompilerCommandLine, string[] SpecialOptions, bool SaveResponseFile = false)
153153
{
154-
Dictionary<string, string> ParsedCompilerOptions = new Dictionary<string,string>();
154+
Dictionary<string, string> ParsedCompilerOptions = new Dictionary<string, string>();
155155

156156
// Some tricky defines /DTROUBLE=\"\\\" abc 123\\\"\" aren't handled properly by either Unreal or Fastbuild, but we do our best.
157157
char[] SpaceChar = { ' ' };
@@ -163,13 +163,13 @@ private Dictionary<string, string> ParseCommandLineOptions(string CompilerComman
163163

164164
if (RawTokens.Length >= 1 && RawTokens[0].StartsWith("@\"")) //Response files are in 4.13 by default. Changing VCToolChain to not do this is probably better.
165165
{
166-
string responseCommandline = RawTokens[0];
166+
string responseCommandline = RawTokens[0];
167167

168-
// If we had spaces inside the response file path, we need to reconstruct the path.
169-
for(int i = 1; i < RawTokens.Length; ++i)
170-
{
171-
responseCommandline += " " + RawTokens[i];
172-
}
168+
// If we had spaces inside the response file path, we need to reconstruct the path.
169+
for (int i = 1; i < RawTokens.Length; ++i)
170+
{
171+
responseCommandline += " " + RawTokens[i];
172+
}
173173

174174
ResponseFilePath = responseCommandline.Substring(2, responseCommandline.Length - 3); // bit of a bodge to get the @"response.txt" path...
175175
try
@@ -178,7 +178,7 @@ private Dictionary<string, string> ParseCommandLineOptions(string CompilerComman
178178
if (File.Exists(ResponseFilePath))
179179
RawTokens = File.ReadAllText(ResponseFilePath).Split(Separators, StringSplitOptions.RemoveEmptyEntries); //Certainly not ideal
180180
}
181-
catch(Exception e)
181+
catch (Exception e)
182182
{
183183
Console.WriteLine("Looks like a response file in: " + CompilerCommandLine + ", but we could not load it! " + e.Message);
184184
ResponseFilePath = "";
@@ -187,12 +187,12 @@ private Dictionary<string, string> ParseCommandLineOptions(string CompilerComman
187187

188188
// Raw tokens being split with spaces may have split up some two argument options and
189189
// paths with multiple spaces in them also need some love
190-
for(int i=0; i < RawTokens.Length; ++i)
190+
for (int i = 0; i < RawTokens.Length; ++i)
191191
{
192192
string Token = RawTokens[i];
193-
if(string.IsNullOrEmpty(Token))
193+
if (string.IsNullOrEmpty(Token))
194194
{
195-
if(ProcessedTokens.Count > 0 && QuotesOpened)
195+
if (ProcessedTokens.Count > 0 && QuotesOpened)
196196
{
197197
string CurrentToken = ProcessedTokens.Last();
198198
CurrentToken += " ";
@@ -203,7 +203,7 @@ private Dictionary<string, string> ParseCommandLineOptions(string CompilerComman
203203

204204
int numQuotes = 0;
205205
// Look for unescaped " symbols, we want to stick those strings into one token.
206-
for(int j = 0; j < Token.Length; ++j)
206+
for (int j = 0; j < Token.Length; ++j)
207207
{
208208
if (Token[j] == '\\') //Ignore escaped quotes
209209
++j;
@@ -213,7 +213,7 @@ private Dictionary<string, string> ParseCommandLineOptions(string CompilerComman
213213

214214
// Defines can have escaped quotes and other strings inside them
215215
// so we consume tokens until we've closed any open unescaped parentheses.
216-
if((Token.StartsWith("/D") || Token.StartsWith("-D")) && !QuotesOpened)
216+
if ((Token.StartsWith("/D") || Token.StartsWith("-D")) && !QuotesOpened)
217217
{
218218
if (numQuotes == 0 || numQuotes == 2)
219219
{
@@ -224,7 +224,7 @@ private Dictionary<string, string> ParseCommandLineOptions(string CompilerComman
224224
PartialToken = Token;
225225
++i;
226226
bool AddedToken = false;
227-
for( ; i < RawTokens.Length; ++i)
227+
for (; i < RawTokens.Length; ++i)
228228
{
229229
string NextToken = RawTokens[i];
230230
if (string.IsNullOrEmpty(NextToken))
@@ -242,7 +242,7 @@ private Dictionary<string, string> ParseCommandLineOptions(string CompilerComman
242242
PartialToken += " " + NextToken;
243243
}
244244
}
245-
if(!AddedToken)
245+
if (!AddedToken)
246246
{
247247
Console.WriteLine("Warning! Looks like an unterminated string in tokens. Adding PartialToken and hoping for the best. Command line: " + CompilerCommandLine);
248248
ProcessedTokens.Add(PartialToken);
@@ -278,17 +278,17 @@ private Dictionary<string, string> ParseCommandLineOptions(string CompilerComman
278278
}
279279

280280
//Processed tokens should now have 'whole' tokens, so now we look for any specified special options
281-
foreach(string specialOption in SpecialOptions)
281+
foreach (string specialOption in SpecialOptions)
282282
{
283-
for(int i=0; i < ProcessedTokens.Count; ++i)
283+
for (int i = 0; i < ProcessedTokens.Count; ++i)
284284
{
285-
if(ProcessedTokens[i] == specialOption && i + 1 < ProcessedTokens.Count)
285+
if (ProcessedTokens[i] == specialOption && i + 1 < ProcessedTokens.Count)
286286
{
287-
ParsedCompilerOptions[specialOption] = ProcessedTokens[i + 1];
287+
ParsedCompilerOptions[specialOption] = ProcessedTokens[i + 1];
288288
ProcessedTokens.RemoveRange(i, 2);
289289
break;
290290
}
291-
else if(ProcessedTokens[i].StartsWith(specialOption))
291+
else if (ProcessedTokens[i].StartsWith(specialOption))
292292
{
293293
ParsedCompilerOptions[specialOption] = ProcessedTokens[i].Replace(specialOption, null);
294294
ProcessedTokens.RemoveAt(i);
@@ -301,26 +301,26 @@ private Dictionary<string, string> ParseCommandLineOptions(string CompilerComman
301301
for (int i = 0; i < ProcessedTokens.Count; ++i)
302302
{
303303
string Token = ProcessedTokens[i];
304-
if(Token.Length == 0)
304+
if (Token.Length == 0)
305305
{
306306
continue;
307307
}
308308

309-
if(Token == "/I" || Token == "/l" || Token == "/D" || Token == "-D" || Token == "-x") // Skip tokens with values, I for cpp includes, l for resource compiler includes
309+
if (Token == "/I" || Token == "/l" || Token == "/D" || Token == "-D" || Token == "-x") // Skip tokens with values, I for cpp includes, l for resource compiler includes
310310
{
311311
++i;
312312
}
313-
else if(!Token.StartsWith("/") && !Token.StartsWith("-"))
313+
else if (!Token.StartsWith("/") && !Token.StartsWith("-"))
314314
{
315315
ParsedCompilerOptions["InputFile"] = Token;
316316
ProcessedTokens.RemoveAt(i);
317317
break;
318-
}
318+
}
319319
}
320320

321321
ParsedCompilerOptions["OtherOptions"] = string.Join(" ", ProcessedTokens) + " ";
322322

323-
if(SaveResponseFile && !string.IsNullOrEmpty(ResponseFilePath))
323+
if (SaveResponseFile && !string.IsNullOrEmpty(ResponseFilePath))
324324
{
325325
ParsedCompilerOptions["@"] = ResponseFilePath;
326326
}
@@ -402,7 +402,7 @@ private List<Action> SortActions(List<Action> InActions)
402402
private string GetOptionValue(Dictionary<string, string> OptionsDictionary, string Key, Action Action, bool ProblemIfNotFound = false)
403403
{
404404
string Value = string.Empty;
405-
if(OptionsDictionary.TryGetValue(Key, out Value))
405+
if (OptionsDictionary.TryGetValue(Key, out Value))
406406
{
407407
return Value.Trim(new Char[] { '\"' });
408408
}
@@ -507,7 +507,7 @@ private void WriteEnvironmentSetup()
507507
else
508508
AddText("\t\t'$WindowsSDKBasePath$/Redist/ucrt/DLLs/x64/ucrtbase.dll'\n\n");
509509
*/
510-
AddText(string.Format("\t\t'$Root$/mspft{0}.dll'\n",platformVersionNumber));
510+
AddText(string.Format("\t\t'$Root$/mspft{0}.dll'\n", platformVersionNumber));
511511
AddText(string.Format("\t\t'$Root$/msobj{0}.dll'\n", platformVersionNumber));
512512
AddText(string.Format("\t\t'$Root$/mspdb{0}.dll'\n", platformVersionNumber));
513513
AddText(string.Format("\t\t'$VSBasePath$/VC/redist/x64/Microsoft.VC{0}.CRT/msvcp{1}.dll'\n", platformVersionNumber, platformVersionNumber));
@@ -568,12 +568,12 @@ private void WriteEnvironmentSetup()
568568
//Start Environment
569569
AddText("\t.Environment = \n\t{\n");
570570
if (VCEnv != null)
571-
AddText("\t\t\"PATH=$VSBasePath$\\Common7\\IDE\\;$VSBasePath$\\VC\\bin\\\",\n");
571+
AddText("\t\t\"PATH=$VSBasePath$\\Common7\\IDE\\;$VSBasePath$\\VC\\bin\\\",\n");
572572
if (envVars.ContainsKey("TMP"))
573573
AddText(string.Format("\t\t\"TMP={0}\",\n", envVars["TMP"]));
574574
if (envVars.ContainsKey("SystemRoot"))
575575
AddText(string.Format("\t\t\"SystemRoot={0}\",\n", envVars["SystemRoot"]));
576-
if(envVars.ContainsKey("INCLUDE"))
576+
if (envVars.ContainsKey("INCLUDE"))
577577
AddText(string.Format("\t\t\"INCLUDE={0}\",\n", envVars["INCLUDE"]));
578578
if (envVars.ContainsKey("LIB"))
579579
AddText(string.Format("\t\t\"LIB={0}\",\n", envVars["LIB"]));
@@ -615,7 +615,7 @@ private void AddCompileAction(Action Action, int ActionIndex, List<int> Dependen
615615
}
616616

617617
string InputFile = GetOptionValue(ParsedCompilerOptions, "InputFile", Action, ProblemIfNotFound: true);
618-
if(string.IsNullOrEmpty(InputFile))
618+
if (string.IsNullOrEmpty(InputFile))
619619
{
620620
Console.WriteLine("We have no InputFile. Bailing.");
621621
return;
@@ -658,7 +658,7 @@ private void AddCompileAction(Action Action, int ActionIndex, List<int> Dependen
658658
}
659659
else
660660
{
661-
if(IsMSVC())
661+
if (IsMSVC())
662662
{
663663
AddText(string.Format("\t.CompilerOptions = '{0} /Fo\"%2\" \"%1\" '\n", OtherCompilerOptions));
664664
CompilerOutputExtension = ".cpp.obj";
@@ -701,13 +701,13 @@ private void AddLinkAction(List<Action> Actions, int ActionIndex, List<int> Depe
701701
else //PS4
702702
{
703703
OutputFile = GetOptionValue(ParsedLinkerOptions, "-o", Action, ProblemIfNotFound: false);
704-
if(string.IsNullOrEmpty(OutputFile))
704+
if (string.IsNullOrEmpty(OutputFile))
705705
{
706706
OutputFile = GetOptionValue(ParsedLinkerOptions, "InputFile", Action, ProblemIfNotFound: true);
707707
}
708708
}
709-
710-
if(string.IsNullOrEmpty(OutputFile))
709+
710+
if (string.IsNullOrEmpty(OutputFile))
711711
{
712712
Console.WriteLine("Failed to find output file. Bailing.");
713713
return;
@@ -729,7 +729,7 @@ private void AddLinkAction(List<Action> Actions, int ActionIndex, List<int> Depe
729729
AddText(string.Format("}}\n\n"));
730730
}
731731
else if (Action.CommandPath.Contains("lib.exe") || Action.CommandPath.Contains("orbis-snarl"))
732-
{
732+
{
733733
if (DependencyIndices.Count > 0)
734734
{
735735
for (int i = 0; i < DependencyIndices.Count; ++i) //Don't specify pch or resource files, they have the wrong name and the response file will have them anyways.
@@ -749,8 +749,8 @@ private void AddLinkAction(List<Action> Actions, int ActionIndex, List<int> Depe
749749
}
750750

751751
AddText(string.Format("Library('Action_{0}')\n{{\n", ActionIndex));
752-
AddText(string.Format("\t.Compiler = '{0}'\n",GetCompilerName()));
753-
if(IsMSVC())
752+
AddText(string.Format("\t.Compiler = '{0}'\n", GetCompilerName()));
753+
if (IsMSVC())
754754
AddText(string.Format("\t.CompilerOptions = '\"%1\" /Fo\"%2\" /c'\n"));
755755
else
756756
AddText(string.Format("\t.CompilerOptions = '\"%1\" -o \"%2\" -c'\n"));
@@ -759,32 +759,32 @@ private void AddLinkAction(List<Action> Actions, int ActionIndex, List<int> Depe
759759

760760
if (!string.IsNullOrEmpty(ResponseFilePath))
761761
{
762-
if(IsMSVC())
762+
if (IsMSVC())
763763
{
764764
if (DependencyIndices.Count > 0)
765765
AddText(string.Format("\t.LibrarianOptions = ' /OUT:\"%2\" @\"{0}\" {1} \"%1\"' \n", ResponseFilePath, OtherCompilerOptions));
766766
else
767767
AddText(string.Format("\t.LibrarianOptions = ' /OUT:\"%2\" @\"%1\" {0}' \n", OtherCompilerOptions));
768-
}
768+
}
769769
else
770770
AddText(string.Format("\t.LibrarianOptions = '\"%2\" @\"%1\" {0}' \n", OtherCompilerOptions));
771771
}
772772
else
773773
{
774-
if(IsMSVC())
774+
if (IsMSVC())
775775
AddText(string.Format("\t.LibrarianOptions = ' /OUT:\"%2\" {0} \"%1\"' \n", OtherCompilerOptions));
776776
}
777777

778778
if (DependencyIndices.Count > 0)
779779
{
780780
List<string> DependencyNames = DependencyIndices.ConvertAll(x => string.Format("'Action_{0}'", x));
781-
if(IsMSVC())
781+
if (IsMSVC())
782782
AddText(string.Format("\t.LibrarianAdditionalInputs = {{ {0} }} \n", string.Join(",", DependencyNames.ToArray())));
783-
else if(!string.IsNullOrEmpty(ResponseFilePath))
783+
else if (!string.IsNullOrEmpty(ResponseFilePath))
784784
AddText(string.Format("\t.LibrarianAdditionalInputs = {{ '{0}' }} \n", ResponseFilePath));
785785
PrebuildDependencies.AddRange(DependencyIndices);
786786
}
787-
else if(!string.IsNullOrEmpty(ResponseFilePath))
787+
else if (!string.IsNullOrEmpty(ResponseFilePath))
788788
{
789789
AddText(string.Format("\t.LibrarianAdditionalInputs = {{ '{0}' }} \n", ResponseFilePath));
790790
}
@@ -819,7 +819,7 @@ private void AddLinkAction(List<Action> Actions, int ActionIndex, List<int> Depe
819819

820820
AddText(string.Format("Executable('Action_{0}')\n{{ \n", ActionIndex));
821821
AddText(string.Format("\t.Linker = '{0}' \n", Action.CommandPath));
822-
if(DependencyIndices.Count == 0)
822+
if (DependencyIndices.Count == 0)
823823
{
824824
AddText(string.Format("\t.Libraries = {{ '{0}' }} \n", ResponseFilePath));
825825
if (IsMSVC())
@@ -830,12 +830,12 @@ private void AddLinkAction(List<Action> Actions, int ActionIndex, List<int> Depe
830830
else
831831
{
832832
AddText(string.Format("\t.Libraries = 'Action_{0}_dummy' \n", ActionIndex));
833-
if(IsMSVC())
833+
if (IsMSVC())
834834
AddText(string.Format("\t.LinkerOptions = '/TLBOUT:\"%1\" /Out:\"%2\" @\"{0}\" ' \n", ResponseFilePath)); // The TLBOUT is a huge bodge to consume the %1.
835835
else
836836
AddText(string.Format("\t.LinkerOptions = '-o \"%2\" @\"{0}\" {1} -MQ \"%1\"' \n", ResponseFilePath, OtherCompilerOptions)); // The MQ is a huge bodge to consume the %1.
837837
}
838-
838+
839839
AddText(string.Format("\t.LinkerOutput = '{0}' \n", OutputFile));
840840
AddText(string.Format("}}\n\n"));
841841
}
@@ -850,13 +850,13 @@ private void CreateBffFile(List<Action> InActions, string BffFilePath)
850850
try
851851
{
852852
bffOutputFileStream = new FileStream(BffFilePath, FileMode.Create, FileAccess.Write);
853-
853+
854854
WriteEnvironmentSetup(); //Compiler, environment variables and base paths
855-
855+
856856
for (int ActionIndex = 0; ActionIndex < Actions.Count; ActionIndex++)
857857
{
858858
Action Action = Actions[ActionIndex];
859-
859+
860860
// Resolve dependencies
861861
List<int> DependencyIndices = new List<int>();
862862
foreach (FileItem Item in Action.PrerequisiteItems)
@@ -875,15 +875,15 @@ private void CreateBffFile(List<Action> InActions, string BffFilePath)
875875
Action.CommandArguments = Action.CommandArguments.Replace("$(SCE_ORBIS_SDK_DIR)", "$SCE_ORBIS_SDK_DIR$");
876876
Action.CommandArguments = Action.CommandArguments.Replace("$(DXSDK_DIR)", "$DXSDK_DIR$");
877877
Action.CommandArguments = Action.CommandArguments.Replace("$(CommonProgramFiles)", "$CommonProgramFiles$");
878-
879-
switch(Action.ActionType)
878+
879+
switch (Action.ActionType)
880880
{
881-
case ActionType.Compile : AddCompileAction(Action, ActionIndex, DependencyIndices); break;
881+
case ActionType.Compile: AddCompileAction(Action, ActionIndex, DependencyIndices); break;
882882
case ActionType.Link: AddLinkAction(Actions, ActionIndex, DependencyIndices); break;
883883
default: Console.WriteLine("Fastbuild is ignoring an unsupported action: " + Action.ActionType.ToString()); break;
884884
}
885885
}
886-
886+
887887
AddText("Alias( 'all' ) \n{\n");
888888
AddText("\t.Targets = { \n");
889889
for (int ActionIndex = 0; ActionIndex < Actions.Count; ActionIndex++)
@@ -924,7 +924,7 @@ private bool ExecuteBffFile(string BffFilePath)
924924

925925
//Interesting flags for FASTBuild: -nostoponerror, -verbose, -monitor (if FASTBuild Monitor Visual Studio Extension is installed!)
926926
string FBCommandLine = string.Format("-monitor -summary {0} {1} -ide -config {2}", distArgument, cacheArgument, BffFilePath);
927-
927+
928928
ProcessStartInfo FBStartInfo = new ProcessStartInfo(string.IsNullOrEmpty(FBuildExePathOverride) ? "fbuild" : FBuildExePathOverride, FBCommandLine);
929929

930930
FBStartInfo.UseShellExecute = false;
@@ -939,19 +939,20 @@ private bool ExecuteBffFile(string BffFilePath)
939939
FBStartInfo.RedirectStandardOutput = true;
940940
FBProcess.EnableRaisingEvents = true;
941941

942-
DataReceivedEventHandler OutputEventHandler = (Sender, Args) => {
942+
DataReceivedEventHandler OutputEventHandler = (Sender, Args) =>
943+
{
943944
if (Args.Data != null)
944945
Console.WriteLine(Args.Data);
945946
};
946947

947948
FBProcess.OutputDataReceived += OutputEventHandler;
948949
FBProcess.ErrorDataReceived += OutputEventHandler;
949-
950+
950951
FBProcess.Start();
951-
952+
952953
FBProcess.BeginOutputReadLine();
953954
FBProcess.BeginErrorReadLine();
954-
955+
955956
FBProcess.WaitForExit();
956957
return FBProcess.ExitCode == 0;
957958
}

0 commit comments

Comments
 (0)