Skip to content

Commit 02ff388

Browse files
Vendor lib/molinillo (#663)
Commits the dependency code into this repository, as suggested in crystal-lang/crystal#15344 (comment). We're already doing the same in https://github.com/crystal-lang/crystal. This simplifies the build process. All code required for building shards is contained in this repository (except for Crystal stdlib). There's no need to bootstrap the initial installation of the molinillo dependency anymore.
1 parent cccd47a commit 02ff388

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2785
-35
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/.crystal
22
/.shards
3-
/lib
43
/bin/shards
54
/bin/shards.dwarf
65
/bin/shards.exe

Makefile

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ BINDIR ?= $(PREFIX)/bin
4646
MANDIR ?= $(PREFIX)/share/man
4747
INSTALL ?= /usr/bin/install
4848

49-
MOLINILLO_VERSION = $(shell $(CRYSTAL) eval 'require "yaml"; puts YAML.parse(File.read("shard.lock"))["shards"]["molinillo"]["version"]')
50-
MOLINILLO_URL = "https://github.com/crystal-lang/crystal-molinillo/archive/v$(MOLINILLO_VERSION).tar.gz"
51-
5249
# MSYS2 support (native Windows should use `Makefile.win` instead)
5350
ifeq ($(OS),Windows_NT)
5451
EXE := .exe
@@ -71,7 +68,7 @@ clean: ## Remove build artifacts
7168
clean: clean_docs
7269
rm -f bin/shards$(EXE)
7370

74-
bin/shards$(EXE): $(SOURCES) $(TEMPLATES) lib
71+
bin/shards$(EXE): $(SOURCES) $(TEMPLATES)
7572
@mkdir -p bin
7673
$(EXPORTS) $(CRYSTAL) build $(FLAGS) src/shards.cr -o "$@"
7774

@@ -103,21 +100,14 @@ test: test_unit test_integration
103100

104101
.PHONY: test_unit
105102
test_unit: ## Run unit tests
106-
test_unit: lib
103+
test_unit:
107104
$(CRYSTAL) spec ./spec/unit/ $(if $(skip_fossil),--tag ~fossil) $(if $(skip_git),--tag ~git) $(if $(skip_hg),--tag ~hg)
108105

109106
.PHONY: test_integration
110107
test_integration: ## Run integration tests
111108
test_integration: bin/shards$(EXE)
112109
$(CRYSTAL) spec ./spec/integration/
113110

114-
lib: shard.lock
115-
mkdir -p lib/molinillo
116-
$(SHARDS) install || (curl -L $(MOLINILLO_URL) | tar -xzf - -C lib/molinillo --strip-components=1)
117-
118-
shard.lock: shard.yml
119-
([ $(SHARDS) = false ] && touch $@) || $(SHARDS) update
120-
121111
man/%.gz: man/%
122112
gzip -c -9 $< > $@
123113

Makefile.win

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ SHARDS_CONFIG_BUILD_COMMIT := $(shell git rev-parse --short HEAD)
4848
SOURCE_DATE_EPOCH := $(shell git show -s --format=%ct HEAD)
4949
export_vars = $(eval export SHARDS_CONFIG_BUILD_COMMIT SOURCE_DATE_EPOCH)
5050

51-
MOLINILLO_VERSION = $(shell $(CRYSTAL) eval 'require "yaml"; puts YAML.parse(File.read("shard.lock"))["shards"]["molinillo"]["version"]')
52-
MOLINILLO_URL = "https://github.com/crystal-lang/crystal-molinillo/archive/v$(MOLINILLO_VERSION).tar.gz"
53-
5451
prefix ?= $(or $(ProgramW6432),$(ProgramFiles))\crystal## Install path prefix
5552
BINDIR ?= $(prefix)
5653

@@ -65,7 +62,7 @@ clean: ## Remove build artifacts
6562
clean:
6663
$(call RM,"bin\shards.exe")
6764

68-
bin\shards.exe: $(SOURCES) $(TEMPLATES) lib
65+
bin\shards.exe: $(SOURCES) $(TEMPLATES)
6966
@$(call MKDIR,"bin")
7067
$(call export_vars)
7168
$(CRYSTAL) build $(FLAGS) -o bin\shards.exe src\shards.cr
@@ -89,21 +86,13 @@ test: test_unit test_integration
8986

9087
.PHONY: test_unit
9188
test_unit: ## Run unit tests
92-
test_unit: lib
9389
$(CRYSTAL) spec $(if $(skip_fossil),--tag ~fossil )$(if $(skip_git),--tag ~git )$(if $(skip_hg),--tag ~hg ).\spec\unit
9490

9591
.PHONY: test_integration
9692
test_integration: ## Run integration tests
9793
test_integration: bin\shards.exe
9894
$(CRYSTAL) spec .\spec\integration
9995

100-
lib: shard.lock
101-
$(call MKDIR,"lib\molinillo")
102-
$(SHARDS) install || (curl -L $(MOLINILLO_URL) | tar -xzf - -C lib\molinillo --strip-components=1)
103-
104-
shard.lock: shard.yml
105-
if not "$(SHARDS)" == "false" $(SHARDS) update
106-
10796
.PHONY: help
10897
help: ## Show this help
10998
@setlocal EnableDelayedExpansion &\

README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,6 @@ These requirements are only necessary for compiling Shards.
6767
Please refer to <https://crystal-lang.org/install/> for
6868
instructions for your operating system.
6969

70-
* `molinillo`
71-
72-
The shard `molinillo` needs to be in the Crystal path.
73-
It is available at <https://github.com/crystal-lang/crystal-molinillo>
74-
You can install it either with a pre-existing `shards` binary (running `shards install`)
75-
or just check out the repository at `lib/crystal-molinillo` (`make lib`).
76-
7770
* libyaml
7871

7972
On Debian/Ubuntu Linux you may install the `libyaml-dev` package.
@@ -90,9 +83,7 @@ These requirements are only necessary for compiling Shards.
9083
### Getting started
9184

9285
It is strongly recommended to use `make` for building shards and developing it.
93-
The [`Makefile`](./Makefile) contains recipes for compiling and testing. Building
94-
with `make` also ensures the source dependency `molinillo` is installed. You don't
95-
need to take care of this yourself.
86+
The [`Makefile`](./Makefile) contains recipes for compiling and testing.
9687

9788
Run `make bin/shards` to build the binary.
9889
* `release=1` for a release build (applies optimizations)

lib/.shards.info

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
version: 1.0
3+
shards:
4+
molinillo:
5+
git: https://github.com/crystal-lang/crystal-molinillo.git
6+
version: 0.2.0

lib/molinillo/.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*.cr]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Crystal CI
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
container:
11+
image: crystallang/crystal
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Install dependencies
16+
run: shards install
17+
- name: Run tests
18+
run: crystal spec

lib/molinillo/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/docs/
2+
/lib/
3+
/bin/
4+
/.shards/
5+
*.dwarf
6+
7+
# Libraries don't need dependency lock
8+
# Dependencies will be locked in applications that use them
9+
/shard.lock

lib/molinillo/.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "spec/fixture"]
2+
path = spec/fixture
3+
url = https://github.com/CocoaPods/Resolver-Integration-Specs

lib/molinillo/.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: crystal
2+
3+
# Uncomment the following if you'd like Travis to run specs and check code formatting
4+
# script:
5+
# - crystal spec
6+
# - crystal tool format --check

lib/molinillo/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
This project is licensed under the MIT license.
2+
3+
Copyright (c) 2020 Manas Technology Solutions
4+
Copyright (c) 2014 Samuel E. Giddins [email protected]
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

lib/molinillo/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# crystal-molinillo
2+
3+
A port of [Molinillo](https://github.com/CocoaPods/Molinillo/) (generic dependency resolution algorithm) to [Crystal](https://crystal-lang.org)
4+
5+
## Installation
6+
7+
1. Add the dependency to your `shard.yml`:
8+
9+
```yaml
10+
dependencies:
11+
molinillo:
12+
github: crystal-lang/crystal-molinillo
13+
```
14+
15+
2. Run `shards install`
16+
17+
## Usage
18+
19+
```crystal
20+
require "molinillo"
21+
```
22+
23+
This was built to be used by [Shards](https://github.com/crystal-lang/shards). Check [`MolinilloSolver`](https://github.com/crystal-lang/shards/blob/master/src/molinillo_solver.cr) for an example of integration.
24+
25+
## Development
26+
27+
This code uses a subrepository with test fixtures. Make sure you clone the repository with `--recursive` before running tests:
28+
29+
```
30+
git clone --recursive https://github.com/crystal-lang/crystal-molinillo
31+
```
32+
33+
## Contributing
34+
35+
1. Fork it (<https://github.com/crystal-lang/crystal-molinillo/fork>)
36+
2. Create your feature branch (`git checkout -b my-new-feature`)
37+
3. Commit your changes (`git commit -am 'Add some feature'`)
38+
4. Push to the branch (`git push origin my-new-feature`)
39+
5. Create a new Pull Request
40+
41+
## Contributors
42+
43+
- [Juan Wajnerman](https://github.com/waj) - creator and maintainer

lib/molinillo/lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
..

lib/molinillo/shard.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: molinillo
2+
version: 0.2.0
3+
4+
authors:
5+
- Juan Wajnerman <[email protected]>
6+
7+
crystal: ">= 0.35.0, < 2.0.0"
8+
9+
license: MIT
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
require "../spec_helper"
4+
5+
alias DG = Molinillo::DependencyGraph(Int32, Int32)
6+
7+
def shared_examples_for_replay(prepare)
8+
it "replays the log" do
9+
copy = DG.new
10+
graph = DG.new.tap { |g| prepare.call(g) }
11+
graph.log.each &.up(copy)
12+
copy.should eq(graph)
13+
end
14+
15+
it "can undo to an empty graph" do
16+
graph = DG.new
17+
tag = Reference.new
18+
graph.tag(tag)
19+
prepare.call(graph)
20+
graph.rewind_to(tag)
21+
graph.should eq(DG.new)
22+
end
23+
end
24+
25+
describe Molinillo::DependencyGraph::Log do
26+
describe "with empty log" do
27+
shared_examples_for_replay ->(g : DG) {}
28+
end
29+
30+
describe "with some graph" do
31+
shared_examples_for_replay ->(g : DG) do
32+
g.add_child_vertex("Foo", 1, [nil] of String?, 4)
33+
g.add_child_vertex("Bar", 2, ["Foo", nil], 3)
34+
g.add_child_vertex("Baz", 3, %w(Foo Bar), 2)
35+
g.add_child_vertex("Foo", 4, [] of String?, 1)
36+
end
37+
end
38+
end
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
require "./spec_helper"
2+
3+
private def test_dependency_graph
4+
graph = Molinillo::DependencyGraph(String, String).new
5+
root = graph.add_vertex("Root", "Root", true)
6+
root2 = graph.add_vertex("Root2", "Root2", true)
7+
child = graph.add_child_vertex("Child", "Child", %w(Root), "Child")
8+
{graph: graph, root: root, root2: root2, child: child}
9+
end
10+
11+
describe Molinillo::DependencyGraph do
12+
describe "in general" do
13+
it "returns root vertices by name" do
14+
data = test_dependency_graph
15+
data[:graph].root_vertex_named("Root").should eq(data[:root])
16+
end
17+
18+
it "returns vertices by name" do
19+
data = test_dependency_graph
20+
data[:graph].vertex_named("Root").should eq(data[:root])
21+
data[:graph].vertex_named("Child").should eq(data[:child])
22+
end
23+
24+
it "returns nil for non-existent root vertices" do
25+
data = test_dependency_graph
26+
data[:graph].root_vertex_named("missing").should be_nil
27+
end
28+
29+
it "returns nil for non-existent vertices" do
30+
data = test_dependency_graph
31+
data[:graph].vertex_named("missing").should be_nil
32+
end
33+
end
34+
35+
describe "detaching a vertex" do
36+
it "detaches a root vertex without successors" do
37+
graph = Molinillo::DependencyGraph(String, String).new
38+
root = graph.add_vertex("root", "root", true)
39+
graph.detach_vertex_named(root.name)
40+
graph.vertex_named(root.name).should be_nil
41+
graph.vertices.should be_empty
42+
end
43+
44+
it "detaches a root vertex with successors" do
45+
graph = Molinillo::DependencyGraph(String, String).new
46+
root = graph.add_vertex("root", "root", true)
47+
child = graph.add_child_vertex("child", "child", %w(root), "child")
48+
graph.detach_vertex_named(root.name)
49+
graph.vertex_named(root.name).should be_nil
50+
graph.vertex_named(child.name).should be_nil
51+
graph.vertices.should be_empty
52+
end
53+
54+
it "detaches a root vertex with successors with other parents" do
55+
graph = Molinillo::DependencyGraph(String, String).new
56+
root = graph.add_vertex("root", "root", true)
57+
root2 = graph.add_vertex("root2", "root2", true)
58+
child = graph.add_child_vertex("child", "child", %w(root root2), "child")
59+
graph.detach_vertex_named(root.name)
60+
graph.vertex_named(root.name).should be_nil
61+
graph.vertex_named(child.name).should eq(child)
62+
child.predecessors.should eq([root2])
63+
graph.vertices.size.should eq(2)
64+
end
65+
66+
it "detaches a vertex with predecessors" do
67+
graph = Molinillo::DependencyGraph(String, String).new
68+
parent = graph.add_vertex("parent", "parent", true)
69+
child = graph.add_child_vertex("child", "child", %w(parent), "child")
70+
graph.detach_vertex_named(child.name)
71+
graph.vertex_named(child.name).should be_nil
72+
graph.vertices.should eq({parent.name => parent})
73+
parent.outgoing_edges.should be_empty
74+
end
75+
end
76+
end

0 commit comments

Comments
 (0)