Integrate cargo fmt into make format

This commit is contained in:
Hui, Chunyang 2020-09-17 07:16:46 +00:00 committed by Tate, Hongliang Tian
parent 8fbd6295bf
commit e82b3dab92
12 changed files with 88 additions and 58 deletions

@ -1,7 +1,13 @@
#!/bin/bash #!/bin/bash
if ! hash astyle; then if ! hash astyle; then
echo "You do not have astyle installed so your code style is not being checked!" echo "Warning: \`astyle\` is not available."
exit 1
fi
cargo fmt --version >/dev/null 2>&1
if [[ $? != 0 ]]; then
echo "Warning: \`cargo fmt\` is not available."
exit 1 exit 1
fi fi
@ -15,23 +21,3 @@ if [ -n "$info" ]; then
echo echo
exit 1 exit 1
fi fi
cd src/libos
output=$(cargo fmt -- --check 2>&1)
retval=$?
if [[ $retval -eq 0 ]]
then
exit 0
elif [[ $retval -eq 1 ]]
then
echo "Rust format suggestsions (generated by \`cd src/libos && cargo fmt -- --check\`):"
echo
echo "$output"
echo
echo "To get rid of the format warnings above, run \`cargo fmt\` before the next commit."
exit 1
else
echo "Warning: \`cargo fmt\` is not available."
exit 1
fi

@ -24,31 +24,21 @@ if ! hash astyle; then
exit 0 exit 0
fi fi
cargo fmt --version >/dev/null 2>&1
if [[ $? != 0 ]]; then
echo "Warning: \`cargo fmt\` is not available."
exit 0
fi
info=$(make format-check) info=$(make format-check)
if [ -n "$info" ]; then if [ -n "$info" ]; then
echo "Format Error detected:" echo "Format Error detected:"
echo echo
echo "$info" echo "$info"
echo echo
echo "Please run \`make format\` before next commit." echo "To get rid of the format warnings above, please run \`make format\` before next commit."
echo echo
exit 1 exit 1
fi fi
cd src/libos
output=$(cargo fmt -- --check 2>&1)
retval=$?
# cargo fmt finds any format issues
if [[ $retval -eq 1 ]]
then
echo "Rust format suggestsions (generated by \`cd src/libos && cargo fmt -- --check\`):"
echo
echo "$output"
echo
echo "To get rid of the format warnings above, run \`cargo fmt\` before the next commit."
exit 1
fi
# If cargo fmt finds no format issues or carg fmt is not available on the # platform
exit 0 exit 0

@ -7,12 +7,16 @@ all:
@$(MAKE) --no-print-directory -C exec @$(MAKE) --no-print-directory -C exec
format: format:
@$(MAKE) --no-print-directory -C libos format
@$(MAKE) --no-print-directory -C pal format @$(MAKE) --no-print-directory -C pal format
@$(MAKE) --no-print-directory -C run format @$(MAKE) --no-print-directory -C run format
@$(MAKE) --no-print-directory -C exec format
format-check: format-check:
@$(MAKE) --no-print-directory -C libos format-check
@$(MAKE) --no-print-directory -C pal format-check @$(MAKE) --no-print-directory -C pal format-check
@$(MAKE) --no-print-directory -C run format-check @$(MAKE) --no-print-directory -C run format-check
@$(MAKE) --no-print-directory -C exec format-check
clean: clean:
@$(MAKE) --no-print-directory -C libos clean @$(MAKE) --no-print-directory -C libos clean

@ -17,6 +17,12 @@ else
@echo "CARGO (debug) => exec" @echo "CARGO (debug) => exec"
endif endif
format: $(SRC_FILES)
@$(call format-rust)
format-check: $(SRC_FILES)
@$(call format-check-rust)
clean: clean:
@cargo clean --target-dir=$(RUST_TARGET_DIR) @cargo clean --target-dir=$(RUST_TARGET_DIR)
@-$(RM) -f $(EXEC_TARGET) @-$(RM) -f $(EXEC_TARGET)

@ -27,8 +27,8 @@ use signal_hook::iterator::Signals;
use signal_hook::{SIGINT, SIGKILL, SIGQUIT, SIGTERM, SIGUSR1}; use signal_hook::{SIGINT, SIGKILL, SIGQUIT, SIGTERM, SIGUSR1};
use std::cmp; use std::cmp;
use std::env; use std::env;
use std::path::Path;
use std::os::unix::net::UnixListener; use std::os::unix::net::UnixListener;
use std::path::Path;
use std::process; use std::process;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@ -309,7 +309,11 @@ fn main() -> Result<(), i32> {
let cmd = cmd_args[0]; let cmd = cmd_args[0];
// Change cmd_args[0] from path name to program name // Change cmd_args[0] from path name to program name
cmd_args[0] = Path::new(cmd_args[0]).file_name().unwrap().to_str().unwrap(); cmd_args[0] = Path::new(cmd_args[0])
.file_name()
.unwrap()
.to_str()
.unwrap();
let env: Vec<&str> = env.iter().map(|string| string.as_str()).collect(); let env: Vec<&str> = env.iter().map(|string| string.as_str()).collect();
// Create the signal handler // Create the signal handler

@ -214,7 +214,8 @@ impl OcclumExec for OcclumExecImpl {
"process:{} finished, send signal to {}", "process:{} finished, send signal to {}",
process_id, client_process_id process_id, client_process_id
); );
signal::kill(Pid::from_raw(client_process_id as i32), Signal::SIGUSR1).unwrap_or_default(); signal::kill(Pid::from_raw(client_process_id as i32), Signal::SIGUSR1)
.unwrap_or_default();
}); });
resp.finish(ExecCommResponse { resp.finish(ExecCommResponse {

@ -88,7 +88,7 @@ _Other_Link_Flags := -L$(RUST_SGX_SDK_DIR)/compiler-rt/ -L$(BUILD_DIR)/lib -L$(R
_Other_Enclave_Libs := -l$(LIBOS_CORE_LIB_NAME) -lsgx_tprotected_fs _Other_Enclave_Libs := -l$(LIBOS_CORE_LIB_NAME) -lsgx_tprotected_fs
LINK_FLAGS := $(SGX_LFLAGS_T) LINK_FLAGS := $(SGX_LFLAGS_T)
.PHONY: all clean .PHONY: all clean format format-c format-rust format-check format-check-c format-check-rust
all: $(ALL_BUILD_SUBDIRS) $(LIBOS_SO_REAL) all: $(ALL_BUILD_SUBDIRS) $(LIBOS_SO_REAL)
@ -136,6 +136,22 @@ $(S_OBJS):$(OBJ_DIR)/libos/$(SRC_OBJ)/%.o: src/%.S
@$(CC) $(C_FLAGS) -c $< -o $@ @$(CC) $(C_FLAGS) -c $< -o $@
@echo "AS <= $@" @echo "AS <= $@"
format: format-c format-rust
format-c: $(C_SRCS) $(CXX_SRCS)
@$(C_FORMATTER) $^
format-rust: $(RUST_SRCS)
@$(call format-rust)
format-check: format-check-c format-check-rust
format-check-c: $(C_SRCS) $(CXX_SRCS)
@$(C_FORMATTER) --check $^
format-check-rust: $(RUST_SRCS)
@$(call format-check-rust)
clean: clean:
@-$(RM) -rf $(OBJ_DIR)/libos @-$(RM) -rf $(OBJ_DIR)/libos
@-$(RM) -f $(LIBOS_SO_REAL) @-$(RM) -f $(LIBOS_SO_REAL)

@ -2,8 +2,7 @@
#include "task.h" #include "task.h"
/* See /<path-to-linux-sgx>/common/inc/internal/thread_data.h */ /* See /<path-to-linux-sgx>/common/inc/internal/thread_data.h */
typedef struct _thread_data_t typedef struct _thread_data_t {
{
uint64_t reserved1[2]; uint64_t reserved1[2];
uint64_t stack_base_addr; uint64_t stack_base_addr;
uint64_t stack_limit_addr; uint64_t stack_limit_addr;

@ -13,6 +13,15 @@ PATCH_VER_NUM = $(shell grep '\#define OCCLUM_PATCH_VERSION' $(PROJECT_DIR)/src/
VERSION_NUM = $(MAJOR_VER_NUM).$(MINOR_VER_NUM).$(PATCH_VER_NUM) VERSION_NUM = $(MAJOR_VER_NUM).$(MINOR_VER_NUM).$(PATCH_VER_NUM)
C_FORMATTER := $(PROJECT_DIR)/tools/c_formatter C_FORMATTER := $(PROJECT_DIR)/tools/c_formatter
# Use echo program instead of built-in echo command in shell. This ensures
# that echo can recognize escaped sequences (with -e argument) regardless of
# the specific shell (e.g., bash, zash, etc.)
ECHO := /bin/echo -e
# Shell escaped sequences for colorful output
CYAN := \033[1;36m
GREEN := \033[1;32m
RED := \033[1;31m
NO_COLOR := \033[0m
# Save code and object file generated during building src # Save code and object file generated during building src
OBJ_DIR := $(PROJECT_DIR)/build/internal/src OBJ_DIR := $(PROJECT_DIR)/build/internal/src
@ -127,3 +136,18 @@ SGX_LFLAGS_T = $(SGX_COMMON_CFLAGS) -nostdlib -L$(SGX_LIBRARY_PATH) $(_Other_Lin
-Wl,--defsym,__ImageBase=0 \ -Wl,--defsym,__ImageBase=0 \
-Wl,--gc-sections \ -Wl,--gc-sections \
-Wl,--version-script=Enclave.lds -Wl,--version-script=Enclave.lds
define format-rust
output=$$(cargo fmt -- --check 2>&1); retval=$$?; \
if [[ $$retval -eq 1 ]]; then \
$(ECHO) "$$output"; cargo fmt; $(ECHO) "$(GREEN)\nRust code format corrected.$(NO_COLOR)"; \
fi
endef
define format-check-rust
output=$$(cargo fmt -- --check 2>&1); retval=$$?; \
if [[ $$retval -eq 1 ]]; then \
$(ECHO) "$(RED)\nSome format issues of Rust code are detected:$(NO_COLOR)"; $(ECHO) "\n$$output"; \
$(ECHO) "\nTo get rid of the format warnings above, run $(CYAN)"make format"$(NO_COLOR) to correct"; \
fi
endef