Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vendor lib/molinillo #663

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/.crystal
/.shards
/lib
/bin/shards
/bin/shards.dwarf
/bin/shards.exe
Expand Down
14 changes: 2 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ BINDIR ?= $(DESTDIR)$(PREFIX)/bin
MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
INSTALL ?= /usr/bin/install

MOLINILLO_VERSION = $(shell $(CRYSTAL) eval 'require "yaml"; puts YAML.parse(File.read("shard.lock"))["shards"]["molinillo"]["version"]')
MOLINILLO_URL = "https://github.com/crystal-lang/crystal-molinillo/archive/v$(MOLINILLO_VERSION).tar.gz"

# MSYS2 support (native Windows should use `Makefile.win` instead)
ifeq ($(OS),Windows_NT)
EXE := .exe
Expand All @@ -71,7 +68,7 @@ clean: ## Remove build artifacts
clean: clean_docs
rm -f bin/shards$(EXE)

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

Expand All @@ -96,21 +93,14 @@ test: test_unit test_integration

.PHONY: test_unit
test_unit: ## Run unit tests
test_unit: lib
test_unit:
$(CRYSTAL) spec ./spec/unit/ $(if $(skip_fossil),--tag ~fossil) $(if $(skip_git),--tag ~git) $(if $(skip_hg),--tag ~hg)

.PHONY: test_integration
test_integration: ## Run integration tests
test_integration: bin/shards$(EXE)
$(CRYSTAL) spec ./spec/integration/

lib: shard.lock
mkdir -p lib/molinillo
$(SHARDS) install || (curl -L $(MOLINILLO_URL) | tar -xzf - -C lib/molinillo --strip-components=1)

shard.lock: shard.yml
([ $(SHARDS) = false ] && touch $@) || $(SHARDS) update

man/%.gz: man/%
gzip -c -9 $< > $@

Expand Down
13 changes: 1 addition & 12 deletions Makefile.win
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ SHARDS_CONFIG_BUILD_COMMIT := $(shell git rev-parse --short HEAD)
SOURCE_DATE_EPOCH := $(shell git show -s --format=%ct HEAD)
export_vars = $(eval export SHARDS_CONFIG_BUILD_COMMIT SOURCE_DATE_EPOCH)

MOLINILLO_VERSION = $(shell $(CRYSTAL) eval 'require "yaml"; puts YAML.parse(File.read("shard.lock"))["shards"]["molinillo"]["version"]')
MOLINILLO_URL = "https://github.com/crystal-lang/crystal-molinillo/archive/v$(MOLINILLO_VERSION).tar.gz"

prefix ?= $(or $(ProgramW6432),$(ProgramFiles))\crystal## Install path prefix
BINDIR ?= $(prefix)

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

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

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

.PHONY: test_integration
test_integration: ## Run integration tests
test_integration: bin\shards.exe
$(CRYSTAL) spec .\spec\integration

lib: shard.lock
$(call MKDIR,"lib\molinillo")
$(SHARDS) install || (curl -L $(MOLINILLO_URL) | tar -xzf - -C lib\molinillo --strip-components=1)

shard.lock: shard.yml
if not "$(SHARDS)" == "false" $(SHARDS) update

.PHONY: help
help: ## Show this help
@setlocal EnableDelayedExpansion &\
Expand Down
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ These requirements are only necessary for compiling Shards.
Please refer to <https://crystal-lang.org/install/> for
instructions for your operating system.

* `molinillo`

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

* libyaml

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

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

Run `make bin/shards` to build the binary.
* `release=1` for a release build (applies optimizations)
Expand Down
6 changes: 6 additions & 0 deletions lib/.shards.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
version: 1.0
shards:
molinillo:
git: https://github.com/crystal-lang/crystal-molinillo.git
version: 0.2.0
9 changes: 9 additions & 0 deletions lib/molinillo/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*.cr]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
18 changes: 18 additions & 0 deletions lib/molinillo/.github/workflows/crystal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Crystal CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

container:
image: crystallang/crystal

steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: shards install
- name: Run tests
run: crystal spec
9 changes: 9 additions & 0 deletions lib/molinillo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/docs/
/lib/
/bin/
/.shards/
*.dwarf

# Libraries don't need dependency lock
# Dependencies will be locked in applications that use them
/shard.lock
3 changes: 3 additions & 0 deletions lib/molinillo/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "spec/fixture"]
path = spec/fixture
url = https://github.com/CocoaPods/Resolver-Integration-Specs
6 changes: 6 additions & 0 deletions lib/molinillo/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: crystal

# Uncomment the following if you'd like Travis to run specs and check code formatting
# script:
# - crystal spec
# - crystal tool format --check
22 changes: 22 additions & 0 deletions lib/molinillo/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
This project is licensed under the MIT license.

Copyright (c) 2020 Manas Technology Solutions
Copyright (c) 2014 Samuel E. Giddins segiddins@segiddins.me

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
43 changes: 43 additions & 0 deletions lib/molinillo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# crystal-molinillo

A port of [Molinillo](https://github.com/CocoaPods/Molinillo/) (generic dependency resolution algorithm) to [Crystal](https://crystal-lang.org)

## Installation

1. Add the dependency to your `shard.yml`:

```yaml
dependencies:
molinillo:
github: crystal-lang/crystal-molinillo
```

2. Run `shards install`

## Usage

```crystal
require "molinillo"
```

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.

## Development

This code uses a subrepository with test fixtures. Make sure you clone the repository with `--recursive` before running tests:

```
git clone --recursive https://github.com/crystal-lang/crystal-molinillo
```

## Contributing

1. Fork it (<https://github.com/crystal-lang/crystal-molinillo/fork>)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request

## Contributors

- [Juan Wajnerman](https://github.com/waj) - creator and maintainer
1 change: 1 addition & 0 deletions lib/molinillo/lib
9 changes: 9 additions & 0 deletions lib/molinillo/shard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: molinillo
version: 0.2.0

authors:
- Juan Wajnerman <waj@manas.tech>

crystal: ">= 0.35.0, < 2.0.0"

license: MIT
38 changes: 38 additions & 0 deletions lib/molinillo/spec/dependency_graph/log_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

require "../spec_helper"

alias DG = Molinillo::DependencyGraph(Int32, Int32)

def shared_examples_for_replay(prepare)
it "replays the log" do
copy = DG.new
graph = DG.new.tap { |g| prepare.call(g) }
graph.log.each &.up(copy)
copy.should eq(graph)
end

it "can undo to an empty graph" do
graph = DG.new
tag = Reference.new
graph.tag(tag)
prepare.call(graph)
graph.rewind_to(tag)
graph.should eq(DG.new)
end
end

describe Molinillo::DependencyGraph::Log do
describe "with empty log" do
shared_examples_for_replay ->(g : DG) {}
end

describe "with some graph" do
shared_examples_for_replay ->(g : DG) do
g.add_child_vertex("Foo", 1, [nil] of String?, 4)
g.add_child_vertex("Bar", 2, ["Foo", nil], 3)
g.add_child_vertex("Baz", 3, %w(Foo Bar), 2)
g.add_child_vertex("Foo", 4, [] of String?, 1)
end
end
end
76 changes: 76 additions & 0 deletions lib/molinillo/spec/dependency_graph_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require "./spec_helper"

private def test_dependency_graph
graph = Molinillo::DependencyGraph(String, String).new
root = graph.add_vertex("Root", "Root", true)
root2 = graph.add_vertex("Root2", "Root2", true)
child = graph.add_child_vertex("Child", "Child", %w(Root), "Child")
{graph: graph, root: root, root2: root2, child: child}
end

describe Molinillo::DependencyGraph do
describe "in general" do
it "returns root vertices by name" do
data = test_dependency_graph
data[:graph].root_vertex_named("Root").should eq(data[:root])
end

it "returns vertices by name" do
data = test_dependency_graph
data[:graph].vertex_named("Root").should eq(data[:root])
data[:graph].vertex_named("Child").should eq(data[:child])
end

it "returns nil for non-existent root vertices" do
data = test_dependency_graph
data[:graph].root_vertex_named("missing").should be_nil
end

it "returns nil for non-existent vertices" do
data = test_dependency_graph
data[:graph].vertex_named("missing").should be_nil
end
end

describe "detaching a vertex" do
it "detaches a root vertex without successors" do
graph = Molinillo::DependencyGraph(String, String).new
root = graph.add_vertex("root", "root", true)
graph.detach_vertex_named(root.name)
graph.vertex_named(root.name).should be_nil
graph.vertices.should be_empty
end

it "detaches a root vertex with successors" do
graph = Molinillo::DependencyGraph(String, String).new
root = graph.add_vertex("root", "root", true)
child = graph.add_child_vertex("child", "child", %w(root), "child")
graph.detach_vertex_named(root.name)
graph.vertex_named(root.name).should be_nil
graph.vertex_named(child.name).should be_nil
graph.vertices.should be_empty
end

it "detaches a root vertex with successors with other parents" do
graph = Molinillo::DependencyGraph(String, String).new
root = graph.add_vertex("root", "root", true)
root2 = graph.add_vertex("root2", "root2", true)
child = graph.add_child_vertex("child", "child", %w(root root2), "child")
graph.detach_vertex_named(root.name)
graph.vertex_named(root.name).should be_nil
graph.vertex_named(child.name).should eq(child)
child.predecessors.should eq([root2])
graph.vertices.size.should eq(2)
end

it "detaches a vertex with predecessors" do
graph = Molinillo::DependencyGraph(String, String).new
parent = graph.add_vertex("parent", "parent", true)
child = graph.add_child_vertex("child", "child", %w(parent), "child")
graph.detach_vertex_named(child.name)
graph.vertex_named(child.name).should be_nil
graph.vertices.should eq({parent.name => parent})
parent.outgoing_edges.should be_empty
end
end
end
Loading