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

Provide a way of getting packageRoot as a Uri #19430

Closed
johnniwinther opened this issue Jun 13, 2014 · 14 comments
Closed

Provide a way of getting packageRoot as a Uri #19430

johnniwinther opened this issue Jun 13, 2014 · 14 comments
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io type-enhancement A request for a change that isn't a bug
Milestone

Comments

@johnniwinther
Copy link
Member

Platform.packageRoot should return a Uri.

Currently is is passed on verbatim from the system, and even though the package root always refers to a directory-like resource every user must ensure that it is normalized before handling.

For instance, you cannot use

Uri packageRoot = Uri.base.resolve(Platform.packageRoot);

because it might be missing a trailing slash and might contain ''.

@kevmoo
Copy link
Member

kevmoo commented Jun 13, 2014

We can't change the type returned from packageRoot – we want to avoid breaking changes.

We could add a packageRootUri property or similar, though


Added Library-IO label.

@andersjohnsen
Copy link

Consider using 'new Uri.file(Platform.packageRoot)' to get the Uri you need. You will still need to look for tailing slash though.

@johnniwinther
Copy link
Member Author

For a Platform-independent version without double slashes that would require:

Uri fileUri = Uri.base.resolveUri(
    new Uri.file(Platform.packageRoot, windows: Platform.isWindows));
Uri dirUri = fileUri.path.endWith('/') ? fileUri
    : new Uri(scheme: fileUri.scheme, path: '${fileUri.path}/');

This is, and will be, handled incorrectly in many use-cases.

@andersjohnsen
Copy link

  Uri fileUri = Uri.base.resolveUri(new Uri.file(Platform.packageRoot));
  Uri dirUri = fileUri.path.endWith('/') ? fileUri
      : new Uri(scheme: fileUri.scheme, path: '${fileUri.path}/');

Should be sufficient.

But I agree, it's non-trivial.

@johnniwinther johnniwinther added Type-Enhancement area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io labels Jun 15, 2014
@sethladd
Copy link
Contributor

cc @iposva-google

@sethladd
Copy link
Contributor

For those following along, this getter will start to return a URI if the VM has resolved packageRoot, even if --package-root was not set on the command line. In other words, if the VM has decided to use a package root, then packageRoot will return something.

@johnniwinther
Copy link
Member Author

That might even be worse. If you want to create a new process in your own package environment you will not be able to do so if you don't rely on packages yourself.

@iposva-google
Copy link
Contributor

Johnni, I am not sure what you are trying to say in your last comment. But let me explain the semantics that Seth has been referring to:

  • If the dart standalone binary is started both with a --package-root and --packages flag then this is an error and launch will be aborted.
  • If the dart standalone binary is started with --package-root=<some/uri> then you will end up with a result which points you at the fully resolved URI of the command line argument. This URI is also used to load all packages.
  • If the dart standalone binary is started with a --packages=<some/uri> then the result is a null packageRoot, since this isolate is not using a package root to load packages.
  • If the dart standalone binary was started with neither a --package-root or --packages flag then the location of a .packages file or packages/ directory according to the packages spec. If the resolution of that operation found a packages/ directory next to the main script, without finding a .packages file next to the main script, then you get the fully resolved URI of that packages/ directory or null if a .packages file was found or no packages/ directory was found. (The rules about http based scripts vary slightly in this case, please see the packages spec.)

The above points are evaluated in the order they have been listed for the root isolate. For spawned isolates the parameters to spawnUri are equivalent to command line flags. In all cases the result is irrespective of whether your isolate has or has not loaded any packages.

@johnniwinther
Copy link
Member Author

Sounds good.

@mit-mit
Copy link
Member

mit-mit commented Sep 17, 2015

@iposva-google, you are working on this, right?

@iposva-google
Copy link
Contributor

Correct. A CL (https://codereview.chromium.org/1334353002/) is in review, but a lot of tests need adjusting...

@mit-mit mit-mit changed the title Platform.packageRoot should return a Uri Provide a way of getting packageRoot as a Uri Sep 29, 2015
@mit-mit
Copy link
Member

mit-mit commented Oct 5, 2015

@mit-mit mit-mit closed this as completed Oct 5, 2015
@nex3
Copy link
Member

nex3 commented Oct 29, 2015

This has been rolled back, so I'm re-opening.

@nex3 nex3 reopened this Oct 29, 2015
@kevmoo kevmoo added this to the 1.14 milestone Oct 30, 2015
@kevmoo kevmoo removed this from the 1.13 milestone Oct 30, 2015
@mit-mit
Copy link
Member

mit-mit commented Jan 14, 2016

And I believe it has been landed again, so closing

@mit-mit mit-mit closed this as completed Jan 14, 2016
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed triaged labels Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

7 participants