ruby-yasm 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/ruby-yasm.gemspec CHANGED
@@ -1,105 +1,58 @@
1
- # encoding: utf-8
2
-
3
1
  require 'yaml'
4
2
 
5
- Gem::Specification.new do |gemspec|
6
- root = File.dirname(__FILE__)
7
- lib_dir = File.join(root,'lib')
8
- files = `git ls-files`.split($/)
9
-
10
- filter_files = lambda { |paths|
11
- files & case paths
12
- when Array
13
- paths
14
- when String
15
- Dir[paths]
16
- end
17
- }
18
-
19
- version = {
20
- :file => 'yasm/version',
21
- :constant => 'YASM::VERSION'
22
- }
23
-
24
- defaults = {
25
- 'name' => File.basename(root),
26
- 'files' => files,
27
- 'require_paths' => ['ext', 'lib'].select { |dir| File.directory?(dir) },
28
- 'executables' => filter_files['bin/*'].map { |path| File.basename(path) },
29
- 'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
30
- 'doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
31
- 'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}']
32
- }
3
+ Gem::Specification.new do |gem|
4
+ gemspec = YAML.load_file('gemspec.yml')
33
5
 
34
- metadata = defaults.merge(YAML.load_file('gemspec.yml'))
6
+ gem.name = gemspec.fetch('name')
7
+ gem.version = gemspec.fetch('version') do
8
+ lib_dir = File.join(File.dirname(__FILE__),'lib')
9
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
35
10
 
36
- gemspec.name = metadata['name']
37
- gemspec.version = if metadata['version']
38
- metadata['version']
39
- else
40
- $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
11
+ require 'yasm/version'
12
+ YASM::VERSION
13
+ end
41
14
 
42
- require version[:file]
43
- eval(version[:constant])
44
- end
15
+ gem.summary = gemspec['summary']
16
+ gem.description = gemspec['description']
17
+ gem.licenses = Array(gemspec['license'])
18
+ gem.authors = Array(gemspec['authors'])
19
+ gem.email = gemspec['email']
20
+ gem.homepage = gemspec['homepage']
21
+ gem.metadata = gemspec['metadata'] if gemspec['metadata']
45
22
 
46
- gemspec.summary = metadata.fetch('summary',metadata['description'])
47
- gemspec.description = metadata.fetch('description',metadata['summary'])
23
+ glob = lambda { |patterns| gem.files & Dir[*patterns] }
48
24
 
49
- gemspec.licenses = Array(metadata['license'])
50
- gemspec.authors = Array(metadata['authors'])
25
+ gem.files = if gemspec['files'] then glob[gemspec['files']]
26
+ else `git ls-files`.split($/)
27
+ end
51
28
 
52
- gemspec.email = metadata['email']
53
- gemspec.homepage = metadata['homepage']
54
-
55
- gemspec.require_paths = Array(metadata['require_paths'])
56
- gemspec.files = filter_files[metadata['files']]
57
- gemspec.files += Array(metadata['generated_files'])
58
- gemspec.executables = metadata['executables']
59
- gemspec.extensions = metadata['extensions']
60
-
61
- if Gem::VERSION < '1.7.'
62
- gemspec.default_executable = gemspec.executables.first
29
+ gem.executables = gemspec.fetch('executables') do
30
+ glob['bin/*'].map { |path| File.basename(path) }
63
31
  end
64
32
 
65
- gemspec.test_files = filter_files[metadata['test_files']]
66
- gemspec.extra_rdoc_files = Array(metadata['extra_doc_files'])
33
+ gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
34
+ gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
67
35
 
68
- gemspec.post_install_message = metadata['post_install_message']
69
- gemspec.requirements = metadata['requirements']
36
+ gem.require_paths = Array(gemspec.fetch('require_paths') {
37
+ %w[ext lib].select { |dir| File.directory?(dir) }
38
+ })
70
39
 
71
- if gemspec.respond_to?(:required_ruby_version=)
72
- gemspec.required_ruby_version = metadata['required_ruby_version']
73
- end
40
+ gem.requirements = gemspec['requirements']
41
+ gem.required_ruby_version = gemspec['required_ruby_version']
42
+ gem.required_rubygems_version = gemspec['required_rubygems_version']
43
+ gem.post_install_message = gemspec['post_install_message']
74
44
 
75
- if gemspec.respond_to?(:required_rubygems_version=)
76
- gemspec.required_rubygems_version = metadata['required_ruby_version']
77
- end
78
-
79
- parse_versions = lambda { |versions|
80
- case versions
81
- when Array
82
- versions.map { |v| v.to_s }
83
- when String
84
- versions.split(/,\s*/)
85
- end
86
- }
87
-
88
- if metadata['dependencies']
89
- metadata['dependencies'].each do |name,versions|
90
- gemspec.add_dependency(name,parse_versions[versions])
91
- end
92
- end
45
+ split = lambda { |string| string.split(/,\s*/) }
93
46
 
94
- if metadata['runtime_dependencies']
95
- metadata['runtime_dependencies'].each do |name,versions|
96
- gemspec.add_runtime_dependency(name,parse_versions[versions])
47
+ if gemspec['dependencies']
48
+ gemspec['dependencies'].each do |name,versions|
49
+ gem.add_dependency(name,split[versions])
97
50
  end
98
51
  end
99
52
 
100
- if metadata['development_dependencies']
101
- metadata['development_dependencies'].each do |name,versions|
102
- gemspec.add_development_dependency(name,parse_versions[versions])
53
+ if gemspec['development_dependencies']
54
+ gemspec['development_dependencies'].each do |name,versions|
55
+ gem.add_development_dependency(name,split[versions])
103
56
  end
104
57
  end
105
58
  end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+ require 'helpers/files'
3
+
4
+ require 'yasm/command'
5
+ require 'tempfile'
6
+
7
+ describe YASM::Command do
8
+ include Helpers::Files
9
+
10
+ describe ".run" do
11
+ subject { described_class }
12
+
13
+ it "should be able to assemble a file" do
14
+ file = Tempfile.new('yasm').path
15
+
16
+ subject.run do |yasm|
17
+ yasm.target = :x86
18
+ yasm.syntax = :gas
19
+ yasm.file = assembly_file('gas')
20
+ yasm.output = file
21
+ end
22
+
23
+ expect(File.size(file)).to be > 0
24
+ end
25
+ end
26
+
27
+ describe "#target" do
28
+ context "when no target has been set" do
29
+ it "must return nil" do
30
+ expect(subject.target).to be(nil)
31
+ end
32
+ end
33
+
34
+ context "when the target has been set to :x86" do
35
+ before { subject.target = :x86 }
36
+
37
+ it "must return :x86" do
38
+ expect(subject.target).to eq(:x86)
39
+ end
40
+ end
41
+
42
+ context "when #arch is :x86 and #machine is :x86" do
43
+ before do
44
+ subject.arch = :x86
45
+ subject.machine = :x86
46
+ end
47
+
48
+ it "must return :x86" do
49
+ expect(subject.target).to eq(:x86)
50
+ end
51
+ end
52
+
53
+ context "when the target has been set to :amd64" do
54
+ before { subject.target = :amd64}
55
+
56
+ it "must return :amd64" do
57
+ expect(subject.target).to eq(:amd64)
58
+ end
59
+ end
60
+
61
+ context "when #arch is :x86 and #machine is :amd64" do
62
+ before do
63
+ subject.arch = :x86
64
+ subject.machine = :amd64
65
+ end
66
+
67
+ it "must return :amd64" do
68
+ expect(subject.target).to eq(:amd64)
69
+ end
70
+ end
71
+
72
+ context "when the target has been set to :lc3b" do
73
+ before { subject.target = :lc3b}
74
+
75
+ it "must return :lc3b" do
76
+ expect(subject.target).to eq(:lc3b)
77
+ end
78
+ end
79
+
80
+ context "when #arch is :lc3b and #machine is :lc3b" do
81
+ before do
82
+ subject.arch = :lc3b
83
+ subject.machine = :lc3b
84
+ end
85
+
86
+ it "must return :lc3b" do
87
+ expect(subject.target).to eq(:lc3b)
88
+ end
89
+ end
90
+ end
91
+ end
data/spec/program_spec.rb CHANGED
@@ -4,22 +4,101 @@ require 'helpers/files'
4
4
  require 'yasm/program'
5
5
  require 'tempfile'
6
6
 
7
- describe Program do
7
+ describe YASM::Program do
8
8
  include Helpers::Files
9
9
 
10
- subject { described_class.find }
10
+ describe ".assemble" do
11
+ subject { described_class }
11
12
 
12
- it "should be able to assemble a file" do
13
- file = Tempfile.new('yasm').path
13
+ it "should be able to assemble a file" do
14
+ file = Tempfile.new('yasm').path
14
15
 
15
- subject.assemble do |yasm|
16
- yasm.target! :x86
16
+ subject.assemble do |yasm|
17
+ yasm.target! :x86
17
18
 
18
- yasm.syntax = :gas
19
- yasm.file = assembly_file('gas')
20
- yasm.output = file
19
+ yasm.syntax = :gas
20
+ yasm.file = assembly_file('gas')
21
+ yasm.output = file
22
+ end
23
+
24
+ expect(File.size(file)).to be > 0
25
+ end
26
+ end
27
+
28
+ describe "#assemble" do
29
+ it "should be able to assemble a file" do
30
+ file = Tempfile.new('yasm').path
31
+
32
+ subject.assemble do |yasm|
33
+ yasm.target! :x86
34
+
35
+ yasm.syntax = :gas
36
+ yasm.file = assembly_file('gas')
37
+ yasm.output = file
38
+ end
39
+
40
+ expect(File.size(file)).to be > 0
41
+ end
42
+ end
43
+
44
+ describe "#initialize" do
45
+ subject { described_class.new(target: :amd64) }
46
+
47
+ it "should support a :target option" do
48
+ expect(subject.arch).to eq(:x86)
49
+ expect(subject.machine).to eq(:amd64)
50
+ end
51
+ end
52
+
53
+ describe "#target!" do
54
+ it "should return true for valid targets" do
55
+ expect(subject.target!(:amd64)).to be(true)
21
56
  end
22
57
 
23
- File.size(file).should > 0
58
+ context "when given an unknown target name" do
59
+ let(:name) { :lol }
60
+
61
+ it "should raise ArgumentError when passed unknown targets" do
62
+ expect {
63
+ subject.target!(name)
64
+ }.to raise_error(ArgumentError,"unknown YASM target: #{name.inspect}")
65
+ end
66
+ end
67
+
68
+ context "when given :x86" do
69
+ before { subject.target!(:x86) }
70
+
71
+ it "should set the #arch value" do
72
+ expect(subject.arch).to eq(:x86)
73
+ end
74
+
75
+ it "should set the #machine value" do
76
+ expect(subject.machine).to eq(:x86)
77
+ end
78
+ end
79
+
80
+ context "when given :amd64" do
81
+ before { subject.target!(:amd64) }
82
+
83
+ it "should set the #arch value" do
84
+ expect(subject.arch).to eq(:x86)
85
+ end
86
+
87
+ it "should set the #machine value" do
88
+ expect(subject.machine).to eq(:amd64)
89
+ end
90
+ end
91
+
92
+ context "when given :lc3b" do
93
+ before { subject.target!(:lc3b) }
94
+
95
+ it "should set the #arch value" do
96
+ expect(subject.arch).to eq(:lc3b)
97
+ end
98
+
99
+ it "should set the #machine value" do
100
+ expect(subject.machine).to eq(:lc3b)
101
+ end
102
+ end
24
103
  end
25
104
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,6 @@
1
- require 'rubygems'
2
- gem 'rspec', '~> 2.4'
3
1
  require 'rspec'
2
+ require 'simplecov'
3
+ SimpleCov.start
4
4
 
5
5
  require 'yasm/version'
6
-
7
6
  include YASM
data/spec/yasm_spec.rb CHANGED
@@ -4,6 +4,6 @@ require 'spec_helper'
4
4
 
5
5
  describe YASM do
6
6
  it "should have a VERSION constant" do
7
- subject.const_defined?('VERSION').should == true
7
+ expect(subject.const_defined?('VERSION')).to eq(true)
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,80 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-yasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Postmodern
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-05-28 00:00:00.000000000 Z
11
+ date: 2022-01-08 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: rprogram
14
+ name: command_mapper
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '0.3'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: '0.3'
30
- - !ruby/object:Gem::Dependency
31
- name: rubygems-tasks
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
17
+ - - "~>"
36
18
  - !ruby/object:Gem::Version
37
19
  version: '0.1'
38
- type: :development
20
+ type: :runtime
39
21
  prerelease: false
40
22
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
23
  requirements:
43
- - - ~>
24
+ - - "~>"
44
25
  - !ruby/object:Gem::Version
45
26
  version: '0.1'
46
27
  - !ruby/object:Gem::Dependency
47
- name: rspec
28
+ name: bundler
48
29
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
30
  requirements:
51
- - - ~>
31
+ - - "~>"
52
32
  - !ruby/object:Gem::Version
53
- version: '2.4'
33
+ version: '2.0'
54
34
  type: :development
55
35
  prerelease: false
56
36
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
37
  requirements:
59
- - - ~>
38
+ - - "~>"
60
39
  - !ruby/object:Gem::Version
61
- version: '2.4'
62
- - !ruby/object:Gem::Dependency
63
- name: yard
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: '0.7'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- version: '0.7'
40
+ version: '2.0'
78
41
  description: ruby-yasm provides a Ruby interface to YASM assembler.
79
42
  email: postmodern.mod3@gmail.com
80
43
  executables: []
@@ -84,55 +47,52 @@ extra_rdoc_files:
84
47
  - LICENSE.txt
85
48
  - README.md
86
49
  files:
87
- - .document
88
- - .gemtest
89
- - .gitignore
90
- - .rspec
91
- - .specopts
92
- - .yardopts
50
+ - ".document"
51
+ - ".gemtest"
52
+ - ".github/workflows/ruby.yml"
53
+ - ".gitignore"
54
+ - ".rspec"
55
+ - ".specopts"
56
+ - ".yardopts"
93
57
  - ChangeLog.md
58
+ - Gemfile
94
59
  - LICENSE.txt
95
60
  - README.md
96
61
  - Rakefile
97
62
  - gemspec.yml
98
63
  - lib/yasm.rb
64
+ - lib/yasm/command.rb
99
65
  - lib/yasm/program.rb
100
- - lib/yasm/task.rb
101
66
  - lib/yasm/version.rb
102
67
  - ruby-yasm.gemspec
68
+ - spec/command_spec.rb
103
69
  - spec/helpers/files.rb
104
70
  - spec/helpers/files/gas.S
105
71
  - spec/program_spec.rb
106
72
  - spec/spec_helper.rb
107
- - spec/task_spec.rb
108
73
  - spec/yasm_spec.rb
109
- homepage: https://github.com/sophsec/ruby-yasm#readme
74
+ homepage: https://github.com/postmodern/ruby-yasm#readme
110
75
  licenses:
111
76
  - MIT
112
- post_install_message:
77
+ metadata: {}
78
+ post_install_message:
113
79
  rdoc_options: []
114
80
  require_paths:
115
81
  - lib
116
82
  required_ruby_version: !ruby/object:Gem::Requirement
117
- none: false
118
83
  requirements:
119
- - - ! '>='
84
+ - - ">="
120
85
  - !ruby/object:Gem::Version
121
86
  version: '0'
122
87
  required_rubygems_version: !ruby/object:Gem::Requirement
123
- none: false
124
88
  requirements:
125
- - - ! '>='
89
+ - - ">="
126
90
  - !ruby/object:Gem::Version
127
91
  version: '0'
128
92
  requirements:
129
93
  - yasm >= 0.6.0
130
- rubyforge_project:
131
- rubygems_version: 1.8.24
132
- signing_key:
133
- specification_version: 3
94
+ rubygems_version: 3.2.22
95
+ signing_key:
96
+ specification_version: 4
134
97
  summary: A Ruby interface to YASM.
135
- test_files:
136
- - spec/program_spec.rb
137
- - spec/task_spec.rb
138
- - spec/yasm_spec.rb
98
+ test_files: []
data/lib/yasm/task.rb DELETED
@@ -1,153 +0,0 @@
1
- require 'rprogram/task'
2
-
3
- module YASM
4
- #
5
- # ## YASM options:
6
- #
7
- # * `--version` - `yasm.version`
8
- # * `--license` - `yasm.license`
9
- # * `--help` - `yasm.help`
10
- #
11
- # * `--arch` - `yasm.arch`
12
- # * `--parser` - `yasm.parser`
13
- # * `--preproc` - `yasm.preprocessor`
14
- # * `--oformat` - `yasm.output_format`
15
- # * `--dformat` - `yasm.debug_format`
16
- # * `--lformat` - `yasm.list_format`
17
- #
18
- # * `--list` - `yasm.list_file`
19
- # * `--objfile` - `yasm.output`
20
- # * `--mapfile` - `yasm.map_file`
21
- #
22
- # * `--machine` - `yasm.machine`
23
- # * `--force-strict` - `yasm.force_strict`
24
- # * `-w` - `yasm.inhibit_warnings`
25
- # * `-W` - `yasm.toggle_warnings`
26
- # * `-M` - `yasm.gen_makefile_deps`
27
- # * `-E` - `yasm.redirect_errors_to`
28
- # * `-e` - `yasm.redirect_errors`
29
- # * `--preproc-only` - `yasm.preprocessor_only`
30
- # * `-I` - `yasm.include`
31
- # * `-P` - `yasm.pre_include`
32
- # * `-D` - `yasm.define`
33
- # * `-U` - `yasm.undefine`
34
- # * `-X` - `yasm.message_style`
35
- # * `--prefix` - `yasm.prefix`
36
- # * `--suffix` - `yasm.suffix`
37
- #
38
- # * `file` - `yasm.file`
39
- #
40
- class Task < RProgram::Task
41
-
42
- # The known YASM targets
43
- TARGETS = {
44
- :x86 => {:arch => :x86, :machine => :x86},
45
- :amd64 => {:arch => :x86, :machine => :amd64},
46
- :lc3b => {:arch => :lc3b, :machine => :lc3b}
47
- }
48
-
49
- long_option :flag => '--version'
50
- long_option :flag => '--license'
51
- long_option :flag => '--help'
52
-
53
- long_option :flag => '--arch', :equals => true
54
- long_option :flag => '--parser', :equals => true
55
- long_option :flag => '--preproc',
56
- :equals => true,
57
- :name => :preprocessor
58
- long_option :flag => '--oformat',
59
- :equals => true,
60
- :name => :output_format
61
- long_option :flag => '--dformat',
62
- :equals => true,
63
- :name => :debug_format
64
- long_option :flag => '--lformat',
65
- :equals => true,
66
- :name => :list_format
67
-
68
- long_option :flag => '--list',
69
- :equals => true,
70
- :name => :list_file
71
- long_option :flag => '--objfile',
72
- :equals => true,
73
- :name => :output
74
- long_option :flag => '--mapfile',
75
- :equals => true,
76
- :name => :map_file
77
-
78
- long_option :flag => '--machine', :equals => true
79
- long_option :flag => '--force-strict'
80
- short_option :flag => '-w', :name => :inhibit_warnings
81
- short_option :flag => '-W', :name => :toggle_warnings
82
- short_option :flag => '-M', :name => :gen_makefile_deps
83
- short_option :flag => '-E', :name => :redirect_errors_to
84
- short_option :flag => '-s', :name => :redirect_errors
85
- long_option :flag => '--preproc-only', :name => :preprocessor_only
86
- short_option :flag => '-I', :name => :include, :multiple => true
87
- short_option :flag => '-P', :name => :pre_include, :multiple => true
88
- short_option :flag => '-D', :name => :define, :multiple => true
89
- short_option :flag => '-U', :name => :undefine, :multiple => true
90
- short_option :flag => '-X', :name => :message_style
91
- long_option :flag => '--prefix'
92
- long_option :flag => '--suffix'
93
-
94
- non_option :tailing => true, :name => :file
95
-
96
- #
97
- # Creates a new Task object.
98
- #
99
- # @param [Hash{Symbol => Object}] options
100
- # Additional options for the task.
101
- #
102
- # @option options [String, Symbol] :target
103
- # The arch/machine to target.
104
- #
105
- # @yield [task]
106
- # If a block is given, it will be passed the newly created task
107
- # object.
108
- #
109
- # @yieldparam [Task] task
110
- # The new task object.
111
- #
112
- # @see Task#target!
113
- #
114
- def initialize(options={},&block)
115
- target = options.delete(:target)
116
-
117
- super(options,&block)
118
-
119
- target!(target) if target
120
- end
121
-
122
- #
123
- # Sets the YASM `arch` and `machine`.
124
- #
125
- # @param [String, Symbol] name
126
- # The target name.
127
- #
128
- # @raise [ArgumentError]
129
- # The specified target is unknown.
130
- #
131
- # @return [true]
132
- # The YASM `arch` and `machine` options were set successfully.
133
- #
134
- # @example
135
- # yasm.target! :amd64
136
- #
137
- def target!(name)
138
- target = TARGETS[name.to_sym]
139
-
140
- unless target
141
- raise(ArgumentError,"unknown YASM target #{name.inspect}")
142
- end
143
-
144
- self.arch = target[:arch]
145
- self.machine = target[:machine]
146
- return true
147
- end
148
-
149
- alias syntax parser
150
- alias syntax= parser=
151
-
152
- end
153
- end