Skip to content

Commit

Permalink
[ci] Don't diff when running clang-format (#10933)
Browse files Browse the repository at this point in the history
* [ci] Don't diff when running clang-format

This takes about 15-20 extra seconds but has the benefit of allowing users to replicate and fix clang format issues locally with ease.

* format files

* Add --fix flag

* Comments

Co-authored-by: driazati <driazati@users.noreply.github.com>
  • Loading branch information
driazati and driazati authored Apr 11, 2022
1 parent 89061fa commit 396a8c6
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ void uart_rx_init(struct ring_buf* rbuf, const struct device* dev) {
// The main function of this application.
extern void __stdout_hook_install(int (*hook)(int));
void main(void) {

#ifdef CONFIG_LED
int ret;
led0_pin = device_get_binding(LED0);
Expand Down
1 change: 0 additions & 1 deletion include/tvm/relay/attrs/annotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ struct CompilerAttrs : public tvm::AttrsNode<CompilerAttrs> {
}
};


} // namespace relay
} // namespace tvm
#endif // TVM_RELAY_ATTRS_ANNOTATION_H_
1 change: 0 additions & 1 deletion src/ir/transform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ class ModulePass : public Pass {
TVM_DEFINE_OBJECT_REF_METHODS(ModulePass, Pass, ModulePassNode);
};


PassInfo::PassInfo(int opt_level, String name, tvm::Array<runtime::String> required) {
auto pass_info = make_object<PassInfoNode>();
pass_info->opt_level = opt_level;
Expand Down
1 change: 0 additions & 1 deletion src/relay/op/tensor/unary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ RELAY_REGISTER_UNARY_OP("bitwise_not")
.set_support_level(4)
.set_attr<FTVMCompute>("FTVMCompute", RELAY_UNARY_COMPUTE(topi::bitwise_not));


Array<te::Tensor> ShapeOfCompute(const Attrs& attrs, const Array<te::Tensor>& inputs,
const Type& out_type) {
ICHECK_EQ(inputs.size(), 1);
Expand Down
2 changes: 1 addition & 1 deletion src/relay/qnn/op/convolution_transpose.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ bool QnnConv2DTransposeRel(const Array<Type>& types, int num_inputs, const Attrs
return false;
}
}
ICHECK(IsScalarType(types[2], DataType::Int(32))); // input_zero_point
ICHECK(IsScalarType(types[2], DataType::Int(32))); // input_zero_point

const auto* weight_zp_type = types[3].as<TensorTypeNode>();
ICHECK(weight_zp_type->dtype == DataType::Int(32)); // weight_zero_point
Expand Down
4 changes: 2 additions & 2 deletions src/relay/qnn/op/dense.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ bool QnnDenseRel(const Array<Type>& types, int num_inputs, const Attrs& attrs,
return false;
}
}
ICHECK(IsScalarType(types[2], DataType::Int(32))); // input_zero_point
ICHECK(IsScalarType(types[4], DataType::Float(32))); // input_scale
ICHECK(IsScalarType(types[2], DataType::Int(32))); // input_zero_point
ICHECK(IsScalarType(types[4], DataType::Float(32))); // input_scale
// weight_zero_point can be a scalar or a vector of the same shape as the weight_scale
AssignType(types[5], DataType::Float(32), param->units, reporter); // weight_scale

Expand Down
1 change: 0 additions & 1 deletion src/runtime/hexagon/hexagon/hexagon_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ namespace tvm {
namespace runtime {
namespace hexagon {


#if defined(__hexagon__)
class HexagonTimerNode : public TimerNode {
public:
Expand Down
56 changes: 28 additions & 28 deletions src/target/source/codegen_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,35 +124,35 @@ class CodeGenC : public ExprFunctor<void(const PrimExpr&, std::ostream&)>,
*/
virtual void InitFuncState(const PrimFunc& f);
// expression
void VisitExpr_(const VarNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const LoadNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const VarNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const LoadNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const BufferLoadNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const LetNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const CallNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const AddNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const SubNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const MulNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const DivNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const ModNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const MinNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const MaxNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const EQNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const NENode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const LTNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const LENode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const GTNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const GENode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const AndNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const OrNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const CastNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const NotNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const SelectNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const RampNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const ShuffleNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const BroadcastNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const IntImmNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const FloatImmNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const StringImmNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const LetNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const CallNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const AddNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const SubNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const MulNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const DivNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const ModNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const MinNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const MaxNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const EQNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const NENode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const LTNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const LENode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const GTNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const GENode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const AndNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const OrNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const CastNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const NotNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const SelectNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const RampNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const ShuffleNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const BroadcastNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const IntImmNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const FloatImmNode* op, std::ostream& os) override; // NOLINT(*)
void VisitExpr_(const StringImmNode* op, std::ostream& os) override; // NOLINT(*)
// statment
void VisitStmt_(const LetStmtNode* op) override;
void VisitStmt_(const StoreNode* op) override;
Expand Down
2 changes: 1 addition & 1 deletion src/te/schedule/schedule_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class SchedulePostProc : public StmtExprMutator {
}
}
} else if (op->attr_key == tir::attr::buffer_bind_scope) {
Array<ObjectRef> tuple = Downcast<Array<ObjectRef> >(op->node);
Array<ObjectRef> tuple = Downcast<Array<ObjectRef>>(op->node);
Tensor tensor = Downcast<Tensor>(tuple[1]);
auto it = replace_op_.find(tensor->op.get());
if (it != replace_op_.end()) {
Expand Down
1 change: 0 additions & 1 deletion src/tir/transforms/make_unpacked_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ PrimFunc MakeUnpackedAPI(PrimFunc&& func) {
const Stmt nop = Evaluate(0);
std::vector<Stmt> device_init;


// Collect variables and buffers to map between
Array<Var> args;
Map<Var, Buffer> new_buffer_map;
Expand Down
4 changes: 1 addition & 3 deletions src/tir/transforms/tensorcore_infer_fragment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ class FragmentGetter : public StmtExprVisitor {
}

// Get memory scope
void VisitStmt_(const AttrStmtNode* op) final {
StmtExprVisitor::VisitStmt_(op);
}
void VisitStmt_(const AttrStmtNode* op) final { StmtExprVisitor::VisitStmt_(op); }

// Fragment metadata for all fragments
std::unordered_map<const VarNode*, FragmentInfo> fragments;
Expand Down
24 changes: 0 additions & 24 deletions tests/lint/clang_format.sh

This file was deleted.

2 changes: 1 addition & 1 deletion tests/lint/git-black.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# under the License.
set -euo pipefail

INPLACE_FORMAT=false
INPLACE_FORMAT=${INPLACE_FORMAT:=false}
LINT_ALL_FILES=true
REVISION=

Expand Down
60 changes: 39 additions & 21 deletions tests/lint/git-clang-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,35 @@ set -e
set -u
set -o pipefail

if [[ "$1" == "-i" ]]; then
INPLACE_FORMAT=1
shift 1
else
INPLACE_FORMAT=0
fi

if [[ "$#" -lt 1 ]]; then
echo "Usage: tests/lint/git-clang-format.sh [-i] <commit>"
echo ""
echo "Run clang-format on files that changed since <commit>"
echo "Examples:"
echo "- Compare last one commit: tests/lint/git-clang-format.sh HEAD~1"
echo "- Compare against upstream/main: tests/lint/git-clang-format.sh upstream/main"
echo "You can also add -i option to do inplace format"
exit 1
fi
INPLACE_FORMAT=${INPLACE_FORMAT:=false}
LINT_ALL_FILES=true
REVISION=$(git rev-list --max-parents=0 HEAD)

while (( $# )); do
case "$1" in
-i)
INPLACE_FORMAT=true
shift 1
;;
--rev)
LINT_ALL_FILES=false
REVISION=$2
shift 2
;;
*)
echo "Usage: tests/lint/git-clang-format.sh [-i] [--rev <commit>]"
echo ""
echo "Run clang-format on files that changed since <commit> or on all files in the repo"
echo "Examples:"
echo "- Compare last one commit: tests/lint/git-clang-format.sh --rev HEAD~1"
echo "- Compare against upstream/main: tests/lint/git-clang-format.sh --rev upstream/main"
echo "The -i will use black to format files in-place instead of checking them."
exit 1
;;
esac
done


cleanup()
{
Expand All @@ -58,14 +70,20 @@ fi
# Print out specific version
${CLANG_FORMAT} --version

if [[ ${INPLACE_FORMAT} -eq 1 ]]; then
echo "Running inplace git-clang-format against" $1
git-${CLANG_FORMAT} --extensions h,mm,c,cc --binary=${CLANG_FORMAT} $1
if [[ "$INPLACE_FORMAT" == "true" ]]; then
echo "Running inplace git-clang-format against $REVISION"
git-${CLANG_FORMAT} --extensions h,mm,c,cc --binary=${CLANG_FORMAT} "$REVISION"
exit 0
fi

echo "Running git-clang-format against" $1
git-${CLANG_FORMAT} --diff --extensions h,mm,c,cc --binary=${CLANG_FORMAT} $1 1> /tmp/$$.clang-format.txt
if [[ "$LINT_ALL_FILES" == "true" ]]; then
echo "Running git-clang-format against all C++ files"
git-${CLANG_FORMAT} --diff --extensions h,mm,c,cc --binary=${CLANG_FORMAT} "$REVISION" 1> /tmp/$$.clang-format.txt
else
echo "Running git-clang-format against $REVISION"
git-${CLANG_FORMAT} --diff --extensions h,mm,c,cc --binary=${CLANG_FORMAT} "$REVISION" 1> /tmp/$$.clang-format.txt
fi

echo "---------clang-format log----------"
cat /tmp/$$.clang-format.txt
echo ""
Expand Down
10 changes: 8 additions & 2 deletions tests/scripts/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,24 @@ def serve_docs(directory: str = "_docs") -> None:
cmd([sys.executable, "-m", "http.server"], cwd=directory_path)


def lint(interactive: bool = False) -> None:
def lint(interactive: bool = False, fix: bool = False) -> None:
"""
Run CI's Sanity Check step
arguments:
interactive -- start a shell after running build / test scripts
fix -- where possible (currently black and clang-format) edit files in place with formatting fixes
"""
env = {}
if fix:
env["IS_LOCAL"] = "true"
env["INPLACE_FORMAT"] = "true"

docker(
name=gen_name(f"ci-lint"),
image="ci_lint",
scripts=["./tests/scripts/task_lint.sh"],
env={},
env=env,
interactive=interactive,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/task_lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ echo "Linting the C++ code..."
tests/lint/cpplint.sh

echo "clang-format check..."
tests/lint/clang_format.sh
tests/lint/git-clang-format.sh

echo "Rust check..."
tests/lint/rust_format.sh
Expand Down

0 comments on commit 396a8c6

Please sign in to comment.