Skip to content

Commit

Permalink
Merge pull request #10856 from rouault/more_optional_drivers
Browse files Browse the repository at this point in the history
Make all OGR drivers optional (but the Memory one)!
  • Loading branch information
rouault authored Sep 30, 2024
2 parents 67daebf + 283ef74 commit 092b1b3
Show file tree
Hide file tree
Showing 130 changed files with 3,410 additions and 3,074 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/cmake_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ jobs:
# Build PDF driver as plugin due to the PDFium build including libopenjp2 symbols which would conflict with external libopenjp2
run: |
mkdir -p $GITHUB_WORKSPACE/build
cmake -G "${generator}" -Werror=dev "-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install-gdal" "-DUSE_CCACHE=ON" "-DCMAKE_PREFIX_PATH=${CONDA}/envs/gdalenv" -DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD} -S "$GITHUB_WORKSPACE" -B "$GITHUB_WORKSPACE/build" -DGDAL_ENABLE_PLUGINS:BOOL=ON -DGDAL_ENABLE_PLUGINS_NO_DEPS:BOOL=ON -DGDAL_USE_PUBLICDECOMPWT:BOOL=ON -DPUBLICDECOMPWT_URL=https://github.com/rouault/PublicDecompWT -DBUILD_JAVA_BINDINGS=OFF -DBUILD_CSHARP_BINDINGS=ON -DGDAL_USE_MYSQL:BOOL=OFF -DCMAKE_C_FLAGS=" /WX" -DCMAKE_CXX_FLAGS=" /WX" -DWERROR_DEV_FLAG="-Werror=dev" -DCMAKE_BUILD_TYPE=Release -DPDFIUM_ROOT=$GITHUB_WORKSPACE/install-pdfium -DGDAL_ENABLE_DRIVER_PDF_PLUGIN:BOOL=ON -DCMAKE_UNITY_BUILD=ON
cmake -G "${generator}" -Werror=dev "-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install-gdal" "-DUSE_CCACHE=ON" "-DCMAKE_PREFIX_PATH=${CONDA}/envs/gdalenv" -DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD} -S "$GITHUB_WORKSPACE" -B "$GITHUB_WORKSPACE/build" -DGDAL_ENABLE_PLUGINS:BOOL=ON -DGDAL_ENABLE_PLUGINS_NO_DEPS:BOOL=ON -DGDAL_USE_PUBLICDECOMPWT:BOOL=ON -DPUBLICDECOMPWT_URL=https://github.com/rouault/PublicDecompWT -DBUILD_JAVA_BINDINGS=OFF -DBUILD_CSHARP_BINDINGS=ON -DGDAL_USE_MYSQL:BOOL=OFF -DCMAKE_C_FLAGS=" /WX" -DCMAKE_CXX_FLAGS=" /WX" -DWERROR_DEV_FLAG="-Werror=dev" -DCMAKE_BUILD_TYPE=Release -DPDFIUM_ROOT=$GITHUB_WORKSPACE/install-pdfium -DGDAL_ENABLE_DRIVER_PDF_PLUGIN:BOOL=ON -DCMAKE_UNITY_BUILD=ON -DOGR_ENABLE_DRIVER_TAB_PLUGIN=OFF
- name: Build
shell: bash -l {0}
run: cmake --build $GITHUB_WORKSPACE/build --config Release -j 2
Expand Down Expand Up @@ -546,6 +546,14 @@ jobs:
shell: bash -l {0}
run: cmake --build $GITHUB_WORKSPACE/build --config RelWithDebInfo -j 2

- name: Re-enable shapefile driver (otherwise lots of python tests would fail)
shell: bash -l {0}
run: |
cmake -S "$GITHUB_WORKSPACE" -B "$GITHUB_WORKSPACE/build" -DOGR_ENABLE_DRIVER_SHAPE=ON -DOGR_ENABLE_DRIVER_SHAPE_PLUGIN=ON
- name: Build
shell: bash -l {0}
run: cmake --build $GITHUB_WORKSPACE/build --config RelWithDebInfo -j 2

# Works around https://github.com/actions/runner-images/issues/10055
- name: Remove conflicting libraries
shell: bash -l {0}
Expand Down
2 changes: 0 additions & 2 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,6 @@ INPUT = port \
ogr \
ogr/ogrsf_frmts \
ogr/ogrsf_frmts/generic \
ogr/ogrsf_frmts/geojson/ogrgeojsonwriter.cpp \
ogr/ogrsf_frmts/kml/ogr2kmlgeometry.cpp \
swig/python/gdal-utils/scripts \
gnm \
doxygen_index.md
Expand Down
6 changes: 3 additions & 3 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ gdal_standard_includes(appslib)
target_compile_options(appslib PRIVATE ${GDAL_CXX_WARNING_FLAGS} ${WFLAG_OLD_STYLE_CAST} ${WFLAG_EFFCXX})
target_include_directories(
appslib PRIVATE $<TARGET_PROPERTY:gdal_vrt,SOURCE_DIR> $<TARGET_PROPERTY:ogrsf_generic,SOURCE_DIR>
$<TARGET_PROPERTY:ogr_geojson,SOURCE_DIR> $<TARGET_PROPERTY:ogr_MEM,SOURCE_DIR>)
$<TARGET_PROPERTY:ogr_MEM,SOURCE_DIR>)

gdal_target_link_libraries(appslib PRIVATE PROJ::proj)

Expand Down Expand Up @@ -132,7 +132,7 @@ if (BUILD_APPS)
add_dependencies(${UTILCMD} generate_gdal_version_h)
target_include_directories(
${UTILCMD} PRIVATE $<TARGET_PROPERTY:gdal_vrt,SOURCE_DIR> $<TARGET_PROPERTY:ogrsf_generic,SOURCE_DIR>
$<TARGET_PROPERTY:ogr_geojson,SOURCE_DIR> $<TARGET_PROPERTY:ogr_MEM,SOURCE_DIR>)
$<TARGET_PROPERTY:ogr_MEM,SOURCE_DIR>)
if (MSVC)
set_target_properties(${UTILCMD} PROPERTIES LINK_FLAGS "wsetargv.obj")
endif ()
Expand Down Expand Up @@ -200,7 +200,7 @@ if (BUILD_APPS)
endif ()
target_include_directories(
${UTILCMD} PRIVATE $<TARGET_PROPERTY:gdal_vrt,SOURCE_DIR> $<TARGET_PROPERTY:ogrsf_generic,SOURCE_DIR>
$<TARGET_PROPERTY:ogr_geojson,SOURCE_DIR> $<TARGET_PROPERTY:ogr_MEM,SOURCE_DIR>)
$<TARGET_PROPERTY:ogr_MEM,SOURCE_DIR>)
target_link_libraries(${UTILCMD} PRIVATE $<TARGET_NAME:${GDAL_LIB_TARGET_NAME}>)
endforeach ()
endif ()
Expand Down
3 changes: 2 additions & 1 deletion apps/gdalinfo_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
#include "ogr_api.h"
#include "ogr_srs_api.h"
#include "ogr_spatialref.h"
#include "ogrgeojsonreader.h"
#include "ogrlibjsonutils.h"
#include "ogrgeojsongeometry.h"
#include "ogrgeojsonwriter.h"

using std::vector;
Expand Down
2 changes: 1 addition & 1 deletion apps/ogrinfo_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#include "cpl_port.h"
#include "cpl_json.h"
#include "ogrgeojsonreader.h"
#include "ogrlibjsonutils.h"
#include "cpl_string.h"
#include "gdal_utils.h"
#include "gdal_utils_priv.h"
Expand Down
3 changes: 3 additions & 0 deletions autotest/alg/rasterize.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,9 @@ def test_rasterize_merge_alg_add_polygon(wkt):


###############################################################################


@pytest.mark.require_driver("GeoJSON")
def test_rasterize_bugfix_gh6981():

bad_geometry = {
Expand Down
15 changes: 6 additions & 9 deletions autotest/cpp/test_ogr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ namespace
// Common fixture with test data
struct test_ogr : public ::testing::Test
{
std::string drv_shape_{"ESRI Shapefile"};
std::string data_{tut::common::data_basedir};
std::string data_tmp_{tut::common::tmp_basedir};
};
Expand All @@ -62,14 +61,6 @@ TEST_F(test_ogr, GetGDALDriverManager)
ASSERT_TRUE(nullptr != GetGDALDriverManager());
}

// Test if Shapefile driver is registered
TEST_F(test_ogr, Shapefile_driver)
{
GDALDriver *drv =
GetGDALDriverManager()->GetDriverByName(drv_shape_.c_str());
ASSERT_TRUE(nullptr != drv);
}

template <class T>
void testSpatialReferenceLeakOnCopy(OGRSpatialReference *poSRS)
{
Expand Down Expand Up @@ -1333,6 +1324,12 @@ TEST_F(test_ogr, OGRToOGCGeomType)
// Test layer, dataset-feature and layer-feature iterators
TEST_F(test_ogr, DatasetFeature_and_LayerFeature_iterators)
{
if (!GDALGetDriverByName("ESRI Shapefile"))
{
GTEST_SKIP() << "ESRI Shapefile driver missing";
return;
}

std::string file(data_ + SEP + "poly.shp");
GDALDatasetUniquePtr poDS(GDALDataset::Open(file.c_str(), GDAL_OF_VECTOR));
ASSERT_TRUE(poDS != nullptr);
Expand Down
4 changes: 3 additions & 1 deletion autotest/cpp/test_ogr_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ struct test_ogr_shape : public ::testing::Test

void TearDown() override
{
if (!drv_)
return;
OGRDataSourceH ds =
OGR_Dr_CreateDataSource(drv_, data_tmp_.c_str(), nullptr);
if (ds == nullptr)
Expand Down Expand Up @@ -545,7 +547,7 @@ TEST_F(test_ogr_shape, spatial_filtering)
OGR_DS_Destroy(ds);
}

TEST(test_ogr_shape_gdal, create)
TEST_F(test_ogr_shape, create_gdal)
{
GDALDriver *shpDriver =
GetGDALDriverManager()->GetDriverByName("ESRI Shapefile");
Expand Down
3 changes: 3 additions & 0 deletions autotest/gcore/tiff_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ def test_tiff_read_stats_from_pam(tmp_path):
# Test extracting georeferencing from a .TAB file


@pytest.mark.require_driver("MapInfo File")
def test_tiff_read_from_tab(tmp_path):

ds = gdal.GetDriverByName("GTiff").Create(tmp_path / "tiff_read_from_tab.tif", 1, 1)
Expand Down Expand Up @@ -2822,6 +2823,7 @@ def test_tiff_read_one_strip_no_bytecount():
# Test GDAL_GEOREF_SOURCES


@pytest.mark.require_driver("MapInfo File")
@pytest.mark.parametrize(
"config_option_value,copy_pam,copy_worldfile,copy_tabfile,expected_srs,expected_gt",
[
Expand Down Expand Up @@ -3027,6 +3029,7 @@ def test_tiff_read_nogeoref(
# Test GDAL_GEOREF_SOURCES


@pytest.mark.require_driver("MapInfo File")
@pytest.mark.parametrize(
"config_option_value,copy_pam,copy_worldfile,copy_tabfile,expected_srs,expected_gt",
[
Expand Down
3 changes: 3 additions & 0 deletions autotest/gdrivers/nwt_grc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@


import gdaltest
import pytest

pytestmark = pytest.mark.require_driver("NWT_GRC")

###############################################################################
# Test a GRC dataset
Expand Down
10 changes: 10 additions & 0 deletions autotest/gdrivers/nwt_grd.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
import shutil

import gdaltest
import pytest

from osgeo import gdal

pytestmark = pytest.mark.require_driver("NWT_GRD")

###############################################################################
# Test a GRD dataset with three bands + Z

Expand All @@ -51,6 +54,13 @@ def test_nwt_grd_1():


def test_nwt_grd_2():

if (
gdal.GetDriverByName("NWT_GRD").GetMetadataItem(gdal.DMD_CREATIONDATATYPES)
is None
):
pytest.skip("NWT_GRD driver has no write support due to missing MITAB driver")

"""
Test writing a GRD via CreateCopy
"""
Expand Down
2 changes: 2 additions & 0 deletions autotest/ogr/ogr_basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,8 @@ def test_driver_open_throw_2():

with gdaltest.enable_exceptions():
drv = ogr.GetDriverByName("MapInfo File")
if not drv:
pytest.skip("MapInfo driver not available")

assert isinstance(drv, ogr.Driver)

Expand Down
1 change: 1 addition & 0 deletions autotest/ogr/ogr_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ def test_ogr_feature_GetFieldAsISO8601DateTime():
assert feature.GetFieldAsISO8601DateTime("field_datetime") == ""


@pytest.mark.require_driver("MapInfo File")
def test_ogr_feature_dump_readable():

ds = ogr.Open("data/mitab/single_point_mapinfo.tab")
Expand Down
2 changes: 2 additions & 0 deletions autotest/ogr/ogr_geojsonseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

from osgeo import gdal, ogr, osr

pytestmark = pytest.mark.require_driver("GeoJSONSeq")


def _ogr_geojsonseq_create(filename, lco, expect_rs):

Expand Down
2 changes: 2 additions & 0 deletions autotest/ogr/ogr_index_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

from osgeo import ogr

pytestmark = pytest.mark.require_driver("MapInfo File")

###############################################################################


Expand Down
4 changes: 4 additions & 0 deletions autotest/ogr/ogr_sql_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def test_ogr_sql_13(data_ds):
# Verify selection of, and on ogr_style and ogr_geom_wkt.


@pytest.mark.require_driver("MapInfo File")
def test_ogr_sql_14():

expect = [
Expand Down Expand Up @@ -452,6 +453,7 @@ def test_ogr_sql_15(data_ds):
###############################################################################


@pytest.mark.require_driver("MapInfo File")
def test_ogr_sql_16():

expect = [2]
Expand All @@ -465,6 +467,7 @@ def test_ogr_sql_16():
###############################################################################
# Test the RFC 21 CAST operator.
#
@pytest.mark.require_driver("MapInfo File")
def test_ogr_sql_17():

expect = ["1", "2"]
Expand Down Expand Up @@ -1285,6 +1288,7 @@ def test_ogr_sql_hstore_get_value_valid(data_ds, sql, expected):
# Test 64 bit GetFeatureCount()


@pytest.mark.require_driver("OGR_VRT")
def test_ogr_sql_45():

ds = ogr.Open(
Expand Down
2 changes: 2 additions & 0 deletions autotest/ogr/ogr_topojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

from osgeo import gdal, ogr

pytestmark = pytest.mark.require_driver("TopoJSON")

###############################################################################
# Test TopoJSON

Expand Down
1 change: 1 addition & 0 deletions autotest/pyscripts/test_gdal_polygonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def test_gdal_polygonize_4bis(script_path, tmp_path):
# Test -8


@pytest.mark.require_driver("GeoJSON")
def test_gdal_polygonize_minus_8(script_path, tmp_path):

outfilename = str(tmp_path / "out.geojson")
Expand Down
11 changes: 7 additions & 4 deletions autotest/pyscripts/test_ogrmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@

from osgeo import gdal, ogr

pytestmark = pytest.mark.skipif(
test_py_scripts.get_py_script("ogrmerge") is None,
reason="ogrmerge.py not available",
)
pytestmark = [
pytest.mark.require_driver("OGR_VRT"),
pytest.mark.skipif(
test_py_scripts.get_py_script("ogrmerge") is None,
reason="ogrmerge.py not available",
),
]


@pytest.fixture()
Expand Down
1 change: 1 addition & 0 deletions autotest/utilities/test_gdal_footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def gdal_footprint_path():
###############################################################################


@pytest.mark.require_driver("GeoJSON")
def test_gdal_footprint_basic(gdal_footprint_path, tmp_path):

footprint_json = str(tmp_path / "out_footprint.json")
Expand Down
2 changes: 2 additions & 0 deletions autotest/utilities/test_gdal_footprint_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def test_gdal_footprint_lib_destSRS():
#


@pytest.mark.require_driver("GeoJSON")
def test_gdal_footprint_lib_inline_geojson():

ret = gdal.Footprint("", "../gcore/data/byte.tif", format="GeoJSON")
Expand All @@ -134,6 +135,7 @@ def test_gdal_footprint_lib_inline_geojson():
#


@pytest.mark.require_driver("GeoJSON")
def test_gdal_footprint_lib_inline_wkt():

ret = gdal.Footprint("", "../gcore/data/byte.tif", format="WKT")
Expand Down
Loading

0 comments on commit 092b1b3

Please sign in to comment.