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

Add GDT_Int8, test GDAL 3.7 on CI and refactor workflow #412

Merged
merged 7 commits into from
Jun 1, 2023
Merged
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
197 changes: 26 additions & 171 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,135 +12,22 @@ env:
RUST_BACKTRACE: 1

jobs:
gdal_36:
name: "ci gdal-36"
runs-on: ubuntu-latest
container:
image: osgeo/gdal:ubuntu-full-3.6.0

strategy:
matrix:
features: ["", "--all-features"]

steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install build deps
shell: bash
run: |
apt-get update -y
apt-get install build-essential curl pkg-config libclang-dev -y
curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --profile minimal --default-toolchain none -y
echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH

- name: Setup building
run: |
export CC="clang-9"
export CXX="clang++-9"

- name: Install stable
run: |
rustup install --no-self-update --profile minimal stable
rustup component add rustfmt clippy

- name: Check with Rustfmt
run: cargo fmt --all --check
- name: Check with Clippy
run: cargo clippy --all-targets ${{ matrix.features }} -- -D warnings
- name: Build
run: cargo build ${{ matrix.features }} --verbose
- name: Run tests
run: cargo test ${{ matrix.features }} --verbose

gdal_35:
name: "ci gdal-35"
runs-on: ubuntu-latest
container:
image: osgeo/gdal:ubuntu-full-3.5.0

strategy:
matrix:
features: ["", "--all-features"]

steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install build deps
shell: bash
run: |
apt-get update -y
apt-get install build-essential curl pkg-config libclang-dev -y
curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --profile minimal --default-toolchain none -y
echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH

- name: Setup building
run: |
export CC="clang-9"
export CXX="clang++-9"

- name: Install stable
run: |
rustup install --no-self-update --profile minimal stable
rustup component add rustfmt clippy

- name: Check with Rustfmt
run: cargo fmt --all --check
- name: Check with Clippy
run: cargo clippy --all-targets ${{ matrix.features }} -- -D warnings
- name: Build
run: cargo build ${{ matrix.features }} --verbose
- name: Run tests
run: cargo test ${{ matrix.features }} --verbose

gdal_34:
name: "ci gdal-34"
runs-on: ubuntu-latest
container:
image: osgeo/gdal:ubuntu-full-3.4.0

gdal:
strategy:
matrix:
features: ["", "--all-features"]

steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install build deps
shell: bash
run: |
apt-get update -y
apt-get install build-essential curl pkg-config libclang-dev -y
curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --profile minimal --default-toolchain none -y
echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH

- name: Setup building
run: |
export CC="clang-9"
export CXX="clang++-9"
version:
- 3.7
- 3.6
- 3.5
- 3.4
- 3.3
- 3.2

- name: Install stable
run: |
rustup install --no-self-update --profile minimal stable
rustup component add rustfmt clippy

- name: Check with Rustfmt
run: cargo fmt --all --check
- name: Check with Clippy
run: cargo clippy --all-targets ${{ matrix.features }} -- -D warnings
- name: Build
run: cargo build ${{ matrix.features }} --verbose
- name: Run tests
run: cargo test ${{ matrix.features }} --verbose

gdal_33:
name: "ci gdal-33"
runs-on: ubuntu-latest
container:
image: osgeo/gdal:ubuntu-full-3.3.0
image: ghcr.io/osgeo/gdal:ubuntu-full-${{ matrix.version }}.0

strategy:
matrix:
features: ["", "--all-features"]
name: "ci gdal-${{ matrix.version }}"

steps:
- name: Checkout code
Expand All @@ -166,60 +53,22 @@ jobs:
- name: Check with Rustfmt
run: cargo fmt --all --check
- name: Check with Clippy
run: cargo clippy --all-targets ${{ matrix.features }} -- -D warnings
run: cargo clippy --all-targets -- -D warnings
- name: Check with Clippy (--all-features)
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Build
run: cargo build ${{ matrix.features }} --verbose
run: cargo build
- name: Run tests
run: cargo test ${{ matrix.features }} --verbose

gdal_32:
name: "ci gdal-32"
runs-on: ubuntu-latest
container:
image: osgeo/gdal:ubuntu-full-3.2.0

strategy:
matrix:
features: ["", "--all-features"]

steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install build deps
shell: bash
run: |
apt-get update -y
apt-get install build-essential curl pkg-config libclang-dev -y
curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --profile minimal --default-toolchain none -y
echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH

- name: Setup building
run: |
export CC="clang-9"
export CXX="clang++-9"

- name: Install stable
run: |
rustup install --no-self-update --profile minimal stable
rustup component add rustfmt clippy

- name: Check with Rustfmt
run: cargo fmt --all --check
- name: Check with Clippy
run: cargo clippy --all-targets ${{ matrix.features }} -- -D warnings
run: cargo test
- name: Build
run: cargo build ${{ matrix.features }} --verbose
run: cargo build --all-features
- name: Run tests
run: cargo test ${{ matrix.features }} --verbose
run: cargo test --all-features

ubuntu_lts:
name: "ci ubuntu-lts"
runs-on: "ubuntu-20.04"

strategy:
matrix:
features: ["", "--all-features"]

steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down Expand Up @@ -247,8 +96,14 @@ jobs:
- name: Check with Rustfmt
run: cargo fmt --all --check
- name: Check with Clippy
run: cargo clippy --all-targets ${{ matrix.features }} -- -D warnings
run: cargo clippy --all-targets -- -D warnings
- name: Check with Clippy (--all-features)
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Build
run: cargo build
- name: Run tests
run: cargo test
- name: Build
run: cargo build ${{ matrix.features }} --verbose
run: cargo build --all-features
- name: Run tests
run: cargo test ${{ matrix.features }} --verbose
run: cargo test --all-features
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Changes

## Unreleased
- Added `Dataset::close`, `Dataset::flush_cache` is now fallible
- Added `GDT_Int8` support

- <https://github.com/georust/gdal/pull/412>

- Added `Dataset::close`, changed `Dataset::flush_cache` to be fallible

- <https://github.com/georust/gdal/pull/410>

Expand Down
15 changes: 6 additions & 9 deletions bors.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
status = [
"ci gdal-35",
"ci gdal-35 (--all-features)",
"ci gdal-34",
"ci gdal-34 (--all-features)",
"ci gdal-33",
"ci gdal-33 (--all-features)",
"ci gdal-32",
"ci gdal-32 (--all-features)",
"ci gdal-3.7",
"ci gdal-3.6",
"ci gdal-3.5",
"ci gdal-3.4",
"ci gdal-3.3",
"ci gdal-3.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG ❤️

"ci ubuntu-lts",
"ci ubuntu-lts (--all-features)"
]
38 changes: 12 additions & 26 deletions src/raster/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ fn test_get_raster_size() {
assert_eq!(size_y, 50);
}

#[test]
fn test_get_raster_block_size() {
let band_index = 1;
let dataset = Dataset::open(fixture("tinymarble.png")).unwrap();
let rasterband = dataset.rasterband(band_index).unwrap();
let (size_x, size_y) = rasterband.block_size();
assert_eq!(size_x, 100);
assert_eq!(size_y, 1);
}

#[test]
fn test_get_raster_count() {
let dataset = Dataset::open(fixture("tinymarble.png")).unwrap();
Expand Down Expand Up @@ -386,20 +376,10 @@ fn test_read_block_dimension() {
let dataset = Dataset::open(fixture("tinymarble.png")).unwrap();
let rasterband = dataset.rasterband(band_index).unwrap();
let array = rasterband.read_block::<u8>(block).unwrap();
let dimension = (1, 100);
assert_eq!(array.dim(), dimension);
}

#[test]
#[cfg(feature = "ndarray")]
fn test_read_block_last_dimension() {
let band_index = 1;
let block = (0, 49);
let dataset = Dataset::open(fixture("tinymarble.png")).unwrap();
let rasterband = dataset.rasterband(band_index).unwrap();
let array = rasterband.read_block::<u8>(block).unwrap();
let dimension = (1, 100);
assert_eq!(array.dim(), dimension);
#[cfg(any(all(major_is_3, minor_ge_7), major_ge_4))]
assert_eq!(array.dim(), (50, 100));
#[cfg(not(any(all(major_is_3, minor_ge_7), major_ge_4)))]
assert_eq!(array.dim(), (1, 100));
}

#[test]
Expand Down Expand Up @@ -524,6 +504,9 @@ fn test_get_rasterband_block_size() {
let dataset = Dataset::open(fixture("tinymarble.png")).unwrap();
let rasterband = dataset.rasterband(1).unwrap();
let size = rasterband.block_size();
#[cfg(any(all(major_ge_3, minor_ge_7), major_ge_4))]
assert_eq!(size, (100, 50));
#[cfg(not(any(all(major_is_3, minor_ge_7), major_ge_4)))]
assert_eq!(size, (100, 1));
}

Expand All @@ -532,8 +515,11 @@ fn test_get_rasterband_block_size() {
fn test_get_rasterband_actual_block_size() {
let dataset = Dataset::open(fixture("tinymarble.png")).unwrap();
let rasterband = dataset.rasterband(1).unwrap();
let size = rasterband.actual_block_size((0, 40));
assert_eq!(size.unwrap(), (100, 1));
let size = rasterband.actual_block_size((0, 0)).unwrap();
#[cfg(any(all(major_ge_3, minor_ge_7), major_ge_4))]
assert_eq!(size, (100, 50));
#[cfg(not(any(all(major_is_3, minor_ge_7), major_ge_4)))]
assert_eq!(size, (100, 1));
}

#[test]
Expand Down
17 changes: 16 additions & 1 deletion src/raster/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub enum GdalDataType {
Unknown = GDALDataType::GDT_Unknown,
/// Eight bit unsigned integer
UInt8 = GDALDataType::GDT_Byte,
/// Eight bit signed integer
#[cfg(any(all(major_ge_3, minor_ge_7), major_ge_4))]
Int8 = GDALDataType::GDT_Int8,
/// Sixteen bit unsigned integer
UInt16 = GDALDataType::GDT_UInt16,
/// Sixteen bit signed integer
Expand Down Expand Up @@ -79,7 +82,6 @@ impl GdalDataType {
/// use gdal::raster::{GdalType, GdalDataType};
/// assert_eq!(GdalDataType::for_value(0), <u8>::datatype());
/// assert_eq!(GdalDataType::for_value(256), <u16>::datatype());
/// assert_eq!(GdalDataType::for_value(-1), <i16>::datatype());
/// assert_eq!(GdalDataType::for_value(<u16>::MAX as f64 * -2.0), <i32>::datatype());
/// ```
pub fn for_value<N: GdalType + Into<f64>>(value: N) -> Self {
Expand Down Expand Up @@ -265,6 +267,8 @@ impl TryFrom<u32> for GdalDataType {
match value {
GDT_Unknown => Ok(GdalDataType::Unknown),
GDT_Byte => Ok(GdalDataType::UInt8),
#[cfg(any(all(major_ge_3, minor_ge_7), major_ge_4))]
GDT_Int8 => Ok(GdalDataType::Int8),
GDT_UInt16 => Ok(GdalDataType::UInt16),
GDT_Int16 => Ok(GdalDataType::Int16),
GDT_UInt32 => Ok(GdalDataType::UInt32),
Expand Down Expand Up @@ -341,6 +345,14 @@ impl GdalType for u8 {
}
}

/// Provides evidence `i8` is a valid [`GDALDataType`].
#[cfg(any(all(major_ge_3, minor_ge_7), major_ge_4))]
impl GdalType for i8 {
fn gdal_ordinal() -> GDALDataType::Type {
GDALDataType::GDT_Int8
}
}

/// Provides evidence `u16` is a valid [`GDALDataType`].
impl GdalType for u16 {
fn gdal_ordinal() -> GDALDataType::Type {
Expand Down Expand Up @@ -498,6 +510,9 @@ mod tests {
fn test_for_value() {
assert_eq!(GdalDataType::for_value(0), <u8>::datatype());
assert_eq!(GdalDataType::for_value(256), <u16>::datatype());
#[cfg(any(all(major_ge_3, minor_ge_7), major_ge_4))]
assert_eq!(GdalDataType::for_value(-1), <i8>::datatype());
#[cfg(not(any(all(major_is_3, minor_ge_7), major_ge_4)))]
assert_eq!(GdalDataType::for_value(-1), <i16>::datatype());
assert_eq!(
GdalDataType::for_value(<u16>::MAX as f64 * -2.0),
Expand Down
6 changes: 3 additions & 3 deletions src/spatial_ref/srs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,11 @@ impl SpatialRef {
/// * `Ok(None)` - if node or attribute are not found (C library will return `nullptr`) or attribute contains no value,
/// * `Err(_)` - if there is a string conversion error.
///
/// # Panics
/// See: [`OSRGetProjParm`](https://gdal.org/api/ogr_srs_api.html#_CPPv415OSRGetAttrValue20OGRSpatialReferenceHPKci)
///
/// If `child` is greater than [`libc::c_int::MAX`].
/// # Panics
///
/// See: [`OSRGetProjParm`](https://gdal.org/api/ogr_srs_api.html#_CPPv415OSRGetAttrValue20OGRSpatialReferenceHPKci)
/// Panics if `child` is greater than [`libc::c_int::MAX`].
pub fn get_attr_value(&self, node_path: &str, child: usize) -> Result<Option<String>> {
assert!(
child <= libc::c_int::MAX as usize,
Expand Down