Merge pull request #99 from cblichmann:01jsonnet-fetchcontent

PiperOrigin-RevId: 424608038
Change-Id: I55241ae066ae339cf948d9c0fce2746bcf4c9482
This commit is contained in:
Copybara-Service 2022-01-27 07:39:08 -08:00
commit 5c7226ced2
6 changed files with 36 additions and 39 deletions

3
.gitmodules vendored
View File

@ -1,9 +1,6 @@
[submodule "oss-internship-2020/sapi_lodepng/lodepng"] [submodule "oss-internship-2020/sapi_lodepng/lodepng"]
path = oss-internship-2020/lodepng/lodepng path = oss-internship-2020/lodepng/lodepng
url = https://github.com/lvandeve/lodepng url = https://github.com/lvandeve/lodepng
[submodule "oss-internship-2020/jsonnet/jsonnet"]
path = oss-internship-2020/jsonnet/jsonnet
url = https://github.com/google/jsonnet.git
[submodule "oss-internship-2020/openjpeg/openjpeg"] [submodule "oss-internship-2020/openjpeg/openjpeg"]
path = oss-internship-2020/openjpeg/openjpeg path = oss-internship-2020/openjpeg/openjpeg
url = https://github.com/uclouvain/openjpeg.git url = https://github.com/uclouvain/openjpeg.git

View File

@ -12,25 +12,29 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.13..3.22)
project(jsonnet-sapi C CXX) project(jsonnet-sapi C CXX)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_CXX_STANDARD_REQUIRED True)
add_subdirectory(jsonnet)
add_subdirectory(examples)
set(SAPI_ROOT "../.." CACHE PATH "Path to the Sandboxed API source tree") set(SAPI_ROOT "../.." CACHE PATH "Path to the Sandboxed API source tree")
set(SAPI_ENABLE_EXAMPLES OFF CACHE BOOL "")
set(SAPI_ENABLE_TESTS OFF CACHE BOOL "")
add_subdirectory("${SAPI_ROOT}" add_subdirectory("${SAPI_ROOT}"
"${CMAKE_BINARY_DIR}/sandboxed-api-build" "${CMAKE_BINARY_DIR}/sandboxed-api-build"
EXCLUDE_FROM_ALL) EXCLUDE_FROM_ALL)
FetchContent_Declare(jsonnet
GIT_REPOSITORY https://github.com/google/jsonnet.git
GIT_TAG v0.18.0 # 2021-12-21
)
set(BUILD_TESTS OFF)
FetchContent_MakeAvailable(jsonnet)
create_directory_symlink("${jsonnet_SOURCE_DIR}"
"${PROJECT_BINARY_DIR}/jsonnet")
add_subdirectory(examples)
add_sapi_library(jsonnet_sapi add_sapi_library(jsonnet_sapi
FUNCTIONS c_free_input FUNCTIONS c_free_input
c_jsonnet_destroy c_jsonnet_destroy
@ -56,4 +60,9 @@ target_include_directories(jsonnet_sapi INTERFACE
target_link_libraries(jsonnet_sapi PUBLIC jsonnet_helper) target_link_libraries(jsonnet_sapi PUBLIC jsonnet_helper)
add_subdirectory(tests) if(SAPI_ENABLE_TESTS)
include(GoogleTest)
enable_testing()
add_subdirectory(tests)
endif()

View File

@ -1,6 +1,6 @@
# Jsonnet Sandboxed API # Jsonnet Sandboxed API
This library provides sandboxed version of the This library provides a sandboxed version of the
[Jsonnet](https://github.com/google/jsonnet) library. [Jsonnet](https://github.com/google/jsonnet) library.
## Examples ## Examples
@ -22,18 +22,12 @@ canonical form.
## Build ## Build
To build these examples, after cloning the whole Sandbox API project, you also To build these examples, after cloning the whole Sandbox API project, this
need to run in the `sandboxed-api/oss-internship-2020/jsonnet`:
``` ```
git submodule update --init --recursive mkdir -p build && cd build
``` cmake .. -G Ninja -Wno-dev -DSAPI_ENABLE_TESTS=ON
anywhere in the project tree in order to clone the `jsonnet` submodule.
Then in the `sandboxed-api/oss-internship-2020/jsonnet` run
```
mkdir build && cd build
cmake -G Ninja
ninja ninja
``` ```
@ -79,6 +73,5 @@ A few tests prepared with a use of
the `tests/` directory. To run them type: the `tests/` directory. To run them type:
``` ```
cd tests ctest ./tests
./tests
``` ```

View File

@ -13,7 +13,7 @@
# limitations under the License. # limitations under the License.
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/gen_files") file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/gen_files")
file(COPY "${PROJECT_SOURCE_DIR}/jsonnet/cmd/jsonnet.cpp" DESTINATION "${PROJECT_BINARY_DIR}/gen_files/") file(COPY "${jsonnet_SOURCE_DIR}/cmd/jsonnet.cpp" DESTINATION "${PROJECT_BINARY_DIR}/gen_files/")
file(COPY "${PROJECT_SOURCE_DIR}/jsonnet.patch" DESTINATION "${PROJECT_BINARY_DIR}/gen_files/") file(COPY "${PROJECT_SOURCE_DIR}/jsonnet.patch" DESTINATION "${PROJECT_BINARY_DIR}/gen_files/")
add_custom_command( add_custom_command(
@ -22,34 +22,35 @@ add_custom_command(
COMMAND mv ${PROJECT_BINARY_DIR}/gen_files/jsonnet.cpp ${PROJECT_BINARY_DIR}/gen_files/write_helper.cc COMMAND mv ${PROJECT_BINARY_DIR}/gen_files/jsonnet.cpp ${PROJECT_BINARY_DIR}/gen_files/write_helper.cc
) )
list(APPEND JSONNET_SAPI_HEADERS list(APPEND JSONNET_SAPI_INCLUDE_DIRS
${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/headers ${PROJECT_SOURCE_DIR}/headers
${PROJECT_BINARY_DIR}
${PROJECT_BINARY_DIR}/gen_files ${PROJECT_BINARY_DIR}/gen_files
) )
add_library(jsonnet_helper STATIC add_library(jsonnet_helper STATIC
${PROJECT_SOURCE_DIR}/jsonnet_helper.cc ${PROJECT_SOURCE_DIR}/jsonnet_helper.cc
${PROJECT_SOURCE_DIR}/jsonnet_helper.h ${PROJECT_SOURCE_DIR}/jsonnet_helper.h
${PROJECT_SOURCE_DIR}/jsonnet/cmd/utils.h ${jsonnet_SOURCE_DIR}/cmd/utils.h
${PROJECT_SOURCE_DIR}/jsonnet/cmd/utils.cpp ${jsonnet_SOURCE_DIR}/cmd/utils.cpp
${PROJECT_BINARY_DIR}/gen_files/write_helper.cc ${PROJECT_BINARY_DIR}/gen_files/write_helper.cc
) )
target_include_directories(jsonnet_helper PUBLIC target_include_directories(jsonnet_helper PUBLIC
${JSONNET_SAPI_HEADERS} ${JSONNET_SAPI_INCLUDE_DIRS}
) )
target_link_libraries(jsonnet_helper target_link_libraries(jsonnet_helper
libjsonnet_for_binaries libjsonnet_for_binaries
) )
foreach(exe base multiple_files yaml_stream formatter) foreach(target IN ITEMS base multiple_files yaml_stream formatter)
add_executable(jsonnet_${exe}_sandboxed add_executable(jsonnet_${target}_sandboxed
jsonnet_${exe}_example.cc jsonnet_${target}_example.cc
) )
target_link_libraries(jsonnet_${exe}_sandboxed PRIVATE target_link_libraries(jsonnet_${target}_sandboxed PRIVATE
libjsonnet libjsonnet
jsonnet_helper jsonnet_helper
jsonnet_sapi jsonnet_sapi
@ -58,8 +59,8 @@ foreach(exe base multiple_files yaml_stream formatter)
sapi::sapi sapi::sapi
) )
target_include_directories(jsonnet_${exe}_sandboxed PUBLIC target_include_directories(jsonnet_${target}_sandboxed PUBLIC
${JSONNET_SAPI_HEADERS} ${JSONNET_SAPI_INCLUDE_DIRS}
) )
endforeach() endforeach()

@ -1 +0,0 @@
Subproject commit 3e25595d5c4acd32a1c3951a57471986b90d3bad

View File

@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
include(GoogleTest)
# We need to prepare convenient directories so the tests will be able to access them # We need to prepare convenient directories so the tests will be able to access them
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/tests/tests_input) file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/tests/tests_input)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/tests/tests_output) file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/tests/tests_output)