From 9321ae1323bbe782b68f03cd7479a3ac3b05b3a0 Mon Sep 17 00:00:00 2001 From: Jackie Ng Date: Sun, 24 Jun 2018 03:19:56 +1000 Subject: [PATCH] #29: Add scripts to bootstrap the internal tools. Modify SwigPrepare to just take the expected relative root to bake into the new file instead of trying to figure out how to compute relative paths in C++ --- README.md | 2 +- build.cmd | 7 +++--- build_tool.sh | 22 +++++++++++++++++ build_tools.cmd | 21 ++++++++++++++++ cmake_build.cmd | 7 +++--- envsetupsdk.cmd | 43 ++++++++++++++++++++------------- envsetupsdk.sh | 44 +++++++++++++++++++++------------- src/Tools/Common/helpers.h | 12 ++++++++++ src/Tools/SwigPrepare/main.cpp | 40 ++++++++++++++++++++++--------- 9 files changed, 146 insertions(+), 52 deletions(-) create mode 100644 build_tool.sh create mode 100644 build_tools.cmd diff --git a/README.md b/README.md index 2d1df0e..babd958 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ MapGuide API bindings to support the following languages/platforms: | Platform | Binding Notes | Windows (x86) | Windows (x64) | Linux (x86) | Linux (x64) | | -------- |:--------------------------------------------:| ------------- | ------------- | ----------- | ----------- | -| .net |[Binding Notes](src/Bindings/DotNet/README.md)| Supported | Supported | No (^1) | TBD (^2) | +| .net |[Binding Notes](src/Bindings/DotNet/README.md)| Supported | Supported | No (^1) | Yes (^2) | | PHP 7.1 |[Binding Notes](src/Bindings/Php/README.md) | TBD (^3) | Supported (^3)| TBD (^3) | TBD (^3) | | Java |[Binding Notes](src/Bindings/Java/README.md) | TBD | Supported | TBD | TBD | diff --git a/build.cmd b/build.cmd index f3ea8a4..5a82729 100644 --- a/build.cmd +++ b/build.cmd @@ -5,6 +5,7 @@ IF "%MG_VERSION%"=="3.1" SET MG_CONFIG=Release_VC14 IF "%MG_VERSION%"=="3.0" SET MG_CONFIG=Release_VC11 IF "%MG_VERSION%"=="2.6" SET MG_CONFIG=Release_VC11 SET PACKAGE_DIR=%CD%\packages +SET TOOLS_DIR=%CD%\tools echo Using configuration [%MG_CONFIG%] pushd src\Bindings msbuild /m /p:Configuration=%MG_CONFIG%;Platform=x86 Bindings.sln @@ -18,11 +19,9 @@ if errorlevel 1 goto error call dotnet pack --configuration Release --output "%PACKAGE_DIR%" if errorlevel 1 goto error popd -pushd src\Tools\PhpPostProcess echo Running PHP post-processor -call dotnet run "%PACKAGE_DIR%\php\Release\x86" -call dotnet run "%PACKAGE_DIR%\php\Release\x64" -popd +%TOOLS_DIR%\PhpPostProcess "%PACKAGE_DIR%\php\Release\x86\MapGuideApi.php" +%TOOLS_DIR%\PhpPostProcess "%PACKAGE_DIR%\php\Release\x64\MapGuideApi.php" echo Building Sample dataset pushd src\TestData\Samples\Sheboygan call build.bat diff --git a/build_tool.sh b/build_tool.sh new file mode 100644 index 0000000..c38ada1 --- /dev/null +++ b/build_tool.sh @@ -0,0 +1,22 @@ +#!/bin/sh +ROOT=$PWD +BUILD_AREA=/tmp/build/mapguide-api-bindings-tools +MG_TOOL_SRC_PATH=$ROOT/src/Tools +if [ ! -d "$BUILD_AREA" ]; then + mkdir -p "$BUILD_AREA" +fi +cd "$BUILD_AREA" +# Test for CMake +which cmake +if test "$?" -ne 0; then + echo "CMake not found. Cannot continue" + exit 1 +fi +cmake -DCMAKE_BUILD_TYPE=Release $MG_TOOL_SRC_PATH +if test "$?" -ne 0; then + exit 1 +fi +cmake --build . --config Release +if test "$?" -ne 0; then + exit 1 +fi diff --git a/build_tools.cmd b/build_tools.cmd new file mode 100644 index 0000000..bd5dc78 --- /dev/null +++ b/build_tools.cmd @@ -0,0 +1,21 @@ +@echo off +SET BUILD_AREA=%TEMP%\mapguide-api-bindings-tools +SET MG_TOOL_SRC_PATH=%CD%\src\Tools +if not exist "%BUILD_AREA%" mkdir "%BUILD_AREA%" +pushd "%BUILD_AREA%" +REM Test for CMake +which cmake +if %errorlevel% neq 0 ( + echo CMake not found + goto error +) +cmake -G "Visual Studio 14 2015" -DCMAKE_BUILD_TYPE=Release %MG_TOOL_SRC_PATH% +if %errorlevel% neq 0 goto error +cmake --build . --config Release +popd +goto end + +:error +echo An error occurred while building a component +popd +:end diff --git a/cmake_build.cmd b/cmake_build.cmd index 32d8ed8..e9e5916 100644 --- a/cmake_build.cmd +++ b/cmake_build.cmd @@ -15,6 +15,7 @@ SET WITH_JAVA=1 SET WITH_PHP=1 SET WITH_DOTNET=1 SET THIS_DIR=%CD% +SET TOOLS_DIR=%CD%\tools SET WORKING_DIR=%1 if "%WORKING_DIR%" == "" goto no_working_dir @@ -53,13 +54,11 @@ if "%WITH_DOTNET%" == "1" ( popd ) if "%WITH_PHP%" == "1" ( - pushd src\Tools\PhpPostProcess echo Running PHP post-processor - call dotnet run "%PACKAGE_DIR%\php\Release\x86" + %TOOLS_DIR%\PhpPostProcess "%PACKAGE_DIR%\php\Release\x86\MapGuideApi.php" if %errorlevel% neq 0 goto error - call dotnet run "%PACKAGE_DIR%\php\Release\x64" + %TOOLS_DIR%\PhpPostProcess "%PACKAGE_DIR%\php\Release\x64\MapGuideApi.php" if %errorlevel% neq 0 goto error - popd ) echo Building Sample dataset pushd src\TestData\Samples\Sheboygan diff --git a/envsetupsdk.cmd b/envsetupsdk.cmd index 6a0c22c..1c3ebb2 100644 --- a/envsetupsdk.cmd +++ b/envsetupsdk.cmd @@ -34,25 +34,36 @@ SET MG_SDK_INC=../../../%MG_SDK_DIR%/Inc SET MG_SDK_LIB=../../../%MG_SDK_DIR%/Lib SET MG_SDK_LIB64=../../../%MG_SDK_DIR%/Lib64 -REM restore nuget packages just in case -pushd src\Tools -call dotnet restore -popd +echo Checking for internal tools +which tools/SwigPrepare +if %errorlevel% neq 0 ( + echo One or more internal tools not found. Run build_tools.cmd + goto error +) +which tools/StampVer +if %errorlevel% neq 0 ( + echo One or more internal tools not found. Run build_tools.cmd + goto error +) +which tools/PhpPostProcess +if %errorlevel% neq 0 ( + echo One or more internal tools not found. Run build_tools.cmd + goto error +) -echo Preparing SWIG configurations -pushd src\Tools\SwigPrepare -call dotnet run ..\..\..\sdk\%MG_VERSION% ..\..\Bindings\MapGuideApi -popd +SET MG_INTERNAL_TOOL_PATH=%CD%\tools +echo Running SwigPrepare +%MG_INTERNAL_TOOL_PATH%\SwigPrepare "sdk\%MG_VERSION%" "../../../sdk/%MG_VERSION%" "src\Bindings\MapGuideApi" +if %errorlevel% neq 0 goto error echo Stamping version [%MG_VER_MAJOR%.%MG_VER_MINOR%.%MG_VER_REV%.%MG_VER_BUILD%] -pushd src\Tools\StampVer -call dotnet run ..\.. %MG_VER_MAJOR% %MG_VER_MINOR% %MG_VER_REV% %MG_VER_BUILD% -popd - -echo Regenerating Class Maps -pushd src\Tools\ClassMapGen -call dotnet run "%SRC_BASE%" -popd +%MG_INTERNAL_TOOL_PATH%\StampVer %MG_VER_MAJOR% %MG_VER_MINOR% %MG_VER_REV% %MG_VER_BUILD% "%CD%\src\Bindings\DotNet\MapGuideDotNetApi\Properties\AssemblyInfo.cs" "%CD%\src\Bindings\DotNet\MapGuideDotNetApi\MapGuideDotNetApi.csproj" +if %errorlevel% neq 0 goto error + +REM echo Regenerating Class Maps +REM pushd src\Tools\ClassMapGen +REM call dotnet run "%SRC_BASE%" +REM popd echo Preparing native binaries for nuget package copy /y "sdk\%MG_VERSION%\Bin\*.dll" "src\Bindings\DotNet\MapGuideDotNetApi\runtimes\win-x86\native" diff --git a/envsetupsdk.sh b/envsetupsdk.sh index e22f41a..4d809bb 100755 --- a/envsetupsdk.sh +++ b/envsetupsdk.sh @@ -79,6 +79,23 @@ install_swig() ./configure --prefix=${ROOT}/swig && make && make install } +echo "Checking for internal tools" +which tools/SwigPrepare +if test "$?" -ne 0; then + echo "One or more internal tools not found. Run build_tools.sh" + exit 1 +fi +which tools/StampVer +if test "$?" -ne 0; then + echo "One or more internal tools not found. Run build_tools.sh" + exit 1 +fi +which tools/PhpPostProcess +if test "$?" -ne 0; then + echo "One or more internal tools not found. Run build_tools.sh" + exit 1 +fi + if [ ! -d $ROOT/downloads ]; then echo "Creating download directory" mkdir -p $ROOT/downloads @@ -140,22 +157,17 @@ if [ `uname -m` = "x86_64" ] && [ "$USE_DOTNET" = "1" ]; then echo "[error]: Please install the .net Core SDK" exit 1 fi - - cd $ROOT/src/Tools - dotnet restore - if test "$?" -ne 0; then - exit 1 - fi - cd $ROOT/src/Tools/SwigPrepare - dotnet run ../../../sdk/$MG_VER_MAJOR.$MG_VER_MINOR ../../Bindings/MapGuideApi - if test "$?" -ne 0; then - exit 1 - fi - cd $ROOT/src/Tools/StampVer - dotnet run ../.. $MG_VER_MAJOR $MG_VER_MINOR $MG_VER_REV $MG_VER_BUILD - if test "$?" -ne 0; then - exit 1 - fi else echo "Skipping check for dotnet: Not a 64-bit OS" +fi + +echo "Running SwigPrepare" +./tools/SwigPrepare "sdk/$MG_VERSION" "../../../sdk/$MG_VERSION" "src/Bindings/MapGuideApi" +if test "$?" -ne 0; then + exit 1 +fi +echo "Stamping version [$MG_VER_MAJOR.$MG_VER_MINOR.$MG_VER_REV.$MG_VER_BUILD]" +./tools/StampVer $MG_VER_MAJOR $MG_VER_MINOR $MG_VER_REV $MG_VER_BUILD "$ROOT/src/Bindings/DotNet/MapGuideDotNetApi/Properties/AssemblyInfo.cs" "$ROOT/src/Bindings/DotNet/MapGuideDotNetApi/MapGuideDotNetApi.csproj" +if test "$?" -ne 0; then + exit 1 fi \ No newline at end of file diff --git a/src/Tools/Common/helpers.h b/src/Tools/Common/helpers.h index f4652df..8c573b6 100644 --- a/src/Tools/Common/helpers.h +++ b/src/Tools/Common/helpers.h @@ -162,4 +162,16 @@ bool read_all_text(const std::string& path, std::string& content) return false; } +std::string combine_paths(const std::string& basePath, const std::string& part) +{ + if (basePath[basePath.length() - 1] == '/' || basePath[basePath.length() - 1] == '\\') + { + return basePath + part; + } + else + { + return basePath + "/" + part; + } +} + #endif \ No newline at end of file diff --git a/src/Tools/SwigPrepare/main.cpp b/src/Tools/SwigPrepare/main.cpp index 7dd4a6c..d81a1da 100644 --- a/src/Tools/SwigPrepare/main.cpp +++ b/src/Tools/SwigPrepare/main.cpp @@ -3,14 +3,15 @@ int main(int argc, char **argv) { - if (argc != 3) + if (argc != 4) { - std::cout << "Usage: SwigPrepare [sdk path] [target dir]" << std::endl; + std::cout << "Usage: SwigPrepare [sdk path] [sdk rel path] [target dir]" << std::endl; return 1; } std::string sdkRoot = argv[1]; - std::string targetDir = argv[2]; + std::string sdkRelPath = argv[2]; + std::string targetDir = argv[3]; if (!directory_exists(sdkRoot)) { @@ -26,8 +27,8 @@ int main(int argc, char **argv) //Normalize on / as separator str_replace(sdkRoot, "\\", "/"); - std::string fConstants = sdkRoot + "SWIG/Constants.xml"; - std::string fMapGuideApiGen = sdkRoot + "SWIG/MapGuideApiGen.xml"; + std::string fConstants = combine_paths(sdkRoot, "SWIG/Constants.xml"); + std::string fMapGuideApiGen = combine_paths(sdkRoot, "SWIG/MapGuideApiGen.xml"); std::string sbConstants; if (!read_all_text(fConstants, sbConstants)) @@ -51,14 +52,31 @@ int main(int argc, char **argv) str_replace(sbMapGuideApiGen, "%include \"../WebApp", "//%include \"../WebApp"); str_replace(sbMapGuideApiGen, "%include \"../HttpHandler", "//%include \"../HttpHandler"); //Fix header relative paths - str_replace(sbMapGuideApiGen, "