Skip to content

Improve missing submodule logic #1217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions make/command
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ifeq ($(CMDSTAN_SUBMODULES),1)
bin/cmdstan/stansummary.o : src/cmdstan/stansummary_helper.hpp
bin/cmdstan/%.o : src/cmdstan/%.cpp
@mkdir -p $(dir $@)
Expand All @@ -11,5 +10,3 @@ bin/print$(EXE) bin/stansummary$(EXE) bin/diagnose$(EXE) : LDLIBS_MPI =
bin/print$(EXE) bin/stansummary$(EXE) bin/diagnose$(EXE) : bin/%$(EXE) : bin/cmdstan/%.o $(TBB_TARGETS)
@mkdir -p $(dir $@)
$(LINK.cpp) $^ $(LDLIBS) $(OUTPUT_OPTION)

endif
7 changes: 1 addition & 6 deletions make/stanc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ endef

# if nothing was set to $(OS) that means that the Stan Math submodule is missing
OS ?= missing-submodules
CMDSTAN_SUBMODULES = 1
STANC_DL_RETRY = 5
STANC_DL_DELAY = 10
STANC3_TEST_BIN_URL ?=
Expand Down Expand Up @@ -38,14 +37,11 @@ else ifeq ($(OS),Linux)
endif
endif

else ifeq ($(OS),missing-submodules)
CMDSTAN_SUBMODULES = 0
else
$(error Cannot detect OS properly. $n This will impede automatically downloading the correct stanc. $n Please visit https://github.com/stan-dev/stanc3/releases and download a stanc binary for your OS and place it in ./bin/stanc. $n )
endif

# bin/stanc build rules - requires stan, stan_math submodules in place
ifeq ($(CMDSTAN_SUBMODULES),1)
# bin/stanc build rules
ifneq ($(STANC3),)
# build stanc3 from local installation
bin/stanc$(EXE) : $(call findfiles,$(STANC3)/src/,*.ml*) $(STANC#)
Expand Down Expand Up @@ -91,5 +87,4 @@ else
curl -L https://github.com/stan-dev/stanc3/releases/download/$(STANC3_VERSION)/$(OS_TAG)$(ARCH_TAG)-stanc -o bin/stanc$(EXE) --retry $(STANC_DL_RETRY) --retry-delay $(STANC_DL_DELAY)
chmod +x bin/stanc$(EXE)
endif
endif
# end bin/stanc build rules
35 changes: 20 additions & 15 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ else
PRECOMPILED_MODEL_HEADER=
endif

-include $(MATH)make/compiler_flags
-include $(MATH)make/dependencies
-include $(MATH)make/libraries
include $(MATH)make/compiler_flags
include $(MATH)make/dependencies
include $(MATH)make/libraries
include make/stanc
include make/program
include make/tests
Expand Down Expand Up @@ -262,7 +262,6 @@ build-mpi: $(MPI_TARGETS)
@echo ''
@echo '--- boost mpi bindings built ---'

ifeq ($(CMDSTAN_SUBMODULES),1)
.PHONY: build
build: bin/stanc$(EXE) $(SUNDIALS_TARGETS) $(MPI_TARGETS) $(TBB_TARGETS) $(CMDSTAN_MAIN_O) $(PRECOMPILED_MODEL_HEADER) bin/stansummary$(EXE) bin/print$(EXE) bin/diagnose$(EXE)
@echo ''
Expand All @@ -275,17 +274,6 @@ ifeq ($(OS),Windows_NT)
@echo 'to automatically update your user configuration.'
endif
@echo '--- CmdStan v$(CMDSTAN_VERSION) built ---'
else
.PHONY: build
build:
@echo 'ERROR: Missing Stan submodules.'
@echo 'Please run the following to fix:'
@echo ''
@echo 'git submodule update --init --recursive'
@echo ''
@echo 'And try building again'
@exit 1
endif

.PHONY: install-tbb
install-tbb: $(TBB_TARGETS)
Expand Down Expand Up @@ -352,3 +340,20 @@ print-% : ; @echo $* = $($*)

.PHONY: clean-build
clean-build: clean-all build


##
# This is only run if the `include` statements earlier fail to find a file.
# We assume that means the submodule is missing
##
$(MATH)make/% :
@echo 'ERROR: Missing Stan submodules.'
@echo 'We tried to find the Stan Math submodule at:'
@echo ' $(MATH)'
@echo ''
@echo 'The most likely source of the problem is CmdStan was cloned without'
@echo 'the --recursive flag. To fix this, run the following command:'
@echo ' git submodule update --init --recursive'
@echo ''
@echo 'And try building again'
@exit 1