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

cinstall: destdir path joining problems on Windows with absolute paths #89

Closed
lazka opened this issue Jul 6, 2020 · 15 comments · Fixed by #90
Closed

cinstall: destdir path joining problems on Windows with absolute paths #89

lazka opened this issue Jul 6, 2020 · 15 comments · Fixed by #90
Labels
bug Something isn't working

Comments

@lazka
Copy link
Contributor

lazka commented Jul 6, 2020

I run

cargo cinstall --release --frozen --library-type=cdylib --destdir=C:/foo

but things get installed into C:/usr:

C:/usr/
└── local
    ├── bin
    │   └── rav1e.dll
    ├── include
    │   └── rav1e
    │       └── rav1e.h
    └── lib
        ├── librav1e.dll.a
        ├── pkgconfig
        │   └── rav1e.pc
        └── rav1e.def
@lu-zero lu-zero added the bug Something isn't working label Jul 7, 2020
@lu-zero
Copy link
Owner

lu-zero commented Jul 7, 2020

You should provide more information on which flavor of windows and how you are getting to this. I do not use windows so I'll need your help in tracking it down.

@1480c1
Copy link
Contributor

1480c1 commented Jul 7, 2020

I think he uses windows with msys2, idk the windows version number

this is probably similar to the situation I mentioned in daala irc

@lazka
Copy link
Contributor Author

lazka commented Jul 7, 2020

yeah, under MSYS2. I worked it around for now by passing a relative prefix (which results in the wrong prefix in the .pc file, but that is ignored on Windows anyway)

My guess is that when concatenating destdir with an absolute prefix only the prefix survives (destdir="C:/foo", prefix="C:/bar" -> "C:\bar")

@lu-zero
Copy link
Owner

lu-zero commented Jul 7, 2020 via email

@lazka
Copy link
Contributor Author

lazka commented Jul 7, 2020

please try to specify all of them and report back

You mean prefix and destdir? --destdir=C:/foo --prefix=C:/bar -> things are written to C:/bar

I can try to look into it if wanted, though my rust skills are minimal.

@lu-zero
Copy link
Owner

lu-zero commented Jul 7, 2020 via email

@lazka
Copy link
Contributor Author

lazka commented Jul 7, 2020

--prefix=bar --destdir=foo -> written to ./foo/bar

@lu-zero
Copy link
Owner

lu-zero commented Jul 7, 2020 via email

@1480c1
Copy link
Contributor

1480c1 commented Jul 7, 2020

I'm assuming it's somewhere around here? https://github.com/lu-zero/cargo-c/blob/master/src/cinstall.rs#L54

@lazka
Copy link
Contributor Author

lazka commented Jul 7, 2020

my attempt :)

fn append_to_destdir(destdir: &PathBuf, path: &PathBuf) -> PathBuf {
    let mut components = path.components();
    while components.as_path().has_root() {
        components.next();
    }
    destdir.join(components.as_path())
}

@lazka lazka changed the title cinstall: destdir ignored on Windows cinstall: destdir path joining problems on Windows with absolute paths Jul 7, 2020
@lu-zero
Copy link
Owner

lu-zero commented Jul 7, 2020

Ideally you could skip only the Component::Prefix(_) using a patter match. That loop would strip too much

@lu-zero
Copy link
Owner

lu-zero commented Jul 7, 2020

I'm assuming it's somewhere around here? https://github.com/lu-zero/cargo-c/blob/master/src/cinstall.rs#L54

That's right, apparently it the case of prefix it should be stripped before stripping the /.

@lazka
Copy link
Contributor Author

lazka commented Jul 7, 2020

Ideally you could skip only the Component::Prefix(_) using a patter match. That loop would strip too much

You need to remove Prefix (C:) and RootDir (/)

@lu-zero
Copy link
Owner

lu-zero commented Jul 7, 2020 via email

@dwbuiten
Copy link
Collaborator

dwbuiten commented Jul 7, 2020

It would need to match all drive letters, and not just C:, FWIW

lazka added a commit to lazka/cargo-c that referenced this issue Jul 8, 2020
It currently uses is_absolute() to strip one leading component which doesn't
work for paths like "C:/foo", "C:foo" and "/foo" which are either not absolute
or have multiple components that need to be stripped.

The goal is to join two paths and removing any components from the second
one that would result in the first one being replaced/changed.

push()/join() alters the first path if it starts with a RootDir, Prefix, or both, so
we push everything from the second path except for those.

Fixes lu-zero#89
lazka added a commit to lazka/cargo-c that referenced this issue Jul 8, 2020
It currently uses is_absolute() to strip one leading component which doesn't
work for paths like "C:/foo", "C:foo" and "/foo" which are either not absolute
or have multiple components that need to be stripped.

The goal is to join two paths and removing any components from the second
one that would result in the first one being replaced/changed.

push()/join() alters the first path if it starts with a RootDir, Prefix, or both, so
we push everything from the second path except for those.

Fixes lu-zero#89
lazka added a commit to lazka/cargo-c that referenced this issue Jul 8, 2020
It currently uses is_absolute() to strip one leading component which doesn't
work for paths like "C:/foo", "C:foo" and "/foo" which are either not absolute
or have multiple components that need to be stripped.

The goal is to join two paths and removing any components from the second
one that would result in the first one being replaced/changed.

push()/join() alters the first path if it starts with a RootDir, Prefix, or both, so
we push everything from the second path except for those.

Fixes lu-zero#89
lu-zero pushed a commit that referenced this issue Jul 8, 2020
It currently uses is_absolute() to strip one leading component which doesn't
work for paths like "C:/foo", "C:foo" and "/foo" which are either not absolute
or have multiple components that need to be stripped.

The goal is to join two paths and removing any components from the second
one that would result in the first one being replaced/changed.

push()/join() alters the first path if it starts with a RootDir, Prefix, or both, so
we push everything from the second path except for those.

Fixes #89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants