Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 97eb263

Browse files
committed
Merge pull request #3779 from ffissore/newcompiler
A new compiler
2 parents 81c7156 + e5ddd0b commit 97eb263

30 files changed

+1334
-97
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ hardware/arduino/bootloaders/caterina_LUFA/Caterina.elf
1414
hardware/arduino/bootloaders/caterina_LUFA/Caterina.eep
1515
hardware/arduino/bootloaders/caterina_LUFA/.dep/
1616
build/*.zip
17+
build/*.tar.bz2
1718
build/windows/work/
1819
build/windows/*.zip
1920
build/windows/*.tgz

‎app/src/cc/arduino/ConsoleOutputStream.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ private void clearBuffer() {
116116
if (document != null) {
117117
SwingUtilities.invokeLater(() -> {
118118
try {
119-
String lineWithoutSlashR = line.replace("\r\n", "\n").replace("\r", "\n");
119+
String lineWithoutCR = line.replace("\r\n", "\n").replace("\r", "\n");
120120
int offset = document.getLength();
121-
document.insertString(offset, lineWithoutSlashR, attributes);
121+
document.insertString(offset, lineWithoutCR, attributes);
122122
} catch (BadLocationException ble) {
123123
//ignore
124124
}

‎app/src/cc/arduino/packages/formatter/AStyle.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2-
31
/*
42
* This file is part of Arduino.
53
*

‎app/src/processing/app/Editor.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,10 @@ public void actionPerformed(ActionEvent e) {
750750
item = newJMenuItemAlt(tr("Export compiled Binary"), 'S');
751751
item.addActionListener(new ActionListener() {
752752
public void actionPerformed(ActionEvent e) {
753+
if (new ShouldSaveReadOnly().test(sketch) && !handleSave(true)) {
754+
System.out.println(tr("Export canceled, changes must first be saved."));
755+
return;
756+
}
753757
handleRun(false, new ShouldSaveReadOnly(), Editor.this.presentAndSaveHandler, Editor.this.runAndSaveHandler);
754758
}
755759
});

‎app/src/processing/app/Sketch.java‎

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323

2424
package processing.app;
2525

26+
import cc.arduino.Compiler;
27+
import cc.arduino.CompilerProgressListener;
28+
import cc.arduino.UploaderUtils;
29+
import cc.arduino.files.DeleteFilesOnShutdown;
2630
import cc.arduino.packages.Uploader;
27-
import processing.app.debug.Compiler;
28-
import processing.app.debug.Compiler.ProgressListener;
2931
import processing.app.debug.RunnerException;
3032
import processing.app.forms.PasswordAuthorizationDialog;
33+
import processing.app.helpers.FileUtils;
3134
import processing.app.helpers.OSUtils;
3235
import processing.app.helpers.PreferencesMapException;
3336
import processing.app.packages.LibraryList;
@@ -37,10 +40,14 @@
3740
import java.awt.*;
3841
import java.io.File;
3942
import java.io.IOException;
43+
import java.nio.file.Files;
44+
import java.nio.file.Paths;
4045
import java.util.Arrays;
4146
import java.util.LinkedList;
4247
import java.util.List;
4348
import java.util.Optional;
49+
import java.util.stream.Collectors;
50+
import java.util.stream.Stream;
4451

4552
import static processing.app.I18n.tr;
4653

@@ -60,7 +67,7 @@ public class Sketch {
6067
private int currentIndex;
6168

6269
private final SketchData data;
63-
70+
6471
/**
6572
* path is location of the main .pde file, because this is also
6673
* simplest to use when opening the file from the finder/explorer.
@@ -1093,7 +1100,7 @@ public void prepare() throws IOException {
10931100
* @return null if compilation failed, main class name if not
10941101
* @throws RunnerException
10951102
*/
1096-
public String build(boolean verbose, boolean save) throws RunnerException, PreferencesMapException {
1103+
public String build(boolean verbose, boolean save) throws RunnerException, PreferencesMapException, IOException {
10971104
return build(tempBuildFolder.getAbsolutePath(), verbose, save);
10981105
}
10991106

@@ -1106,15 +1113,32 @@ public String build(boolean verbose, boolean save) throws RunnerException, Prefe
11061113
*
11071114
* @return null if compilation failed, main class name if not
11081115
*/
1109-
private String build(String buildPath, boolean verbose, boolean save) throws RunnerException, PreferencesMapException {
1116+
private String build(String buildPath, boolean verbose, boolean save) throws RunnerException, PreferencesMapException, IOException {
11101117
// run the preprocessor
11111118
editor.status.progressUpdate(20);
11121119

11131120
ensureExistence();
1114-
1115-
ProgressListener pl = editor.status::progressUpdate;
1116-
1117-
return Compiler.build(data, buildPath, tempBuildFolder, pl, verbose, save);
1121+
1122+
CompilerProgressListener progressListener = editor.status::progressUpdate;
1123+
1124+
String pathToSketch = data.getMainFilePath();
1125+
if (isModified()) {
1126+
pathToSketch = saveSketchInTempFolder();
1127+
}
1128+
1129+
return new Compiler(pathToSketch, data, buildPath).build(progressListener, save);
1130+
}
1131+
1132+
private String saveSketchInTempFolder() throws IOException {
1133+
File tempFolder = FileUtils.createTempFolder();
1134+
DeleteFilesOnShutdown.add(tempFolder);
1135+
FileUtils.copy(getFolder(), tempFolder);
1136+
1137+
for (SketchCode sc : Stream.of(data.getCodes()).filter(SketchCode::isModified).collect(Collectors.toList())) {
1138+
Files.write(Paths.get(tempFolder.getAbsolutePath(), sc.getFileName()), sc.getProgram().getBytes());
1139+
}
1140+
1141+
return Paths.get(tempFolder.getAbsolutePath(), data.getPrimaryFile().getName()).toString();
11181142
}
11191143

11201144
protected boolean exportApplet(boolean usingProgrammer) throws Exception {
@@ -1153,7 +1177,7 @@ private boolean exportApplet(String appletPath, boolean usingProgrammer)
11531177

11541178
private boolean upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws Exception {
11551179

1156-
Uploader uploader = Compiler.getUploaderByPreferences(false);
1180+
Uploader uploader = newUploaderUtils().getUploaderByPreferences(false);
11571181

11581182
boolean success = false;
11591183
do {
@@ -1172,7 +1196,7 @@ private boolean upload(String buildPath, String suggestedClassName, boolean usin
11721196

11731197
List<String> warningsAccumulator = new LinkedList<>();
11741198
try {
1175-
success = Compiler.upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, false, warningsAccumulator);
1199+
success = newUploaderUtils().upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, false, warningsAccumulator);
11761200
} finally {
11771201
if (uploader.requiresAuthorization() && !success) {
11781202
PreferencesData.remove(uploader.getAuthorizationKey());

‎app/src/processing/app/debug/MessageStream.java‎

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
5+
*
6+
* Arduino is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
* As a special exception, you may use this file as part of a free software
21+
* library without restriction. Specifically, if other files instantiate
22+
* templates or use macros or inline functions from this file, or you compile
23+
* this file and link it with other files to produce an executable, this
24+
* file does not by itself cause the resulting executable to be covered by
25+
* the GNU General Public License. This exception does not however
26+
* invalidate any other reasons why the executable file might be covered by
27+
* the GNU General Public License.
28+
*/
29+
30+
package cc.arduino.i18n;
31+
32+
import org.junit.Test;
33+
34+
import java.util.Map;
35+
36+
import static org.junit.Assert.assertEquals;
37+
38+
public class ExternalProcessOutputParserTest {
39+
40+
@Test
41+
public void testParser1() throws Exception {
42+
Map<String, Object> output = new ExternalProcessOutputParser().parse("===WARNING: Category '{0}' in library {1} is not valid. Setting to '{2}' ||| [ Wire Uncategorized]");
43+
44+
assertEquals("WARNING: Category '{0}' in library {1} is not valid. Setting to '{2}'", output.get("msg"));
45+
Object[] args = (Object[]) output.get("args");
46+
assertEquals(3, args.length);
47+
assertEquals("", args[0]);
48+
assertEquals("Wire", args[1]);
49+
assertEquals("Uncategorized", args[2]);
50+
}
51+
52+
@Test
53+
public void testParser2() throws Exception {
54+
Map<String, Object> output = new ExternalProcessOutputParser().parse("===Using previously compiled file: {0} ||| [%2Ftmp%2Farduino-sketch-456612873D8321DA02916066CB8B2FE6%2Flibraries%2FBridge%2FBridge.cpp.o]");
55+
56+
assertEquals("Using previously compiled file: {0}", output.get("msg"));
57+
Object[] args = (Object[]) output.get("args");
58+
assertEquals(1, args.length);
59+
assertEquals("/tmp/arduino-sketch-456612873D8321DA02916066CB8B2FE6/libraries/Bridge/Bridge.cpp.o", args[0]);
60+
}
61+
62+
@Test
63+
public void testParser3() throws Exception {
64+
Map<String, Object> output = new ExternalProcessOutputParser().parse("===Using library {0} at version {1} in folder: {2} {3} {4} ||| [Stepper 1.1.1 %2Fhome%2Ffederico%2Fmateriale%2Fworks_Arduino%2FArduino%2Fbuild%2Flinux%2Fwork%2Flibraries%2FStepper ]");
65+
66+
assertEquals("Using library {0} at version {1} in folder: {2} {3} {4}", output.get("msg"));
67+
Object[] args = (Object[]) output.get("args");
68+
assertEquals(5, args.length);
69+
assertEquals("Stepper", args[0]);
70+
assertEquals("1.1.1", args[1]);
71+
assertEquals("/home/federico/materiale/works_Arduino/Arduino/build/linux/work/libraries/Stepper", args[2]);
72+
assertEquals("", args[3]);
73+
assertEquals("", args[4]);
74+
}
75+
76+
@Test
77+
public void testParser4() throws Exception {
78+
Map<String, Object> output = new ExternalProcessOutputParser().parse("==={0} ||| []");
79+
80+
assertEquals("{0}", output.get("msg"));
81+
Object[] args = (Object[]) output.get("args");
82+
assertEquals(0, args.length);
83+
}
84+
85+
@Test
86+
public void testParser5() throws Exception {
87+
Map<String, Object> output = new ExternalProcessOutputParser().parse("==={0} ||| [ ]");
88+
89+
assertEquals("{0}", output.get("msg"));
90+
Object[] args = (Object[]) output.get("args");
91+
assertEquals(1, args.length);
92+
assertEquals("", args[0]);
93+
}
94+
95+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
5+
*
6+
* Arduino is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
* As a special exception, you may use this file as part of a free software
21+
* library without restriction. Specifically, if other files instantiate
22+
* templates or use macros or inline functions from this file, or you compile
23+
* this file and link it with other files to produce an executable, this
24+
* file does not by itself cause the resulting executable to be covered by
25+
* the GNU General Public License. This exception does not however
26+
* invalidate any other reasons why the executable file might be covered by
27+
* the GNU General Public License.
28+
*/
29+
30+
package cc.arduino.i18n;
31+
32+
import org.junit.Test;
33+
import processing.app.AbstractWithPreferencesTest;
34+
import processing.app.I18n;
35+
36+
import java.util.Map;
37+
38+
import static org.junit.Assert.assertEquals;
39+
40+
public class I18NTest extends AbstractWithPreferencesTest {
41+
42+
@Test
43+
public void testMessageFormat() throws Exception {
44+
Object[] args = new Object[]{"a", "b", "c"};
45+
String actual = I18n.format("WARNING: Category '{0}' in library {1} is not valid. Setting to '{2}'", args);
46+
assertEquals("WARNING: Category 'a' in library b is not valid. Setting to 'c'", actual);
47+
}
48+
49+
@Test
50+
public void testMessageFormatFromExternalProcess() throws Exception {
51+
Map<String, Object> output = new ExternalProcessOutputParser().parse("===WARNING: Category '{0}' in library {1} is not valid. Setting to '{2}' ||| [ Wire Uncategorized]");
52+
53+
String actual = I18n.format((String) output.get("msg"), (Object[])output.get("args"));
54+
assertEquals("WARNING: Category '' in library Wire is not valid. Setting to 'Uncategorized'", actual);
55+
}
56+
}

‎app/test/processing/app/debug/CompilerTest.java‎ renamed to ‎app/test/processing/app/debug/OldCompilerTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
package processing.app.debug;
3131

3232
import static org.junit.Assert.assertEquals;
33-
import static processing.app.debug.Compiler.unescapeDepFile;
33+
import static processing.app.debug.OldCompiler.unescapeDepFile;
3434

3535
import org.junit.Test;
3636

3737
import processing.app.AbstractWithPreferencesTest;
3838

39-
public class CompilerTest extends AbstractWithPreferencesTest {
39+
public class OldCompilerTest extends AbstractWithPreferencesTest {
4040

4141
@Test
4242
public void makeDepUnescapeTest() throws Exception {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /