2323
2424package processing .app .debug ;
2525
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 ;
3627import cc .arduino .MyStreamPumper ;
3728import cc .arduino .contributions .packages .ContributedPlatform ;
3829import cc .arduino .contributions .packages .ContributedTool ;
3930import cc .arduino .packages .BoardPort ;
4031import cc .arduino .packages .Uploader ;
4132import cc .arduino .packages .UploaderFactory ;
42-
4333import cc .arduino .packages .uploaders .MergeSketchWithBooloader ;
4434import cc .arduino .utils .Pair ;
4535import 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 ;
5344import processing .app .helpers .filefilters .OnlyDirs ;
54- import processing .app .packages .LibraryList ;
55- import processing .app .preproc .PdePreprocessor ;
5645import processing .app .legacy .PApplet ;
5746import processing .app .packages .LegacyUserLibrary ;
47+ import processing .app .packages .LibraryList ;
5848import processing .app .packages .UserLibrary ;
49+ import processing .app .preproc .PdePreprocessor ;
5950import processing .app .tools .DoubleQuotedArgumentsOnWindowsCommandLine ;
6051
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+
6163public class Compiler implements MessageConsumer {
6264
6365 /**
@@ -561,28 +563,30 @@ private PreferencesMap createBuildPreferences(String _buildPath,
561563 }
562564
563565 // 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 ());
578582
579583 // Platform.txt should define its own compiler.path. For
580584 // compatibility with earlier 1.5 versions, we define a (ugly,
581585 // avr-specific) default for it, but this should be removed at some
582586 // point.
583- if (!p .containsKey ("compiler.path" )) {
587+ if (!buildPref .containsKey ("compiler.path" )) {
584588 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 ());
586590 }
587591
588592 TargetPlatform referencePlatform = null ;
@@ -592,21 +596,21 @@ private PreferencesMap createBuildPreferences(String _buildPath,
592596 referencePlatform = targetPlatform ;
593597 }
594598
595- p .put ("build.platform.path" , referencePlatform .getFolder ().getAbsolutePath ());
599+ buildPref .put ("build.platform.path" , referencePlatform .getFolder ().getAbsolutePath ());
596600
597601 // Core folder
598602 File coreFolder = new File (referencePlatform .getFolder (), "cores" );
599603 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 ());
602606
603607 // System Folder
604608 File systemFolder = referencePlatform .getFolder ();
605609 systemFolder = new File (systemFolder , "system" );
606- p .put ("build.system.path" , systemFolder .getAbsolutePath ());
610+ buildPref .put ("build.system.path" , systemFolder .getAbsolutePath ());
607611
608612 // Variant Folder
609- String variant = p .get ("build.variant" );
613+ String variant = buildPref .get ("build.variant" );
610614 if (variant != null ) {
611615 TargetPlatform t ;
612616 if (!variant .contains (":" )) {
@@ -618,9 +622,9 @@ private PreferencesMap createBuildPreferences(String _buildPath,
618622 }
619623 File variantFolder = new File (t .getFolder (), "variants" );
620624 variantFolder = new File (variantFolder , variant );
621- p .put ("build.variant.path" , variantFolder .getAbsolutePath ());
625+ buildPref .put ("build.variant.path" , variantFolder .getAbsolutePath ());
622626 } else {
623- p .put ("build.variant.path" , "" );
627+ buildPref .put ("build.variant.path" , "" );
624628 }
625629
626630 ContributedPlatform installedPlatform = BaseNoGui .indexer .getInstalled (referencePlatform .getContainerPackage ().getId (), referencePlatform .getId ());
@@ -630,17 +634,28 @@ private PreferencesMap createBuildPreferences(String _buildPath,
630634 }
631635
632636 // Build Time
633- Date d = new Date ();
634637 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 ;
644659 }
645660
646661 private List <File > compileFiles (File outputPath , File sourcePath ,
0 commit comments