didgood 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 30468ec76fd6ef7bcf9811dd6b789a0dcf5a01b97d7cbadddaacda4e9efee011
4
+ data.tar.gz: e7dd28d517d84ffaaf3dc0c7b34bf945efd59ea84f57a66f30184c5c1759c8b7
5
+ SHA512:
6
+ metadata.gz: 34f947738281d597651c2dd87037dabfcb91ca3e8422335b6a4b8710b64850d62fd59504b0973ff816a4177ff22336b1f8758d0aa8830f4e4ed3671a80a54eb8
7
+ data.tar.gz: da573cf10011fc0e6a15c8d9d822d4acc47603953ffd85b9330dfb36fe524352f4f3f0ba68adf208f34553d1fb9f75f8577b0d40adaa5375311094d480cbf6ea
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in DidGood.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ didgood (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.14.2)
10
+ rake (12.3.3)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ didgood!
17
+ minitest (~> 5.0)
18
+ rake (~> 12.0)
19
+
20
+ BUNDLED WITH
21
+ 2.1.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Noah Gibbs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # DidGood
2
+
3
+ DidGood is an experimental library system for [DGD](https://github.com/dworkin/LPC). DGD is an interpreter for a dialect of LPC, the C-like language of LPMuds. I don't actually know of a second attempt to set up a library system for it. DidGood is inspired loosely by RubyGems and the Ruby [Bundler](https://bundler.io).
4
+
5
+ DidGood refers to its libraries as Goods. The file dgd.didgood, if it's present in your application's directory, specifies where and how to find its various libraries. By running "didgood install", you can install those various files into a complete application.
6
+
7
+ DidGood is a simple initial library system. I'm sure I'll figure more out as I go along, and I'm sure it'll need changes. But you have to start somewhere!
8
+
9
+ This work has grown out of [SkotOS and ChatTheatre](https://github.com/ChatTheatre) tasks.
10
+
11
+ DidGood requires Ruby. It comes preinstalled on recent Mac computers, or you can install it yourself on Linux. On Windows, if you're not using WSL or similar, you're going to have a less-than-optimal experience.
12
+
13
+ ## Installation
14
+
15
+ You would normally install DidGood directly: `gem install didgood`.
16
+
17
+ It's possible to add it to a Ruby's application's Gemfile. Ordinarily you wouldn't.
18
+
19
+ ## Usage
20
+
21
+ If you have a DGD application that uses didgood, run `didgood install` to download its dependencies and create a fully-assembled DGD directory for it.
22
+
23
+ ## Using DidGood with your DGD Application
24
+
25
+ DidGood needs a .goods file for each library you intend to use, or it needs the information that would normally have been in that .goods file. DidGood keeps its various settings in JSON.
26
+
27
+
28
+
29
+ ## Creating the Goods
30
+
31
+ To create a new DidGood-usable library, you'll want to create a Goods file for it.
32
+
33
+ ## Design Notes on Libraries
34
+
35
+ The Kernel Library allows changing some config settings, including the name of the "/usr" dir. Consider some other name? Should definitely decide which direction to set "persistent" and stick with it.
36
+
37
+ Having admin users exist as library-ettes next to libraries seems highly dubious. But to avoid it, there would need to be a whole other permissions system sitting on top of the Kernel Library (like SkotOS, but more so.)
38
+
39
+
40
+
41
+ ## Development
42
+
43
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
44
+
45
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/noahgibbs/DidGood.
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the AGPL.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "DidGood"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ require_relative 'lib/DidGood/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "didgood"
5
+ spec.version = DidGood::VERSION
6
+ spec.authors = ["Noah Gibbs"]
7
+ spec.email = ["the.codefolio.guy@gmail.com"]
8
+
9
+ spec.summary = %q{DidGood is an experimental library and packaging system for the DGD language.}
10
+ spec.description = spec.summary
11
+ spec.homepage = "https://github.com/noahgibbs/didgood"
12
+ spec.license = "AGPL"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "didgood"
4
+
5
+ if ARGV.size == 0
6
+ ARGV.push "install"
7
+ end
8
+
9
+ case ARGV[0]
10
+ when "test"
11
+ unless File.exist?("dgd.didgood")
12
+ raise "I don't see a dgd.didgood file in this directory!"
13
+ end
14
+ puts "Running didgood installer..."
15
+ repo = DidGood::Repo.new
16
+ repo.didgood_file("dgd.didgood")
17
+ puts "Verified Goods packages: this looks likely correct."
18
+ when "install"
19
+ unless File.exist?("dgd.didgood")
20
+ raise "I don't see a dgd.didgood file in this directory!"
21
+ end
22
+ puts "Running didgood installer..."
23
+ repo = DidGood::Repo.new
24
+ repo.didgood_file("dgd.didgood")
25
+ repo.assemble_app(".")
26
+ when "work"
27
+ puts "Starting DGD server... (not yet)"
28
+ else
29
+ raise "Unrecognised didgood command: #{ARGV[0].inspect}!"
30
+ end
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "SkotOS HTTPD",
3
+ "git": {
4
+ "url": "https://github.com/ChatTheatre/SkotOS.git",
5
+ "branch": "master"
6
+ },
7
+ "paths": {
8
+ "skoot/usr/HTTP": "usr/HTTP"
9
+ }
10
+ }
@@ -0,0 +1,265 @@
1
+ require "DidGood/version"
2
+
3
+ require "json"
4
+ require "open-uri"
5
+ require "fileutils"
6
+
7
+ module DidGood
8
+ class Error < StandardError; end
9
+
10
+ DGD_BUILD_COMMAND = %(make DEFINES='-DUINDEX_TYPE="unsigned int" -DUINDEX_MAX=UINT_MAX -DEINDEX_TYPE="unsigned short" -DEINDEX_MAX=USHRT_MAX -DSSIZET_TYPE="unsigned int" -DSSIZET_MAX=1048576' install
11
+ )
12
+ KERNEL_PATHS = ["/include/kernel", "/kernel"]
13
+ DEFAULT_KERNELLIB_URL = "https://github.com/ChatTheatre/kernellib"
14
+
15
+ GENERATED_ROOT = ".root"
16
+
17
+ def self.system_call(cmd)
18
+ puts "Running command: #{cmd.inspect}..."
19
+ system(cmd, out: $stdout, err: :out)
20
+ unless $?.success?
21
+ raise "Error running command: #{cmd.inspect}!"
22
+ end
23
+ end
24
+
25
+ # This is a repo of everything DidGood saves between runs.
26
+ # It includes downloaded Git repos, Goods files and more.
27
+ class Repo
28
+ attr_reader :didgood_dir
29
+
30
+ def initialize
31
+ @home = ENV["HOME"]
32
+ @didgood_dir = "#{@home}/.didgood"
33
+ Dir.mkdir(@didgood_dir) unless File.directory?(@didgood_dir)
34
+ ["git", "goods"].each do |subdir|
35
+ full_subdir = "#{@didgood_dir}/#{subdir}"
36
+ Dir.mkdir(full_subdir) unless File.directory?(full_subdir)
37
+ end
38
+
39
+ unless File.exist?("#{@didgood_dir}/dgd/bin/dgd")
40
+ dgd_dir = "#{@didgood_dir}/dgd"
41
+ if File.directory?(dgd_dir)
42
+ # Not clear to me what to do here...
43
+ else
44
+ DidGood.system_call("git clone https://github.com/ChatTheatre/dgd.git #{dgd_dir}")
45
+ Dir.chdir("#{@didgood_dir}/dgd/src") do
46
+ DidGood.system_call(DGD_BUILD_COMMAND)
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ def git_repo(git_url)
53
+ @git_repos ||= {}
54
+ @git_repos[git_url] ||= GitRepo.new(self, git_url)
55
+ end
56
+
57
+ def didgood_file(path)
58
+ raise "Already have a dgd.didgood file!" if @didgood_file
59
+
60
+ @didgood_file ||= AppFile.new(self, path)
61
+ end
62
+
63
+ def assemble_app(location)
64
+ dgd_root = "#{File.expand_path(location)}/#{GENERATED_ROOT}"
65
+ FileUtils.rm_rf(dgd_root)
66
+ Dir.mkdir(dgd_root)
67
+
68
+ write_config_file("#{location}/dgd.config")
69
+ specs = @didgood_file.specs
70
+
71
+
72
+ specs.each do |spec|
73
+ git_repo = spec.source
74
+ git_repo.use_details(spec.source_details)
75
+
76
+ spec.paths.each do |from, to|
77
+ from_path = "#{git_repo.local_dir}/#{from}"
78
+ to_path = "#{dgd_root}/#{to}"
79
+ FileUtils.mkdir_p to_path
80
+ FileUtils.cp_r(from_path, to_path)
81
+ end
82
+ end
83
+ end
84
+
85
+ def write_config_file(path)
86
+ File.open(path, "wb") do |f|
87
+ f.write <<CONTENTS
88
+ /* These are SkotOS limits. They are enormous. They should
89
+ be configurable but they are not yet. */
90
+ telnet_port = ([
91
+ "*":50100 /* telnet port number */
92
+ ]);
93
+ binary_port = ([
94
+ "*":50110, /* Failsafe */
95
+ ]); /* binary ports */
96
+ directory = "./#{GENERATED_ROOT}";
97
+
98
+ users = 100; /* max # of users */
99
+ editors = 40; /* max # of editor sessions */
100
+ ed_tmpfile = "../state/ed"; /* proto editor tmpfile */
101
+ swap_file = "../state/swap"; /* swap file */
102
+ swap_size = 1048576; /* # sectors in swap file */
103
+ sector_size = 512; /* swap sector size */
104
+ swap_fragment = 4096; /* fragment to swap out */
105
+ static_chunk = 64512; /* static memory chunk */
106
+ dynamic_chunk = 261120; /* dynamic memory chunk */
107
+ dump_file = "../state/dump"; /* dump file */
108
+ dump_interval = 3600; /* dump interval */
109
+
110
+ typechecking = 2; /* highest level of typechecking */
111
+ include_file = "/include/std.h"; /* standard include file */
112
+ include_dirs = ({ "/include", "~/include" }); /* directories to search */
113
+ auto_object = "/kernel/lib/auto"; /* auto inherited object */
114
+ driver_object = "/kernel/sys/driver"; /* driver object */
115
+ create = "_F_create"; /* name of create function */
116
+
117
+ array_size = 16384; /* max array size */
118
+ objects = 262144; /* max # of objects */
119
+ call_outs = 16384; /* max # of call_outs */
120
+ CONTENTS
121
+ end
122
+ end
123
+ end
124
+
125
+ # This is a DidGood-downloaded Git repo.
126
+ # It can be a source for a GoodsSpec
127
+ class GitRepo
128
+ attr_reader :local_dir
129
+ attr_reader :git_url
130
+
131
+ def initialize(repo, git_url)
132
+ @git_url = git_url
133
+ @repo = repo
134
+ local_path = git_url.tr("/\\", "_")
135
+ @local_dir = "#{@repo.didgood_dir}/git/#{local_path}"
136
+
137
+ if File.directory?(@local_dir)
138
+ Dir.chdir(@local_dir) do
139
+ DidGood.system_call("git checkout #{default_branch} && git pull")
140
+ end
141
+ else
142
+ DidGood.system_call("git clone #{@git_url} #{@local_dir}")
143
+ end
144
+ end
145
+
146
+ def default_branch
147
+ return @default_branch if @default_branch
148
+ output = `git rev-parse --abbrev-ref origin/HEAD`.chomp
149
+ @default_branch = output.gsub(/^origin\//, "")
150
+ end
151
+
152
+ def use_details(details)
153
+ if details["branch"]
154
+ Dir.chdir(@local_dir) do
155
+ DidGood.system_call("git checkout #{details["branch"]}")
156
+ end
157
+ else
158
+ Dir.chdir(@local_dir) do
159
+ DidGood.system_call("git checkout #{default_branch}")
160
+ end
161
+ end
162
+ end
163
+ end
164
+
165
+ class AppFile
166
+ attr_reader :path
167
+ attr_reader :repo
168
+ attr_reader :specs
169
+
170
+ def initialize(repo, path)
171
+ @path = path
172
+ @repo = repo
173
+ raise("No such dgd.didgood file as #{path.inspect}!") unless File.exist?(path)
174
+ contents = JSON.load(File.read(path))
175
+
176
+ raise "Expected a top-level JSON array in dgd.didgood!" unless contents.is_a?(Array)
177
+
178
+ @specs = contents.flat_map { |item| json_to_specs(item) }
179
+
180
+ paths = @specs.flat_map { |s| s.paths }
181
+ unless paths == paths.uniq
182
+ repeated_paths = paths.select { |p| paths.count(p) > 1 }
183
+ raise "Repeated (conflicting?) paths in dgd.didgood! #{repeated_paths.inspect}"
184
+ end
185
+
186
+ # Make sure the dgd.didgood file overrides either no kernel paths or both/all
187
+ if KERNEL_PATHS.any? { |kp| paths.include?(kp) }
188
+ unless KERNEL_PATHS.all? { |kp| paths.include?(kp) }
189
+ raise "dgd.didgood file #{path.inspect} includes some Kernel Library paths but not all! All needed: #{KERNEL_PATHS}!"
190
+ end
191
+ puts "This dgd.didgood file overrides the Kernel Library with its own."
192
+ else
193
+ # This app has specified no kernellib paths -- add them
194
+ git_repo = @repo.git_repo(DEFAULT_KERNELLIB_URL)
195
+ kl_paths = { "src/kernel" => "/kernel", "src/include/kernel" => "/include/kernel", "src/doc/kernel" => "/doc/kernel" }
196
+ klib_spec = GoodsSpec.new @repo, name: "default Kernel Library",
197
+ source: git_repo, paths: kl_paths
198
+ specs.push klib_spec
199
+ end
200
+
201
+ nil
202
+ end
203
+
204
+ def json_to_specs(item)
205
+ raise "Expected every spec to be a JSON object, not #{item.inspect}!" unless item.is_a?(Hash)
206
+ return [] if item.size == 0 || item.all? { |k, v| k == "" }
207
+
208
+ if item["unbundled_goods"]
209
+ raise "Unbundled_goods must have only one key!" unless item.size == 1
210
+
211
+ return [unbundled_json_to_spec(item["unbundled_goods"])]
212
+ end
213
+
214
+ # A string-to-string mapping means a list of names and Goods URLs
215
+ if item.is_a?(Hash) && item.all? { |k, v| k.is_a?(String) && v.is_a?(String) }
216
+ return item.map do |name, goods_url|
217
+ begin
218
+ contents = JSON.parse(URI.open(goods_url).read)
219
+ rescue
220
+ STDERR.puts "Error reading or parsing by URL: #{goods_url.inspect}"
221
+ raise
222
+ end
223
+ unbundled_json_to_spec(contents)
224
+ end
225
+ end
226
+
227
+ raise "Didn't recognize JSON objects as Goods specs in dgd.didgood!"
228
+ end
229
+
230
+ def unbundled_json_to_spec(fields)
231
+ source = nil
232
+ source_details = nil
233
+ if fields["git"]
234
+ raise "A git source requires a git url: #{fields.inspect}!" unless fields["git"]["url"]
235
+ source = @repo.git_repo(fields["git"]["url"])
236
+ source_details = fields["git"] # May contain branch info, etc.
237
+ else
238
+ raise "Didgood currently requires a Git-based source!"
239
+ end
240
+
241
+ unless fields["paths"].all? { |k, v| k.is_a?(String) && v.is_a?(String) }
242
+ raise "Paths in Goods files must map strings to strings! #{fields["paths"].inspect}"
243
+ end
244
+
245
+ spec = GoodsSpec.new(@repo, name: fields["name"], source: source, source_details: source_details, paths: fields["paths"])
246
+ return spec
247
+ end
248
+ end
249
+
250
+ class GoodsSpec
251
+ attr_reader :repo
252
+ attr_reader :name
253
+ attr_reader :source
254
+ attr_reader :source_details
255
+ attr_reader :paths
256
+
257
+ def initialize(repo, name:, source:, source_details: {}, paths:)
258
+ @repo = repo
259
+ @name = name
260
+ @source = source
261
+ @source_details = source_details
262
+ @paths = paths
263
+ end
264
+ end
265
+ end
@@ -0,0 +1,3 @@
1
+ module DidGood
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: didgood
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Noah Gibbs
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: DidGood is an experimental library and packaging system for the DGD language.
14
+ email:
15
+ - the.codefolio.guy@gmail.com
16
+ executables:
17
+ - didgood
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".travis.yml"
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - didgood.gemspec
31
+ - exe/didgood
32
+ - goods/skotos_httpd.goods
33
+ - lib/didgood.rb
34
+ - lib/didgood/version.rb
35
+ homepage: https://github.com/noahgibbs/didgood
36
+ licenses:
37
+ - AGPL
38
+ metadata:
39
+ homepage_uri: https://github.com/noahgibbs/didgood
40
+ source_code_uri: https://github.com/noahgibbs/didgood
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.3.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubygems_version: 3.1.2
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: DidGood is an experimental library and packaging system for the DGD language.
60
+ test_files: []