Skip to content
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: |
cd test
make env
make env-info
make info

- name: example
run: |
Expand All @@ -50,4 +50,4 @@ jobs:
- name: test
run: |
cd test
make test-command
make test-command || make -d test-command
17 changes: 11 additions & 6 deletions Makefile.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ REQUIREMENTS_FILE := requirements.txt
# https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
ENVIRONMENT_FILE := environment.yml

include third_party/make-env/conda.mk
# Rule to checkout the git submodule if it wasn't cloned.
$(TOP_DIR)/third_party/make-env/env.mk: $(TOP_DIR)/.gitmodules
cd $(TOP_DIR); git submodule update --init third_party/make-env
touch $(TOP_DIR)/third_party/make-env/env.mk

-include $(TOP_DIR)/third_party/make-env/env.mk

# Example make target which runs commands inside the conda environment.
example-command: | $(CONDA_ENV_PYTHON)
$(IN_CONDA_ENV) echo "Python is $$(which python)"
$(IN_CONDA_ENV) python --version
example-command: | $(ENV_PYTHON)
$(IN_ENV) echo "Python is $$(which python)"
@$(IN_ENV) python --version

# Check that no system packages are found in the environment.
test-command: | $(CONDA_ENV_PYTHON)
$(IN_CONDA_ENV) python check.py
test-command: | $(ENV_PYTHON)
$(IN_ENV) python check.py
20 changes: 13 additions & 7 deletions conda.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

.SUFFIXES:

ENV := conda
UENV := CONDA

MAKE_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))

SHELL := bash
Expand Down Expand Up @@ -47,12 +50,18 @@ endif
ifeq (,$(REQUIREMENTS_FILE))
$(error "Set REQUIREMENTS_FILE value before including 'conda.mk'.")
else
REQUIREMENTS_FILE := $(abspath $(TOP_DIR)$(SEP)$(REQUIREMENTS_FILE))
REQUIREMENTS_FILE := $(abspath $(REQUIREMENTS_FILE))
endif
ifeq (,$(wildcard $(REQUIREMENTS_FILE)))
$(error "REQUIREMENTS_FILE ($(REQUIREMENTS_FILE)) does not exist!?")
endif

ifeq (,$(ENVIRONMENT_FILE))
$(error "Set ENVIRONMENT_FILE value before including 'conda.mk'.")
ENVIRONMENT_FILE := $(abspath $(TOP_DIR)$(SEP)$(ENVIRONMENT_FILE))
ENVIRONMENT_FILE := $(abspath $(ENVIRONMENT_FILE))
endif
ifeq (,$(wildcard $(ENVIRONMENT_FILE)))
$(error "ENVIRONMENT_FILE ($(ENVIRONMENT_FILE)) does not exist!?")
endif

CONDA_ENV_NAME := $(strip $(patsubst name:%,,$(CONDA_ENV_NAME_LINE)))
Expand Down Expand Up @@ -144,11 +153,6 @@ env:: $(CONDA_ENV_PYTHON)

.PHONY: env

enter: $(CONDA_ENV_PYTHON)
$(IN_CONDA_ENV) bash

.PHONY: enter

clean::
rm -rf $(CONDA_DIR)

Expand All @@ -161,6 +165,8 @@ dist-clean::

FILTER_TOP = sed -e's@$(TOP_DIR)/@$$TOP_DIR/@'
env-info:
@echo
@echo " Using conda environment."
@echo " Currently running on: '$(OS_TYPE) ($(CPU_TYPE))'"
@echo
@echo " Conda environment is named: '$(CONDA_ENV_NAME)'"
Expand Down
82 changes: 82 additions & 0 deletions env.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright (C) 2020 The SymbiFlow Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC

.SUFFIXES:

MAKE_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))

SHELL := bash

# Makefile for downloading and creating environments (with tools like conda).

# Usage
# - Set TOP_DIR to the top directory where environment will be created.
# - Set REQUIREMENTS_FILE to a pip `requirements.txt` file.
# - Set ENVIRONMENT_FILE to a conda `environment.yml` file.
# - Put $(IN_ENV) before commands which should run inside the
# environment.

# Configuration
ifeq (,$(TOP_DIR))
$(error "Set TOP_DIR value before including 'env.mk'.")
endif

ifeq (,$(REQUIREMENTS_FILE))
$(error "Set REQUIREMENTS_FILE value before including 'conda.mk'.")
else
REQUIREMENTS_FILE := $(abspath $(REQUIREMENTS_FILE))
endif
ifeq (,$(wildcard $(REQUIREMENTS_FILE)))
$(error "REQUIREMENTS_FILE ($(REQUIREMENTS_FILE)) does not exist!?")
endif

ifeq (,$(ENVIRONMENT_FILE))
$(error "Set ENVIRONMENT_FILE value before including 'conda.mk'.")
ENVIRONMENT_FILE := $(abspath $(ENVIRONMENT_FILE))
endif
ifeq (,$(wildcard $(ENVIRONMENT_FILE)))
$(error "ENVIRONMENT_FILE ($(ENVIRONMENT_FILE)) does not exist!?")
endif

# Default to conda if no other option is provided.
ifeq (,$(ENV))
ENV := conda
endif

ifeq (,$(wildcard $(MAKE_DIR)/$(ENV).mk))
$(error Unknown environment provider (ENV='$(ENV)')?)
endif

export ENV
include $(MAKE_DIR)/$(ENV).mk
ifeq (,$(UENV))
$(error Missing UENV definition)
endif

ENV_PYTHON := $($(UENV)_ENV_PYTHON)
IN_ENV := $(IN_$(UENV)_ENV)

clean::
true

.PHONY: clean

dist-clean::
true

.PHONY: dist-clean

enter: | $(ENV_PYTHON)
$(IN_ENV) bash

.PHONY: enter

info: | $(ENV_PYTHON)
@$(IN_ENV) $(MAKE) --no-print-directory env-info

.PHONY: info
28 changes: 28 additions & 0 deletions system.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) 2020 The SymbiFlow Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC

ENV := system
UENV := SYSTEM

include $(MAKE_DIR)/os.mk

SYSTEM_ENV_PYTHON :=
IN_SYSTEM_ENV :=

FILTER_TOP = sed -e's@$(TOP_DIR)/@$$TOP_DIR/@'
env-info:
@echo
@echo " Using system environment."
@echo " Currently running on: '$(OS_TYPE) ($(CPU_TYPE))'"
@echo
@echo " Git top level directory is: '$$(git rev-parse --show-toplevel)'"
@echo " The version number is: '$$(git describe)'"
@echo " Python binary is: '$$(which python)'"\
| $(FILTER_TOP)

.PHONY: env-info
Empty file added test/.gitmodules
Empty file.