From 3949154a19a1e58ad6840fdcd30b574dc46b4f5d Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Tue, 3 Sep 2024 11:10:14 -0700 Subject: [PATCH] Automatically set the version number by the latest tag --- .github/workflows/main.yml | 2 ++ .gitignore | 3 +++ meson.build | 36 +++++++++++++++++++++++------------- src/pluginMain.cpp | 1 + src/version.h.in | 3 +++ 5 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 src/version.h.in diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7952588..869dd0c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -49,6 +49,8 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 + - run: git fetch --tags origin + - name: Get Maya Devkit id: get-devkit uses: blurstudio/mayaModuleActions/getMayaDevkit@v1 diff --git a/.gitignore b/.gitignore index 99f03d6..bac292a 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,6 @@ $RECYCLE.BIN/ Network Trash Folder Temporary Items .apdisk + +# Auto-created version files +version.h diff --git a/meson.build b/meson.build index 807f87a..49b65fc 100644 --- a/meson.build +++ b/meson.build @@ -4,21 +4,31 @@ maya_dep = dependency('maya') maya_name_suffix = maya_dep.get_variable('name_suffix') maya_version = maya_dep.get_variable('maya_version') -source_files = files([ - 'src/pluginMain.cpp', - 'src/drawOverride.cpp', - 'src/twistSplineData.cpp', - 'src/twistSplineNode.cpp', - 'src/riderConstraint.cpp', - 'src/twistTangentNode.cpp', - 'src/twistMultiTangentNode.cpp', -]) +source_files = [ + 'src/pluginMain.cpp', + 'src/drawOverride.cpp', + 'src/twistSplineData.cpp', + 'src/twistSplineNode.cpp', + 'src/riderConstraint.cpp', + 'src/twistTangentNode.cpp', + 'src/twistMultiTangentNode.cpp', +] -latest_tag = run_command('git', 'describe', '--tags', '--abbrev=0').stdout().strip() -if latest_tag == '' - latest_tag = 'NOTAG' +# If a user-built version file exists, then just use that +# Otherwise grab the latest tag from git +fs = import('fs') +if fs.is_file('src/version.h') + message('Using existing version.h') +else + git = find_program('git', native: true, required: true) + version_h = vcs_tag( + command: [git, 'describe', '--tags', '--match', 'v[0-9]*', '--dirty=+'], + fallback: 'v0.0.1', + input: 'src/version.h.in', + output: 'version.h', + ) + source_files = source_files + version_h endif -add_project_arguments('-DVERSION_STRING="' + latest_tag + '"', language: 'cpp') outlib = shared_library( meson.project_name(), diff --git a/src/pluginMain.cpp b/src/pluginMain.cpp index 8476ef8..7ca32e0 100644 --- a/src/pluginMain.cpp +++ b/src/pluginMain.cpp @@ -29,6 +29,7 @@ SOFTWARE. #include "twistMultiTangentNode.h" #include "drawOverride.h" #include +#include "version.h" MStatus initializePlugin( MObject obj ) { MStatus status; diff --git a/src/version.h.in b/src/version.h.in new file mode 100644 index 0000000..b7f88a8 --- /dev/null +++ b/src/version.h.in @@ -0,0 +1,3 @@ +#pragma once +#define VERSION_STRING "@VCS_TAG@" +