Skip to content

Fix windows build #961

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

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ conduit-middleware = "0.8"
conduit-router = "0.8"
conduit-static = "0.8"
conduit-git-http-backend = "0.8"
civet = "0.9"
civet = "0.10"

[dev-dependencies]
conduit-test = "0.8"
Expand All @@ -80,6 +80,7 @@ hyper-tls = "0.1"
futures = "0.1"
tokio-core = "0.1"
tokio-service = "0.1"
uuid = { version = "0.5", features = ["v4"] }

[build-dependencies]
dotenv = "0.10"
Expand Down
51 changes: 51 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: '0.1.{build}'

platform: x64

services:
- postgresql96

environment:
global:
PGUSER: postgres
PGPASSWORD: Password12!
OPENSSL_VERSION: 1_1_0f
OPENSSL_DIR: "c:\\openssl"
SSL_CERT_FILE: "c:\\openssl\\cacert.pem"
TEST_DATABASE_URL: "postgres://postgres:Password12!@localhost/cargo_registry_test"

matrix:
- APPVEYOR_RUST_CHANNEL: stable
- APPVEYOR_RUST_CHANNEL: beta
- APPVEYOR_RUST_CHANNEL: nightly

matrix:
allow_failures:
- APPVEYOR_RUST_CHANNEL: nightly

install:
# Install OpenSSL
- mkdir c:\openssl
- ps: Start-FileDownload "http://slproweb.com/download/Win64OpenSSL-${env:OPENSSL_VERSION}.exe"
- Win64OpenSSL-%OPENSSL_VERSION%.exe /SILENT /VERYSILENT /SP- /DIR="C:\openssl"
- appveyor DownloadFile https://curl.haxx.se/ca/cacert.pem -FileName c:\openssl\cacert.pem
# Install rust and cargo
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
- rustup-init.exe -y --default-host x86_64-pc-windows-msvc --default-toolchain %APPVEYOR_RUST_CHANNEL%
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
# Debug information
- rustc -V
- cargo -V

build: false

before_test:
# Setup test database
- set PATH=%PATH%;C:\Program Files\PostgreSQL\9.6\bin
- createdb cargo_registry_test

test_script:
- cargo test

cache:
- C:\Users\appveyor\.cargo\registry -> Cargo.lock
10 changes: 8 additions & 2 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ like to see all new types and functions, public and private, to have documentati
comments on them. If you change an existing type or function, and it doesn't have
a documentation comment on it, it'd be great if you could add one to it too.

When you submit a pull request, it will be automatically tested on TravisCI. In
When you submit a pull request, it will be automatically tested on TravisCI and Appveyor. In
addition to running both the frontend and the backend tests described below,
Travis runs [jslint], [clippy], and [rustfmt] on each PR.

Expand Down Expand Up @@ -312,12 +312,18 @@ diesel migration run

##### Setting up the git index

Set up the git repo for the crate index by running:
If you're running Linux or macOS, you can set up the git repo for the crate index by running:

```
./script/init-local-index.sh
```

If you're running Windows, you can set up the git repo for the crate index by running the following command in PowerShell:

```
.\script\init-local-index.ps1
```

##### Starting the server and the frontend

Build and start the server by running this command (you'll need to stop this
Expand Down
35 changes: 35 additions & 0 deletions script/init-local-index.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
if (Test-Path -Path ".\tmp\index-bare") {
Write-Host "tmp\index-bare already exists, exiting"
exit
}

New-Item -Path "." -Name "tmp" -ItemType "directory" -Force 2>&1 | out-null
Remove-Item -Path ".\tmp\index-bare" -Recurse -Force 2>&1 | out-null
Remove-Item -Path ".\tmp\index-co" -Recurse -Force 2>&1 | out-null

Write-Host "Initializing repository in tmp\index-bare..."
git init -q --bare ".\tmp\index-bare"

Write-Host "Creating checkout in tmp/index-bare..."
git init -q ".\tmp\index-co"
Set-Location ".\tmp\index-co"

New-Item -Path "." -Name "config.json" -ItemType "file" -Value @'
{
"dl": "http://localhost:8888/api/v1/crates",
"api": "http://localhost:8888/"
}
'@ 2>&1 | out-null
git add config.json 2>&1 | out-null
git commit -qm "Initial commit" 2>&1 | out-null
$origin = [string]::Format("file:///{0}/../index-bare", (Get-Location))
git remote add origin $origin 2>&1 | out-null
git push -q origin master -u 2>&1 | out-null
Set-Location ..\..
New-Item -Path "tmp\index-co\.git" -Name "git-daemon-export-ok" -ItemType "file" 2>&1 | out-null

Write-Host @'
Your local git index is ready to go!

Please refer to https://github.com/rust-lang/crates.io/blob/master/README.md for more info!
'@
1 change: 1 addition & 0 deletions src/tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern crate serde_derive;
extern crate serde_json;
extern crate tar;
extern crate url;
extern crate uuid;

use std::borrow::Cow;
use std::collections::HashMap;
Expand Down
69 changes: 58 additions & 11 deletions src/tests/git.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use std::fs;
use std::env;
use std::fs;
use std::io;
use std::path::{Path, PathBuf};
use std::thread;
use std::path::PathBuf;
use std::sync::{Once, ONCE_INIT};

use git2;
use url::Url;
use uuid::Uuid;

fn root() -> PathBuf {
env::current_dir()
.unwrap()
.join("tmp")
.join(thread::current().name().unwrap())
.join(thread::current().name().unwrap().replace("::", "_"))
}

pub fn checkout() -> PathBuf {
Expand All @@ -21,14 +22,60 @@ pub fn bare() -> PathBuf {
root().join("bare")
}

pub fn init() {
static INIT: Once = ONCE_INIT;
let _ = fs::remove_dir_all(&checkout());
let _ = fs::remove_dir_all(&bare());
#[cfg(target_os = "windows")]
fn remove_dir_all(path: &Path) -> Result<(), io::Error> {
fn rename_temp(path: &Path) -> Result<PathBuf, io::Error> {
let temp_name = Uuid::new_v4().hyphenated().to_string();
let temp_path = env::temp_dir().join(temp_name);
fs::rename(path, &temp_path)?;
Ok(temp_path)
}

fn remove_file(path: &Path) -> Result<(), io::Error> {
let temp_path = rename_temp(path)?;
fs::remove_file(&temp_path)
}

fn remove_dir(path: &Path) -> Result<(), io::Error> {
let temp_path = rename_temp(path)?;
fs::remove_dir(&temp_path)
}

for cursor in fs::read_dir(path)? {
let entry = cursor?;
let file_type = entry.file_type()?;
if file_type.is_dir() {
remove_dir_all(&entry.path())?;
} else {
let mut permissions = entry.metadata()?.permissions();
if permissions.readonly() {
permissions.set_readonly(false);
fs::set_permissions(entry.path(), permissions)?;
}
remove_file(&entry.path())?;
}
}
remove_dir(path)
}

INIT.call_once(|| {
fs::create_dir_all(root().parent().unwrap()).unwrap();
});
#[cfg(not(target_os = "windows"))]
fn remove_dir_all(path: &Path) -> Result<(), io::Error> {
fs::remove_dir_all(path)
}

pub fn init() {
if let Err(e) = remove_dir_all(&checkout()) {
println!("Errored: {:?}", e);
}
if let Err(e) = remove_dir_all(&bare()) {
println!("Errored: {:?}", e);
}
if let Err(e) = fs::create_dir_all(&checkout()) {
println!("Errored: {:?}", e);
}
if let Err(e) = fs::create_dir_all(&bare()) {
println!("Errored: {:?}", e);
}

// Prepare a bare remote repo
{
Expand Down