Skip to content

Commit

Permalink
Merge changes from 0.24.2 with master
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardiff committed Mar 9, 2018
2 parents 4f9ed8d + 4ef9167 commit 731e9c0
Show file tree
Hide file tree
Showing 312 changed files with 9,502 additions and 3,448 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ matrix:
os: linux

before_install:
- echo '{"ipv6":true, "fixed-cidr-v6":"2001:db8:1::/64"}' | sudo tee /etc/docker/daemon.json
- sudo service docker restart
- bin/ci prepare_system

install:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ RUN \

WORKDIR /opt/crystal

CMD ["bash"]
CMD ["sh"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2012-2017 Manas Technology Solutions.
Copyright 2012-2018 Manas Technology Solutions.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ static ?= ## Enable static linking
O := .build
SOURCES := $(shell find src -name '*.cr')
SPEC_SOURCES := $(shell find spec -name '*.cr')
FLAGS := $(if $(release),--release )$(if $(stats),--stats )$(if $(progress),--progress )$(if $(threads),--threads $(threads) )$(if $(debug),-d )$(if $(static),--static )
FLAGS := $(if $(release),--release )$(if $(stats),--stats )$(if $(progress),--progress )$(if $(threads),--threads $(threads) )$(if $(debug),-d )$(if $(static),--static )$(if $(LDFLAGS),--link-flags="$(LDFLAGS)" )
SPEC_FLAGS := $(if $(verbose),-v )$(if $(junit_output),--junit_output $(junit_output) )
EXPORTS := $(if $(release),,CRYSTAL_CONFIG_PATH=`pwd`/src)
SHELL = bash
EXPORTS := $(if $(release),,CRYSTAL_CONFIG_PATH="$(PWD)/src")
SHELL = sh
LLVM_CONFIG_FINDER := \
[ -n "$(LLVM_CONFIG)" ] && command -v "$(LLVM_CONFIG)" || \
command -v llvm-config-5.0 || command -v llvm-config50 || \
(command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 5.0*) command -v llvm-config;; *) false;; esac)) || \
command -v llvm-config-4.0 || command -v llvm-config40 || \
(command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 4.0*) command -v llvm-config;; *) false;; esac)) || \
command -v llvm-config-3.9 || command -v llvm-config39 || \
Expand Down Expand Up @@ -118,7 +120,7 @@ $(O)/crystal: $(DEPS) $(SOURCES)
$(BUILD_PATH) $(EXPORTS) ./bin/crystal build $(FLAGS) -o $@ src/compiler/crystal.cr -D without_openssl -D without_zlib

$(LLVM_EXT_OBJ): $(LLVM_EXT_DIR)/llvm_ext.cc
$(CXX) -c $(CXXFLAGS) -o $@ $< `$(LLVM_CONFIG) --cxxflags`
$(CXX) -c $(CXXFLAGS) -o $@ $< $(shell $(LLVM_CONFIG) --cxxflags)

$(LIB_CRYSTAL_TARGET): $(LIB_CRYSTAL_OBJS)
$(AR) -rcs $@ $^
Expand All @@ -131,4 +133,4 @@ clean: clean_crystal ## Clean up built directories and files
.PHONY: clean_crystal
clean_crystal: ## Clean up crystal built files
rm -rf $(O)
rm -rf ./doc
rm -rf ./docs
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Vagrant.configure("2") do |config|
c.vm.box = "ubuntu/#{box_name}"

c.vm.provision :shell, inline: %(
curl -s https://dist.crystal-lang.org/apt/setup.sh | bash
curl -s https://dist.crystal-lang.org/apt/setup.sh | sh
apt-get install -y crystal git libgmp3-dev zlib1g-dev libedit-dev libxml2-dev libssl-dev libyaml-dev libreadline-dev g++
curl -s https://crystal-lang.s3.amazonaws.com/llvm/llvm-3.5.0-1-linux-`uname -m`.tar.gz | tar xz -C /opt
echo 'export LIBRARY_PATH="/opt/crystal/embedded/lib"' > /etc/profile.d/crystal.sh
Expand Down
32 changes: 17 additions & 15 deletions bin/ci
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

fail() {
echo "${@}" >&2
Expand Down Expand Up @@ -97,32 +97,34 @@ with_build_env() {
on_linux docker run \
--rm -t \
-u $(id -u) \
-v $(pwd):/mnt \
-v $PWD:/mnt \
-w /mnt \
-e LIBRARY_PATH="${ARCH_LIBRARY_PATH:-/usr/lib/crystal/lib/}" \
-e CRYSTAL_CACHE_DIR="/tmp/crystal" \
"jhass/crystal-build-$ARCH" \
"$ARCH_CMD" /bin/bash -c "'$command'"
"$ARCH_CMD" /bin/sh -c "'$command'"

on_osx sudo systemsetup -settimezone $TZ
on_osx PATH="/usr/local/opt/llvm/bin:\$PATH" \
CRYSTAL_CACHE_DIR="/tmp/crystal" \
/bin/bash -c "'$command'"
/bin/sh -c "'$command'"

}

usage() {
echo -e "bin/ci [-h|--help] command [parameter ...]"
echo -e ""
echo -e "Helper script to prepare and run the testsuite on Travis CI."
echo -e ""
echo -e "Commands:"
echo -e " prepare_system setup any necessaries repositories etc."
echo -e " prepare_build download and extract any dependencies needed for the build"
echo -e " build run specs, build crystal, run format check, build samples, build the docs"
echo -e " with_build_env command run command in the build environment"
echo -e " help display this"
echo -e ""
cat <<EOF
bin/ci [-h|--help] command [parameter ...]
Helper script to prepare and run the testsuite on Travis CI.
Commands:
prepare_system setup any necessaries repositories etc.
prepare_build download and extract any dependencies needed for the build
build run specs, build crystal, run format check, build samples, build the docs
with_build_env command run command in the build environment
help display this
EOF
}

command="$1"
Expand Down
11 changes: 4 additions & 7 deletions bin/crystal
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ _resolve_symlinks() {

local dir_context path
path=$(readlink -- "$1")
if [ $? -eq 0 ]; then
if [ $? = 0 ]; then
dir_context=$(dirname -- "$1")
_resolve_symlinks "$(_prepend_dir_context_if_necessary "$dir_context" "$path")" "$@"
else
Expand Down Expand Up @@ -141,16 +141,13 @@ CRYSTAL_DIR="$CRYSTAL_ROOT/.build"
export CRYSTAL_PATH=$CRYSTAL_ROOT/src:lib
export CRYSTAL_HAS_WRAPPER=true

if [ -x "$CRYSTAL_DIR/crystal" ]
then
if [ -x "$CRYSTAL_DIR/crystal" ]; then
__warning_msg "Using compiled compiler at \`.build/crystal'"
exec "$CRYSTAL_DIR/crystal" "$@"
elif ! command -v crystal > /dev/null
then
elif ! command -v crystal > /dev/null; then
__error_msg 'You need to have a crystal executable in your path!'
exit 1
elif [ "$(command -v crystal)" = "$SCRIPT_PATH" ] || [ "$(command -v crystal)" = "bin/crystal" ]
then
elif [ "$(command -v crystal)" = "$SCRIPT_PATH" ] || [ "$(command -v crystal)" = "bin/crystal" ]; then
export PATH="$(remove_path_item "$(remove_path_item "$PATH" "$SCRIPT_ROOT")" "bin")"
exec "$SCRIPT_PATH" "$@"
else
Expand Down
15 changes: 1 addition & 14 deletions etc/completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ _crystal()
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"

commands="init build deps docs eval play run spec tool help version --help --version"
commands="init build docs eval play run spec tool help version --help --version"

case "${cmd}" in
init)
Expand All @@ -32,19 +32,6 @@ _crystal()
COMPREPLY=($(_crystal_compgen_files $cur))
fi
;;
deps)
if [[ ${cur} == -* ]] ; then
local opts="--no-color --version --production"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
else
if [[ "${prev}" == "deps" ]] ; then
local subcommands="check install list update"
COMPREPLY=( $(compgen -W "${subcommands}" -- ${cur}) )
else
COMPREPLY=($(_crystal_compgen_files $cur))
fi
fi
;;
run)
if [[ ${cur} == -* ]] ; then
local opts="--debug --define --emit --format --help --ll --link-flags --mcpu --no-color --no-codegen --prelude --release --stats --single-module --threads --verbose"
Expand Down
13 changes: 0 additions & 13 deletions etc/completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ _crystal_commands() {
commands=(
"init:generate new crystal project"
"build:build an executable"
"deps:install project dependencies"
"docs:generate documentation"
"env:print Crystal environment information"
"eval:eval code from args or standard input"
Expand Down Expand Up @@ -100,18 +99,6 @@ _crystal-build() {
&& ret=0
}

_crystal-deps() {
_arguments \
'1:type:(build check init install list prune update)' \
$help_args \
$no_color_args \
'(--version)--version[version]' \
'(--production)--production[production mode]' \
'(-v --verbose)'{-v,--verbose}'[verbose mode]' \
'(-q --quiet)'{-q,--quiet}'[quiet mode]' \
&& ret=0
}

_crystal-env() {
_arguments \
'(--help)--help[prints help]' \
Expand Down
13 changes: 3 additions & 10 deletions man/crystal.1
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ The optimizations are not turned on by default because the compile times are muc
.Bl -tag -width "12345678" -compact
.Pp
.Sh OPTIONS
The crystal command accepts the following options
The crystal command accepts the following options

.Bl -tag -width "12345678" -compact
.Pp
.It
.It
.Cm init
TYPE
NAME
Expand Down Expand Up @@ -141,18 +141,11 @@ Display the commands executed by the system.
Source file name to be read from STDIN.
.El

.Pp
.It
.Cm deps
.Op options
.Ar <command>
.Pp
Alias for shards, the dependency manager for Crystal language.
.Pp
.It
.Cm docs
.Pp
Generate documentation from comments using a subset of markdown. The output is saved in html format on the created doc/ folder. More information about documentation conventions can be found at https://crystal-lang.org/docs/conventions/documenting_code.html.
Generate documentation from comments using a subset of markdown. The output is saved in html format on the created docs/ folder. More information about documentation conventions can be found at https://crystal-lang.org/docs/conventions/documenting_code.html.
.Pp
.It Cm eval
.Pp
Expand Down
76 changes: 76 additions & 0 deletions scripts/generate_windows_zone_names.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# This script generates the file src/crystal/system/win32/zone_names.cr
# that contains mappings for windows time zone names based on the values
# found in http://unicode.org/cldr/data/common/supplemental/windowsZones.xml

require "http/client"
require "xml"
require "../src/compiler/crystal/formatter"

WINDOWS_ZONE_NAMES_SOURCE = "http://unicode.org/cldr/data/common/supplemental/windowsZones.xml"
TARGET_FILE = File.join(__DIR__, "..", "src", "crystal", "system", "win32", "zone_names.cr")

response = HTTP::Client.get(WINDOWS_ZONE_NAMES_SOURCE)

# Simple redirection resolver
# TODO: Needs to be replaced by proper redirect handling that should be provided by `HTTP::Client`
if (300..399).includes?(response.status_code) && (location = response.headers["Location"]?)
response = HTTP::Client.get(location)
end

xml = XML.parse(response.body)

nodes = xml.xpath_nodes("/supplementalData/windowsZones/mapTimezones/mapZone[@territory=001]")

entries = [] of {key: String, zones: {String, String}, tzdata_name: String}

nodes.each do |node|
location = Time::Location.load(node["type"])
next unless location
time = Time.now(location).at_beginning_of_year
zone1 = time.zone
zone2 = (time + 6.months).zone

if zone1.offset > zone2.offset
# southern hemisphere
zones = {zone2.name, zone1.name}
else
# northern hemisphere
zones = {zone1.name, zone2.name}
end

entries << {key: node["other"], zones: zones, tzdata_name: location.name}
rescue err : Time::Location::InvalidLocationNameError
pp err
end

# sort by IANA database identifier
entries.sort_by! &.[:tzdata_name]

hash_items = String.build do |io|
entries.each do |entry|
entry[:key].inspect(io)
io << " => "
entry[:zones].inspect(io)
io << ", # " << entry[:tzdata_name] << "\n"
end
end

source = <<-CRYSTAL
# This file was automatically generated by running:
#
# scripts/generate_windows_zone_names.cr
#
# DO NOT EDIT
module Crystal::System::Time
# These mappings for windows time zone names are based on
# #{WINDOWS_ZONE_NAMES_SOURCE}
WINDOWS_ZONE_NAMES = {
#{hash_items}
}
end
CRYSTAL

source = Crystal.format(source)

File.write(TARGET_FILE, source)
46 changes: 46 additions & 0 deletions spec/compiler/codegen/array_literal_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,50 @@ describe "Code gen: array literal spec" do
custom.value
)).to_i.should eq(6)
end

it "creates custom non-generic array in module" do
run(%(
module Moo
class Custom
def initialize
@value = 0
end
def <<(element)
@value += element
end
def value
@value
end
end
end
custom = Moo::Custom {1, 2, 3}
custom.value
)).to_i.should eq(6)
end

it "creates custom generic array in module (#5684)" do
run(%(
module Moo
class Custom(T)
def initialize
@value = 0
end
def <<(element : T)
@value += element
end
def value
@value
end
end
end
custom = Moo::Custom {1, 2, 3}
custom.value
)).to_i.should eq(6)
end
end
22 changes: 22 additions & 0 deletions spec/compiler/codegen/debug_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,26 @@ describe "Code gen: debug" do
A
), debug: Crystal::Debug::All)
end

it "has debug info in closure inside if (#5593)" do
codegen(%(
require "prelude"
def foo
if true && true
yield 1
end
end
def bar(&block)
block
end
foo do |i|
bar do
i
end
end
), debug: Crystal::Debug::All)
end
end
Loading

0 comments on commit 731e9c0

Please sign in to comment.