Skip to content
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

feat(Build, workflow): Add Version Info Files #937

Merged
merged 12 commits into from
Mar 15, 2024
Merged
2 changes: 1 addition & 1 deletion .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v2.3.3
Expand Down
105 changes: 105 additions & 0 deletions .github/workflows/scripts/update_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
copyright = """###############################################################################
#
# Copyright (C) 2024 Analog Devices, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################"""

copyright_c = """/******************************************************************************
*
* Copyright (C) 2024 Analog Devices, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/"""

from subprocess import run
from pathlib import Path

if __name__ == "__main__":
# 'git describe will print a string with info about the current commit's relationship
# to the last tag. '--tags' gets it working with non-annoted tags.
command = "git describe --tags"
result = run(command, shell=True, capture_output=True)
if result.returncode != 0:
print(f"Failed to run {command} with error {result.returncode}:\n{result.stderr.decode(encoding='utf-8')}")
exit(result.returncode)

version = result.stdout.decode(encoding="utf-8").strip()
print(version)
# Our tagging convention is v{version_year}_{version_month}
# git describe will sometimes return something like v2024_02-5-g5f0770a64e
version_year = int(version.split("_")[0][1:]) # Split the year and month based on the '_', and strip off the leading 'v'
version_minor = version.split("_")[1].split("-")[0]
version_month = int(version_minor[0]) if isinstance(version_minor, list) else int(version_minor)

# Locate maxim_path relative to this file.
maxim_path = Path(__file__).parent.parent.parent.parent

# Place mxc_version.h in the root directory of the MSDK
filename = "mxc_version"
output_file = maxim_path / f"{filename}.h"
with open(output_file, "w") as f:
print(f"Writing to {output_file}")
f.write(
f"""{copyright_c}
#ifndef MXC_VERSION_H_
#define MXC_VERSION_H_
// @autogenerated version info

/**
* @brief The string representing the current MSDK version.
* Format: `[Release tag]-[commits since release tag]-g[commit SHA]`
* If exactly on a release tag, this string will match the tag
*/
#define MSDK_VERSION_STRING "{version}"
/**
* @brief The month of the current MSDK version
*/
#define MSDK_VERSION_YEAR {version_year}
/**
* @brief The year of the current MSDK version
*/
#define MSDK_VERSION_MONTH {version_month}

#endif // MXC_VERSION_H_
""")

# Place msdk_version.mk next to the gcc/gcc_riscv.mk files.
# This file will be used to print version info at build time.
# Generating it is easier than trying to parse msdk_version.h with native Make functions
output_file = maxim_path / f"Libraries/CMSIS/Device/Maxim/GCC/{filename}.mk"
with open(output_file, "w") as f:
print(f"Writing to {output_file}")
f.write(
f"""{copyright}
# Autogenerated version info for build system.
MSDK_VERSION_STRING := {version}
MSDK_VERSION_YEAR := {version_year}
MSDK_VERSION_MONTH := {version_month}

# Add root MAXIM_PATH to IPATH so compiler can locate msdk_version.h
IPATH += $(MAXIM_PATH)
"""
)
31 changes: 31 additions & 0 deletions .github/workflows/update_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Update Version Info

on:
push:
tags: [ "release" ]

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v2.3.3

- name: Update Version Files
run: |
python3 .github/workflows/scripts/update_version.py

- uses: EndBug/add-and-commit@v9

- name: Update Existing Tag
run: |
CURRENT_TAG=$(git describe --abbrev=0 --tags)
git tag -f $CURRENT_TAG
git push --tags --force
81 changes: 64 additions & 17 deletions Libraries/CMSIS/Device/Maxim/GCC/gcc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,70 @@
#
##############################################################################

################################################################################
# Detect whether we're working from the Github repo or not.
# If so, attempt to update the version number files every time we build.

ifeq "$(PYTHON_CMD)" ""
# Try python
ifneq "$(wildcard $(MAXIM_PATH)/.git)" ""
PYTHON_VERSION := $(shell python --version)
ifneq ($(.SHELLSTATUS),0)
PYTHON_CMD := none
else
PYTHON_CMD := python
endif

# Try python3
ifeq "$(PYTHON_CMD)" "none"
PYTHON_VERSION := $(shell python3 --version)
ifneq ($(.SHELLSTATUS),0)
PYTHON_CMD := none
else
PYTHON_CMD := python
endif
endif

# Export PYTHON_CMD so we don't check for it again unnecessarily
export PYTHON_CMD
endif

# Run script
ifneq "$(PYTHON_CMD)" "none"
UPDATE_VERSION_OUTPUT := $(shell python $(MAXIM_PATH)/.github/workflows/scripts/update_version.py)
else
$(warning No Python installation detected on your system! Will not automatically update version info.)
endif
endif


ifneq "$(wildcard $(MAXIM_PATH)/Libraries/CMSIS/Device/Maxim/GCC/mxc_version.mk)" ""
include $(MAXIM_PATH)/Libraries/CMSIS/Device/Maxim/GCC/mxc_version.mk
endif
################################################################################

SUPPRESS_HELP ?= 0
ifeq "$(SUPPRESS_HELP)" "0"
ifneq "$(HELP_COMPLETE)" "1"

$(info ****************************************************************************)
$(info * Analog Devices MSDK)
ifneq "$(MSDK_VERSION_STRING)" ""
$(info * $(MSDK_VERSION_STRING))
endif
$(info * - User Guide: https://analogdevicesinc.github.io/msdk/USERGUIDE/)
$(info * - Get Support: https://www.analog.com/support/technical-support.html)
$(info * - Report Issues: https://github.com/analogdevicesinc/msdk/issues)
$(info * - Contributing: https://analogdevicesinc.github.io/msdk/CONTRIBUTING/)
$(info ****************************************************************************)
# export HELP_COMPLETE so that it's only printed once.
HELP_COMPLETE = 1
export HELP_COMPLETE
endif
endif

################################################################################

# The build directory
ifeq "$(BUILD_DIR)" ""
BUILD_DIR=$(CURDIR)/build
Expand Down Expand Up @@ -641,20 +705,3 @@ else
$(MAKE) debug
endif

#################################################################################
SUPPRESS_HELP ?= 0
ifeq "$(SUPPRESS_HELP)" "0"
ifneq "$(HELP_COMPLETE)" "1"
$(info ****************************************************************************)
$(info * Analog Devices MSDK)
$(info * - User Guide: https://analogdevicesinc.github.io/msdk/USERGUIDE/)
$(info * - Get Support: https://www.analog.com/support/technical-support.html)
$(info * - Report Issues: https://github.com/analogdevicesinc/msdk/issues)
$(info * - Contributing: https://analogdevicesinc.github.io/msdk/CONTRIBUTING/)
$(info ****************************************************************************)
# export HELP_COMPLETE so that it's only printed once.
HELP_COMPLETE = 1
export HELP_COMPLETE
endif
endif

80 changes: 64 additions & 16 deletions Libraries/CMSIS/Device/Maxim/GCC/gcc_riscv.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,70 @@
#
##############################################################################

################################################################################
# Detect whether we're working from the Github repo or not.
# If so, attempt to update the version number files every time we build.

ifeq "$(PYTHON_CMD)" ""
# Try python
ifneq "$(wildcard $(MAXIM_PATH)/.git)" ""

PYTHON_VERSION := $(shell python --version)
ifneq ($(.SHELLSTATUS),0)
PYTHON_CMD := none
else
PYTHON_CMD := python
endif

# Try python3
ifeq "$(PYTHON_CMD)" "none"
PYTHON_VERSION := $(shell python3 --version)
ifneq ($(.SHELLSTATUS),0)
PYTHON_CMD := none
else
PYTHON_CMD := python
endif
endif

# Export PYTHON_CMD so we don't check for it again unnecessarily
export PYTHON_CMD
endif

# Run script
ifneq "$(PYTHON_CMD)" "none"
UPDATE_VERSION_OUTPUT := $(shell python $(MAXIM_PATH)/.github/workflows/scripts/update_version.py)
else
$(warning No Python installation detected on your system! Will not automatically update version info.)
endif
endif

ifneq "$(wildcard $(MAXIM_PATH)/Libraries/CMSIS/Device/Maxim/GCC/mxc_version.mk)" ""
include $(MAXIM_PATH)/Libraries/CMSIS/Device/Maxim/GCC/mxc_version.mk
endif
################################################################################

SUPPRESS_HELP ?= 0
ifeq "$(SUPPRESS_HELP)" "0"
ifneq "$(HELP_COMPLETE)" "1"

$(info ****************************************************************************)
$(info * Analog Devices MSDK)
ifneq "$(MSDK_VERSION_STRING)" ""
$(info * $(MSDK_VERSION_STRING))
endif
$(info * - User Guide: https://analogdevicesinc.github.io/msdk/USERGUIDE/)
$(info * - Get Support: https://www.analog.com/support/technical-support.html)
$(info * - Report Issues: https://github.com/analogdevicesinc/msdk/issues)
$(info * - Contributing: https://analogdevicesinc.github.io/msdk/CONTRIBUTING/)
$(info ****************************************************************************)
# export HELP_COMPLETE so that it's only printed once.
HELP_COMPLETE = 1
export HELP_COMPLETE
endif
endif

################################################################################

# The build directory
ifeq "$(BUILD_DIR)" ""
BUILD_DIR=$(CURDIR)/buildrv
Expand Down Expand Up @@ -639,19 +703,3 @@ else
$(MAKE) debug
endif

#################################################################################
SUPPRESS_HELP ?= 0
ifeq "$(SUPPRESS_HELP)" "0"
ifneq "$(HELP_COMPLETE)" "1"
$(info ****************************************************************************)
$(info * Analog Devices MSDK)
$(info * - User Guide: https://analogdevicesinc.github.io/msdk/USERGUIDE/)
$(info * - Get Support: https://www.analog.com/support/technical-support.html)
$(info * - Report Issues: https://github.com/analogdevicesinc/msdk/issues)
$(info * - Contributing: https://analogdevicesinc.github.io/msdk/CONTRIBUTING/)
$(info ****************************************************************************)
# export HELP_COMPLETE so that it's only printed once.
HELP_COMPLETE = 1
export HELP_COMPLETE
endif
endif
24 changes: 24 additions & 0 deletions Libraries/CMSIS/Device/Maxim/GCC/mxc_version.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
###############################################################################
#
# Copyright (C) 2024 Analog Devices, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
# Autogenerated version info for build system.
MSDK_VERSION_STRING := v2024_02-13-gece5e1409b
MSDK_VERSION_YEAR := 2024
MSDK_VERSION_MONTH := 2

# Add root MAXIM_PATH to IPATH so compiler can locate msdk_version.h
IPATH += $(MAXIM_PATH)
37 changes: 37 additions & 0 deletions mxc_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/******************************************************************************
*
* Copyright (C) 2024 Analog Devices, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
#ifndef MXC_VERSION_H_
#define MXC_VERSION_H_
// @autogenerated version info

/**
* @brief The string representing the current MSDK version.
* Format: `[Release tag]-[commits since release tag]-g[commit SHA]`
* If exactly on a release tag, this string will match the tag
*/
#define MSDK_VERSION_STRING "v2024_02-13-gece5e1409b"
/**
* @brief The month of the current MSDK version
*/
#define MSDK_VERSION_YEAR 2024
/**
* @brief The year of the current MSDK version
*/
#define MSDK_VERSION_MONTH 2

#endif // MXC_VERSION_H_
Loading