Skip to content

Commit cc773fb

Browse files
matthijskooijmancmaglie
authored andcommitted
Take into account --curdir for all relative paths
In a lot of places, (potentially) relative paths were passed to File without any processing, making them be resolved without taking into account --curdir. By passing them through Base.absoluteFile instead, these paths are resolved relative to the working directory before starting arduino (at least on Linux, which is currently the only platform supporting --curdir). This applies --curdir to the --preferences-file option and the build.path, settings.path, sketchbook.path preferences. For example, this now works as expected: arduino --pref build.path=build_dir --verify Blink.ino
1 parent 4f33d08 commit cc773fb

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

app/src/processing/app/Base.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static public void main(String args[]) throws Exception {
143143
if (!portableFolder.exists())
144144
portableFolder = null;
145145

146-
File preferencesFile = null;
146+
String preferencesFile = null;
147147

148148
// Do a first pass over the commandline arguments, the rest of them
149149
// will be processed by the Base constructor. Note that this loop
@@ -153,7 +153,7 @@ static public void main(String args[]) throws Exception {
153153
for (int i = 0; i < args.length - 1; i++) {
154154
if (args[i].equals("--preferences-file")) {
155155
++i;
156-
preferencesFile = new File(args[i]);
156+
preferencesFile = args[i];
157157
continue;
158158
}
159159
if (args[i].equals("--curdir")) {
@@ -164,7 +164,7 @@ static public void main(String args[]) throws Exception {
164164
}
165165

166166
// run static initialization that grabs all the prefs
167-
Preferences.init(preferencesFile);
167+
Preferences.init(absoluteFile(preferencesFile));
168168

169169
try {
170170
File versionFile = getContentFile("lib/version.txt");
@@ -296,6 +296,8 @@ static protected void initRequirements() {
296296
// directory when starting the IDE (which is not the same as the
297297
// current working directory!).
298298
static public File absoluteFile(String path) {
299+
if (path == null) return null;
300+
299301
File file = new File(path);
300302
if (!file.isAbsolute()) {
301303
file = new File(currentDirectory, path);
@@ -320,7 +322,7 @@ public Base(String[] args) throws Exception {
320322
if (portableFolder != null)
321323
sketchbookFolder = new File(portableFolder, sketchbookPath);
322324
else
323-
sketchbookFolder = new File(sketchbookPath);
325+
sketchbookFolder = Base.absoluteFile(sketchbookPath);
324326
if (!sketchbookFolder.exists()) {
325327
Base.showWarning(_("Sketchbook folder disappeared"),
326328
_("The sketchbook folder no longer exists.\n" +
@@ -2047,7 +2049,7 @@ static public File getSettingsFolder() {
20472049

20482050
String preferencesPath = Preferences.get("settings.path");
20492051
if (preferencesPath != null) {
2050-
settingsFolder = new File(preferencesPath);
2052+
settingsFolder = absoluteFile(preferencesPath);
20512053

20522054
} else {
20532055
try {
@@ -2086,8 +2088,7 @@ static public File getBuildFolder() {
20862088
if (buildFolder == null) {
20872089
String buildPath = Preferences.get("build.path");
20882090
if (buildPath != null) {
2089-
buildFolder = new File(buildPath);
2090-
2091+
buildFolder = Base.absoluteFile(buildPath);
20912092
} else {
20922093
//File folder = new File(getTempFolder(), "build");
20932094
//if (!folder.exists()) folder.mkdirs();
@@ -2248,7 +2249,7 @@ static public String getPortableSketchbookFolder() {
22482249
static public File getSketchbookFolder() {
22492250
if (portableFolder != null)
22502251
return new File(portableFolder, Preferences.get("sketchbook.path"));
2251-
return new File(Preferences.get("sketchbook.path"));
2252+
return absoluteFile(Preferences.get("sketchbook.path"));
22522253
}
22532254

22542255

build/shared/manpage.adoc

+7
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,13 @@ HISTORY
280280
file, just like *--pref*. The *--verbose* options still only
281281
apply to the current run.
282282
283+
{empty}::
284+
A path passed to *--preferences-file*, or set in the
285+
*build.path*, *preferences.path* or *settings.path* is now
286+
interpreted relative to the current directory instead of the
287+
location of the arduino command itself.
288+
289+
283290
RESOURCES
284291
---------
285292
Web site: <http://arduino.cc/>

0 commit comments

Comments
 (0)