Skip to content

Commit 6a51f73

Browse files
committed
Merge branch 'gnzlbg-fix'
2 parents bd2cd27 + d7ad440 commit 6a51f73

29 files changed

+4756
-1578
lines changed

.travis.yml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
language: rust
2-
32
rust: nightly
3+
sudo: false
44

5-
os:
6-
- linux
7-
# coming soon:
8-
# - osx
9-
10-
env:
11-
global:
12-
- RUST_BACKTRACE=full
13-
14-
script:
15-
- |
16-
set -e
17-
if [ "$TRAVIS_OS_NAME" == "osx" ]; then
18-
# test output for a different libc is expected to be different
19-
mv tests/full_cases/libc-0.2.28-0.2.31.osx tests/full_cases/libc-0.2.28-0.2.31
20-
fi
21-
22-
cargo build
23-
cargo test --verbose
5+
matrix:
6+
fast_finish: true
7+
include:
8+
# Targets
9+
- name: "linux"
10+
os: linux
11+
env: RUST_BACKTRACE=full
12+
- name: "osx"
13+
os: osx
14+
osx_image: xcode10
15+
env: RUST_BACKTRACE=full
16+
- name: "windows"
17+
os: windows
2418

25-
# install
26-
mkdir -p ~/rust/cargo/bin
27-
cp target/debug/cargo-semver ~/rust/cargo/bin
28-
cp target/debug/rust-semverver ~/rust/cargo/bin
19+
# Tools:
20+
- name: "rustfmt"
21+
install: rustup component add rustfmt-preview
22+
script: cargo fmt --all -- --check
23+
- name: "clippy"
24+
script: |
25+
if rustup component add clippy-preview; then
26+
cargo clippy --all -- -D clippy::pedantic
27+
fi
28+
- name: "Shellcheck"
29+
script:
30+
- shellcheck --version
31+
- shellcheck ci/*.sh
2932

30-
# become semververver
31-
eval "current_version=$(grep -e '^version = .*$' Cargo.toml | cut -d ' ' -f 3)"
32-
PATH=~/rust/cargo/bin:$PATH cargo semver | tee semver_out
33-
(head -n 1 semver_out | grep "\-> $current_version") || (echo "versioning mismatch" && return 1)
33+
script: sh ci/run.sh

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ name = "rust-semverver"
2525
path = "src/bin/rust_semverver.rs"
2626

2727
[dependencies]
28-
cargo = "0.29"
29-
crates-io = "0.17"
30-
env_logger = "0.5"
28+
cargo = "0.31"
29+
crates-io = "0.19"
30+
env_logger = "0.6"
3131
log = "0.4"
3232
semver = "0.9"
33-
rand = "0.5"
33+
rand = "0.6"
3434

3535
[dev-dependencies]
3636
quickcheck = "0.7"

appveyor.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ install:
1414

1515
build: false
1616

17-
test_script:
18-
- set RUST_BACKTRACE=full
19-
- cargo build
20-
# - cargo test --verbose
17+
test_script: C:\msys64\usr\bin\sh ci\run.sh
2118

2219
notifications:
2320
- provider: Email

ci/run.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env sh
2+
3+
set -ex
4+
5+
export RUST_TEST_THREADS=1
6+
export RUST_BACKTRACE=full
7+
#export RUST_TEST_NOCAPTURE=1
8+
9+
cargo build
10+
cargo test --verbose -- --nocapture
11+
12+
# install
13+
mkdir -p ~/rust/cargo/bin
14+
cp target/debug/cargo-semver ~/rust/cargo/bin
15+
cp target/debug/rust-semverver ~/rust/cargo/bin
16+
17+
# become semververver
18+
PATH=~/rust/cargo/bin:$PATH cargo semver | tee semver_out
19+
current_version="$(grep -e '^version = .*$' Cargo.toml | cut -d ' ' -f 3)"
20+
current_version="${current_version%\"}"
21+
current_version="${current_version#\"}"
22+
result="$(head -n 1 semver_out)"
23+
if echo "$result" | grep -- "-> $current_version"; then
24+
echo "version ok"
25+
exit 0
26+
else
27+
echo "versioning mismatch"
28+
cat semver_out
29+
echo "versioning mismatch"
30+
exit 1
31+
fi

src/bin/cargo_semver.rs

Lines changed: 88 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,23 @@ extern crate getopts;
88
#[macro_use]
99
extern crate log;
1010

11+
use cargo::{
12+
core::{compiler::CompileMode, Package, PackageId, Source, SourceId, Workspace},
13+
exit_with_error,
14+
ops::{compile, CompileOptions},
15+
util::{
16+
config::Config, important_paths::find_root_manifest_for_wd, CargoError, CargoResult,
17+
CliError,
18+
},
19+
};
1120
use crates_io::{Crate, Registry};
12-
13-
use cargo::exit_with_error;
14-
use cargo::core::{Package, PackageId, Source, SourceId, Workspace};
15-
use cargo::core::compiler::CompileMode;
16-
use cargo::ops::{compile, CompileOptions};
17-
use cargo::util::{CargoError, CargoResult, CliError};
18-
use cargo::util::config::Config;
19-
use cargo::util::important_paths::find_root_manifest_for_wd;
20-
2121
use getopts::{Matches, Options};
22-
23-
use std::env;
24-
use std::error;
25-
use std::fmt;
26-
use std::io::Write;
27-
use std::path::PathBuf;
28-
use std::process::{Stdio, Command};
22+
use std::{
23+
env, error, fmt,
24+
io::Write,
25+
path::PathBuf,
26+
process::{Command, Stdio},
27+
};
2928

3029
/// Very simple error representation.
3130
#[derive(Debug)]
@@ -51,15 +50,18 @@ fn exact_search(query: &str) -> CargoResult<Crate> {
5150

5251
registry
5352
.search(query, 1)
54-
.map_err(|e|
55-
Error(format!("failed to retrieve search results from the registry: {}", e))
56-
.into())
53+
.map_err(|e| {
54+
Error(format!(
55+
"failed to retrieve search results from the registry: {}",
56+
e
57+
))
58+
.into()
59+
})
5760
.and_then(|(mut crates, _)| {
5861
crates
5962
.drain(..)
6063
.find(|krate| krate.name == query)
61-
.ok_or_else(|| Error(format!("failed to find a matching crate `{}`", query))
62-
.into())
64+
.ok_or_else(|| Error(format!("failed to find a matching crate `{}`", query)).into())
6365
})
6466
}
6567

@@ -87,9 +89,9 @@ impl<'a> SourceInfo<'a> {
8789

8890
debug!("source id loaded: {:?}", source_id);
8991

90-
Ok(SourceInfo {
92+
Ok(Self {
9193
id: source_id,
92-
source: source,
94+
source,
9395
})
9496
}
9597
}
@@ -114,34 +116,33 @@ impl<'a> WorkInfo<'a> {
114116
let workspace = Workspace::new(&manifest_path, config)?;
115117
let package = workspace.load(&manifest_path)?;
116118

117-
Ok(WorkInfo {
118-
package,
119-
workspace,
120-
})
119+
Ok(Self { package, workspace })
121120
}
122121

123122
/// Construct a package/workspace pair by fetching the package of a specified name and
124123
/// version.
125-
fn remote(config: &'a Config, source: &mut SourceInfo<'a>, info: &NameAndVersion)
126-
-> CargoResult<WorkInfo<'a>>
127-
{
124+
fn remote(
125+
config: &'a Config,
126+
source: &mut SourceInfo<'a>,
127+
info: &NameAndVersion,
128+
) -> CargoResult<WorkInfo<'a>> {
128129
// TODO: fall back to locally cached package instance, or better yet, search for it
129130
// first.
130131
let package_id = PackageId::new(info.name, info.version, &source.id)?;
131132
debug!("(remote) package id: {:?}", package_id);
132133
let package = source.source.download(&package_id)?;
133134
let workspace = Workspace::ephemeral(package.clone(), config, None, false)?;
134135

135-
Ok(WorkInfo {
136-
package: package,
137-
workspace: workspace,
138-
})
136+
Ok(Self { package, workspace })
139137
}
140138

141139
/// Obtain the paths to the produced rlib and the dependency output directory.
142-
fn rlib_and_dep_output(&self, config: &'a Config, name: &str, current: bool)
143-
-> CargoResult<(PathBuf, PathBuf)>
144-
{
140+
fn rlib_and_dep_output(
141+
&self,
142+
config: &'a Config,
143+
name: &str,
144+
current: bool,
145+
) -> CargoResult<(PathBuf, PathBuf)> {
145146
let opts = CompileOptions::new(config, CompileMode::Build).unwrap();
146147

147148
if current {
@@ -161,7 +162,6 @@ impl<'a> WorkInfo<'a> {
161162

162163
Ok((rlib.1.clone(), compilation.deps_output))
163164
}
164-
165165
}
166166

167167
/// Perform the heavy lifting.
@@ -170,7 +170,6 @@ impl<'a> WorkInfo<'a> {
170170
/// and/or defaults, and dispatch the actual analysis.
171171
// TODO: possibly reduce the complexity by finding where some info can be taken from directly
172172
fn do_main(config: &Config, matches: &Matches, explain: bool) -> CargoResult<()> {
173-
debug!("running cargo-semver");
174173
fn parse_arg(opt: &str) -> CargoResult<NameAndVersion> {
175174
let mut split = opt.split(':');
176175
let name = if let Some(n) = split.next() {
@@ -188,9 +187,11 @@ fn do_main(config: &Config, matches: &Matches, explain: bool) -> CargoResult<()>
188187
return Err(Error("spec has to be of form `name:version`".to_owned()).into());
189188
}
190189

191-
Ok(NameAndVersion { name: name, version: version })
190+
Ok(NameAndVersion { name, version })
192191
}
193192

193+
debug!("running cargo-semver");
194+
194195
let mut source = SourceInfo::new(config)?;
195196

196197
let current = if let Some(opt) = matches.opt_str("C") {
@@ -214,7 +215,10 @@ fn do_main(config: &Config, matches: &Matches, explain: bool) -> CargoResult<()>
214215
(work_info, version)
215216
} else {
216217
let stable_crate = exact_search(&name)?;
217-
let info = NameAndVersion { name: &name, version: &stable_crate.max_version };
218+
let info = NameAndVersion {
219+
name: &name,
220+
version: &stable_crate.max_version,
221+
};
218222
let work_info = WorkInfo::remote(config, &mut source, &info)?;
219223

220224
(work_info, stable_crate.max_version.clone())
@@ -224,11 +228,13 @@ fn do_main(config: &Config, matches: &Matches, explain: bool) -> CargoResult<()>
224228
let (stable_rlib, stable_deps_output) = stable.rlib_and_dep_output(config, &name, false)?;
225229

226230
if matches.opt_present("d") {
227-
println!("--extern old={} -L{} --extern new={} -L{}",
228-
stable_rlib.display(),
229-
stable_deps_output.display(),
230-
current_rlib.display(),
231-
current_deps_output.display());
231+
println!(
232+
"--extern old={} -L{} --extern new={} -L{}",
233+
stable_rlib.display(),
234+
stable_deps_output.display(),
235+
current_rlib.display(),
236+
current_deps_output.display()
237+
);
232238
return Ok(());
233239
}
234240

@@ -250,10 +256,12 @@ fn do_main(config: &Config, matches: &Matches, explain: bool) -> CargoResult<()>
250256
if let Some(ref mut stdin) = child.stdin {
251257
// The order of the `extern crate` declaration is important here: it will later
252258
// be used to select the `old` and `new` crates.
253-
stdin.write_fmt(format_args!("#[allow(unused_extern_crates)] \
254-
extern crate old; \
255-
#[allow(unused_extern_crates)] \
256-
extern crate new;"))?;
259+
stdin.write_fmt(format_args!(
260+
"#[allow(unused_extern_crates)] \
261+
extern crate old; \
262+
#[allow(unused_extern_crates)] \
263+
extern crate new;"
264+
))?;
257265
} else {
258266
return Err(Error("could not pipe to rustc (wtf?)".to_owned()).into());
259267
}
@@ -296,12 +304,30 @@ fn main() {
296304
opts.optflag("V", "version", "print version information and exit");
297305
opts.optflag("e", "explain", "print detailed error explanations");
298306
opts.optflag("d", "debug", "print command to debug and exit");
299-
opts.optopt("s", "stable-path", "use local path as stable/old crate", "PATH");
300-
opts.optopt("c", "current-path", "use local path as current/new crate", "PATH");
301-
opts.optopt("S", "stable-pkg", "use a `name:version` string as stable/old crate",
302-
"NAME:VERSION");
303-
opts.optopt("C", "current-pkg", "use a `name:version` string as current/new crate",
304-
"NAME:VERSION");
307+
opts.optopt(
308+
"s",
309+
"stable-path",
310+
"use local path as stable/old crate",
311+
"PATH",
312+
);
313+
opts.optopt(
314+
"c",
315+
"current-path",
316+
"use local path as current/new crate",
317+
"PATH",
318+
);
319+
opts.optopt(
320+
"S",
321+
"stable-pkg",
322+
"use a `name:version` string as stable/old crate",
323+
"NAME:VERSION",
324+
);
325+
opts.optopt(
326+
"C",
327+
"current-pkg",
328+
"use a `name:version` string as current/new crate",
329+
"NAME:VERSION",
330+
);
305331

306332
let config = match Config::default() {
307333
Ok(cfg) => cfg,
@@ -323,15 +349,17 @@ fn main() {
323349
return;
324350
}
325351

326-
if (matches.opt_present("s") && matches.opt_present("S")) ||
327-
matches.opt_count("s") > 1 || matches.opt_count("S") > 1
352+
if (matches.opt_present("s") && matches.opt_present("S"))
353+
|| matches.opt_count("s") > 1
354+
|| matches.opt_count("S") > 1
328355
{
329356
let msg = "at most one of `-s,--stable-path` and `-S,--stable-pkg` allowed";
330357
err(&config, Error(msg.to_owned()).into());
331358
}
332359

333-
if (matches.opt_present("c") && matches.opt_present("C")) ||
334-
matches.opt_count("c") > 1 || matches.opt_count("C") > 1
360+
if (matches.opt_present("c") && matches.opt_present("C"))
361+
|| matches.opt_count("c") > 1
362+
|| matches.opt_count("C") > 1
335363
{
336364
let msg = "at most one of `-c,--current-path` and `-C,--current-pkg` allowed";
337365
err(&config, Error(msg.to_owned()).into());

0 commit comments

Comments
 (0)