Skip to content

Commit c101224

Browse files
authored
Merge pull request #150 from pulp-platform/windows
Add Windows support & release
2 parents 436377f + 781b154 commit c101224

10 files changed

Lines changed: 139 additions & 20 deletions

File tree

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ jobs:
3535
run: tests/run_all.sh
3636
shell: bash
3737

38+
test-windows:
39+
runs-on: windows-latest
40+
steps:
41+
- uses: actions/checkout@v3
42+
- uses: dtolnay/rust-toolchain@stable
43+
with:
44+
toolchain: stable
45+
- name: Build
46+
run: cargo build
47+
- name: Cargo Test
48+
run: cargo test --all
49+
- name: Run unit-tests
50+
run: tests/run_all.sh
51+
shell: bash
52+
3853
clippy_check:
3954
name: Clippy
4055
runs-on: ubuntu-latest

.github/workflows/release.yaml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobs:
127127
rustup target add aarch64-apple-darwin
128128
cargo install universal2
129129
- name: MacOS Build
130-
run: cargo universal2 --release
130+
run: cargo-universal2 --release
131131
- name: Get Artifact Name
132132
run: |
133133
if [[ "$GITHUB_REF" =~ ^refs/tags/v.*$ ]]; then \
@@ -151,3 +151,38 @@ jobs:
151151
asset_path: ${{ env.ARTIFACT_PATHNAME }}
152152
asset_name: ${{ env.ARTIFACT_NAME }}
153153
asset_content_type: application/tar.gz
154+
release-windows:
155+
runs-on: windows-latest
156+
steps:
157+
- uses: actions/checkout@v3
158+
- name: Install Rust
159+
uses: dtolnay/rust-toolchain@stable
160+
with:
161+
toolchain: stable
162+
- name: Build
163+
run: cargo build --release
164+
- name: Get Artifact Name
165+
shell: bash
166+
run: |
167+
if [[ "$GITHUB_REF" =~ ^refs/tags/v.*$ ]]; then \
168+
PKG_VERSION=$(echo $GITHUB_REF | sed -n 's/^refs\/tags\/v//p'); \
169+
else \
170+
PKG_VERSION=$(echo $GITHUB_REF | sed -n 's/^refs\/tags\///p'); \
171+
fi
172+
ARTIFACT_PATHNAME="bender-$PKG_VERSION-x86_64-pc-windows-msvc.tar.gz"
173+
ARTIFACT_NAME=$(basename $ARTIFACT_PATHNAME)
174+
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
175+
echo "ARTIFACT_PATHNAME=${ARTIFACT_PATHNAME}" >> $GITHUB_ENV
176+
- name: Create Package
177+
run: |
178+
cp target/release/bender.exe .
179+
& 'C:\Program Files\Git\usr\bin\tar.exe' czf $Env:ARTIFACT_PATHNAME --owner=0 --group=0 bender.exe
180+
- name: Upload Release Asset
181+
uses: actions/upload-release-asset@v1
182+
env:
183+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
184+
with:
185+
upload_url: ${{ github.event.release.upload_url }}
186+
asset_path: ${{ env.ARTIFACT_PATHNAME }}
187+
asset_name: ${{ env.ARTIFACT_NAME }}
188+
asset_content_type: application/tar.gz

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ glob = "0.3"
3333
walkdir = "2"
3434
subst = "0.3"
3535
tera = "1.19"
36+
37+
[target.'cfg(windows)'.dependencies]
38+
dunce = "1.0.4"

src/cli.rs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
66
use std;
77
use std::ffi::OsString;
8-
use std::fs::{canonicalize, metadata};
98
use std::path::{Path, PathBuf};
109
use std::process::Command as SysCommand;
1110

11+
#[cfg(unix)]
12+
use std::fs::{canonicalize, metadata};
13+
14+
#[cfg(windows)]
15+
use dunce::canonicalize;
16+
1217
use clap::parser::ValuesRef;
1318
use clap::{Arg, ArgAction, Command};
1419
use serde_yaml;
@@ -251,7 +256,7 @@ pub fn main() -> Result<()> {
251256
}
252257
None => None,
253258
};
254-
std::os::unix::fs::symlink(&pkg_path, path).map_err(|cause| {
259+
symlink_dir(&pkg_path, path).map_err(|cause| {
255260
Error::chain(
256261
format!(
257262
"Failed to create symlink to {:?} at path {:?}.",
@@ -291,10 +296,21 @@ pub fn main() -> Result<()> {
291296
}
292297
}
293298

299+
#[cfg(target_family = "unix")]
300+
fn symlink_dir(p: &Path, q: &Path) -> Result<()> {
301+
Ok(std::os::unix::fs::symlink(p, q)?)
302+
}
303+
304+
#[cfg(target_os = "windows")]
305+
fn symlink_dir(p: &Path, q: &Path) -> Result<()> {
306+
Ok(std::os::windows::fs::symlink_dir(p, q)?)
307+
}
308+
294309
/// Find the root directory of a package.
295310
///
296311
/// Traverses the directory hierarchy upwards until a `Bender.yml` file is found.
297312
fn find_package_root(from: &Path) -> Result<PathBuf> {
313+
#[cfg(unix)]
298314
use std::os::unix::fs::MetadataExt;
299315

300316
// Canonicalize the path. This will resolve any intermediate links.
@@ -304,7 +320,9 @@ fn find_package_root(from: &Path) -> Result<PathBuf> {
304320

305321
// Look up the device at the current path. This information will then be
306322
// used to stop at filesystem boundaries.
323+
#[cfg(unix)]
307324
let limit_rdev: Option<_> = metadata(&path).map(|m| m.dev()).ok();
325+
#[cfg(unix)]
308326
debugln!("find_package_root: limit rdev = {:?}", limit_rdev);
309327

310328
// Step upwards through the path hierarchy.
@@ -326,13 +344,16 @@ fn find_package_root(from: &Path) -> Result<PathBuf> {
326344
}
327345

328346
// Abort if we have crossed the filesystem boundary.
329-
let rdev: Option<_> = metadata(&path).map(|m| m.dev()).ok();
330-
debugln!("find_package_root: rdev = {:?}", rdev);
331-
if rdev != limit_rdev {
332-
return Err(Error::new(format!(
333-
"No manifest (`Bender.yml` file) found. Stopped searching at filesystem boundary {:?}.",
334-
tested_path
335-
)));
347+
#[cfg(unix)]
348+
{
349+
let rdev: Option<_> = metadata(&path).map(|m| m.dev()).ok();
350+
debugln!("find_package_root: rdev = {:?}", rdev);
351+
if rdev != limit_rdev {
352+
return Err(Error::new(format!(
353+
"No manifest (`Bender.yml` file) found. Stopped searching at filesystem boundary {:?}.",
354+
tested_path
355+
)));
356+
}
336357
}
337358
}
338359

@@ -358,7 +379,9 @@ pub fn read_manifest(path: &Path) -> Result<Manifest> {
358379

359380
/// Load a configuration by traversing a directory hierarchy upwards.
360381
fn load_config(from: &Path) -> Result<Config> {
382+
#[cfg(unix)]
361383
use std::os::unix::fs::MetadataExt;
384+
362385
let mut out = PartialConfig::new();
363386

364387
// Canonicalize the path. This will resolve any intermediate links.
@@ -368,7 +391,9 @@ fn load_config(from: &Path) -> Result<Config> {
368391

369392
// Look up the device at the current path. This information will then be
370393
// used to stop at filesystem boundaries.
394+
#[cfg(unix)]
371395
let limit_rdev: Option<_> = metadata(&path).map(|m| m.dev()).ok();
396+
#[cfg(unix)]
372397
debugln!("load_config: limit rdev = {:?}", limit_rdev);
373398

374399
// Step upwards through the path hierarchy.
@@ -390,10 +415,13 @@ fn load_config(from: &Path) -> Result<Config> {
390415
}
391416

392417
// Abort if we have crossed the filesystem boundary.
393-
let rdev: Option<_> = metadata(&path).map(|m| m.dev()).ok();
394-
debugln!("load_config: rdev = {:?}", rdev);
395-
if rdev != limit_rdev {
396-
break;
418+
#[cfg(unix)]
419+
{
420+
let rdev: Option<_> = metadata(&path).map(|m| m.dev()).ok();
421+
debugln!("load_config: rdev = {:?}", rdev);
422+
if rdev != limit_rdev {
423+
break;
424+
}
397425
}
398426
}
399427

src/cmd/clone.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ pub fn run(sess: &Session, path: &Path, matches: &ArgMatches) -> Result<()> {
288288
}
289289
None => None,
290290
};
291-
std::os::unix::fs::symlink(&pkg_path, link_path).map_err(|cause| {
291+
symlink_dir(&pkg_path, link_path).map_err(|cause| {
292292
Error::chain(
293293
format!(
294294
"Failed to create symlink to {:?} at path {:?}.",
@@ -307,3 +307,13 @@ pub fn run(sess: &Session, path: &Path, matches: &ArgMatches) -> Result<()> {
307307

308308
Ok(())
309309
}
310+
311+
#[cfg(unix)]
312+
fn symlink_dir(p: &Path, q: &Path) -> Result<()> {
313+
Ok(std::os::unix::fs::symlink(p, q)?)
314+
}
315+
316+
#[cfg(windows)]
317+
fn symlink_dir(p: &Path, q: &Path) -> Result<()> {
318+
Ok(std::os::windows::fs::symlink_dir(p, q)?)
319+
}

src/cmd/vendor.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,7 @@ pub fn copy_recursively(
698698
)?;
699699
} else if filetype.is_symlink() {
700700
let orig = std::fs::read_link(entry.path());
701-
std::os::unix::fs::symlink(
702-
orig.unwrap(),
703-
destination.as_ref().join(entry.file_name()),
704-
)?;
701+
symlink_dir(orig.unwrap(), destination.as_ref().join(entry.file_name()))?;
705702
} else {
706703
std::fs::copy(entry.path(), destination.as_ref().join(entry.file_name())).map_err(
707704
|cause| {
@@ -741,3 +738,13 @@ pub fn extend_paths(
741738
})
742739
.collect::<Result<_>>()
743740
}
741+
742+
#[cfg(unix)]
743+
fn symlink_dir(p: PathBuf, q: PathBuf) -> Result<()> {
744+
Ok(std::os::unix::fs::symlink(p, q)?)
745+
}
746+
747+
#[cfg(windows)]
748+
fn symlink_dir(p: PathBuf, q: PathBuf) -> Result<()> {
749+
Ok(std::os::windows::fs::symlink_dir(p, q)?)
750+
}

src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ pub enum LockedSource {
954954
Registry(String),
955955
}
956956

957+
#[cfg(unix)]
957958
fn env_path_from_string(path_str: String) -> Result<PathBuf> {
958959
Ok(PathBuf::from(
959960
subst::substitute(&path_str, &subst::Env).map_err(|cause| {
@@ -964,3 +965,8 @@ fn env_path_from_string(path_str: String) -> Result<PathBuf> {
964965
})?,
965966
))
966967
}
968+
969+
#[cfg(windows)]
970+
fn env_path_from_string(path_str: String) -> Result<PathBuf> {
971+
Ok(PathBuf::from(path_str))
972+
}

src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ extern crate subst;
2424
extern crate tempfile;
2525
extern crate typed_arena;
2626

27+
#[cfg(windows)]
28+
extern crate dunce;
29+
2730
#[macro_use]
2831
pub mod error;
2932
pub mod cli;

src/sess.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use std;
99
use std::fmt;
10-
use std::fs::canonicalize;
1110
use std::io::Write;
1211
use std::iter::FromIterator;
1312
use std::mem::swap;
@@ -16,6 +15,12 @@ use std::sync::atomic::AtomicUsize;
1615
use std::sync::{Arc, Mutex};
1716
use std::time::SystemTime;
1817

18+
#[cfg(unix)]
19+
use std::fs::canonicalize;
20+
21+
#[cfg(windows)]
22+
use dunce::canonicalize;
23+
1924
use crate::futures::{FutureExt, TryFutureExt};
2025
use async_recursion::async_recursion;
2126
use futures::future::{self, join_all};

0 commit comments

Comments
 (0)