23
23
24
24
package processing .app .debug ;
25
25
26
- import static processing .app .I18n ._ ;
27
-
28
- import java .io .*;
29
- import java .nio .file .Files ;
30
- import java .nio .file .Path ;
31
- import java .nio .file .Paths ;
32
- import java .nio .file .StandardCopyOption ;
33
- import java .util .*;
34
- import java .util .stream .Stream ;
35
-
26
+ import cc .arduino .Constants ;
36
27
import cc .arduino .MyStreamPumper ;
37
28
import cc .arduino .contributions .packages .ContributedPlatform ;
38
29
import cc .arduino .contributions .packages .ContributedTool ;
39
30
import cc .arduino .packages .BoardPort ;
40
31
import cc .arduino .packages .Uploader ;
41
32
import cc .arduino .packages .UploaderFactory ;
42
-
43
33
import cc .arduino .packages .uploaders .MergeSketchWithBooloader ;
44
34
import cc .arduino .utils .Pair ;
45
35
import org .apache .commons .compress .utils .IOUtils ;
46
- import org .apache .commons .exec .*;
47
- import processing .app .BaseNoGui ;
48
- import processing .app .I18n ;
49
- import processing .app .PreferencesData ;
50
- import processing .app .SketchCode ;
51
- import processing .app .SketchData ;
52
- import processing .app .helpers .*;
36
+ import org .apache .commons .exec .CommandLine ;
37
+ import org .apache .commons .exec .DefaultExecutor ;
38
+ import org .apache .commons .exec .PumpStreamHandler ;
39
+ import processing .app .*;
40
+ import processing .app .helpers .FileUtils ;
41
+ import processing .app .helpers .PreferencesMap ;
42
+ import processing .app .helpers .PreferencesMapException ;
43
+ import processing .app .helpers .StringReplacer ;
53
44
import processing .app .helpers .filefilters .OnlyDirs ;
54
- import processing .app .packages .LibraryList ;
55
- import processing .app .preproc .PdePreprocessor ;
56
45
import processing .app .legacy .PApplet ;
57
46
import processing .app .packages .LegacyUserLibrary ;
47
+ import processing .app .packages .LibraryList ;
58
48
import processing .app .packages .UserLibrary ;
49
+ import processing .app .preproc .PdePreprocessor ;
59
50
import processing .app .tools .DoubleQuotedArgumentsOnWindowsCommandLine ;
60
51
52
+ import java .io .*;
53
+ import java .nio .file .Files ;
54
+ import java .nio .file .Path ;
55
+ import java .nio .file .Paths ;
56
+ import java .nio .file .StandardCopyOption ;
57
+ import java .util .*;
58
+ import java .util .stream .Collectors ;
59
+ import java .util .stream .Stream ;
60
+
61
+ import static processing .app .I18n ._ ;
62
+
61
63
public class Compiler implements MessageConsumer {
62
64
63
65
/**
@@ -561,28 +563,30 @@ private PreferencesMap createBuildPreferences(String _buildPath,
561
563
}
562
564
563
565
// Merge all the global preference configuration in order of priority
564
- PreferencesMap p = new PreferencesMap ();
565
- p .putAll (PreferencesData .getMap ());
566
- if (corePlatform != null )
567
- p .putAll (corePlatform .getPreferences ());
568
- p .putAll (targetPlatform .getPreferences ());
569
- p .putAll (BaseNoGui .getBoardPreferences ());
570
- for (String k : p .keySet ()) {
571
- if (p .get (k ) == null )
572
- p .put (k , "" );
573
- }
574
-
575
- p .put ("build.path" , _buildPath );
576
- p .put ("build.project_name" , _primaryClassName );
577
- p .put ("build.arch" , targetPlatform .getId ().toUpperCase ());
566
+ PreferencesMap buildPref = new PreferencesMap ();
567
+ buildPref .putAll (PreferencesData .getMap ());
568
+ if (corePlatform != null ) {
569
+ buildPref .putAll (corePlatform .getPreferences ());
570
+ }
571
+ buildPref .putAll (targetPlatform .getPreferences ());
572
+ buildPref .putAll (BaseNoGui .getBoardPreferences ());
573
+ for (String k : buildPref .keySet ()) {
574
+ if (buildPref .get (k ) == null ) {
575
+ buildPref .put (k , "" );
576
+ }
577
+ }
578
+
579
+ buildPref .put ("build.path" , _buildPath );
580
+ buildPref .put ("build.project_name" , _primaryClassName );
581
+ buildPref .put ("build.arch" , targetPlatform .getId ().toUpperCase ());
578
582
579
583
// Platform.txt should define its own compiler.path. For
580
584
// compatibility with earlier 1.5 versions, we define a (ugly,
581
585
// avr-specific) default for it, but this should be removed at some
582
586
// point.
583
- if (!p .containsKey ("compiler.path" )) {
587
+ if (!buildPref .containsKey ("compiler.path" )) {
584
588
System .err .println (_ ("Third-party platform.txt does not define compiler.path. Please report this to the third-party hardware maintainer." ));
585
- p .put ("compiler.path" , BaseNoGui .getAvrBasePath ());
589
+ buildPref .put ("compiler.path" , BaseNoGui .getAvrBasePath ());
586
590
}
587
591
588
592
TargetPlatform referencePlatform = null ;
@@ -592,21 +596,21 @@ private PreferencesMap createBuildPreferences(String _buildPath,
592
596
referencePlatform = targetPlatform ;
593
597
}
594
598
595
- p .put ("build.platform.path" , referencePlatform .getFolder ().getAbsolutePath ());
599
+ buildPref .put ("build.platform.path" , referencePlatform .getFolder ().getAbsolutePath ());
596
600
597
601
// Core folder
598
602
File coreFolder = new File (referencePlatform .getFolder (), "cores" );
599
603
coreFolder = new File (coreFolder , core );
600
- p .put ("build.core" , core );
601
- p .put ("build.core.path" , coreFolder .getAbsolutePath ());
604
+ buildPref .put ("build.core" , core );
605
+ buildPref .put ("build.core.path" , coreFolder .getAbsolutePath ());
602
606
603
607
// System Folder
604
608
File systemFolder = referencePlatform .getFolder ();
605
609
systemFolder = new File (systemFolder , "system" );
606
- p .put ("build.system.path" , systemFolder .getAbsolutePath ());
610
+ buildPref .put ("build.system.path" , systemFolder .getAbsolutePath ());
607
611
608
612
// Variant Folder
609
- String variant = p .get ("build.variant" );
613
+ String variant = buildPref .get ("build.variant" );
610
614
if (variant != null ) {
611
615
TargetPlatform t ;
612
616
if (!variant .contains (":" )) {
@@ -618,9 +622,9 @@ private PreferencesMap createBuildPreferences(String _buildPath,
618
622
}
619
623
File variantFolder = new File (t .getFolder (), "variants" );
620
624
variantFolder = new File (variantFolder , variant );
621
- p .put ("build.variant.path" , variantFolder .getAbsolutePath ());
625
+ buildPref .put ("build.variant.path" , variantFolder .getAbsolutePath ());
622
626
} else {
623
- p .put ("build.variant.path" , "" );
627
+ buildPref .put ("build.variant.path" , "" );
624
628
}
625
629
626
630
ContributedPlatform installedPlatform = BaseNoGui .indexer .getInstalled (referencePlatform .getContainerPackage ().getId (), referencePlatform .getId ());
@@ -630,17 +634,28 @@ private PreferencesMap createBuildPreferences(String _buildPath,
630
634
}
631
635
632
636
// Build Time
633
- Date d = new Date ();
634
637
GregorianCalendar cal = new GregorianCalendar ();
635
- long current = d .getTime ()/1000 ;
636
- long timezone = cal .get (cal .ZONE_OFFSET )/1000 ;
637
- long daylight = cal .get (cal .DST_OFFSET )/1000 ;
638
- p .put ("extra.time.utc" , Long .toString (current ));
639
- p .put ("extra.time.local" , Long .toString (current + timezone + daylight ));
640
- p .put ("extra.time.zone" , Long .toString (timezone ));
641
- p .put ("extra.time.dst" , Long .toString (daylight ));
642
-
643
- return p ;
638
+ long current = new Date ().getTime () / 1000 ;
639
+ long timezone = cal .get (Calendar .ZONE_OFFSET ) / 1000 ;
640
+ long daylight = cal .get (Calendar .DST_OFFSET ) / 1000 ;
641
+ buildPref .put ("extra.time.utc" , Long .toString (current ));
642
+ buildPref .put ("extra.time.local" , Long .toString (current + timezone + daylight ));
643
+ buildPref .put ("extra.time.zone" , Long .toString (timezone ));
644
+ buildPref .put ("extra.time.dst" , Long .toString (daylight ));
645
+
646
+ List <Map .Entry <String , String >> unsetPrefs = buildPref .entrySet ().stream ()
647
+ .filter (entry -> Constants .PREF_REMOVE_PLACEHOLDER .equals (entry .getValue ()))
648
+ .collect (Collectors .toList ());
649
+
650
+ buildPref .entrySet ().stream ()
651
+ .filter (entry -> {
652
+ return unsetPrefs .stream ()
653
+ .filter (unsetPrefEntry -> entry .getValue ().contains (unsetPrefEntry .getKey ()))
654
+ .count () > 0 ;
655
+ })
656
+ .forEach (invalidEntry -> buildPref .put (invalidEntry .getKey (), "" ));
657
+
658
+ return buildPref ;
644
659
}
645
660
646
661
private List <File > compileFiles (File outputPath , File sourcePath ,
0 commit comments