From c83f8bddf28d23e8bb2e5287fb5eef66d1fe452e Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Thu, 1 Aug 2024 11:47:58 -0400 Subject: [PATCH] Working towards gemifying and automatically reporting version. --- Gemfile | 7 ------- cmock.gemspec | 34 ++++++++++++++++++++++++++++++++++ lib/cmock.rb | 6 ++++++ lib/cmock_version.rb | 23 +++++++++++++++++++++++ 4 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 cmock.gemspec create mode 100644 lib/cmock_version.rb diff --git a/Gemfile b/Gemfile index 96ac06ec..c6d4f853 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1 @@ source "http://rubygems.org/" - -gem "bundler" -gem "rake" -gem "minitest" -gem "require_all" -gem "constructor" -gem "diy" diff --git a/cmock.gemspec b/cmock.gemspec new file mode 100644 index 00000000..9253126d --- /dev/null +++ b/cmock.gemspec @@ -0,0 +1,34 @@ +# -*- encoding: utf-8 -*- +$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), 'lib')) +require "lib/cmock_version" +require 'date' + +Gem::Specification.new do |s| + s.name = "cmock" + s.version = CMockVersion::GEM + s.platform = Gem::Platform::RUBY + s.authors = ["Mark VanderVoord", "Michael Karlesky", "Greg Williams"] + s.email = ["mark@vandervoord.net", "michael@karlesky.net", "barney.williams@gmail.com"] + s.homepage = "http://throwtheswitch.org/cmock" + s.summary = "CMock is a mocking framework for C unit testing. It's a member of the ThrowTheSwitch.org family of tools." + s.description = <<-DESC +CMock is a mocking framework for C unit testing. It accepts header files and generates mocks automagically for you. + DESC + s.licenses = ['MIT'] + + s.metadata = { + "homepage_uri" => s.homepage, + "bug_tracker_uri" => "https://github.com/ThrowTheSwitch/CMock/issues", + "documentation_uri" => "https://github.com/ThrowTheSwitch/CMock/blob/master/docs/CMock_Summary.md", + "mailing_list_uri" => "https://groups.google.com/forum/#!categories/throwtheswitch/cmock", + "source_code_uri" => "https://github.com/ThrowTheSwitch/CMock" + } + + s.required_ruby_version = ">= 3.0.0" + + s.files += Dir['**/*'] + s.test_files = Dir['test/**/*'] + s.executables = ['lib/cmock.rb'] + + s.require_paths = ["lib"] +end diff --git a/lib/cmock.rb b/lib/cmock.rb index 0e5cc7ad..daa34048 100644 --- a/lib/cmock.rb +++ b/lib/cmock.rb @@ -1,3 +1,4 @@ +#!/bin/ruby # ========================================== # CMock Project - Automatic Mock Generation for C # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams @@ -95,6 +96,11 @@ def option_maker(options, key, val) opt_flag = true when '--skeleton' options[:skeleton] = true + when '--version' + require 'cmock_version' + include CMockVersion + puts CMOCK_VERSION + exit(0) when /^--strippables="?(.*)"?/ # --strippables are dealt with separately since the user is allowed to # enter any valid regular expression as argument diff --git a/lib/cmock_version.rb b/lib/cmock_version.rb new file mode 100644 index 00000000..dc77c23e --- /dev/null +++ b/lib/cmock_version.rb @@ -0,0 +1,23 @@ + +module CMockVersion + # Where is the header file from here? + path = File.expand_path( File.join(File.dirname(__FILE__),"..","src","cmock.h") ) + + # Actually look up the version in the header file + a = [0,0,0] + begin + File.readlines(path).each do |line| + ["VERSION_MAJOR", "VERSION_MINOR", "VERSION_BUILD"].each_with_index do |field, i| + m = line.match(/CMOCK_#{field}\s+(\d+)/) + a[i] = m[1] unless (m.nil?) + end + end + rescue + abort("Can't find my header file.") + end + + # splat it to return the final value + CMOCK_VERSION = "#{a.join(".")}" + + GEM = "0.32.0" +end