11using System . Diagnostics . CodeAnalysis ;
2+ using System . Runtime . InteropServices . JavaScript ;
23using System . Text ;
34using System . Text . Json ;
45using System . Text . Json . Nodes ;
56using System . Text . RegularExpressions ;
7+ using BuildConfigGen . Debugging ;
68
79namespace BuildConfigGen
810{
@@ -63,11 +65,12 @@ public record ConfigRecord(string name, string constMappingKey, bool isDefault,
6365 /// <param name="writeUpdates">Write updates if true, else validate that the output is up-to-date</param>
6466 /// <param name="allTasks"></param>
6567 /// <param name="getTaskVersionTable"></param>
66- static void Main ( string ? task = null , string ? configs = null , int ? currentSprint = null , bool writeUpdates = false , bool allTasks = false , bool getTaskVersionTable = false )
68+ /// <param name="debugAgentDir">When set to the local pipeline agent directory, this tool will produce tasks in debug mode with the corresponding visual studio launch configurations that can be used to attach to built tasks running on this agent</param>
69+ static void Main ( string ? task = null , string ? configs = null , int ? currentSprint = null , bool writeUpdates = false , bool allTasks = false , bool getTaskVersionTable = false , string ? debugAgentDir = null )
6770 {
6871 try
6972 {
70- MainInner ( task , configs , currentSprint , writeUpdates , allTasks , getTaskVersionTable ) ;
73+ MainInner ( task , configs , currentSprint , writeUpdates , allTasks , getTaskVersionTable , debugAgentDir ) ;
7174 }
7275 catch ( Exception e2 )
7376 {
@@ -85,7 +88,7 @@ static void Main(string? task = null, string? configs = null, int? currentSprint
8588 }
8689 }
8790
88- private static void MainInner ( string ? task , string ? configs , int ? currentSprint , bool writeUpdates , bool allTasks , bool getTaskVersionTable )
91+ private static void MainInner ( string ? task , string ? configs , int ? currentSprint , bool writeUpdates , bool allTasks , bool getTaskVersionTable , string ? debugAgentDir )
8992 {
9093 if ( allTasks )
9194 {
@@ -98,11 +101,10 @@ private static void MainInner(string? task, string? configs, int? currentSprint,
98101 NotNullOrThrow ( configs , "Configs is required" ) ;
99102 }
100103
104+ string currentDir = Environment . CurrentDirectory ;
105+ string gitRootPath = GitUtil . GetGitRootPath ( currentDir ) ;
101106 if ( getTaskVersionTable )
102107 {
103- string currentDir = Environment . CurrentDirectory ;
104- string gitRootPath = GitUtil . GetGitRootPath ( currentDir ) ;
105-
106108 var tasks = MakeOptionsReader . ReadMakeOptions ( gitRootPath ) ;
107109
108110 Console . WriteLine ( "config\t task\t version" ) ;
@@ -120,15 +122,16 @@ private static void MainInner(string? task, string? configs, int? currentSprint,
120122 return ;
121123 }
122124
125+ IDebugConfigGenerator debugConfGen = string . IsNullOrEmpty ( debugAgentDir )
126+ ? new NoDebugConfigGenerator ( )
127+ : new VsCodeLaunchConfigGenerator ( gitRootPath , debugAgentDir ) ;
128+
123129 if ( allTasks )
124130 {
125- string currentDir = Environment . CurrentDirectory ;
126- string gitRootPath = GitUtil . GetGitRootPath ( currentDir ) ;
127-
128131 var tasks = MakeOptionsReader . ReadMakeOptions ( gitRootPath ) ;
129132 foreach ( var t in tasks . Values )
130133 {
131- MainUpdateTask ( t . Name , string . Join ( '|' , t . Configs ) , writeUpdates , currentSprint ) ;
134+ MainUpdateTask ( t . Name , string . Join ( '|' , t . Configs ) , writeUpdates , currentSprint , debugConfGen ) ;
132135 }
133136 }
134137 else
@@ -139,10 +142,12 @@ private static void MainInner(string? task, string? configs, int? currentSprint,
139142 // 3. Ideally default windows exception will occur and errors reported to WER/watson. I'm not sure this is happening, perhaps DragonFruit is handling the exception
140143 foreach ( var t in task ! . Split ( ',' , '|' ) )
141144 {
142- MainUpdateTask ( t , configs ! , writeUpdates , currentSprint ) ;
145+ MainUpdateTask ( t , configs ! , writeUpdates , currentSprint , debugConfGen ) ;
143146 }
144147 }
145148
149+ debugConfGen . WriteLaunchConfigurations ( ) ;
150+
146151 if ( notSyncronizedDependencies . Count > 0 )
147152 {
148153 notSyncronizedDependencies . Insert ( 0 , $ "##vso[task.logissue type=error]There are problems with the dependencies in the buildConfig's package.json files. Please fix the following issues:") ;
@@ -225,7 +230,12 @@ private static void GetVersions(string task, string configsString, out List<(str
225230 }
226231 }
227232
228- private static void MainUpdateTask ( string task , string configsString , bool writeUpdates , int ? currentSprint )
233+ private static void MainUpdateTask (
234+ string task ,
235+ string configsString ,
236+ bool writeUpdates ,
237+ int ? currentSprint ,
238+ IDebugConfigGenerator debugConfigGen )
229239 {
230240 if ( string . IsNullOrEmpty ( task ) )
231241 {
@@ -265,7 +275,7 @@ private static void MainUpdateTask(string task, string configsString, bool write
265275 {
266276 ensureUpdateModeVerifier = new EnsureUpdateModeVerifier ( ! writeUpdates ) ;
267277
268- MainUpdateTaskInner ( task , currentSprint , targetConfigs ) ;
278+ MainUpdateTaskInner ( task , currentSprint , targetConfigs , debugConfigGen ) ;
269279
270280 ThrowWithUserFriendlyErrorToRerunWithWriteUpdatesIfVeriferError ( task , skipContentCheck : false ) ;
271281 }
@@ -309,7 +319,11 @@ private static void ThrowWithUserFriendlyErrorToRerunWithWriteUpdatesIfVeriferEr
309319 }
310320 }
311321
312- private static void MainUpdateTaskInner ( string task , int ? currentSprint , HashSet < Config . ConfigRecord > targetConfigs )
322+ private static void MainUpdateTaskInner (
323+ string task ,
324+ int ? currentSprint ,
325+ HashSet < Config . ConfigRecord > targetConfigs ,
326+ IDebugConfigGenerator debugConfigGen )
313327 {
314328 if ( ! currentSprint . HasValue )
315329 {
@@ -387,7 +401,8 @@ private static void MainUpdateTaskInner(string task, int? currentSprint, HashSet
387401 EnsureBuildConfigFileOverrides ( config , taskTargetPath ) ;
388402 }
389403
390- var taskConfigExists = File . Exists ( Path . Combine ( taskOutput , "task.json" ) ) ;
404+ var taskConfigPath = Path . Combine ( taskOutput , "task.json" ) ;
405+ var taskConfigExists = File . Exists ( taskConfigPath ) ;
391406
392407 // only update task output if a new version was added, the config exists, or the task contains preprocessor instructions
393408 // Note: CheckTaskInputContainsPreprocessorInstructions is expensive, so only call if needed
@@ -423,6 +438,9 @@ private static void MainUpdateTaskInner(string task, int? currentSprint, HashSet
423438 Path . Combine ( taskTargetPath , buildConfigs , configTaskPath , "package.json" ) ) ;
424439 WriteNodePackageJson ( taskOutput , config . nodePackageVersion , config . shouldUpdateTypescript ) ;
425440 }
441+
442+ debugConfigGen . WriteTypescriptConfig ( taskOutput ) ;
443+ debugConfigGen . AddForTask ( taskConfigPath ) ;
426444 }
427445
428446 // delay updating version map file until after buildconfigs generated
0 commit comments