-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Formatting: JsThemis native extension (#412)
* Formatting: JsThemis native extension Add native extension of JsThemis to "make fmt" target group. This requires quite a bit of effort because clang-tidy insists on having access to *all* source code involved in complation, including all those NodeJS headers and its modules. First of all, we have to add some hardcoded paths to NodeJS headers. I have not found a proper way to get these paths so we just hardcode them and hope that this is fine. Then we need to have <nan.h> header file for which we have to install the nan module. We do a little hack to achieve that, pretending to 'format' the installation path for Node modules. * Add NodeJS to format checking image Install npm and nodejs as we need them for checking JsThemis native source code. At least for now. * Add a warning if NodeJS is not installed Print out a warning when formatting files if NodeJS is not installed and we are not able to reformat JsThemis files. * Add symlink to jsthemis.mk for Rust's libthemis-src The current build system for libthemis-src is quite messed up and requires peculiar symlinking to work. Add a symlink for the new file included from the main Makefile.
- Loading branch information
1 parent
969998f
commit 4d11421
Showing
22 changed files
with
1,487 additions
and
1,027 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# | ||
# Copyright (c) 2019 Cossack Labs Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
JSTHEMIS_SRC = $(SRC_PATH)/wrappers/themis/jsthemis | ||
JSTHEMIS_OBJ = $(OBJ_PATH)/wrappers/themis/jsthemis | ||
|
||
JSTHEMIS_SOURCES = $(wildcard $(JSTHEMIS_SRC)/*.cpp) | ||
JSTHEMIS_HEADERS = $(wildcard $(JSTHEMIS_SRC)/*.hpp) | ||
|
||
# Unfortunately, clang-tidy requires full compilation flags to be able to work and | ||
# node-gyp add quite a few custom flags with include search paths. It also requires | ||
# some Node modules for compilation. We recreate the same environment here as for | ||
# the "jsthemis_install" target. However, we can't do that without NPM present. | ||
# Therefore we format JsThemis code only if NodeJS is actually installed. | ||
ifdef NPM_VERSION | ||
|
||
# A hack to install "nan" before formatting any JsThemis files | ||
FMT_FIXUP += $(JSTHEMIS_OBJ)/node_modules/nan | ||
FMT_CHECK += $(JSTHEMIS_OBJ)/node_modules/nan | ||
|
||
$(JSTHEMIS_OBJ)/node_modules/nan: | ||
@mkdir -p $(JSTHEMIS_OBJ) && cd $(JSTHEMIS_OBJ) && npm install nan && cd - | ||
|
||
FMT_FIXUP += $(patsubst $(SRC_PATH)/%,$(OBJ_PATH)/%.fmt_fixup,$(JSTHEMIS_SOURCES) $(JSTHEMIS_HEADERS)) | ||
FMT_CHECK += $(patsubst $(SRC_PATH)/%,$(OBJ_PATH)/%.fmt_check,$(JSTHEMIS_SOURCES) $(JSTHEMIS_HEADERS)) | ||
|
||
JSTHEMIS_CFLAGS += $(CFLAGS) | ||
JSTHEMIS_CFLAGS += -I$(JSTHEMIS_OBJ)/node_modules/nan | ||
|
||
ifdef IS_LINUX | ||
JSTHEMIS_CFLAGS += -I/usr/include/nodejs/src | ||
JSTHEMIS_CFLAGS += -I/usr/include/nodejs/deps/v8/include | ||
endif | ||
|
||
$(JSTHEMIS_OBJ)/%.hpp.fmt_fixup $(JSTHEMIS_OBJ)/%.cpp.fmt_fixup: \ | ||
CMD = $(CLANG_TIDY) -fix $< -- $(JSTHEMIS_CFLAGS) 2>/dev/null && $(CLANG_FORMAT) -i $< && touch $@ | ||
|
||
$(JSTHEMIS_OBJ)/%.hpp.fmt_check $(JSTHEMIS_OBJ)/%.cpp.fmt_check: \ | ||
CMD = $(CLANG_FORMAT) $< | diff -u $< - && $(CLANG_TIDY) $< -- $(JSTHEMIS_CFLAGS) 2>/dev/null && touch $@ | ||
|
||
else # ifdef NPM_VERSION | ||
|
||
FMT_FIXUP += $(JSTHEMIS_OBJ)/warning_fixup | ||
FMT_CHECK += $(JSTHEMIS_OBJ)/warning_check | ||
|
||
$(JSTHEMIS_OBJ)/warning_fixup: | ||
$(warning NodeJS not installed, JsThemis code will not be formatted) | ||
|
||
$(JSTHEMIS_OBJ)/warning_check: | ||
$(warning NodeJS not installed, JsThemis code will not be checked) | ||
|
||
endif # ifdef NPM_VERSION |
Oops, something went wrong.