forked from google/rust_icu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes broken test behaviors on old and new ICUs
With the following changes, we should be well positioned to tackle ICU 67.1 - ICU4C correctly implements language fallbacks starting version 67.1, added two flavors of the same test, one for ICU versions 67 and onwards, and another for older versions. Feature: `icu_version_67_plus`. This happens in issue google#59. - ICU4C version 63 has wrong result for a certain test, possibly due to the CLDR version on my machine, so test failed. Turned that test off for versions less than 64. This happens on my machine only, when the system ICU is used.
- Loading branch information
Showing
6 changed files
with
170 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#![feature(try_trait)] | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// See LICENSE for licensing information. | ||
// | ||
// This build.rs script tries to generate low-level rust bindings for the current ICU library. | ||
// Please refer to README.md for instructions on how to build the library for | ||
// your use. | ||
|
||
use { | ||
anyhow::{Context, Result}, | ||
std::process, | ||
}; | ||
|
||
/// A `Command` that also knows its name. | ||
struct Command { | ||
name: String, | ||
rep: process::Command, | ||
} | ||
|
||
impl Command { | ||
/// Creates a new command to run, with the executable `name`. | ||
pub fn new(name: &'static str) -> Self { | ||
let rep = process::Command::new(&name); | ||
let name = String::from(name); | ||
Command { name, rep } | ||
} | ||
|
||
/// Runs this command with `args` as arguments. | ||
pub fn run(&mut self, args: &[&str]) -> Result<String> { | ||
self.rep.args(args); | ||
let stdout = self.stdout()?; | ||
Ok(String::from(&stdout).trim().to_string()) | ||
} | ||
|
||
// Captures the stdout of the command. | ||
fn stdout(&mut self) -> Result<String> { | ||
let output = self | ||
.rep | ||
.output() | ||
.with_context(|| format!("could not execute command: {}", self.name))?; | ||
let result = String::from_utf8(output.stdout) | ||
.with_context(|| format!("could not convert output to UTF8"))?; | ||
Ok(result.trim().to_string()) | ||
} | ||
} | ||
|
||
/// A command representing an auto-configuration detector. Use `ICUConfig::new()` to create. | ||
struct ICUConfig { | ||
rep: Command, | ||
} | ||
|
||
impl ICUConfig { | ||
/// Creates a new ICUConfig. | ||
fn new() -> Self { | ||
ICUConfig { | ||
rep: Command::new("pkg-config"), | ||
} | ||
} | ||
/// Obtains the major-minor version number for the library. Returns a string like `64.2`. | ||
fn version(&mut self) -> Result<String> { | ||
self.rep | ||
.run(&["--modversion", "icu-i18n"]) | ||
.with_context(|| format!("while getting ICU version; is icu-config in $PATH?")) | ||
} | ||
|
||
/// Returns the config major number. For example, will return "64" for | ||
/// version "64.2" | ||
fn version_major() -> Result<String> { | ||
let version = ICUConfig::new().version()?; | ||
let components = version.split("."); | ||
let last = components | ||
.take(1) | ||
.last() | ||
.with_context(|| format!("could not parse version number: {}", version))?; | ||
Ok(last.to_string()) | ||
} | ||
|
||
fn version_major_int() -> Result<i32> { | ||
let version_str = ICUConfig::version_major()?; | ||
Ok(version_str.parse().unwrap()) | ||
} | ||
} | ||
|
||
fn main() -> Result<()> { | ||
std::env::set_var("RUST_BACKTRACE", "full"); | ||
let icu_major_version = ICUConfig::version_major_int()?; | ||
println!("icu-major-version: {}", icu_major_version); | ||
if icu_major_version >= 64 { | ||
println!("cargo:rustc-cfg=features=\"icu_version_64_plus\""); | ||
} | ||
if icu_major_version >= 67 { | ||
println!("cargo:rustc-cfg=features=\"icu_version_67_plus\""); | ||
} | ||
println!("done"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters