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

rustbuild: canonicalize prefix install_sh #49778

Merged
merged 1 commit into from
Apr 9, 2018

Conversation

tamird
Copy link
Contributor

@tamird tamird commented Apr 8, 2018

Testing:

  $ git diff
  diff --git a/config.toml.example b/config.toml.example
  index 9dd3002506..b47bc490cd 100644
  --- a/config.toml.example
  +++ b/config.toml.example
  @@ -196,7 +196,7 @@
   [install]

   # Instead of installing to /usr/local, install to this path instead.
  -#prefix = "/usr/local"
  +prefix = "install-prefix"

   # Where to install system configuration files
   # If this is a relative path, it will get installed in `prefix` above
  $ mkdir install-prefix
  $ ./x.py install -i --stage 0 --config config.toml.example
  ...
  $ ls install-prefix/
  bin	lib	share

Closes #36989.

r? @Mark-Simulacrum

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 8, 2018
fs::canonicalize(p).expect(&format!("could not canonicalize {}", p.display()))
};
let prefix = build.config.prefix.as_ref().map_or(prefix_default, canonicalize);
let sysconfdir = build.config.sysconfdir.as_ref().map_or(sysconfdir_default, canonicalize);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might have to be more careful about sysconfdir here. If it's an absolute path, then canonicalizing it is fine, but if it's relative, it'll be relative to prefix per the documentation, which makes this code (I believe) do the wrong thing.

I think I'd probably branch on is_absolute/is_relative on the path after mapping it to the default to determine if we need to canonicalize it (though it might be true that like all of the other paths, there's never a need to do so?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're absolutely right. I was confused by the default value being "/etc" rather than "etc". Fixed.

@tamird tamird changed the title Canonicalize paths in install_sh rustbuild: canonicalize prefix install_sh Apr 8, 2018
@@ -66,13 +66,15 @@ fn install_sh(
build.info(&format!("Install {} stage{} ({:?})", package, stage, host));

let prefix_default = PathBuf::from("/usr/local");
let sysconfdir_default = PathBuf::from("/etc");
let sysconfdir_default = PathBuf::from("etc");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, no, the previous default was correct I think? In that normally you want to have the sysconfdir be /etc and the rest of the dirs be relative to /usr/local. The confusing part of this is that Path::new("/usr/local").join("/etc") evaluates to /etc which is somewhat unexpected, though correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wow - that is very surprising, but of course, you are right. https://play.rust-lang.org/?gist=9fca8ef12a8ac532ceaa12383983c62f&version=stable

Fixed again!

Testing:
```
  $ git diff
  diff --git a/config.toml.example b/config.toml.example
  index 9dd3002506..b47bc490cd 100644
  --- a/config.toml.example
  +++ b/config.toml.example
  @@ -196,7 +196,7 @@
   [install]

   # Instead of installing to /usr/local, install to this path instead.
  -#prefix = "/usr/local"
  +prefix = "install-prefix"

   # Where to install system configuration files
   # If this is a relative path, it will get installed in `prefix` above
  $ mkdir install-prefix
  $ ./x.py install -i --stage 0 --config config.toml.example
  ...
  $ ls install-prefix/
  bin	lib	share
```

Closes rust-lang#36989.
@Mark-Simulacrum
Copy link
Member

@bors r+ rollup (can't fail because, well, not tested...)

@bors
Copy link
Contributor

bors commented Apr 8, 2018

📌 Commit 9487902 has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 8, 2018
@bors
Copy link
Contributor

bors commented Apr 9, 2018

⌛ Testing commit 9487902 with merge 561fb39...

bors added a commit that referenced this pull request Apr 9, 2018
rustbuild: canonicalize prefix `install_sh`

Testing:
```
  $ git diff
  diff --git a/config.toml.example b/config.toml.example
  index 9dd3002506..b47bc490cd 100644
  --- a/config.toml.example
  +++ b/config.toml.example
  @@ -196,7 +196,7 @@
   [install]

   # Instead of installing to /usr/local, install to this path instead.
  -#prefix = "/usr/local"
  +prefix = "install-prefix"

   # Where to install system configuration files
   # If this is a relative path, it will get installed in `prefix` above
  $ mkdir install-prefix
  $ ./x.py install -i --stage 0 --config config.toml.example
  ...
  $ ls install-prefix/
  bin	lib	share
```

Closes #36989.

r? @Mark-Simulacrum
@bors
Copy link
Contributor

bors commented Apr 9, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: Mark-Simulacrum
Pushing 561fb39 to master...

@bors bors merged commit 9487902 into rust-lang:master Apr 9, 2018
@tamird tamird deleted the install-relative-prefix branch April 9, 2018 09:36
nodakai added a commit to nodakai/rust that referenced this pull request Jun 15, 2020
PR rust-lang#49778 introduced fs::canonicalize() which fails for a nonexistent path.
This is a surprise for someone used to GNU Autotools' configure which can create any necessary intermediate directories in prefix.

This change makes it run fs::create_dir_all() before canonicalize().
Manishearth added a commit to Manishearth/rust that referenced this pull request Jun 16, 2020
…ent-prefix, r=Mark-Simulacrum

bootstrap/install.rs: support a nonexistent `prefix` in `x.py install`

PR rust-lang#49778 introduced fs::canonicalize() which fails for a nonexistent path.
This is a surprise for someone used to GNU Autotools' configure which can create any necessary intermediate directories in prefix.

This change makes it run fs::create_dir_all() before canonicalize().
Manishearth added a commit to Manishearth/rust that referenced this pull request Jun 19, 2020
…ent-prefix, r=Mark-Simulacrum

bootstrap/install.rs: support a nonexistent `prefix` in `x.py install`

PR rust-lang#49778 introduced fs::canonicalize() which fails for a nonexistent path.
This is a surprise for someone used to GNU Autotools' configure which can create any necessary intermediate directories in prefix.

This change makes it run fs::create_dir_all() before canonicalize().
RalfJung added a commit to RalfJung/rust that referenced this pull request Jun 19, 2020
…ent-prefix, r=Mark-Simulacrum

bootstrap/install.rs: support a nonexistent `prefix` in `x.py install`

PR rust-lang#49778 introduced fs::canonicalize() which fails for a nonexistent path.
This is a surprise for someone used to GNU Autotools' configure which can create any necessary intermediate directories in prefix.

This change makes it run fs::create_dir_all() before canonicalize().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make install doesn't work correctly with relative directory prefixes
4 participants