nxbuild 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2835dce041e72293902dc74d0c9a953de5b0cae3
4
+ data.tar.gz: cdeb13a3f7c9d51e6aebee5a7e9e28eed8817e40
5
+ SHA512:
6
+ metadata.gz: ff4ce25dbb1289722163c1689f8154c9d9694ce02e38236c08e313fd05b4d7bc9619c63c0682f2d404873139b61c2e22b79c1c44f0dc04bbac4c6bf8b91e1586
7
+ data.tar.gz: 894e062d9a9ed56222b58cd7bd7032181c38d69234efacf78fbaf354df76e12294887e539ee268861d054f4a8e03ced339616de52150f523a499ea197a748d94
data/exe/nxbuild ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'nxbuild'
4
+
5
+ NxBuild.run ARGV
data/lib/nxbuild.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'nxbuild/generator'
2
+ require 'nxbuild/os'
3
+ require 'nxbuild/project'
4
+ require 'nxbuild/sln'
5
+ require 'nxbuild/target'
6
+ require 'nxbuild/uuid'
7
+ require 'nxbuild/version'
8
+ require 'nxbuild/xml'
9
+
10
+ module NxBuild
11
+ def self.run(args)
12
+ # TODO parse args
13
+ config = Project.new
14
+ config.import 'project.nx'
15
+ gen = Generator::VS2015.new
16
+ gen.config = config
17
+ gen.generate
18
+ end
19
+ end
@@ -0,0 +1,2 @@
1
+ require 'nxbuild/generator/base'
2
+ require 'nxbuild/generator/vs2015'
@@ -0,0 +1,13 @@
1
+ require 'fileutils'
2
+
3
+ module NxBuild
4
+ module Generator
5
+ class Base
6
+ attr_accessor :config
7
+
8
+ def generate
9
+ FileUtils.mkdir_p 'build'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,135 @@
1
+ require 'nxbuild/generator/base'
2
+ require 'nxbuild/uuid'
3
+ require 'nxbuild/sln'
4
+ require 'nxbuild/xml'
5
+
6
+ module NxBuild
7
+ module Generator
8
+ class VS2015 < Generator::Base
9
+ CONFIGS = ['Debug', 'Release']
10
+
11
+ def initialize
12
+ @targets_uuid = {}
13
+ end
14
+
15
+ def target_uuid(name, escaped = true)
16
+ unless @targets_uuid.include? name
17
+ @targets_uuid[name] = NxBuild::UUID.create
18
+ end
19
+ uuid = @targets_uuid[name]
20
+ if escaped
21
+ uuid = %["{#{uuid}}"]
22
+ else
23
+ uuid = %[{#{uuid}}]
24
+ end
25
+ return uuid
26
+ end
27
+
28
+ def generate
29
+ super
30
+ generate_sln
31
+ @config.targets.each do |target|
32
+ generate_vcxproj target
33
+ end
34
+ end
35
+
36
+ def generate_sln
37
+ tree = Sln.new
38
+ buffer = "Microsoft Visual Studio Solution File, Format Version 12.00\n"
39
+ buffer << "# Visual Studio 14\n"
40
+ @config.targets.each do |t|
41
+ generate_sln_target tree, t
42
+ end
43
+ tree.dump(buffer)
44
+ File.write("build/" + @config.name + ".sln", buffer)
45
+ end
46
+
47
+ def generate_sln_target(tree, target)
48
+ cpp_uuid = %["{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"]
49
+ node = SlnNode.new 'Project'
50
+ node.key = cpp_uuid
51
+ node.values << %{"#{target.name}"}
52
+ node.values << %{"#{target.name}.vcxproj"}
53
+ node.values << target_uuid(target.name)
54
+ tree.children << node
55
+ end
56
+
57
+ def generate_vcxproj(target)
58
+ name = target.name
59
+ vcx = name + ".vcxproj"
60
+ xml = Xml.new('Project')
61
+ xml['DefaultTargets'] = 'Build'
62
+ xml['ToolsVersion'] = '14.0'
63
+ xml['xmlns'] = "http://schemas.microsoft.com/developer/msbuild/2003"
64
+ generate_vcxproj_config(xml, target)
65
+ generate_vcxproj_globals(xml, target)
66
+ generate_vcxproj_cpp_config(xml, target)
67
+ buffer = ""
68
+ xml.dump(buffer)
69
+ File.write("build/" + vcx, buffer)
70
+ end
71
+
72
+ def generate_vcxproj_config(xml, target)
73
+ node = XmlNode.new 'ItemGroup'
74
+ node['Label'] = 'ProjectConfigurations'
75
+ CONFIGS.each do |config|
76
+ pc = XmlNode.new 'ProjectConfiguration'
77
+ pc['Include'] = "#{config}|x64"
78
+ conf = XmlNode.new 'Configuration'
79
+ conf << config
80
+ platform = XmlNode.new 'Platform'
81
+ platform << 'x64'
82
+ pc << conf
83
+ pc << platform
84
+ node << pc
85
+ end
86
+ xml << node
87
+ end
88
+
89
+ def generate_vcxproj_globals(xml, target)
90
+ pg = XmlNode.new 'PropertyGroup'
91
+ pg['Label'] = 'Globals'
92
+ guid = XmlNode.new 'ProjectGUID'
93
+ guid << target_uuid(target.name, false)
94
+ pg << guid
95
+ keyword = XmlNode.new 'Keyword'
96
+ keyword << 'Win32Proj'
97
+ pg << keyword
98
+ platform = XmlNode.new 'Platform'
99
+ platform << 'x64'
100
+ pg << platform
101
+ project_name = XmlNode.new 'ProjectName'
102
+ project_name << target.name
103
+ pg << project_name
104
+ xml << pg
105
+ end
106
+
107
+ def generate_vcxproj_cpp_config(xml, target)
108
+ import = XmlNode.new 'Import'
109
+ import['Project'] = "$(VCTargetsPath)\\Microsoft.Cpp.Default.props"
110
+ xml << import
111
+ CONFIGS.each do |conf|
112
+ pg = XmlNode.new 'PropertyGroup'
113
+ pg['Condition'] = "'$(Configuration)|$(Platform)'=='#{conf}|x64'"
114
+ pg['Label'] = "Configuration"
115
+ ctype = XmlNode.new 'ConfigurationType'
116
+ ctype << 'Application'
117
+ pg << ctype
118
+ mfc = XmlNode.new 'UseOfMfc'
119
+ mfc << 'false'
120
+ pg << mfc
121
+ character_set = XmlNode.new 'CharacterSet'
122
+ character_set << 'MultiByte'
123
+ pg << character_set
124
+ toolset = XmlNode.new 'PlatformToolset'
125
+ toolset << 'v140'
126
+ pg << toolset
127
+ xml << pg
128
+ end
129
+ import = XmlNode.new 'Import'
130
+ import['Project'] = "$(VCTargetsPath)\\Microsoft.Cpp.props"
131
+ xml << import
132
+ end
133
+ end
134
+ end
135
+ end
data/lib/nxbuild/os.rb ADDED
@@ -0,0 +1,7 @@
1
+ module NxBuild
2
+ module OS
3
+ def self.windows?
4
+ return ENV['OS'] == 'Windows_NT'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ require 'nxbuild/target'
2
+
3
+ module NxBuild
4
+ class Project
5
+ attr_reader :name
6
+ attr_reader :targets
7
+ attr_reader :targets_hash
8
+
9
+ def initialize
10
+ @targets = []
11
+ @targets_hash = {}
12
+ end
13
+
14
+ def project(name)
15
+ @name = name
16
+ end
17
+
18
+ def import(path)
19
+ buffer = File.read(path)
20
+ self.instance_eval(buffer, path, 1)
21
+ end
22
+
23
+ def cpp_target(name, &block)
24
+ _target(name, Target::Cpp, &block)
25
+ end
26
+
27
+ def _target(name, klass, &block)
28
+ t = klass.new
29
+ t.name = name
30
+ t.instance_exec &block
31
+ @targets << t
32
+ @targets_hash[name] = t
33
+ return t
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ require 'nxbuild/sln/node'
2
+ require 'nxbuild/sln/property'
3
+ require 'nxbuild/sln/sln'
@@ -0,0 +1,31 @@
1
+ require 'nxbuild/sln/property'
2
+
3
+ module NxBuild
4
+ class SlnNode < SlnProperty
5
+ attr_accessor :tag
6
+ attr_reader :children
7
+
8
+ def initialize(tag)
9
+ super()
10
+ @tag = tag
11
+ @children = []
12
+ end
13
+
14
+ def dump(buffer, indent = 0)
15
+ buffer << "\t" * indent
16
+ tagline = tag
17
+ unless @key.nil?
18
+ tagline += '(' + @key + ')'
19
+ end
20
+ unless @values.nil?
21
+ tagline += ' = ' + @values.join(', ')
22
+ end
23
+ buffer << "#{tagline}\n"
24
+ @children.each do |c|
25
+ c.dump(buffer, indent + 1)
26
+ end
27
+ buffer << "\t" * indent
28
+ buffer << "End#{@tag}\n"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ module NxBuild
2
+ class SlnProperty
3
+ attr_accessor :key
4
+ attr_accessor :values
5
+
6
+ def initialize
7
+ @values = []
8
+ end
9
+
10
+ def dump(buffer, indent = 0)
11
+ buffer << "\t" * indent
12
+ unless @key.nil?
13
+ buffer << @key
14
+ end
15
+ unless @values.nil?
16
+ buffer << ' = '
17
+ buffer << @values.join(', ')
18
+ end
19
+ buffer << "\n"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ module NxBuild
2
+ class Sln
3
+ attr_accessor :children
4
+
5
+ def initialize
6
+ @children = []
7
+ end
8
+
9
+ def dump(buffer)
10
+ @children.each {|c| c.dump(buffer) }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ require 'nxbuild/target/base'
2
+ require 'nxbuild/target/cpp'
@@ -0,0 +1,7 @@
1
+ module NxBuild
2
+ module Target
3
+ class Base
4
+ attr_accessor :name
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,34 @@
1
+ require 'nxbuild/target/base'
2
+
3
+ module NxBuild
4
+ module Target
5
+ class Cpp < Target::Base
6
+ attr_reader :sources
7
+
8
+ def initialize
9
+ @sources = []
10
+ end
11
+
12
+ def source(path)
13
+ files = Dir[path + '/**/*.c'] + Dir[path + '/**/*.cpp'] + Dir[path + '/**/*.m'] + Dir[path + '/**/*.mm']
14
+ @sources += filter(files)
15
+ end
16
+
17
+ def filter(files)
18
+ filters = ['Mac', 'Windows']
19
+ if OS.windows?
20
+ filters.delete('Windows')
21
+ end
22
+ filters.each do |filter|
23
+ new_files = []
24
+ files.each_with_index do |file, i|
25
+ s = file.split('/')
26
+ new_files << file unless s.any? {|seg| seg == filter}
27
+ end
28
+ files = new_files
29
+ end
30
+ files
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ module NxBuild
2
+ module UUID
3
+ def self.create
4
+ fields = []
5
+ 5.times do
6
+ fields << rand()
7
+ end
8
+ coeff = [
9
+ 2**32,
10
+ 2**16,
11
+ 2**16,
12
+ 2**16,
13
+ 2**48
14
+ ]
15
+ uuid_arr = fields.zip(coeff).map{|a| (a[0] * a[1]).to_i }
16
+ '%08X-%04X-%04X-%04X-%012X' % uuid_arr
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module NxBuild
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'nxbuild/xml/node'
2
+ require 'nxbuild/xml/xml'
@@ -0,0 +1,56 @@
1
+ module NxBuild
2
+ class XmlNode
3
+ attr_accessor :children
4
+ attr_accessor :attr
5
+ attr_reader :tag
6
+
7
+ def initialize(tag)
8
+ @tag = tag
9
+ @attr = {}
10
+ @children = []
11
+ end
12
+
13
+ def [](str)
14
+ @attr[str]
15
+ end
16
+
17
+ def []=(str, value)
18
+ @attr[str] = value
19
+ end
20
+
21
+ def <<(value)
22
+ @children << value
23
+ end
24
+
25
+ def dump(buffer, indent = 0)
26
+ buffer << " " * indent
27
+ tagline = "<" + @tag
28
+ @attr.each do |k, v|
29
+ tagline += " #{k}=\"#{v}\""
30
+ end
31
+ if children.empty?
32
+ tagline += "/>\n"
33
+ buffer << tagline
34
+ return
35
+ end
36
+ tagline += ">"
37
+ unless children.size == 1 && !(children.first.is_a? XmlNode)
38
+ tagline += "\n"
39
+ end
40
+ buffer << tagline
41
+ children.each do |c|
42
+ if c.is_a? XmlNode
43
+ c.dump(buffer, indent + 1)
44
+ elsif children.size == 1
45
+ buffer << c
46
+ else
47
+ buffer << " " * (indent + 1) + c + "\n"
48
+ end
49
+ end
50
+ unless children.size == 1 && !(children.first.is_a? XmlNode)
51
+ buffer << " " * indent
52
+ end
53
+ buffer << "</#{@tag}>\n"
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,14 @@
1
+ require 'nxbuild/xml/node'
2
+
3
+ module NxBuild
4
+ class Xml < XmlNode
5
+ def initialize(tag)
6
+ super
7
+ end
8
+
9
+ def dump(buffer, indent = 0)
10
+ buffer << %{<?xml version="1.0" encoding="UTF-8"?>\n}
11
+ super
12
+ end
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nxbuild
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nax
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - max.bacoux@gmail.com
44
+ executables:
45
+ - nxbuild
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - exe/nxbuild
50
+ - lib/nxbuild.rb
51
+ - lib/nxbuild/generator.rb
52
+ - lib/nxbuild/generator/base.rb
53
+ - lib/nxbuild/generator/vs2015.rb
54
+ - lib/nxbuild/os.rb
55
+ - lib/nxbuild/project.rb
56
+ - lib/nxbuild/sln.rb
57
+ - lib/nxbuild/sln/node.rb
58
+ - lib/nxbuild/sln/property.rb
59
+ - lib/nxbuild/sln/sln.rb
60
+ - lib/nxbuild/target.rb
61
+ - lib/nxbuild/target/base.rb
62
+ - lib/nxbuild/target/cpp.rb
63
+ - lib/nxbuild/uuid.rb
64
+ - lib/nxbuild/version.rb
65
+ - lib/nxbuild/xml.rb
66
+ - lib/nxbuild/xml/node.rb
67
+ - lib/nxbuild/xml/xml.rb
68
+ homepage: https://github.com/Nax/nxbuild
69
+ licenses: []
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.4.5.1
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: A sane, (c)make friendly build system, scriptable in ruby.
91
+ test_files: []