diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..8f96bf79d --- /dev/null +++ b/.clang-format @@ -0,0 +1,89 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: false +AlignOperands: false +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 8 +ContinuationIndentWidth: 8 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IndentCaseLabels: false +IndentWidth: 8 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: false +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 8 +UseTab: ForContinuationAndIndentation +... diff --git a/hypervisor/scripts/genconf.sh b/hypervisor/scripts/genconf.sh index f19642816..6c8847d7e 100644 --- a/hypervisor/scripts/genconf.sh +++ b/hypervisor/scripts/genconf.sh @@ -6,6 +6,9 @@ base_dir=$1 board_xml=$2 scenario_xml=$3 out=$4 +unified_xml=$5 +scenario=$(xmllint --xpath "string(//@scenario)" --xinclude $unified_xml) +year=$(date +'%Y') apply_patch () { echo "Applying patch ${1}:" @@ -26,6 +29,37 @@ if [ $? -ne 0 ]; then exit $? fi +if ! which xsltproc ; then + echo "xsltproc cannot be found, please install it and make sure it is in your PATH." + exit 1 +fi + +transform() { + echo "Generating ${1}:" + xsltproc -o ${out}/scenarios/${scenario}/${1} --xinclude --xincludestyle ${tool_dir}/xforms/${1}.xsl ${unified_xml} + if [ $? -ne 0 ]; then + echo "Failed to generate ${1} with xsltproc!" + exit 1 + fi + sed -i -e "s/YEAR/$year/" ${out}/scenarios/${scenario}/${1} + echo "${1} was generated using xsltproc succesfully." +} + +transform vm_configurations.c +transform vm_configurations.h +transform pt_intx.c +transform ivshmem_cfg.h +transform misc_cfg.h + +if which clang-format ; then + find ${out}/scenarios/${scenario} -iname *.h -o -iname *.c \ + | xargs clang-format --style=file -i --fallback-style=none +else + echo "clang-format cannot be found. The generated files under ${out}/scenarios/${scenario} are not formatted." + echo "clang-format is a tool to format the C code automatically and improve the code readibility." + echo "Please install clang-format and format the generated files if those need to be included and reviewed." +fi + if [ -f ${diffconfig_list} ]; then cd ${out} && cat ${diffconfig_list} | while read line; do diff --git a/hypervisor/scripts/makefile/config.mk b/hypervisor/scripts/makefile/config.mk index 3b08de168..2c224d719 100644 --- a/hypervisor/scripts/makefile/config.mk +++ b/hypervisor/scripts/makefile/config.mk @@ -238,7 +238,7 @@ $(HV_CONFIG_H): $(HV_UNIFIED_XML) @echo "$@ generated" $(HV_CONFIG_TIMESTAMP): $(HV_UNIFIED_XML) ${HV_DIFFCONFIG_LIST} | $(HV_CONFIG_DIR) - @sh $(BASEDIR)/scripts/genconf.sh $(BASEDIR) $(HV_BOARD_XML) $(HV_SCENARIO_XML) $(HV_CONFIG_DIR) + @sh $(BASEDIR)/scripts/genconf.sh $(BASEDIR) $(HV_BOARD_XML) $(HV_SCENARIO_XML) $(HV_CONFIG_DIR) $(HV_UNIFIED_XML) @touch $@ .PHONY: defconfig @@ -253,7 +253,7 @@ showconfig: diffconfig: @rm -rf $(HV_CONFIG_A_DIR) $(HV_CONFIG_B_DIR) - @sh $(BASEDIR)/scripts/genconf.sh $(BASEDIR) $(BOARD_FILE) $(HV_SCENARIO_XML) $(HV_CONFIG_A_DIR) + @sh $(BASEDIR)/scripts/genconf.sh $(BASEDIR) $(BOARD_FILE) $(HV_SCENARIO_XML) $(HV_CONFIG_A_DIR) $(HV_UNIFIED_XML) @cd $(HV_CONFIG_DIR) && find . -name '*.c' -or -name '*.h' -or -name '*.config' -or -name '*.asl' | while read f; do \ nf=$(HV_CONFIG_B_DIR)/$${f}; mkdir -p `dirname $${nf}` && cp $${f} $${nf}; \ done