diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-08-28 16:29:40 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-28 16:29:40 -0400 |
| commit | ce5fd43b0c9c60ad85e7c5a54161b37897640ea6 (patch) | |
| tree | a3828c8f717a4fcae3b36b7f4f046cc30ef4cffc | |
| parent | fecfb36e61c3bdb133b57713c2b6d27ff7924a9b (diff) | |
Support for getting git version from IGlobalSession (#1040)
* Added slang-tag-version.h and travis code to generate the file.
* Generate slang-tag-version.h on appveyor.
* Move where slang-tag-version.h is generated on appveyor.
* Dump slang-tag-version.h to console on travis.
* Cat slang-tag-version.h
* Added method getBuildTagVersion to IGlobalSession.
Added -v option.
| -rw-r--r-- | .travis.yml | 2 | ||||
| -rw-r--r-- | appveyor.yml | 5 | ||||
| -rw-r--r-- | docs/command-line-slangc.md | 2 | ||||
| -rw-r--r-- | slang-tag-version.h | 1 | ||||
| -rw-r--r-- | slang.h | 9 | ||||
| -rw-r--r-- | source/slang/slang-compiler.h | 2 | ||||
| -rw-r--r-- | source/slang/slang-options.cpp | 4 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 6 | ||||
| -rw-r--r-- | travis_build.sh | 4 |
9 files changed, 33 insertions, 2 deletions
diff --git a/.travis.yml b/.travis.yml index 15f630776..b613fdbfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,7 +46,7 @@ before_deploy: | export SLANG_ARCH_NAME=`uname -p` export SLANG_TAG=${TRAVIS_TAG#v} export SLANG_BINARY_ARCHIVE=slang-${SLANG_TAG}-${SLANG_OS_NAME}-${SLANG_ARCH_NAME}.zip - zip -r ${SLANG_BINARY_ARCHIVE} bin/*/*/slangc bin/*/*/libslang.so bin/*/*/libslang-glslang.so docs/*.md README.md LICENSE slang.h slang-com-helper.h slang-com-ptr.h prelude/*.h + zip -r ${SLANG_BINARY_ARCHIVE} bin/*/*/slangc bin/*/*/libslang.so bin/*/*/libslang-glslang.so docs/*.md README.md LICENSE slang.h slang-com-helper.h slang-com-ptr.h slang-tag-version.h prelude/*.h # We are going to deploy to GitHub Releases # on a successful build from a tag, but only diff --git a/appveyor.yml b/appveyor.yml index 91dce1671..7a0e194a2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,11 +12,12 @@ init: { $env:SLANG_VERSION = "dev-$($env:APPVEYOR_REPO_COMMIT.Substring(0, 7))" } - + # The project uses a submodule for the "glslang" dependency, # so we need to make sure to pull that before building. install: - git submodule update --init --recursive + - ps: git describe --tags | %{$_ -replace "^", "#define SLANG_TAG_VERSION """ -replace "$", """"} > slang-tag-version.h # We want to build the full matrix of platforms and configurations # that we support on Windows. @@ -85,6 +86,7 @@ after_build: 7z a "$env:SLANG_BINARY_ARCHIVE" slang.h 7z a "$env:SLANG_BINARY_ARCHIVE" slang-com-helper.h 7z a "$env:SLANG_BINARY_ARCHIVE" slang-com-ptr.h + 7z a "$env:SLANG_BINARY_ARCHIVE" slang-tag-version.h 7z a "$env:SLANG_BINARY_ARCHIVE" prelude\*.h 7z a "$env:SLANG_BINARY_ARCHIVE" bin\*\*\slang.dll 7z a "$env:SLANG_BINARY_ARCHIVE" bin\*\*\slang.lib @@ -97,6 +99,7 @@ after_build: 7z a "$env:SLANG_SOURCE_ARCHIVE" slang.h 7z a "$env:SLANG_SOURCE_ARCHIVE" slang-com-helper.h 7z a "$env:SLANG_SOURCE_ARCHIVE" slang-com-ptr.h + 7z a "$env:SLANG_SOURCE_ARCHIVE" slang-tag-version.h 7z a "$env:SLANG_SOURCE_ARCHIVE" prelude\*.h 7z a "$env:SLANG_SOURCE_ARCHIVE" source\*\*.h 7z a "$env:SLANG_SOURCE_ARCHIVE" source\*\*.cpp diff --git a/docs/command-line-slangc.md b/docs/command-line-slangc.md index 65ac7411b..233656057 100644 --- a/docs/command-line-slangc.md +++ b/docs/command-line-slangc.md @@ -80,6 +80,8 @@ Options For completeness, here are the options that `slangc` currently accepts: +* `-v`: Displays the build version. This is the contents of `git describe --tags`. It is typically only set from automated builds (such as distros available on github). A user build will by default be 'unknown'. + * `-D <name>[=<value>]`: Insert a preprocessor macro definition * The space between `-D` and `<name>` is optional * If no `<value>` is specified, Slang will define the macro with an empty value diff --git a/slang-tag-version.h b/slang-tag-version.h new file mode 100644 index 000000000..f2ecc1d4f --- /dev/null +++ b/slang-tag-version.h @@ -0,0 +1 @@ +#define SLANG_TAG_VERSION "unknown" @@ -2669,6 +2669,15 @@ namespace slang virtual SLANG_NO_THROW void SLANG_MCALL setDownstreamCompilerPrelude( SlangPassThrough passThrough, const char* preludeText) = 0; + + /** Get the build version 'tag' string. The string is the same as produced via `git describe --tags` + for the project. If Slang is built separately from the automated build scripts + the contents will by default be 'unknown'. Any string can be set by changing the + contents of 'slang-tag-version.h' file and recompiling the project. + + @return The build tag string + */ + virtual SLANG_NO_THROW const char* SLANG_MCALL getBuildTagString() = 0; }; #define SLANG_UUID_IGlobalSession { 0xc140b5fd, 0xc78, 0x452e, { 0xba, 0x7c, 0x1a, 0x1e, 0x70, 0xc7, 0xf7, 0x1c } }; diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index a6be59c76..0b97e2af7 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -1807,6 +1807,8 @@ namespace Slang SlangPassThrough inPassThrough, char const* prelude) override; + SLANG_NO_THROW const char* SLANG_MCALL getBuildTagString() override; + enum class SharedLibraryFuncType { Glslang_Compile, diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index a55322d31..94f82ef31 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -800,6 +800,10 @@ struct OptionsParser return SLANG_FAIL; } } + else if (argStr == "-v") + { + sink->diagnoseRaw(Severity::Note, session->getBuildTagString()); + } else if (argStr == "--") { // The `--` option causes us to stop trying to parse options, diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 601312def..da04587fd 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -1,4 +1,5 @@ #include "../../slang.h" +#include "../../slang-tag-version.h" #include "../core/slang-io.h" #include "../core/slang-string-util.h" @@ -201,6 +202,11 @@ SLANG_NO_THROW void SLANG_MCALL Session::setDownstreamCompilerPrelude( m_downstreamCompilerPreludes[int(passThrough)] = prelude; } +SLANG_NO_THROW const char* SLANG_MCALL Session::getBuildTagString() +{ + return SLANG_TAG_VERSION; +} + struct IncludeHandlerImpl : IncludeHandler { Linkage* linkage; diff --git a/travis_build.sh b/travis_build.sh index d25958906..82ac8788b 100644 --- a/travis_build.sh +++ b/travis_build.sh @@ -4,6 +4,10 @@ wget https://github.com/shader-slang/slang-binaries/blob/master/premake/premake-5.0.0-alpha13/bin/linux-64/premake5?raw=true -O premake5 chmod u+x premake5 +# generate slang-tag-version.h +git describe --tags | sed -e "s/\(.*\)/\#define SLANG_TAG_VERSION \"\1\"/" > slang-tag-version.h +cat slang-tag-version.h + # Create the makefile ./premake5 gmake --cc=${CC} |
