kar 0.1.3 → 6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e88a860068093597ff4434adfe3ff6f5f7f3db2576b66708e0e57d0dc0bb96d
4
- data.tar.gz: 1949ce09fc44920dbe98c61f2214ee7d81323f60e6a7f22b082068ecaf25b52e
3
+ metadata.gz: 370a71b352efdc345562491f694552d0450a7eb7bb3b73f4e2f70d89f8ead35d
4
+ data.tar.gz: 04d19c674fdd8afc2d7c588429642c641ec2ea0c431855d1ebc877d7f06f80b4
5
5
  SHA512:
6
- metadata.gz: 892276c83f0431711faaf1569154b9ec04e06b7689e34eca638dd55c3d69da91dda5720f9af844f8794755c01e0f3b1dacee5064e00e182a00a8a2e0533607fc
7
- data.tar.gz: a135684469b46c1b14896faa8f3abdff6a364edde5ec006864bb8bd9bbffac62bacaae26acc8d4cf79e913a91cb09fbd3ef6ae373d237920c005cf2afffe1bf9
6
+ metadata.gz: ccc1f62a586e54a7d3c4b65181cbee1dac9752c6a59e47379e552da7230913db46f3ff9f6090e16004850898adf0efc1b37f6c06d26cbc37044b84462f8eef1a
7
+ data.tar.gz: f21722ed42367ddb8be79c63bf1b528f1c80fd9cf84fe2e763dc2f7f9df18efffa153afe9d6dfb9adcec80119ad92f53f5609826784b26c610f0427e9492de22
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ # [6] - 2025-11-16
4
+
5
+ * Don't remove compiled files in CargoTask
6
+
7
+ # [5] - 2025-11-14
8
+
9
+ * Use open-uri for URITask
10
+ * Add Cargo.lock generate task in CargoTask
11
+
3
12
  ## [0.1.3] - 2025-10-26
4
13
 
5
14
  - Make cargo task to be dependent on Rust source files
data/kar.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "kar"
3
- spec.version = "0.1.3"
3
+ spec.version = "6"
4
4
  spec.authors = ["Kitaiti Makoto"]
5
5
  spec.email = ["KitaitiMakoto@gmail.com"]
6
6
 
data/lib/kar/cargotask.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "rake/clean"
2
+ require "rake/tasklib"
2
3
  require "rubygems/ext"
3
4
  require "json"
4
5
  require "shellwords"
@@ -19,10 +20,10 @@ module Kar
19
20
  end
20
21
 
21
22
  def define
22
- file dl_path => [manifest, lock_file] + src do |t|
23
+ file dl_path => [lock_file] + src do |t|
23
24
  results = Results.new
24
25
  begin
25
- Gem::Ext::CargoBuilder.new.build t.source, ".", results, [], lib_dir, File.expand_path(ext_dir)
26
+ CargoBuilder.new.build t.source, ext_dir, results, [], lib_dir, File.expand_path(ext_dir)
26
27
  rescue => error
27
28
  $stderr.puts results unless verbose?
28
29
  fail
@@ -30,13 +31,17 @@ module Kar
30
31
  end
31
32
  CLEAN.include dl_name, dl_path
32
33
 
34
+ file lock_file => manifest do |t|
35
+ sh "cargo", "generate-lockfile", "--manifest-path", t.source
36
+ end
37
+
33
38
  namespace :cargo do
34
39
  task @target => dl_path
35
40
 
36
41
  # TODO: Consider the case `target` is "check"
37
42
  namespace :check do
38
43
  task @target => manifest do |t|
39
- sh "cargo", "check", "--manifest-path", manifest.shellescape, "--locked", "--quiet"
44
+ sh "cargo", "check", "--manifest-path", manifest, "--locked", "--quiet"
40
45
  end
41
46
  end
42
47
 
@@ -106,5 +111,56 @@ module Kar
106
111
  Rake.verbose == true
107
112
  end
108
113
  end
114
+
115
+ class CargoBuilder < Gem::Ext::CargoBuilder
116
+ # Original Gem::Ext::CargoBuilder removes compiled files after installation.
117
+ # It is ideal for installation, but not for development.
118
+ # We override the behavior to keep the compiled files.
119
+ def build(extension, dest_path, results, args = [], lib_dir = nil, cargo_dir = Dir.pwd,
120
+ target_rbconfig=Gem.target_rbconfig)
121
+ require "tempfile"
122
+ require "fileutils"
123
+
124
+ if target_rbconfig.path
125
+ warn "--target-rbconfig is not yet supported for Rust extensions. Ignoring"
126
+ end
127
+
128
+ # Where's the Cargo.toml of the crate we're building
129
+ cargo_toml = File.join(cargo_dir, "Cargo.toml")
130
+ # What's the crate's name
131
+ crate_name = cargo_crate_name(cargo_dir, cargo_toml, results)
132
+
133
+ # Run the build
134
+ cmd = cargo_command(cargo_toml, cargo_dir, args, crate_name)
135
+ runner.call(cmd, results, "cargo", cargo_dir, build_env)
136
+
137
+ # Where do we expect Cargo to write the compiled library
138
+ dylib_path = cargo_dylib_path(cargo_dir, crate_name)
139
+
140
+ # Helpful error if we didn't find the compiled library
141
+ raise DylibNotFoundError, cargo_dir unless File.exist?(dylib_path)
142
+
143
+ # Cargo and Ruby differ on how the library should be named, rename from
144
+ # what Cargo outputs to what Ruby expects
145
+ dlext_name = "#{crate_name}.#{makefile_config("DLEXT")}"
146
+ dlext_path = File.join(File.dirname(dylib_path), dlext_name)
147
+ FileUtils.cp(dylib_path, dlext_path)
148
+
149
+ nesting = extension_nesting(extension)
150
+
151
+ if Gem.install_extension_in_lib && lib_dir
152
+ nested_lib_dir = File.join(lib_dir, nesting)
153
+ FileUtils.mkdir_p nested_lib_dir
154
+ FileUtils.cp_r dlext_path, nested_lib_dir, remove_destination: true
155
+ end
156
+
157
+ # move to final destination
158
+ nested_dest_path = File.join(dest_path, nesting)
159
+ FileUtils.mkdir_p nested_dest_path
160
+ FileUtils.cp_r dlext_path, nested_dest_path, remove_destination: true
161
+
162
+ results
163
+ end
164
+ end
109
165
  end
110
166
  end
data/lib/kar/uritask.rb CHANGED
@@ -1,77 +1,11 @@
1
1
  require "rake/tasklib"
2
- require "rake/file_task"
3
2
  require "uri"
4
- require "net/https"
5
3
  require "tempfile"
6
4
  require "time"
7
5
 
8
6
  module Kar
9
7
  # Instanctiated in {DSL#download}
10
8
  class URITask < Rake::TaskLib
11
- module Util
12
- REDIRECT_LIMIT = 3
13
-
14
- module_function
15
-
16
- # @todo Consider return value type
17
- #
18
- # @param uri [URI] URI to fetch content
19
- # @param to [String] File path to save content
20
- # @param headers [Hash<String, Object?>] HTTP headers
21
- # @return [String] File path content saved, same to +to+
22
- # @return [nil] if remote file responded with 304 Not Modified
23
- def fetch_http(uri, to, headers = {}, redirected = 0)
24
- if redirected > REDIRECT_LIMIT
25
- raise "Too many HTTP redirects"
26
- end
27
- Net::HTTP.start uri.host, uri.port, use_ssl: uri.scheme == "https" do |http|
28
- request = Net::HTTP::Get.new(uri, headers)
29
- http.request request do |response|
30
- case response
31
- when Net::HTTPNotModified
32
- # noop
33
- when Net::HTTPOK
34
- File.open to, "wb" do |file|
35
- response.read_body do |chunk|
36
- file.write chunk
37
- end
38
- now = Time.now
39
- last_modified = response["last-modified"]
40
- mtime = last_modified ? Time.httpdate(last_modified) : now
41
- File.utime now, Time.httpdate(response["Last-Modified"]), to
42
- end
43
- when Net::HTTPRedirection
44
- fetch_http URI(response["location"]), to, headers, redirected + 1
45
- else
46
- raise "#{response.code} #{response.message}\n#{response.body}"
47
- end
48
- end
49
- end
50
-
51
- to
52
- end
53
-
54
- private
55
-
56
- def fetch_http_with_redirection_handling(uri, headers = {})
57
- Net::HTTP.start uri.host, uri.port, use_ssl: uri.scheme == "https" do |http|
58
- request = Net::HTTP::Get.new(uri, headers)
59
- http.request request do |response|
60
- case response
61
- when Net::HTTPRedirection
62
- return fetch_http_with_redirection_handling(URI(response["location"]), headers)
63
- when Net::HTTPOK
64
- return response
65
- else
66
- raise "#{response.code} #{response.message}\n#{response.body}"
67
- end
68
- end
69
- end
70
- end
71
- end
72
-
73
- include Util
74
-
75
9
  def initialize(file_and_uri)
76
10
  @to = file_and_uri.keys.first
77
11
  @uri = URI(file_and_uri.values.first)
@@ -81,29 +15,25 @@ module Kar
81
15
  private
82
16
 
83
17
  def define
84
- unless %w[http https].include? @uri.scheme
18
+ unless %w[http https ftp].include? @uri.scheme
85
19
  raise ArgumentError, "Unsupported URI scheme: #{@uri}"
86
20
  end
87
21
 
88
22
  file @to do |t|
89
- mtime = File.mtime(t.name) if File.file? t.name
90
- tempfile = Tempfile.new
91
- tempfile.close
92
- case @uri.scheme
93
- when "http", "https"
94
- result = fetch_http(@uri, tempfile, {"If-Modified-Since" => mtime&.httpdate})
95
- if result
96
- move tempfile, t.name
97
- else
98
- File.unlink tempfile
99
- Rake::Task[@to].tap do |task|
100
- def task.needed?
101
- false
102
- end
23
+ require "open-uri"
24
+
25
+ @uri.open do |input|
26
+ tempfile =
27
+ if input.respond_to?(:to_path)
28
+ input.close
29
+ input
30
+ else
31
+ Tempfile.open {|output|
32
+ output.write input.read
33
+ output
34
+ }
103
35
  end
104
- end
105
- else
106
- raise ArgumentError, "Unsupported URI scheme: #{@uri}"
36
+ move tempfile.to_path, t.name
107
37
  end
108
38
  end
109
39
  end
data/lib/kar.rb CHANGED
@@ -1,8 +1,2 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "kar/version"
4
-
5
- module Kar
6
- class Error < StandardError; end
7
- # Your code goes here...
8
- end
1
+ require "kar/uritask"
2
+ require "kar/cargotask"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: '6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kitaiti Makoto
@@ -74,7 +74,6 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - CHANGELOG.md
77
- - CODE_OF_CONDUCT.md
78
77
  - README.md
79
78
  - Rakefile
80
79
  - agpl-3.0.txt
data/CODE_OF_CONDUCT.md DELETED
@@ -1,84 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at KitaitiMakoto@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.