Skip to content

Commit

Permalink
#29: Add scripts to bootstrap the internal tools. Modify SwigPrepare …
Browse files Browse the repository at this point in the history
…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++
  • Loading branch information
jumpinjackie committed Jun 23, 2018
1 parent 541d2fe commit 9321ae1
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 52 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
7 changes: 3 additions & 4 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions build_tool.sh
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions build_tools.cmd
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions cmake_build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
43 changes: 27 additions & 16 deletions envsetupsdk.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
44 changes: 28 additions & 16 deletions envsetupsdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
12 changes: 12 additions & 0 deletions src/Tools/Common/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 29 additions & 11 deletions src/Tools/SwigPrepare/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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))
Expand All @@ -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, "<Header path=\"../../../Common", "<Header path=\"" + sdkRoot + "/Inc/Common");
str_replace(sbMapGuideApiGen, "<Header path=\"../WebApp", "<Header path=\"" + sdkRoot + "/Inc/Web/WebApp");
str_replace(sbMapGuideApiGen, "<Header path=\"../HttpHandler", "<Header path=\"" + sdkRoot + "/Inc/Web/HttpHandler");
str_replace(sbMapGuideApiGen, "<Header path=\"../../../Common", "<Header path=\"" + sdkRelPath + "/Inc/Common");
str_replace(sbMapGuideApiGen, "<Header path=\"../WebApp", "<Header path=\"" + sdkRelPath + "/Inc/Web/WebApp");
str_replace(sbMapGuideApiGen, "<Header path=\"../HttpHandler", "<Header path=\"" + sdkRelPath + "/Inc/Web/HttpHandler");
//#elseif must've been valid in our custom version of SWIG we're using. Not here
str_replace(sbMapGuideApiGen, "#elseif", "#elif");

//Fix header relative paths
str_replace(sbConstants, "<Header path=\"../../../Common", "<Header path=\"" + sdkRoot + "/Inc/Common");
str_replace(sbConstants, "<Header path=\"../WebApp", "<Header path=\"" + sdkRoot + "/Inc/Web/WebApp");
str_replace(sbConstants, "<Header path=\"../HttpHandler", "<Header path=\"" + sdkRoot + "/Inc/Web/HttpHandler");
str_replace(sbConstants, "<Header path=\"../../../Common", "<Header path=\"" + sdkRelPath + "/Inc/Common");
str_replace(sbConstants, "<Header path=\"../WebApp", "<Header path=\"" + sdkRelPath + "/Inc/Web/WebApp");
str_replace(sbConstants, "<Header path=\"../HttpHandler", "<Header path=\"" + sdkRelPath + "/Inc/Web/HttpHandler");

std::string outConstants = combine_paths(targetDir, "Constants.xml");
std::string outMapGuideApiGen = combine_paths(targetDir, "MapGuideApiGen.xml");

if (!write_all_text(outConstants, sbConstants))
{
std::cout << "Failed to write Constants.xml" << std::endl;
return 1;
}
std::cout << "Wrote: " << outConstants << std::endl;
if (!write_all_text(outMapGuideApiGen, sbMapGuideApiGen))
{
std::cout << "Failed to write MapGuideApiGen.xml" << std::endl;
return 1;
}
std::cout << "Wrote: " << outMapGuideApiGen << std::endl;
return 0;
}

0 comments on commit 9321ae1

Please sign in to comment.