Skip to content

Commit

Permalink
[chore] Fix misspell run on Windows (open-telemetry#29776)
Browse files Browse the repository at this point in the history
**Description:**
Misspell run fails on Windows because of command size limits on the
platform. With the change, on Windows, instead of passing all files at
once to misspell, the files are grouped via use of `xargs`. The current
behavior is not changed for non-Windows OSes.

This is helpful to eventually enabling lint for Windows.

**Testing:**
Forced a typo on Windows and Linux and checked if `make` from the
component folder was detecting and passing when the typo was fixed.
  • Loading branch information
pjanotti committed Dec 14, 2023
1 parent 31d9d92 commit 3f9b105
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,16 @@ ALL_SRC := $(shell find $(ALL_PKG_DIRS) -name '*.go' \
-type f | sort)

# All source code and documents. Used in spell check.
ALL_SRC_AND_DOC := $(shell find $(ALL_PKG_DIRS) -name "*.md" -o -name "*.go" -o -name "*.yaml" \
-not -path '*/third_party/*' \
-type f | sort)
ALL_SRC_AND_DOC_CMD := find $(ALL_PKG_DIRS) -name "*.md" -o -name "*.go" -o -name "*.yaml" -not -path '*/third_party/*' -type f | sort
ifeq ($(UNIX_SHELL_ON_WINDOWS),true)
# Windows has a low limit, 8192 chars, to create a process. Workaround it by breaking it in smaller commands.
MISSPELL_CMD := $(ALL_SRC_AND_DOC_CMD) | xargs -n 20 $(MISSPELL)
MISSPELL_CORRECTION_CMD := $(ALL_SRC_AND_DOC_CMD) | xargs -n 20 $(MISSPELL_CORRECTION)
else
ALL_SRC_AND_DOC := $(shell $(ALL_SRC_AND_DOC_CMD))
MISSPELL_CMD := $(MISSPELL) $(ALL_SRC_AND_DOC)
MISSPELL_CORRECTION_CMD := $(MISSPELL_CORRECTION) $(ALL_SRC_AND_DOC)
endif

# ALL_PKGS is used with 'go cover'
ALL_PKGS := $(shell $(GOCMD) list $(sort $(dir $(ALL_SRC))))
Expand Down Expand Up @@ -190,11 +197,11 @@ tidy:
.PHONY: misspell
misspell: $(TOOLS_BIN_DIR)/misspell
@echo "running $(MISSPELL)"
@$(MISSPELL) $(ALL_SRC_AND_DOC)
@$(MISSPELL_CMD)

.PHONY: misspell-correction
misspell-correction: $(TOOLS_BIN_DIR)/misspell
$(MISSPELL_CORRECTION) $(ALL_SRC_AND_DOC)
$(MISSPELL_CORRECTION_CMD)

.PHONY: moddownload
moddownload:
Expand Down

0 comments on commit 3f9b105

Please sign in to comment.