Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
add script executor
Browse files Browse the repository at this point in the history
also added a postcompile script to each project to place the outputs in the right folder

fixes #237
  • Loading branch information
analogrelay committed Nov 18, 2015
1 parent 3245130 commit 21487bc
Show file tree
Hide file tree
Showing 29 changed files with 807 additions and 182 deletions.
24 changes: 24 additions & 0 deletions scripts/build/place-binary.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@echo off

REM Copyright (c) .NET Foundation and contributors. All rights reserved.
REM Licensed under the MIT license. See LICENSE file in the project root for full license information.

set SRC=%1

set SRC=%SRC:/=\%

pushd %~dp0..\..
set DST=%CD%\artifacts\win7-x64\stage2\bin
popd

if not exist "%SRC%" goto end
if not exist "%DST%" goto skip

xcopy /F /Y /I "%SRC%" "%DST%"

goto end

:skip
echo The destination "%DST%" does not exist. This script is only designed to update a previous full build!

:end
33 changes: 33 additions & 0 deletions scripts/build/place-binary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#
set -e

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
REPOROOT="$( cd -P "$DIR/../.." && pwd )"

source "$SCRIPT_DIR/../_common.sh"

echo "Copy From: $1"
echo " To: $STAGE2_DIR/bin/"

src=${1//\\//}
dst=$STAGE2_DIR/bin/

if [ ! -d "$dst" ]; then
mkdir -p $dst
fi

# Copy the files, if they exist
if ls $src 1> /dev/null 2>&1; then
cp $src $dst
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
fi
6 changes: 6 additions & 0 deletions src/Microsoft.DotNet.Cli.Utils/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ public CommandResult Execute()
_stdErrCapture?.GetStringBuilder()?.ToString());
}

public Command WorkingDirectory(string projectDirectory)
{
_process.StartInfo.WorkingDirectory = projectDirectory;
return this;
}

public Command EnvironmentVariable(string name, string value)
{
_process.StartInfo.Environment[name] = value;
Expand Down
18 changes: 18 additions & 0 deletions src/Microsoft.DotNet.Cli.Utils/CommandParsing/Chain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.DotNet.Cli.Utils.CommandParsing
{
internal struct Chain<TLeft, TDown>
{
public Chain(TLeft left, TDown down)
: this()
{
Left = left;
Down = down;
}

public readonly TLeft Left;
public readonly TDown Down;
}
}
62 changes: 62 additions & 0 deletions src/Microsoft.DotNet.Cli.Utils/CommandParsing/CommandGrammar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.DotNet.Cli.Utils.CommandParsing
{
internal class CommandGrammar : Grammar
{
private CommandGrammar(Func<string, string> variable, bool preserveSurroundingQuotes)
{
var environmentVariablePiece = Ch('%').And(Rep(Ch().Not(Ch('%')))).And(Ch('%')).Left().Down().Str()
.Build(key => variable(key) ?? "%" + key + "%");

var escapeSequencePiece =
Ch('%').And(Ch('%')).Build(_=>"%")
.Or(Ch('^').And(Ch('^')).Build(_ => "^"))
.Or(Ch('\\').And(Ch('\\')).Build(_ => "\\"))
.Or(Ch('\\').And(Ch('\"')).Build(_ => "\""))
;

var specialPiece = environmentVariablePiece.Or(escapeSequencePiece);

var unquotedPiece = Rep1(Ch().Not(specialPiece).Not(Ch(' '))).Str();

var quotedPiece = Rep1(Ch().Not(specialPiece).Not(Ch('\"'))).Str();

var unquotedTerm = Rep1(unquotedPiece.Or(specialPiece)).Str();

var quotedTerm = Ch('\"').And(Rep(quotedPiece.Or(specialPiece)).Str()).And(Ch('\"')).Left().Down();
if (preserveSurroundingQuotes)
{
// Str() value assigned to quotedTerm does not include quotation marks surrounding the quoted or
// special piece. Add those quotes back if requested.
quotedTerm = quotedTerm.Build(str => "\"" + str + "\"");
}

var whitespace = Rep(Ch(' '));

var term = whitespace.And(quotedTerm.Or(unquotedTerm)).And(whitespace).Left().Down();

Parse = Rep(term);
}

public readonly Parser<IList<string>> Parse;

public static string[] Process(string text, Func<string, string> variables, bool preserveSurroundingQuotes)
{
var grammar = new CommandGrammar(variables, preserveSurroundingQuotes);
var cursor = new Cursor(text, 0, text.Length);

var result = grammar.Parse(cursor);
if (!result.Remainder.IsEnd)
{
throw new ArgumentException($"Malformed command text '{text}'", nameof(text));
}
return result.Value.ToArray();
}
}
}
34 changes: 34 additions & 0 deletions src/Microsoft.DotNet.Cli.Utils/CommandParsing/Cursor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.DotNet.Cli.Utils.CommandParsing
{
internal struct Cursor
{
private readonly string _text;
private readonly int _start;
private readonly int _end;

public Cursor(string text, int start, int end)
{
_text = text;
_start = start;
_end = end;
}

public bool IsEnd
{
get { return _start == _end; }
}

public char Peek(int index)
{
return (index + _start) >= _end ? (char)0 : _text[index + _start];
}

public Result<TValue> Advance<TValue>(TValue result, int length)
{
return new Result<TValue>(result, new Cursor(_text, _start + length, _end));
}
}
}
52 changes: 52 additions & 0 deletions src/Microsoft.DotNet.Cli.Utils/CommandParsing/Grammar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Linq;

namespace Microsoft.DotNet.Cli.Utils.CommandParsing
{
internal class Grammar
{
protected static Parser<IList<TValue>> Rep1<TValue>(Parser<TValue> parser)
{
Parser<IList<TValue>> rep = Rep(parser);
return pos =>
{
var result = rep(pos);
return result.IsEmpty || !result.Value.Any() ? Result<IList<TValue>>.Empty : result;
};
}

protected static Parser<IList<TValue>> Rep<TValue>(Parser<TValue> parser)
{
return pos =>
{
var data = new List<TValue>();
for (; ; )
{
var result = parser(pos);
if (result.IsEmpty) break;
data.Add(result.Value);
pos = result.Remainder;
}
return new Result<IList<TValue>>(data, pos);
};
}

protected static Parser<char> Ch()
{
return pos => pos.IsEnd ? Result<char>.Empty : pos.Advance(pos.Peek(0), 1);
}

private static Parser<bool> IsEnd()
{
return pos => pos.IsEnd ? pos.Advance(true, 0) : Result<bool>.Empty;
}

protected static Parser<char> Ch(char ch)
{
return pos => pos.Peek(0) != ch ? Result<char>.Empty : pos.Advance(ch, 1);
}
}
}
7 changes: 7 additions & 0 deletions src/Microsoft.DotNet.Cli.Utils/CommandParsing/Parser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.DotNet.Cli.Utils.CommandParsing
{
internal delegate Result<TValue> Parser<TValue>(Cursor cursor);
}
85 changes: 85 additions & 0 deletions src/Microsoft.DotNet.Cli.Utils/CommandParsing/ParserExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.DotNet.Cli.Utils.CommandParsing
{
internal static class ParserExtensions
{
public static Parser<Chain<T1, T2>> And<T1, T2>(this Parser<T1> parser1,
Parser<T2> parser2)
{
return pos =>
{
var result1 = parser1(pos);
if (result1.IsEmpty) return Result<Chain<T1, T2>>.Empty;
var result2 = parser2(result1.Remainder);
if (result2.IsEmpty) return Result<Chain<T1, T2>>.Empty;
return result2.AsValue(new Chain<T1, T2>(result1.Value, result2.Value));
};
}

public static Parser<T1> Or<T1>(this Parser<T1> parser1, Parser<T1> parser2)
{
return pos =>
{
var result1 = parser1(pos);
if (!result1.IsEmpty) return result1;
var result2 = parser2(pos);
if (!result2.IsEmpty) return result2;
return Result<T1>.Empty;
};
}

public static Parser<T1> Not<T1, T2>(this Parser<T1> parser1, Parser<T2> parser2)
{
return pos =>
{
var result2 = parser2(pos);
if (!result2.IsEmpty) return Result<T1>.Empty;
return parser1(pos);
};
}

public static Parser<T1> Left<T1, T2>(this Parser<Chain<T1, T2>> parser)
{
return pos =>
{
var result = parser(pos);
return result.IsEmpty ? Result<T1>.Empty : result.AsValue(result.Value.Left);
};
}

public static Parser<T2> Down<T1, T2>(this Parser<Chain<T1, T2>> parser)
{
return pos =>
{
var result = parser(pos);
return result.IsEmpty ? Result<T2>.Empty : result.AsValue(result.Value.Down);
};
}

public static Parser<T2> Build<T1, T2>(this Parser<T1> parser, Func<T1, T2> builder)
{
return pos =>
{
var result = parser(pos);
if (result.IsEmpty) return Result<T2>.Empty;
return result.AsValue(builder(result.Value));
};
}

public static Parser<string> Str(this Parser<IList<char>> parser)
{
return parser.Build(x => new string(x.ToArray()));
}

public static Parser<string> Str(this Parser<IList<string>> parser)
{
return parser.Build(x => String.Concat(x.ToArray()));
}
}
}
33 changes: 33 additions & 0 deletions src/Microsoft.DotNet.Cli.Utils/CommandParsing/Result.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.DotNet.Cli.Utils.CommandParsing
{
internal struct Result<TValue>
{
public Result(TValue value, Cursor remainder)
: this()
{
Value = value;
Remainder = remainder;
}

public readonly TValue Value;
public readonly Cursor Remainder;

public bool IsEmpty
{
get { return Equals(this, default(Result<TValue>)); }
}

public static Result<TValue> Empty
{
get { return default(Result<TValue>); }
}

public Result<TValue2> AsValue<TValue2>(TValue2 value2)
{
return new Result<TValue2>(value2, Remainder);
}
}
}
2 changes: 2 additions & 0 deletions src/Microsoft.DotNet.Cli.Utils/CommandResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Microsoft.DotNet.Cli.Utils
{
public struct CommandResult
{
public static readonly CommandResult Empty = new CommandResult();

public int ExitCode { get; }
public string StdOut { get; }
public string StdErr { get; }
Expand Down
Loading

0 comments on commit 21487bc

Please sign in to comment.