@@ -1759,19 +1759,9 @@ protected boolean addRuleForTool(ITool tool, StringBuffer buffer, boolean bTarge
1759
1759
// TODO report error
1760
1760
flags = EMPTY_STRING_ARRAY ;
1761
1761
}
1762
- String command = tool .getToolCommand ();
1763
- try {
1764
- // try to resolve the build macros in the tool command
1765
- String resolvedCommand = ManagedBuildManager .getBuildMacroProvider ()
1766
- .resolveValueToMakefileFormat (command , EMPTY_STRING , WHITESPACE ,
1767
- IBuildMacroProvider .CONTEXT_FILE , new FileContextData (null , null , null , tool ))
1768
- .replaceFirst (" -w " , " " ); //$NON-NLS-1$ //$NON-NLS-2$
1769
- if ((resolvedCommand = resolvedCommand .trim ()).length () > 0 )
1770
- command = resolvedCommand ;
1771
-
1772
- } catch (BuildMacroException e ) {// JABA is not going to write this
1773
- // code
1774
- }
1762
+
1763
+ String command = resolveCommand (true , tool .getToolCommand (), null , null , tool );
1764
+
1775
1765
String [] cmdInputs = inputs .toArray (new String [inputs .size ()]);
1776
1766
IManagedCommandLineGenerator gen = tool .getCommandLineGenerator ();
1777
1767
IManagedCommandLineInfo cmdLInfo = gen .generateCommandLineInfo (tool , command , flags , outflag , outputPrefix ,
@@ -1794,17 +1784,7 @@ IBuildMacroProvider.CONTEXT_FILE, new FileContextData(null, null, null, tool))
1794
1784
1795
1785
// resolve any remaining macros in the command after it has been
1796
1786
// generated
1797
- try {
1798
- String resolvedCommand = ManagedBuildManager .getBuildMacroProvider ()
1799
- .resolveValueToMakefileFormat (buildCmd , EMPTY_STRING , WHITESPACE ,
1800
- IBuildMacroProvider .CONTEXT_FILE , new FileContextData (null , null , null , tool ))
1801
- .replaceFirst (" -w " , " " ); //$NON-NLS-1$//$NON-NLS-2$
1802
- if ((resolvedCommand = resolvedCommand .trim ()).length () > 0 )
1803
- buildCmd = resolvedCommand ;
1804
-
1805
- } catch (BuildMacroException e ) {// JABA is not going to write this
1806
- // code
1807
- }
1787
+ buildCmd = resolveCommand (true , buildCmd , null , null , tool );
1808
1788
1809
1789
// buffer.append(TAB + AT + escapedEcho(buildCmd));
1810
1790
// buffer.append(TAB + AT + buildCmd);
@@ -2375,40 +2355,17 @@ protected void addToBuildVar(LinkedHashMap<String, String> buildVarToRuleStringM
2375
2355
}
2376
2356
}
2377
2357
2378
- @ SuppressWarnings ({ "static-method" })
2358
+ @ SuppressWarnings ({ "static-method" , "nls" })
2379
2359
private IManagedCommandLineInfo generateToolCommandLineInfo (ITool tool , String sourceExtension , String [] flags ,
2380
2360
String outputFlag , String outputPrefix , String outputName , String [] inputResources , IPath inputLocation ,
2381
2361
IPath outputLocation ) {
2382
2362
2383
2363
String cmd = tool .getToolCommand ();
2384
2364
// try to resolve the build macros in the tool command
2385
- try {
2386
- String resolvedCommand = null ;
2387
2365
2388
- if ((inputLocation != null && inputLocation .toString ().indexOf (" " ) != -1 ) || //$NON-NLS-1$
2389
- (outputLocation != null && outputLocation .toString ().indexOf (" " ) != -1 )) //$NON-NLS-1$
2390
- {
2391
- resolvedCommand = ManagedBuildManager .getBuildMacroProvider ()
2392
- .resolveValue (cmd , "" , //$NON-NLS-1$
2393
- " " , //$NON-NLS-1$
2394
- IBuildMacroProvider .CONTEXT_FILE ,
2395
- new FileContextData (inputLocation , outputLocation , null , tool ))
2396
- .replaceFirst (" -w " , " " ); //$NON-NLS-1$ //$NON-NLS-2$
2397
- }
2398
-
2399
- else {
2400
- resolvedCommand = ManagedBuildManager .getBuildMacroProvider ()
2401
- .resolveValueToMakefileFormat (cmd , "" , //$NON-NLS-1$
2402
- " " , //$NON-NLS-1$
2403
- IBuildMacroProvider .CONTEXT_FILE ,
2404
- new FileContextData (inputLocation , outputLocation , null , tool ))
2405
- .replaceFirst (" -w " , " " ); //$NON-NLS-1$ //$NON-NLS-2$
2406
- }
2407
- if ((resolvedCommand = resolvedCommand .trim ()).length () > 0 )
2408
- cmd = resolvedCommand ;
2409
-
2410
- } catch (BuildMacroException e ) {// JABA is not going to write this code
2411
- }
2366
+ boolean useMakeFileFormat = !((inputLocation != null && inputLocation .toString ().indexOf (" " ) != -1 )
2367
+ || (outputLocation != null && outputLocation .toString ().indexOf (" " ) != -1 ));
2368
+ cmd = resolveCommand (useMakeFileFormat , cmd , inputLocation , outputLocation , tool );
2412
2369
2413
2370
IManagedCommandLineGenerator gen = tool .getCommandLineGenerator ();
2414
2371
return gen .generateCommandLineInfo (tool , cmd , flags , outputFlag , outputPrefix , outputName , inputResources ,
@@ -2614,28 +2571,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
2614
2571
// Get and resolve the command
2615
2572
String cmd = tool .getToolCommand ();
2616
2573
2617
- try {
2618
- String resolvedCommand = null ;
2619
- if (!needExplicitRuleForFile ) {
2620
- resolvedCommand = ManagedBuildManager .getBuildMacroProvider ()
2621
- .resolveValueToMakefileFormat (cmd , EMPTY_STRING , WHITESPACE , IBuildMacroProvider .CONTEXT_FILE ,
2622
- new FileContextData (sourceLocation , outputLocation , null , tool ))
2623
- .replaceFirst (" -w " , " " ); //$NON-NLS-1$ //$NON-NLS-2$
2624
- } else {
2625
- // if we need an explicit rule then don't use any builder
2626
- // variables, resolve everything
2627
- // to explicit strings
2628
- resolvedCommand = ManagedBuildManager .getBuildMacroProvider ()
2629
- .resolveValue (cmd , EMPTY_STRING , WHITESPACE , IBuildMacroProvider .CONTEXT_FILE ,
2630
- new FileContextData (sourceLocation , outputLocation , null , tool ))
2631
- .replaceFirst (" -w " , " " ); //$NON-NLS-1$ //$NON-NLS-2$
2632
- }
2633
-
2634
- if ((resolvedCommand = resolvedCommand .trim ()).length () > 0 )
2635
- cmd = resolvedCommand ;
2636
-
2637
- } catch (BuildMacroException e ) {// JABA is not going to write this code
2638
- }
2574
+ cmd = resolveCommand (!needExplicitRuleForFile , cmd , sourceLocation , outputLocation , tool );
2639
2575
2640
2576
String defaultOutputName = EMPTY_STRING ;
2641
2577
String primaryDependencyName = EMPTY_STRING ;
@@ -2765,31 +2701,9 @@ && containsSpecialCharacters(sourceLocation.toString()))
2765
2701
String [] preToolCommands = depCommands .getPreToolDependencyCommands ();
2766
2702
if (preToolCommands != null && preToolCommands .length > 0 ) {
2767
2703
for (String preCmd : preToolCommands ) {
2768
- try {
2769
- String resolvedCommand ;
2770
- IBuildMacroProvider provider = ManagedBuildManager .getBuildMacroProvider ();
2771
- if (!needExplicitRuleForFile ) {
2772
- resolvedCommand = provider
2773
- .resolveValueToMakefileFormat (preCmd , EMPTY_STRING , WHITESPACE ,
2774
- IBuildMacroProvider .CONTEXT_FILE ,
2775
- new FileContextData (sourceLocation , outputLocation , null , tool ))
2776
- .replaceFirst (" -w " , " " ); //$NON-NLS-1$ //$NON-NLS-2$
2777
- } else {
2778
- // if we need an explicit rule then don't use
2779
- // any builder
2780
- // variables, resolve everything to explicit
2781
- // strings
2782
- resolvedCommand = provider
2783
- .resolveValue (preCmd , EMPTY_STRING , WHITESPACE ,
2784
- IBuildMacroProvider .CONTEXT_FILE ,
2785
- new FileContextData (sourceLocation , outputLocation , null , tool ))
2786
- .replaceFirst (" -w " , " " ); //$NON-NLS-1$ //$NON-NLS-2$
2787
- }
2788
- if (resolvedCommand != null )
2789
- buffer .append (resolvedCommand + NEWLINE );
2790
- } catch (BuildMacroException e ) {// JABA is not going to
2791
- // write this code
2792
- }
2704
+ buffer .append (
2705
+ resolveCommand (!needExplicitRuleForFile , preCmd , sourceLocation , outputLocation , tool )
2706
+ + NEWLINE );
2793
2707
}
2794
2708
}
2795
2709
}
@@ -2872,32 +2786,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
2872
2786
+ outputPrefix + OUT_MACRO + otherPrimaryOutputs + WHITESPACE + IN_MACRO ;
2873
2787
}
2874
2788
2875
- // resolve any remaining macros in the command after it has been
2876
- // generated
2877
- try {
2878
- String resolvedCommand ;
2879
- IBuildMacroProvider provider = ManagedBuildManager .getBuildMacroProvider ();
2880
- if (!needExplicitRuleForFile ) {
2881
- resolvedCommand = provider
2882
- .resolveValueToMakefileFormat (buildCmd , EMPTY_STRING , WHITESPACE ,
2883
- IBuildMacroProvider .CONTEXT_FILE ,
2884
- new FileContextData (sourceLocation , outputLocation , null , tool ))
2885
- .replaceFirst (" -w " , " " ); //$NON-NLS-1$ //$NON-NLS-2$
2886
- } else {
2887
- // if we need an explicit rule then don't use any builder
2888
- // variables, resolve everything to explicit strings
2889
- resolvedCommand = provider
2890
- .resolveValue (buildCmd , EMPTY_STRING , WHITESPACE , IBuildMacroProvider .CONTEXT_FILE ,
2891
- new FileContextData (sourceLocation , outputLocation , null , tool ))
2892
- .replaceFirst (" -w " , " " ); //$NON-NLS-1$ //$NON-NLS-2$
2893
- }
2894
-
2895
- if ((resolvedCommand = resolvedCommand .trim ()).length () > 0 )
2896
- buildCmd = resolvedCommand ;
2897
-
2898
- } catch (BuildMacroException e ) {// JABA is not going to write this
2899
- // code
2900
- }
2789
+ buildCmd = resolveCommand (!needExplicitRuleForFile , buildCmd , sourceLocation , outputLocation , tool );
2901
2790
2902
2791
// buffer.append(TAB + AT + escapedEcho(buildCmd));
2903
2792
// buffer.append(TAB + AT + buildCmd);
@@ -4951,4 +4840,31 @@ private ToolInfoHolder getToolInfo(IPath path, boolean create) {
4951
4840
}
4952
4841
return h ;
4953
4842
}
4843
+
4844
+ @ SuppressWarnings ("nls" )
4845
+ private static String resolveCommand (boolean makeFormat , String inCommand , IPath inputLocation ,
4846
+ IPath outputLocation , IBuildObject tool ) {
4847
+ String returnedCommand = inCommand ;
4848
+ try {
4849
+ if (makeFormat ) {
4850
+ returnedCommand = ManagedBuildManager .getBuildMacroProvider ().resolveValueToMakefileFormat (inCommand ,
4851
+ "" , " " , IBuildMacroProvider .CONTEXT_FILE ,
4852
+ new FileContextData (inputLocation , outputLocation , null , tool ));
4853
+ } else {
4854
+ returnedCommand = ManagedBuildManager .getBuildMacroProvider ().resolveValue (inCommand , "" , " " ,
4855
+ IBuildMacroProvider .CONTEXT_FILE ,
4856
+ new FileContextData (inputLocation , outputLocation , null , tool ));
4857
+ }
4858
+
4859
+ } catch (BuildMacroException e ) {// JABA is not going to write this
4860
+ // code
4861
+ }
4862
+ returnedCommand = returnedCommand .replaceFirst (" -w " , " " ).trim ();
4863
+ if (returnedCommand .isEmpty ()) {
4864
+ return inCommand ;
4865
+
4866
+ }
4867
+ return ArduinoLanguageProvider .adaptCompilerCommand (returnedCommand );
4868
+
4869
+ }
4954
4870
}
0 commit comments