1616using System . Text . Json ;
1717using System . Text . Json . Nodes ;
1818using System . Text . RegularExpressions ;
19- using System . Threading ;
2019using System . Threading . Tasks ;
2120using System . Xml ;
2221
@@ -34,12 +33,14 @@ public class Config
3433 private string _arch = null ;
3534 private string _os = null ;
3635 private string _build = null ;
37- private string _rootPath = null ;
36+ private string _runtimePath = null ;
37+ private string _coreclrPath = null ;
3838 private IReadOnlyList < string > _filenames = Array . Empty < string > ( ) ;
3939 private IReadOnlyList < string > _projects = Array . Empty < string > ( ) ;
4040 private string _srcDirectory = null ;
4141 private bool _untidy = false ;
4242 private bool _noformat = false ;
43+ private bool _cross = false ;
4344 private bool _fix = false ;
4445 private bool _verbose = false ;
4546 private bool _ignoreErrors = false ;
@@ -58,11 +59,12 @@ public Config(string[] args)
5859 syntax . DefineOption ( "a|arch" , ref _arch , "The architecture of the build (options: x64, x86)" ) ;
5960 syntax . DefineOption ( "o|os" , ref _os , "The operating system of the build (options: Windows, OSX, Linux etc.)" ) ;
6061 syntax . DefineOption ( "b|build" , ref _build , "The build type of the build (options: Release, Checked, Debug)" ) ;
61- syntax . DefineOption ( "c|coreclr " , ref _rootPath , "Full path to base runtime/src/coreclr directory" ) ;
62+ syntax . DefineOption ( "r|runtime " , ref _runtimePath , "Full path to runtime directory" ) ;
6263 syntax . DefineOption ( "compile-commands" , ref _compileCommands , "Full path to compile_commands.json" ) ;
6364 syntax . DefineOption ( "v|verbose" , ref _verbose , "Enable verbose output." ) ;
6465 syntax . DefineOption ( "untidy" , ref _untidy , "Do not run clang-tidy" ) ;
6566 syntax . DefineOption ( "noformat" , ref _noformat , "Do not run clang-format" ) ;
67+ syntax . DefineOption ( "cross" , ref _cross , "If on Linux, run the configure build as a cross build." ) ;
6668 syntax . DefineOption ( "f|fix" , ref _fix , "Fix formatting errors discovered by clang-format and clang-tidy." ) ;
6769 syntax . DefineOption ( "i|ignore-errors" , ref _ignoreErrors , "Ignore clang-tidy errors" ) ;
6870 syntax . DefineOptionList ( "projects" , ref _projects , "List of build projects clang-tidy should consider (e.g. dll, standalone, protojit, etc.). Default: dll" ) ;
@@ -177,6 +179,15 @@ private void validate()
177179 }
178180 }
179181
182+ if ( ( _os != null ) && ( _os . ToLower ( ) != "linux" ) && _cross )
183+ {
184+ if ( _verbose )
185+ {
186+ Console . WriteLine ( "--cross specified for non-Linux OS. Ignoring." ) ;
187+ }
188+ _cross = false ;
189+ }
190+
180191 if ( _srcDirectory == null )
181192 {
182193 if ( _verbose )
@@ -196,33 +207,33 @@ private void validate()
196207 _syntaxResult . ReportError ( "Specify --arch, --os, and --build for clang-tidy run." ) ;
197208 }
198209
199- if ( _rootPath == null )
210+ if ( _runtimePath == null )
200211 {
201212 if ( _verbose )
202213 {
203- Console . WriteLine ( "Discovering --coreclr ." ) ;
214+ Console . WriteLine ( "Discovering --runtime ." ) ;
204215 }
205- _rootPath = Utility . GetRepoRoot ( _verbose ) ;
206- _rootPath = Path . Combine ( _rootPath , "src" , "coreclr" ) ;
207- if ( _rootPath == null )
216+ _runtimePath = Utility . GetRepoRoot ( _verbose ) ;
217+ if ( _runtimePath == null )
208218 {
209- _syntaxResult . ReportError ( "Specify --coreclr " ) ;
219+ _syntaxResult . ReportError ( "Specify --runtime " ) ;
210220 }
211221 else
212222 {
213- Console . WriteLine ( "Using --coreclr= {0}" , _rootPath ) ;
223+ Console . WriteLine ( "Using --runtime {0}" , _runtimePath ) ;
214224 }
215225 }
216226
217- if ( ! Directory . Exists ( _rootPath ) )
227+ _coreclrPath = Path . Combine ( _runtimePath , "src" , "coreclr" ) ;
228+ if ( ! Directory . Exists ( _coreclrPath ) )
218229 {
219- // If _rootPath doesn't exist, it is an invalid path
220- _syntaxResult . ReportError ( "Invalid path to coreclr directory. Specify with --coreclr " ) ;
230+ // If _coreclrPath doesn't exist, it is an invalid path
231+ _syntaxResult . ReportError ( "Invalid path to runtime directory. Specify with --runtime " ) ;
221232 }
222- else if ( ! File . Exists ( Path . Combine ( _rootPath , "build-runtime.cmd" ) ) || ! File . Exists ( Path . Combine ( _rootPath , "build-runtime.sh" ) ) || ! File . Exists ( Path . Combine ( _rootPath , "clr.featuredefines.props" ) ) )
233+ else if ( ! File . Exists ( Path . Combine ( _coreclrPath , "build-runtime.cmd" ) ) || ! File . Exists ( Path . Combine ( _coreclrPath , "build-runtime.sh" ) ) || ! File . Exists ( Path . Combine ( _coreclrPath , "clr.featuredefines.props" ) ) )
223234 {
224235 // Doesn't look like the coreclr directory.
225- _syntaxResult . ReportError ( "Invalid path to coreclr directory. Specify with --coreclr " ) ;
236+ _syntaxResult . ReportError ( "Invalid path to coreclr directory. Specify with --runtime " ) ;
226237 }
227238
228239 // Check that we can find compile_commands.json on windows
@@ -232,8 +243,8 @@ private void validate()
232243 if ( ! _untidy && _compileCommands == null )
233244 {
234245 // Check both the nmakeobj and obj paths for back-compat with the old Ninja/NMake output dir.
235- string [ ] nmakeObjCompileCommandsPathSegments = { _rootPath , ".." , ".." , "artifacts" , "nmakeobj" , _os + "." + _arch + "." + _build , "compile_commands.json" } ;
236- string [ ] compileCommandsPathSegments = { _rootPath , ".." , ".." , "artifacts" , "obj" , "coreclr" , _os + "." + _arch + "." + _build , "compile_commands.json" } ;
246+ string [ ] nmakeObjCompileCommandsPathSegments = { _runtimePath , "artifacts" , "nmakeobj" , _os + "." + _arch + "." + _build , "compile_commands.json" } ;
247+ string [ ] compileCommandsPathSegments = { _runtimePath , "artifacts" , "obj" , "coreclr" , _os + "." + _arch + "." + _build , "compile_commands.json" } ;
237248 string nmakeObjCompileCommands = Path . Combine ( nmakeObjCompileCommandsPathSegments ) ;
238249 string compileCommandsPath = Path . Combine ( compileCommandsPathSegments ) ;
239250 _rewriteCompileCommands = true ;
@@ -255,14 +266,14 @@ private void validate()
255266 }
256267
257268 string [ ] commandArgs = { _arch , _build , "-configureonly" , "-ninja" } ;
258- string buildPath = Path . Combine ( _rootPath , "build-runtime.cmd" ) ;
269+ string buildPath = Path . Combine ( _coreclrPath , "build-runtime.cmd" ) ;
259270
260271 if ( _verbose )
261272 {
262273 Console . WriteLine ( "Running: {0} {1}" , buildPath , String . Join ( " " , commandArgs ) ) ;
263274 }
264275
265- ProcessResult result = Utility . ExecuteProcess ( buildPath , commandArgs , ! _verbose , _rootPath ) ;
276+ ProcessResult result = Utility . ExecuteProcess ( buildPath , commandArgs , ! _verbose , _coreclrPath ) ;
266277
267278 if ( result . ExitCode != 0 )
268279 {
@@ -293,26 +304,26 @@ private void validate()
293304 // If the user didn't specify a compile_commands.json, we need to see if one exists, and if not, create it.
294305 if ( ! _untidy && _compileCommands == null )
295306 {
296- string [ ] compileCommandsPath = { _rootPath , ".." , ".." , "artifacts" , "obj" , "coreclr" , _os + "." + _arch + "." + _build , "compile_commands.json" } ;
307+ string [ ] compileCommandsPath = { _runtimePath , "artifacts" , "obj" , "coreclr" , _os + "." + _arch + "." + _build , "compile_commands.json" } ;
297308 _compileCommands = Path . Combine ( compileCommandsPath ) ;
298309 _rewriteCompileCommands = true ;
299310
300311 if ( ! File . Exists ( Path . Combine ( compileCommandsPath ) ) )
301312 {
302313 Console . WriteLine ( "Can't find compile_commands.json file. Running configure." ) ;
303314 List < string > commandArgs = new ( ) { _arch , _build , "configureonly" , "-cmakeargs" , "-DCMAKE_EXPORT_COMPILE_COMMANDS=1" } ;
304- if ( _os . ToLower ( ) == "linux" )
315+ if ( _os . ToLower ( ) == "linux" && _cross )
305316 {
306317 commandArgs . Add ( "-cross" ) ;
307318 }
308- string buildPath = Path . Combine ( _rootPath , "build-runtime.sh" ) ;
319+ string buildPath = Path . Combine ( _coreclrPath , "build-runtime.sh" ) ;
309320
310321 if ( _verbose )
311322 {
312323 Console . WriteLine ( "Running: {0} {1}" , buildPath , String . Join ( " " , commandArgs ) ) ;
313324 }
314325
315- ProcessResult result = Utility . ExecuteProcess ( buildPath , commandArgs , true , _rootPath ) ;
326+ ProcessResult result = Utility . ExecuteProcess ( buildPath , commandArgs , true , _coreclrPath ) ;
316327
317328 if ( result . ExitCode != 0 )
318329 {
@@ -355,9 +366,9 @@ private void LoadFileConfig()
355366 var os = ExtractDefault < string > ( "os" , out found ) ;
356367 _os = ( found ) ? os : _os ;
357368
358- // Set up _rootPath .
359- var rootPath = ExtractDefault < string > ( "coreclr " , out found ) ;
360- _rootPath = ( found ) ? rootPath : _rootPath ;
369+ // Set up _runtimePath .
370+ var runtimePath = ExtractDefault < string > ( "runtime " , out found ) ;
371+ _runtimePath = ( found ) ? runtimePath : _runtimePath ;
361372
362373 // Set up compileCommands
363374 var compileCommands = ExtractDefault < string > ( "compile-commands" , out found ) ;
@@ -418,7 +429,8 @@ public T ExtractDefault<T>(string name, out bool found)
418429 public bool Fix { get { return _fix ; } }
419430 public bool IgnoreErrors { get { return _ignoreErrors ; } }
420431 public bool RewriteCompileCommands { get { return _rewriteCompileCommands ; } }
421- public string CoreCLRRoot { get { return _rootPath ; } }
432+ public string RuntimePath { get { return _runtimePath ; } }
433+ public string CoreCLRPath { get { return _coreclrPath ; } }
422434 public string Arch { get { return _arch ; } }
423435 public string OS { get { return _os ; } }
424436 public string Build { get { return _build ; } }
@@ -456,7 +468,7 @@ public static int Main(string[] args)
456468 if ( config . Filenames . Count ( ) == 0 )
457469 {
458470 // add all files to a list of files
459- foreach ( string filename in Directory . GetFiles ( Path . Combine ( config . CoreCLRRoot , config . SourceDirectory ) ) )
471+ foreach ( string filename in Directory . GetFiles ( Path . Combine ( config . CoreCLRPath , config . SourceDirectory ) ) )
460472 {
461473 // if it's not a directory, add it to our list
462474 if ( ! Directory . Exists ( filename ) && ( filename . EndsWith ( ".cpp" ) || filename . EndsWith ( ".h" ) || filename . EndsWith ( ".hpp" ) ) )
@@ -470,9 +482,9 @@ public static int Main(string[] args)
470482 foreach ( string filename in config . Filenames )
471483 {
472484 string prefix = "" ;
473- if ( ! filename . Contains ( config . CoreCLRRoot ) )
485+ if ( ! filename . Contains ( config . CoreCLRPath ) )
474486 {
475- prefix = Path . Combine ( config . CoreCLRRoot , config . SourceDirectory ) ;
487+ prefix = Path . Combine ( config . CoreCLRPath , config . SourceDirectory ) ;
476488 }
477489
478490 if ( File . Exists ( Path . Combine ( prefix , filename ) ) )
@@ -489,8 +501,7 @@ public static int Main(string[] args)
489501
490502 if ( config . DoClangTidy )
491503 {
492- string [ ] newCompileCommandsDirPath = { config . CoreCLRRoot , ".." , ".." , "artifacts" , "obj" , "coreclr" , config . OS + "." + config . Arch + "." + config . Build } ;
493- string compileCommands = config . CompileCommands ;
504+ string [ ] newCompileCommandsDirPath = { config . RuntimePath , "artifacts" , "obj" , "coreclr" , config . OS + "." + config . Arch + "." + config . Build } ;
494505 string newCompileCommandsDir = Path . Combine ( newCompileCommandsDirPath ) ;
495506 string newCompileCommands = Path . Combine ( newCompileCommandsDir , "compile_commands_full.json" ) ;
496507
@@ -519,7 +530,7 @@ public static int Main(string[] args)
519530
520531 foreach ( string project in config . Projects )
521532 {
522- compileCommands = rewriteCompileCommands ( newCompileCommands , project ) ;
533+ string compileCommands = rewriteCompileCommands ( newCompileCommands , project ) ;
523534
524535 if ( verbose )
525536 {
@@ -703,7 +714,10 @@ public static bool DoClangTidyInnerLoop(bool fix, bool ignoreErrors, string chec
703714
704715 if ( verbose && ! fix && ( result . StdOut . Contains ( "warning:" ) || ! ignoreErrors ) )
705716 {
706- Console . WriteLine ( result . StdOut ) ;
717+ if ( ! string . IsNullOrEmpty ( result . StdOut ) )
718+ {
719+ Console . WriteLine ( result . StdOut ) ;
720+ }
707721 }
708722 }
709723
0 commit comments