summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-09-23 13:04:22 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-09-23 13:05:49 +0100
commit25d852fe66df96f7a9b6feb898a085949bb02713 (patch)
treea1c13789abe6004a90d1321a594b1d04d33b1208
parent60777d91f7b3c6dd370911ac213693404809f55e (diff)
downloadmorph-25d852fe66df96f7a9b6feb898a085949bb02713.tar.gz
import: Check that .gemspec version matches what's expected
Some Gemspecs change the version number based on environment vars, etc.
-rw-r--r--import/main.py11
-rwxr-xr-ximport/rubygems.to_chunk21
2 files changed, 25 insertions, 7 deletions
diff --git a/import/main.py b/import/main.py
index d914fffc..968c1dcf 100644
--- a/import/main.py
+++ b/import/main.py
@@ -602,10 +602,15 @@ class BaserockImportApplication(cliapp.Application):
return version, ref
def generate_chunk_morph_for_package(self, kind, source_repo, name,
- filename):
+ version, filename):
tool = '%s.to_chunk' % kind
self.status('Calling %s to generate chunk morph for %s', tool, name)
- text = run_extension(tool, [source_repo.dirname, name])
+
+ args = [source_repo.dirname, name]
+ if version != 'master':
+ args.append(version)
+ text = run_extension(tool, args)
+
loader = morphlib.morphloader.MorphologyLoader()
return loader.load_from_string(text, filename)
@@ -617,7 +622,7 @@ class BaserockImportApplication(cliapp.Application):
def generate_morphology():
morphology = self.generate_chunk_morph_for_package(
- kind, source_repo, name, morphology_filename)
+ kind, source_repo, name, version, morphology_filename)
morph_set.save_morphology(morphology_filename, morphology)
return morphology
diff --git a/import/rubygems.to_chunk b/import/rubygems.to_chunk
index fbf9de96..e1d24ec7 100755
--- a/import/rubygems.to_chunk
+++ b/import/rubygems.to_chunk
@@ -60,23 +60,30 @@ class RubyGemChunkMorphologyGenerator
# No options so far ..
opts = OptionParser.new
- opts.banner = "Usage: rubygems.to_chunk SOURCE_DIR GEM_NAME"
+ opts.banner = "Usage: rubygems.to_chunk SOURCE_DIR GEM_NAME [VERSION]"
opts.separator ""
opts.separator "This tool reads the Gemfile and optionally the " +
"Gemfile.lock from a Ruby project "
opts.separator "source tree in SOURCE_DIR. It outputs a chunk " +
"morphology for GEM_NAME on stdout."
+ opts.separator "If VERSION is supplied, it is used to check that " +
+ "the build instructions will"
+ opts.separator "produce the expected version of the Gem."
opts.separator ""
opts.separator "It is intended for use with the `baserock-import` tool."
parsed_arguments = opts.parse!(arguments)
- if parsed_arguments.length != 2
+ if parsed_arguments.length != 2 && parsed_arguments.length != 3
STDERR.puts opts.help
exit 1
end
- parsed_arguments
+ source_dir, gem_name, expected_version = parsed_arguments
+ if expected_version != nil
+ expected_version = Gem::Version.new(expected_version)
+ end
+ [source_dir, gem_name, expected_version]
end
def error(message)
@@ -225,7 +232,7 @@ class RubyGemChunkMorphologyGenerator
end
def run
- source_dir_name, gem_name = parse_options(ARGV)
+ source_dir_name, gem_name, expected_version = parse_options(ARGV)
Log.info("Creating chunk morph for #{gem_name} based on " +
"source code in #{source_dir_name}")
@@ -250,6 +257,12 @@ class RubyGemChunkMorphologyGenerator
exit 1
end
+ if expected_version != nil && spec.version != expected_version
+ error "Source in #{source_dir_name} produces #{spec.full_name}, but " +
+ "the expected version was #{expected_version}."
+ exit 1
+ end
+
morph = generate_chunk_morph_for_gem(spec)
# One might think that you could use the Bundler::Dependency.groups