arduino / Arduino

Arduino IDE 1.x
https://www.arduino.cc/en/software
Other
14.11k stars 7k forks source link

CLI should look in sketchbook for sketch #9266

Closed slomobileAdmin closed 3 years ago

slomobileAdmin commented 4 years ago

According to the man page arduino [FILE.ino…​] "A single .ino file should be given. If the sketch contains multiple .ino files, any one can be specified on the commandline, but the entire sketch will be compiled."

It says nothing about requiring an absolute path. It is convenient and reasonable to assume, given just a sketch file name, arduino will look in the sketchbook for a folder with the same name as sketch minus .ino, then look for the sketch and use it. It does not.

slo@sloNano:~$ arduino --version
Arduino: 1.8.10
slo@sloNano:~$ arduino --get-pref sketchbook.path
/home/slo/Arduino
slo@sloNano:~$ arduino --verify /home/slo/Arduino/Blink/Blink.ino
Verifying...
Sketch uses 12160 bytes (0%) of program storage space. Maximum is 2031616 bytes.
Global variables use 18528 bytes (1%) of dynamic memory, leaving 1030048 bytes for local 
variables. Maximum is 1048576 bytes.
slo@sloNano:~$ arduino --verify Blink.ino
Verifying...
java.io.IOException: No valid code files found
    at processing.app.Sketch.listSketchFiles(Sketch.java:117)
at processing.app.Sketch.<init>(Sketch.java:54)
at processing.app.Base.<init>(Base.java:415)
at processing.app.Base.main(Base.java:150)
java.io.IOException: Stream closed
at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:170)
at java.io.BufferedInputStream.read(BufferedInputStream.java:336)
at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.ensureLoaded(ByteSourceJsonBootstrapper.java:522)
at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.detectEncoding(ByteSourceJsonBootstrapper.java:150)
at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.constructParser(ByteSourceJsonBootstrapper.java:246)
at com.fasterxml.jackson.core.JsonFactory._createParser(JsonFactory.java:1315)
at com.fasterxml.jackson.core.JsonFactory.createParser(JsonFactory.java:820)
at cc.arduino.packages.discoverers.PluggableDiscovery.run(PluggableDiscovery.java:80)
at java.lang.Thread.run(Thread.java:748)
facchinm commented 4 years ago

Probably related with https://github.com/arduino/arduino-builder/pull/342 . @cmaglie should we provide an hourly build with that builder?

cmaglie commented 4 years ago

I think this is java-related, @slomobileAdmin which version of the IDE are you running?

slomobileAdmin commented 4 years ago

The above was the Linux ARM 64bit version of the IDE running on a Jetson Nano with Ubuntu 18.04 with MATE desktop installed via apt-get, local terminal session. Teensyduino 1.48 beta #1 is also installed and generating Java exceptions but I assumed they were unrelated to the above issue so I stripped them out of the above quoted terminal session for readability, perhaps I stripped too much. Information regarding that other issue is located in this thread
Here is the unedited output from a new ssh session into the same machine without anything stripped out.

slo@sloNano:~$ arduino --version
Picked up JAVA_TOOL_OPTIONS: 
Set log4j store directory /home/slo/.arduino15
Loading configuration...
Initializing packages...
Preparing boards...
[JmDNS(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).Timer] WARN javax.jmdns.impl.tasks.resolver.DNSResolverTask - ServiceResolver(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).run() exception 
java.io.IOException: Cannot assign requested address (sendto failed)
    at java.net.PlainDatagramSocketImpl.send(Native Method)
    at java.net.DatagramSocket.send(DatagramSocket.java:693)
    at javax.jmdns.impl.JmDNSImpl.send(JmDNSImpl.java:1618)
    at javax.jmdns.impl.tasks.resolver.DNSResolverTask.run(DNSResolverTask.java:73)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
[fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local..recover()] WARN javax.jmdns.impl.JmDNSImpl - RECOVERING
[JmDNS(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).State.Timer] WARN javax.jmdns.impl.tasks.state.DNSStateTask - Canceler(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).run() exception 
java.io.IOException: Cannot assign requested address (sendto failed)
    at java.net.PlainDatagramSocketImpl.send(Native Method)
    at java.net.DatagramSocket.send(DatagramSocket.java:693)
    at javax.jmdns.impl.JmDNSImpl.send(JmDNSImpl.java:1618)
    at javax.jmdns.impl.tasks.state.DNSStateTask.run(DNSStateTask.java:131)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
Arduino: 1.8.10
java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:170)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:336)
    at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.ensureLoaded(ByteSourceJsonBootstrapper.java:522)
    at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.detectEncoding(ByteSourceJsonBootstrapper.java:150)
    at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.constructParser(ByteSourceJsonBootstrapper.java:246)
    at com.fasterxml.jackson.core.JsonFactory._createParser(JsonFactory.java:1315)
    at com.fasterxml.jackson.core.JsonFactory.createParser(JsonFactory.java:820)
    at cc.arduino.packages.discoverers.PluggableDiscovery.run(PluggableDiscovery.java:80)
    at java.lang.Thread.run(Thread.java:748)
slo@sloNano:~$ arduino --get-pref sketchbook.path
Picked up JAVA_TOOL_OPTIONS: 
Set log4j store directory /home/slo/.arduino15
Loading configuration...
Initializing packages...
Preparing boards...
[JmDNS(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).Timer] WARN javax.jmdns.impl.tasks.resolver.DNSResolverTask - ServiceResolver(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).run() exception 
java.io.IOException: Cannot assign requested address (sendto failed)
    at java.net.PlainDatagramSocketImpl.send(Native Method)
    at java.net.DatagramSocket.send(DatagramSocket.java:693)
    at javax.jmdns.impl.JmDNSImpl.send(JmDNSImpl.java:1618)
    at javax.jmdns.impl.tasks.resolver.DNSResolverTask.run(DNSResolverTask.java:73)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
[fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local..recover()] WARN javax.jmdns.impl.JmDNSImpl - RECOVERING
[JmDNS(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).State.Timer] WARN javax.jmdns.impl.tasks.state.DNSStateTask - Canceler(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).run() exception 
java.io.IOException: Cannot assign requested address (sendto failed)
    at java.net.PlainDatagramSocketImpl.send(Native Method)
    at java.net.DatagramSocket.send(DatagramSocket.java:693)
    at javax.jmdns.impl.JmDNSImpl.send(JmDNSImpl.java:1618)
    at javax.jmdns.impl.tasks.state.DNSStateTask.run(DNSStateTask.java:131)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
/home/slo/Arduino
java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:170)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:336)
    at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.ensureLoaded(ByteSourceJsonBootstrapper.java:522)
    at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.detectEncoding(ByteSourceJsonBootstrapper.java:150)
    at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.constructParser(ByteSourceJsonBootstrapper.java:246)
    at com.fasterxml.jackson.core.JsonFactory._createParser(JsonFactory.java:1315)
    at com.fasterxml.jackson.core.JsonFactory.createParser(JsonFactory.java:820)
    at cc.arduino.packages.discoverers.PluggableDiscovery.run(PluggableDiscovery.java:80)
    at java.lang.Thread.run(Thread.java:748)
slo@sloNano:~$ arduino --verify /home/slo/Arduino/Blink/Blink.ino
Picked up JAVA_TOOL_OPTIONS: 
Set log4j store directory /home/slo/.arduino15
Loading configuration...
Initializing packages...
Preparing boards...
[JmDNS(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).Timer] WARN javax.jmdns.impl.tasks.resolver.DNSResolverTask - ServiceResolver(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).run() exception 
java.io.IOException: Cannot assign requested address (sendto failed)
    at java.net.PlainDatagramSocketImpl.send(Native Method)
    at java.net.DatagramSocket.send(DatagramSocket.java:693)
    at javax.jmdns.impl.JmDNSImpl.send(JmDNSImpl.java:1618)
    at javax.jmdns.impl.tasks.resolver.DNSResolverTask.run(DNSResolverTask.java:73)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
[fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local..recover()] WARN javax.jmdns.impl.JmDNSImpl - RECOVERING
[JmDNS(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).State.Timer] WARN javax.jmdns.impl.tasks.state.DNSStateTask - Canceler(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).run() exception 
java.io.IOException: Cannot assign requested address (sendto failed)
    at java.net.PlainDatagramSocketImpl.send(Native Method)
    at java.net.DatagramSocket.send(DatagramSocket.java:693)
    at javax.jmdns.impl.JmDNSImpl.send(JmDNSImpl.java:1618)
    at javax.jmdns.impl.tasks.state.DNSStateTask.run(DNSStateTask.java:131)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
Verifying...
[fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local..recover()] WARN javax.jmdns.impl.DNSStatefulObject$DefaultImplementation - Wait for canceled timed out: DNS: fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local. [fe80:0:0:0:5de6:8665:7fcd:96fe%wlan0/fe80:0:0:0:5de6:8665:7fcd:96fe%wlan0] state: canceling 1 task: null
[fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local..recover()] WARN javax.jmdns.impl.JmDNSImpl - fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local..recover() Could not recover we are Down!
Opening Teensy Loader...
Unable find Teensy Loader.  (p)  Is the Teensy Loader application running?
quitexit status 1
slo@sloNano:~$ arduino --verify /home/slo/Arduino/Blink/Blink.ino
Picked up JAVA_TOOL_OPTIONS: 
Set log4j store directory /home/slo/.arduino15
Loading configuration...
Initializing packages...
Preparing boards...
[JmDNS(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).Timer] WARN javax.jmdns.impl.tasks.resolver.DNSResolverTask - ServiceResolver(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).run() exception 
java.io.IOException: Cannot assign requested address (sendto failed)
    at java.net.PlainDatagramSocketImpl.send(Native Method)
    at java.net.DatagramSocket.send(DatagramSocket.java:693)
    at javax.jmdns.impl.JmDNSImpl.send(JmDNSImpl.java:1618)
    at javax.jmdns.impl.tasks.resolver.DNSResolverTask.run(DNSResolverTask.java:73)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
[fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local..recover()] WARN javax.jmdns.impl.JmDNSImpl - RECOVERING
[JmDNS(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).State.Timer] WARN javax.jmdns.impl.tasks.state.DNSStateTask - Canceler(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).run() exception 
java.io.IOException: Cannot assign requested address (sendto failed)
    at java.net.PlainDatagramSocketImpl.send(Native Method)
    at java.net.DatagramSocket.send(DatagramSocket.java:693)
    at javax.jmdns.impl.JmDNSImpl.send(JmDNSImpl.java:1618)
    at javax.jmdns.impl.tasks.state.DNSStateTask.run(DNSStateTask.java:131)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
Verifying...
[fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local..recover()] WARN javax.jmdns.impl.DNSStatefulObject$DefaultImplementation - Wait for canceled timed out: DNS: fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local. [fe80:0:0:0:5de6:8665:7fcd:96fe%wlan0/fe80:0:0:0:5de6:8665:7fcd:96fe%wlan0] state: canceling 1 task: null
[fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local..recover()] WARN javax.jmdns.impl.JmDNSImpl - fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local..recover() Could not recover we are Down!
Opening Teensy Loader...
Unable find Teensy Loader.  (p)  Is the Teensy Loader application running?
quitexit status 1
slo@sloNano:~$ arduino
Picked up JAVA_TOOL_OPTIONS: 
Set log4j store directory /home/slo/.arduino15
java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
    at java.awt.SplashScreen.getSplashScreen(SplashScreen.java:117)
    at processing.app.Base.<init>(Base.java:238)
    at processing.app.Base.main(Base.java:150)
slo@sloNano:~$ arduino --verify Blink.ino
Picked up JAVA_TOOL_OPTIONS: 
Set log4j store directory /home/slo/.arduino15
Loading configuration...
Initializing packages...
Preparing boards...
[JmDNS(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).Timer] WARN javax.jmdns.impl.tasks.resolver.DNSResolverTask - ServiceResolver(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).run() exception 
java.io.IOException: Cannot assign requested address (sendto failed)
    at java.net.PlainDatagramSocketImpl.send(Native Method)
    at java.net.DatagramSocket.send(DatagramSocket.java:693)
    at javax.jmdns.impl.JmDNSImpl.send(JmDNSImpl.java:1618)
    at javax.jmdns.impl.tasks.resolver.DNSResolverTask.run(DNSResolverTask.java:73)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
[fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local..recover()] WARN javax.jmdns.impl.JmDNSImpl - RECOVERING
[JmDNS(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).State.Timer] WARN javax.jmdns.impl.tasks.state.DNSStateTask - Canceler(fe80-0-0-0-5de6-8665-7fcd-96fe-wlan0.local.).run() exception 
java.io.IOException: Cannot assign requested address (sendto failed)
    at java.net.PlainDatagramSocketImpl.send(Native Method)
    at java.net.DatagramSocket.send(DatagramSocket.java:693)
    at javax.jmdns.impl.JmDNSImpl.send(JmDNSImpl.java:1618)
    at javax.jmdns.impl.tasks.state.DNSStateTask.run(DNSStateTask.java:131)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
Verifying...
java.io.IOException: No valid code files found
    at processing.app.Sketch.listSketchFiles(Sketch.java:117)
    at processing.app.Sketch.<init>(Sketch.java:54)
    at processing.app.Base.<init>(Base.java:415)
    at processing.app.Base.main(Base.java:150)
java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:170)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:336)
    at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.ensureLoaded(ByteSourceJsonBootstrapper.java:522)
    at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.detectEncoding(ByteSourceJsonBootstrapper.java:150)
    at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.constructParser(ByteSourceJsonBootstrapper.java:246)
    at com.fasterxml.jackson.core.JsonFactory._createParser(JsonFactory.java:1315)
    at com.fasterxml.jackson.core.JsonFactory.createParser(JsonFactory.java:820)
    at cc.arduino.packages.discoverers.PluggableDiscovery.run(PluggableDiscovery.java:80)
    at java.lang.Thread.run(Thread.java:748)

This is from a different Ubuntu machine running Arduino 1.8.9 Linux 64bit version, x86_64

slo@black:~/arduino-1.8.9/arduino-1.8.9$ arduino --version
Picked up JAVA_TOOL_OPTIONS: 
Error: unknown option: --version
slo@black:~/arduino-1.8.9/arduino-1.8.9$ arduino --verify /home/slo/Arduino/Blink/Blink.ino
Picked up JAVA_TOOL_OPTIONS: 
Loading configuration...
Initializing packages...
Preparing boards...
Verifying...
Archiving built core (caching) in: /tmp/arduino_cache_90380/core/core_esp32_esp32_esp32cam_d97b79a4f488d816dc93fc537258a0b0.a
Sketch uses 239612 bytes (7%) of program storage space. Maximum is 3145728 bytes.
Global variables use 13396 bytes (4%) of dynamic memory, leaving 314284 bytes for local variables. Maximum is 327680 bytes.
slo@black:~/arduino-1.8.9/arduino-1.8.9$ 
slo@black:~/arduino-1.8.9/arduino-1.8.9$ 
slo@black:~/arduino-1.8.9/arduino-1.8.9$ arduino --version
Picked up JAVA_TOOL_OPTIONS: 
Error: unknown option: --version
slo@black:~/arduino-1.8.9/arduino-1.8.9$ arduino --get-pref sketchbook.path
Picked up JAVA_TOOL_OPTIONS: 
Loading configuration...
Initializing packages...
Preparing boards...
/home/slo/Arduino
slo@black:~/arduino-1.8.9/arduino-1.8.9$ arduino --verify /home/slo/Arduino/Blink/Blink.ino
Picked up JAVA_TOOL_OPTIONS: 
Loading configuration...
Initializing packages...
Preparing boards...
Verifying...
Archiving built core (caching) in: /tmp/arduino_cache_85586/core/core_esp32_esp32_esp32cam_d97b79a4f488d816dc93fc537258a0b0.a
Sketch uses 239612 bytes (7%) of program storage space. Maximum is 3145728 bytes.
Global variables use 13396 bytes (4%) of dynamic memory, leaving 314284 bytes for local variables. Maximum is 327680 bytes.
slo@black:~/arduino-1.8.9/arduino-1.8.9$ arduino --verify Blink.inoPicked up JAVA_TOOL_OPTIONS: 
Loading configuration...
Initializing packages...
Preparing boards...
Verifying...
java.io.IOException: No valid code files found
    at processing.app.Sketch.listSketchFiles(Sketch.java:117)
    at processing.app.Sketch.<init>(Sketch.java:54)
    at processing.app.Base.<init>(Base.java:390)
    at processing.app.Base.main(Base.java:144)
facchinm commented 4 years ago

@slomobileAdmin ah now I re-read it and got what your request was. The relative path method requires you to be in the same folder of the .ino (and I believe it's always been like this, for the principle of least astonishment). All unix tools work with both absolute and relative paths, but you must pick the relative based on which folder you are into. Basing the non-absolute path on the sketchbook would make things very very strange for a CLI program. I'd close the issue as wontfix; @per1234 @cmaglie do you agree?

slomobileAdmin commented 4 years ago

@facchinm I do see your point. Yet the sketchbook as a place to store sketches, as well as the requirement to have a sketch in a folder of the same name is an Arduino convention, not Unix. Providing the requested functionality need not break relative paths. Search for absolute and relative paths first. If they fail to find a candidate, only then search the sketchbook.

The arduino requirement for sketches in same named folders breaks the common practice of searching for code files in a common folder. This functionality provides a workaround for that break. Analogous concepts would be exporting the sketchbook folder into the $PATH, or how #include will magically find a file without providing a path. I think this is the behavior a typical arduino user would expect.
It will provide a more consistent experience with the gui arduino where File>Open Recent, File>Sketchbook, and File>Examples just list the sketch name and not the path. It will save newbies some typing and frustration from needless cryptic exceptions where user intent is very clear. As the man page points out, the parameter is a filename, not a path. It should not fail by default if a bare filename is provided.
If you do indeed close this as wontfix, at least clarify the documentation.

slomobileAdmin commented 4 years ago

https://linux.die.net/man/3/filename provides the Linux method and precedent to do this.
value of sketchbook.path is the absolute directory, naked filename parameter is the relative filename.

absname(Filename, Dir) -> file:filename()

    Types:

        Filename = file:name()
        Dir = file:filename()

    This function works like absname/1, except that the directory to which the file name should be made relative is given explicitly in the Dir argument.

absname_join(Dir, Filename) -> file:filename()

    Types:

        Dir = file:filename()
        Filename = file:name()

    Joins an absolute directory with a relative filename. Similar to join/2, but on platforms with tight restrictions on raw filename length and no support for symbolic links (read: VxWorks), leading parent directory components in Filename are matched against trailing directory components in Dir so they can be removed from the result - minimizing its length.
chrissound commented 4 years ago

@facchinm surely this error should be reported in a more informative matter? As you mentioned wanting to close this. I received a similar java error message to this.. Not sure if it's related.