-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Build, workflow): Add Version Info Files (#937)
Co-authored-by: Lorne Smith <[email protected]>
- Loading branch information
1 parent
65259f2
commit f1d7a10
Showing
7 changed files
with
326 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
""" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/[email protected] | ||
|
||
- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |