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

CRLF preservation #11

Open
wants to merge 10 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
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Default behaviour, for if core.autocrlf isn't set
* text=auto

appveyor.sh text eol=lf
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
*.cmxa
*.cmxs
*.a
*.lib
*.o
*.obj
src/.depend
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: c
sudo: required
install: wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-opam.sh
script: bash -ex .travis-opam.sh
env:
global:
- PACKAGE=opam-file-format
matrix:
- OCAML_VERSION=4.02
- OCAML_VERSION=4.03
- OCAML_VERSION=4.04
- OCAML_VERSION=4.05
- OCAML_VERSION=4.06
os:
- linux
- osx
94 changes: 94 additions & 0 deletions appveyor.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
@rem ***********************************************************************
@rem * *
@rem * opam *
@rem * *
@rem * David Allsopp, OCaml Labs, Cambridge. *
@rem * *
@rem * Copyright 2018 MetaStack Solutions Ltd. *
@rem * *
@rem * All rights reserved. This file is distributed under the terms of *
@rem * the GNU Lesser General Public License version 2.1, with the *
@rem * special exception on linking described in the file LICENSE. *
@rem * *
@rem ***********************************************************************

@rem BE CAREFUL ALTERING THIS FILE TO ENSURE THAT ERRORS PROPAGATE
@rem IF A COMMAND SHOULD FAIL IT PROBABLY NEEDS TO END WITH
@rem || exit /b 1
@rem BASICALLY, DO THE TESTING IN BASH...

@rem Do not call setlocal!
@echo off

goto %1

goto :EOF

:CheckPackage
"%CYG_ROOT%\bin\bash.exe" -lc "cygcheck -dc %1" | findstr %1 > nul
if %ERRORLEVEL% equ 1 (
echo Cygwin package %1 will be installed
set CYGWIN_INSTALL_PACKAGES=%CYGWIN_INSTALL_PACKAGES%,%1
)
goto :EOF

:UpgradeCygwin
if "%CYGWIN_INSTALL_PACKAGES%" neq "" "%CYG_ROOT%\setup-%CYG_ARCH%.exe" --quiet-mode --no-shortcuts --no-startmenu --no-desktop --only-site --root "%CYG_ROOT%" --site "%CYG_MIRROR%" --local-package-dir "%CYG_CACHE%" --packages %CYGWIN_INSTALL_PACKAGES:~1% > nul
for %%P in (%CYGWIN_COMMANDS%) do "%CYG_ROOT%\bin\bash.exe" -lc "%%P --help" > nul || set CYGWIN_UPGRADE_REQUIRED=1
"%CYG_ROOT%\bin\bash.exe" -lc "cygcheck -dc %CYGWIN_PACKAGES%"
if %CYGWIN_UPGRADE_REQUIRED% equ 1 (
echo Cygwin package upgrade required - please go and drink coffee
"%CYG_ROOT%\setup-%CYG_ARCH%.exe" --quiet-mode --no-shortcuts --no-startmenu --no-desktop --only-site --root "%CYG_ROOT%" --site "%CYG_MIRROR%" --local-package-dir "%CYG_CACHE%" --upgrade-also > nul
"%CYG_ROOT%\bin\bash.exe" -lc "cygcheck -dc %CYGWIN_PACKAGES%"
)
goto :EOF

:install
set CYG_ROOT=C:\%CYG_ROOT%

cd "%APPVEYOR_BUILD_FOLDER%"

rem CYGWIN_PACKAGES is the list of required Cygwin packages (cygwin is included
rem in the list just so that the Cygwin version is always displayed on the log).
rem CYGWIN_COMMANDS is a corresponding command to run with --version to test
rem whether the package works. This is used to verify whether the installation
rem needs upgrading.
set CYGWIN_PACKAGES=cygwin make patch diffutils tar unzip
set CYGWIN_COMMANDS=cygcheck make patch diff tar unzip

if "%OCAML_PORT%" equ "mingw" (
set CYGWIN_PACKAGES=%CYGWIN_PACKAGES% mingw64-i686-gcc-core
set CYGWIN_COMMANDS=%CYGWIN_COMMANDS% i686-w64-mingw32-core
)
if "%OCAML_PORT%" equ "mingw64" (
set CYGWIN_PACKAGES=%CYGWIN_PACKAGES% mingw64-x86_64-gcc-core
set CYGWIN_COMMANDS=%CYGWIN_COMMANDS% x86_64-w64-mingw32-core
)
if "%OCAML_PORT:~0,6%" equ "cygwin" (
set CYGWIN_PACKAGES=%CYGWIN_PACKAGES% flexdll gcc-core
set CYGWIN_COMMANDS=%CYGWIN_COMMANDS% flexlink gcc
)

set CYGWIN_INSTALL_PACKAGES=
set CYGWIN_UPGRADE_REQUIRED=0

for %%P in (%CYGWIN_PACKAGES%) do call :CheckPackage %%P
call :UpgradeCygwin

if "%OCAML_PORT%" equ "msvc64" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
if "%OCAML_PORT%" equ "msvc" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat"

"%CYG_ROOT%\bin\bash.exe" -lc "$APPVEYOR_BUILD_FOLDER/appveyor.sh install" || exit /b 1

set PATH=%OCAML_ROOT%\%OCAML_VERSION%\%OCAML_PORT%\bin;%PATH%

goto :EOF

:build
"%CYG_ROOT%\bin\bash.exe" -lc "$APPVEYOR_BUILD_FOLDER/appveyor.sh build" || exit /b 1

goto :EOF

:test

goto :EOF
167 changes: 167 additions & 0 deletions appveyor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#!/bin/bash

TERM=st

# Increment whenever the OCaml version or a package is updated to invalidate the caches
SERIAL=1

ROOT_CYG=$(echo $OCAML_ROOT| cygpath -f -)
APPVEYOR_BUILD_FOLDER=$(echo $APPVEYOR_BUILD_FOLDER| cygpath -f -)

ERRORS_ALLOWED=0
function quietly_log {
if ! script --quiet --return --append --command "$1" $LOG_FILE > /dev/null 2>&1 ; then
sed -e 's/\d027\[K//g' \
-e 's/\d027\[m/\d027[0m/g' \
-e 's/\d027\[01\([m;]\)/\d027[1\1/g' $LOG_FILE
if ((ERRORS_ALLOWED)) ; then
return 1
else
exit 1
fi
fi
}

function msvs_promote_path {
if [[ ${1%64} = "msvc" ]] ; then
eval $($ROOT_CYG/msvs-promote-path)
fi
}

case "$1" in
install)
# @@DRA TODO This should be converted OCAML_ROOT to a regexp, not having C:\\\\OCaml hard coded!
if ! cat $APPVEYOR_BUILD_FOLDER/appveyor.yml | tr -d '\015' | sed -e '1,/^cache:/d' -e '/^$/,$d' | grep -q "^ \+- \+C:\\\\OCaml$" ; then
echo "$(tput setf 4)ERROR$(tput sgr0) C:\\OCaml doesn't appear to be cached in appveyor.yml"
exit 1
fi

if [[ ! -e $ROOT_CYG/$OCAML_VERSION/$OCAML_PORT/bin/ocamlopt.exe || ! -e $ROOT_CYG/$OCAML_VERSION/version || $(cat $ROOT_CYG/$OCAML_VERSION/version) != "$OCAML_VERSION-$SERIAL" ]] ; then
if [[ -e $ROOT_CYG/$OCAML_VERSION/version && $(cat $ROOT_CYG/$OCAML_VERSION/version) != "$OCAML_VERSION-$SERIAL" ]] ; then
echo "Build cache for $OCAML_VERSION has serial $(cat $ROOT_CYG/$OCAML_VERSION/version); should be $OCAML_VERSION-$SERIAL -- clearing"
rm -rf $ROOT_CYG/$OCAML_VERSION
elif [[ ! -e $ROOT_CYG/$OCAML_VERSION/version ]] ; then
rm -rf $ROOT_CYG/$OCAML_VERSION
fi

PREFIX=$ROOT_CYG/$OCAML_VERSION/$OCAML_PORT
ROOT=$(echo $OCAML_ROOT| cygpath -m -f -)/$OCAML_VERSION/$OCAML_PORT
OCAML_BRANCH=${OCAML_VERSION%.*}
OCAML_BRANCH=${OCAML_BRANCH/.}

if [[ ! -d $APPVEYOR_BUILD_FOLDER/../src ]] ; then
mkdir -p $APPVEYOR_BUILD_FOLDER/../src
cd $APPVEYOR_BUILD_FOLDER/../src
git clone https://github.com/ocaml/ocaml.git
cd ocaml
mkdir -p $PREFIX
cp tools/msvs-promote-path $ROOT_CYG/
cd ..
FLEXDLL_VER=0.37
appveyor DownloadFile "https://github.com/alainfrisch/flexdll/releases/download/$FLEXDLL_VER/flexdll-bin-$FLEXDLL_VER.zip" -FileName flexdll-bin-$FLEXDLL_VER.zip
[[ -e $PREFIX/../version ]] || echo $OCAML_VERSION-$SERIAL> $PREFIX/../version
fi

cd $APPVEYOR_BUILD_FOLDER/../src/ocaml
git checkout $OCAML_VERSION
git worktree add ../$OCAML_VERSION/$OCAML_PORT/ocaml -b build-$OCAML_VERSION-$OCAML_PORT
if [[ $OCAML_BRANCH -ge 403 ]] ; then
pushd ../$OCAML_VERSION/$OCAML_PORT/ocaml > /dev/null
git submodule update --init
popd > /dev/null
fi
cd ../$OCAML_VERSION/$OCAML_PORT/ocaml
if [[ ${OCAML_PORT%64} = "cygwin" ]] ; then
if [[ $OCAML_BRANCH -gt 406 ]] ; then
NO_ALT_RUNTIMES="-no-instrumented-runtime -no-debug-runtime"
else
NO_ALT_RUNTIMES=
fi
PRE_WORLD=
POST_WORLD=
MAKEFILE=
./configure -prefix $PREFIX -no-ocamldoc -no-debugger $NO_ALT_RUNTIMES
else
if [[ $OCAML_BRANCH -ge 406 ]] ; then
cp config/s-nt.h byterun/caml/s.h
cp config/m-nt.h byterun/caml/m.h
else
cp config/s-nt.h config/s.h
cp config/m-nt.h config/m.h
fi
if [[ $OCAML_BRANCH -ge 405 ]] ; then
POST_WORLD=flexlink.opt
MAKEFILE=
else
POST_WORLD=
MAKEFILE=-f Makefile.nt
fi
if [[ $OCAML_BRANCH -lt 403 ]] ; then
mkdir -p $PREFIX/bin
pushd $PREFIX/bin > /dev/null
case $OCAML_PORT in
msvc)
MANIFEST=default.manifest;;
msvc64)
MANIFEST=default_amd64.manifest;;
*)
MANIFEST=;;
esac
unzip $APPVEYOR_BUILD_FOLDER/../src/flexdll-bin-$FLEXDLL_VER.zip flexdll_*$OCAML_PORT.* flexdll.h flexlink.exe $MANIFEST
popd > /dev/null
PRE_WORLD=
else
PRE_WORLD=flexdll
fi
sed -e "s|PREFIX=[^\r]*|PREFIX=$ROOT|" config/Makefile.$OCAML_PORT > config/Makefile
msvs_promote_path $OCAML_PORT
fi

LOG_FILE=OCaml-$OCAML_VERSION-$OCAML_PORT.log
echo "Building OCaml $OCAML_VERSION for $OCAML_PORT" | tee $LOG_FILE
echo "Please see $LOG_FILE for further information"
LOG_FILE="$APPVEYOR_BUILD_FOLDER/$LOG_FILE"
quietly_log "make $MAKEFILE $PRE_WORLD world.opt $POST_WORLD install"
# Remove unnecessary executables to keep the build cache size down
# These are removed here to ensure findlib doesn't configure itself
# to use .opt commands
if [[ $OCAML_BRANCH -ge 404 ]] ; then
if [[ ${OCAML_PORT%64} != "cygwin" ]] ; then
rm $PREFIX/bin/*.opt.exe
fi
rm $PREFIX/bin/*.byte.exe
else
for i in $PREFIX/bin/*.opt.exe ; do
rm ${i%.opt.exe}.exe
mv $i ${i%.opt.exe}.exe
done
fi
# Remove unnecessary commands to keep the build cache size down
rm -f $PREFIX/bin/{ocamlcp,ocamldebug,ocamldoc,ocamlmktop,ocamlobjinfo,ocamloptp,ocamlprof}.exe \
$PREFIX/lib/{expunge,extract_crc,objinfo_helper}.exe
# Remove unnecessary files
if [[ $OCAML_BRANCH -lt 405 && $OCAML_BRANCH -gt 402 ]] ; then
rm $PREFIX/*.txt
fi
find $PREFIX -name \*.cmt\* | xargs rm
find $PREFIX -name \*.ml\* | xargs rm
rm -f $PREFIX/lib/compiler-libs/*.cmx* $PREFIX/lib/compiler-libs/*.{lib,a} $PREFIX/lib/compiler-libs/ocamloptcomp.cma
echo "Complete"
appveyor PushArtifact $(echo $LOG_FILE| cygpath -m -f -)
fi
;;
build)
if [[ -z $2 ]] ; then
set -o pipefail
SCRIPT=$(echo "$0"| cygpath -f -)
script -qec "\"$SCRIPT\" $1 script" | sed -e 's/\d027\[K//g' \
-e 's/\d027\[m/\d027[0m/g' \
-e 's/\d027\[01\([m;]\)/\d027[1\1/g'
exit $?
fi

msvs_promote_path $OCAML_PORT

make -C $APPVEYOR_BUILD_FOLDER all
;;
esac
42 changes: 42 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
platform:
- x64

image: Visual Studio 2017

clone_depth: 1

environment:
global:
CYG_ROOT: cygwin64
CYG_ARCH: x86_64
OCAML_ROOT: C:\OCaml
OCAML_VERSION: 4.06.1
CYG_CACHE: C:\cygwin\var\cache\setup
CYG_MIRROR: http://mirrors.kernel.org/sourceware/cygwin/
matrix:
- CYG_ROOT: cygwin
CYG_ARCH: x86
OCAML_PORT: cygwin
- CYG_ROOT: cygwin64
OCAML_PORT: cygwin64
- OCAML_PORT: msvc
- OCAML_PORT: msvc64
- OCAML_PORT: mingw
- OCAML_PORT: mingw64

cache:
- C:\OCaml

install:
- call "%APPVEYOR_BUILD_FOLDER%\appveyor.cmd" install

build_script:
- call "%APPVEYOR_BUILD_FOLDER%\appveyor.cmd" build

test_script:
- call "%APPVEYOR_BUILD_FOLDER%\appveyor.cmd" test

# Uncomment this to enable Remote Desktop on the build worker at the end of the
# build. The worker is available for the remainder of the allocated hour.
#on_finish:
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
1 change: 0 additions & 1 deletion opam
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
opam-version: "1.2"
name: "opam-file-format"
version: "2.0.0~rc2"
synopsis: "Parser and printer for the opam file syntax"
maintainer: "Louis Gesbert <[email protected]>"
authors: "Louis Gesbert <[email protected]>"
license: "LGPL-2.1 with OCaml linking exception"
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ opam-file-format.cmxs: $(MODULES:%=%.cmx)

.PHONY: clean
clean:
rm -f *.cm* *.o *.a $(GENERATED) .depend
rm -f *.cm* *.o *.obj *.a *.lib $(GENERATED) .depend

.depend: *.ml *.mli $(GENERATED)
ocamldep *.mli *.ml > .depend
Expand Down
17 changes: 11 additions & 6 deletions src/opamBaseParser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let get_pos n =

%token <string> STRING IDENT
%token <bool> BOOL
%token EOF
%token <bool option> EOF
%token LBRACKET RBRACKET
%token LPAR RPAR
%token LBRACE RBRACE
Expand All @@ -48,14 +48,19 @@ let get_pos n =
%nonassoc URELOP

%start main value
%type <string -> OpamParserTypes.opamfile> main
%type <?default_eol_style:bool -> string -> OpamParserTypes.opamfile> main
%type <OpamParserTypes.value> value

%%

main:
| items EOF { fun file_name ->
{ file_contents = $1; file_name } }
| items EOF { fun ?(default_eol_style = Sys.win32) file_name ->
let file_crlf =
match $2 with
| None -> default_eol_style
| Some style -> style
in
{ file_contents = $1; file_crlf; file_name } }
;

items:
Expand Down Expand Up @@ -102,9 +107,9 @@ atom:

%%

let main t l f =
let main t l ?default_eol_style f =
try
let r = main t l f in
let r = main t l ?default_eol_style f in
Parsing.clear_parser ();
r
with
Expand Down
Loading