Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Difference in sed invocation between Linux and OSX #233

@nevercast

Description

@nevercast

The invocations of sed are different between OSX and Linux during the build (relative lines linked below), this means the OSX version correctly handles leading forward slashes due to the different delimiter used for sed, =. But forward slashes do not work for Linux without being escaped. Such that setting FROZEN_MPY_DIR=/frozens causes a syntax error and the build to fail later with no frozen files for mpy-cross to build.

ifneq ($(FROZEN_MPY_DIR),)
OS_NAME := $(shell uname -s)
ifeq ($(OS_NAME), Linux)
# make a list of all the .py files that need compiling and freezing
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR)/Base/ -type f -name '*.py' | $(SED) -e 's/$(FROZEN_MPY_DIR)\/Base\///')
FROZEN_MPY_PY_FILES += $(shell find -L $(FROZEN_MPY_DIR)/Common/ -type f -name '*.py' | $(SED) -e 's/$(FROZEN_MPY_DIR)\/Common\///')
ifeq ($(BOARD), $(filter $(BOARD), GPY FIPY))
FROZEN_MPY_PY_FILES += $(shell find -L $(FROZEN_MPY_DIR)/LTE/ -type f -name '*.py' | $(SED) -e 's/$(FROZEN_MPY_DIR)\/LTE\///')
endif
else
# make a list of all the .py files that need compiling and freezing
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR)/Base/ -type f -name '*.py' | $(SED) -e 's=^$(FROZEN_MPY_DIR)\/Base\//==')
FROZEN_MPY_PY_FILES += $(shell find -L $(FROZEN_MPY_DIR)/Common/ -type f -name '*.py' | $(SED) -e 's=^$(FROZEN_MPY_DIR)\/Common\//==')
ifeq ($(BOARD), $(filter $(BOARD), GPY FIPY))
FROZEN_MPY_PY_FILES += $(shell find -L $(FROZEN_MPY_DIR)/LTE/ -type f -name '*.py' | $(SED) -e 's=^$(FROZEN_MPY_DIR)\/LTE\//==')
endif
endif

I propose bringing these two in line, the only fundamental difference, other than the delimiter of the two sed invocations is the leading ^, is there a real world need for this match? If not, the sed command for both OSX and Linux can be the same.

I've changed my end to use

ifneq ($(FROZEN_MPY_DIR),)
OS_NAME := $(shell uname -s)
ifeq ($(OS_NAME), Linux)
# make a list of all the .py files that need compiling and freezing
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR)/Base/ -type f -name '*.py' | $(SED) -e 's=$(FROZEN_MPY_DIR)\/Base\/==')
FROZEN_MPY_PY_FILES += $(shell find -L $(FROZEN_MPY_DIR)/Common/ -type f -name '*.py' | $(SED) -e 's=$(FROZEN_MPY_DIR)\/Common\/==')
ifeq ($(BOARD), $(filter $(BOARD), GPY FIPY))
FROZEN_MPY_PY_FILES += $(shell find -L $(FROZEN_MPY_DIR)/LTE/ -type f -name '*.py' | $(SED) -e 's=$(FROZEN_MPY_DIR)\/LTE\/==')
endif
else
# make a list of all the .py files that need compiling and freezing
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR)/Base/ -type f -name '*.py' | $(SED) -e 's=^$(FROZEN_MPY_DIR)\/Base\//==')
FROZEN_MPY_PY_FILES += $(shell find -L $(FROZEN_MPY_DIR)/Common/ -type f -name '*.py' | $(SED) -e 's=^$(FROZEN_MPY_DIR)\/Common\//==')
ifeq ($(BOARD), $(filter $(BOARD), GPY FIPY))
FROZEN_MPY_PY_FILES += $(shell find -L $(FROZEN_MPY_DIR)/LTE/ -type f -name '*.py' | $(SED) -e 's=^$(FROZEN_MPY_DIR)\/LTE\//==')
endif
endif

Note: I would prefer to do away with ifeq ($(OS_NAME), Linux) entirely.

This has resolved my issue with having frozens stored at the root, /frozen

I can create a pull request for this, firstly I would like to know why the "start of match" character, ^ is required. I cannot test on OSX.

Side Note: The build should probably fail if find/sed terminates with a non zero return value.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions