Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't run dart command line script using a symlink #16212

Closed
DartBot opened this issue Jan 20, 2014 · 6 comments
Closed

Can't run dart command line script using a symlink #16212

DartBot opened this issue Jan 20, 2014 · 6 comments
Assignees
Labels
area-vm type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@DartBot
Copy link

DartBot commented Jan 20, 2014

This issue was originally filed by @zoechi


What steps will reproduce the problem?
1.
I created a symlink in /usr/bin to /home/myuser/dart/scripts/bin/testscript.dart
2.
Unable to open file: /usr/bin/packages/args/args.dart'file:///usr/bin/testscript': error: line 4 pos 1: library handler failed
import 'package:args/args.dart' show ArgParser;
3.

What is the expected output? What do you see instead?
I think this should work to make Dart a convenient language for batch scripts.

What version of the product are you using? On what operating system?
Dart VM version: 1.2.0-dev.1.0 (Fri Jan 17 19:12:36 2014) on "linux_x64"

Please provide any additional information below.

@DartBot
Copy link
Author

DartBot commented Jan 20, 2014

This comment was originally written by @zoechi


A workaround I use now is to create a bash script named 'testscript' in the same directory as testscript.dart and link to this script instead

I lookup the current directory of the bash script and start the dart script
(http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in).

#!/bin/bash
ME="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  SOURCE="$(readlink "$SOURCE")"
  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

${DIR}/${ME}.dart ${BASH_SOURCE[0]}

 
Instead of getting the command's (symlinks) name with io.Platform.script I have to pass it as an argument to have it available inside the dart script (I use the name of the symlink used to start the script like an argument inside the dart script)
This way I have to distinguish if the script was started directly and use io.Platform.script and args[0] otherwise.

I think this should all be easier.

@kasperl
Copy link

kasperl commented Jan 20, 2014

Added Area-VM, Triaged labels.

@iposva-google
Copy link
Contributor

Set owner to @rmacnak-google.
Added Accepted label.

@DartBot
Copy link
Author

DartBot commented Jul 14, 2014

This comment was originally written by @seaneagan


I believe this is solved by issue #18538. Instead of symlinking, you would "globally install" the package (if you want a path package, see issue #19902), and then call "pub global run <package>:<script>" (see issue #19863) or create a shell script which does that, probably using issue #18539.

@DartBot
Copy link
Author

DartBot commented Jul 14, 2014

This comment was originally written by @zoechi


You are right, this is the global strategy ;-)
19902 is a real blocker.
I have no intention to publish packages for scripts I write to automate tasks on my local machine or my network.

@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
@rmacnak-google
Copy link
Contributor

I believe package maps are expected to address this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants