public bool Emit(PublishRoot root) { root.Reports.Quiet.WriteLine("Bundling runtime {0}", Name); if (Directory.Exists(TargetPath)) { root.Reports.Quiet.WriteLine(" {0} already exists.", TargetPath); // REVIEW: IS this correct? return(true); } if (!Directory.Exists(TargetPath)) { Directory.CreateDirectory(TargetPath); } new PublishOperations().Copy(_runtimePath, TargetPath); if (!RuntimeEnvironmentHelper.IsWindows) { // Executable permissions on dnx lost on copy. var dnxPath = Path.Combine(TargetPath, "bin", "dnx"); if (!FileOperationUtils.MarkExecutable(dnxPath)) { root.Reports.Information.WriteLine("Failed to mark {0} as executable".Yellow(), dnxPath); } } return(true); }
public void Emit(PublishRoot root) { root.Reports.Quiet.WriteLine("Bundling runtime {0}", Name); if (Directory.Exists(TargetPath)) { root.Reports.Quiet.WriteLine(" {0} already exists.", TargetPath); return; } if (!Directory.Exists(TargetPath)) { Directory.CreateDirectory(TargetPath); } new PublishOperations().Copy(_runtimePath, TargetPath); if (PlatformHelper.IsMono) { // Executable permissions on dnx lost on copy. var dnxPath = Path.Combine(TargetPath, "bin", "dnx"); if (!FileOperationUtils.MarkExecutable(dnxPath)) { root.Reports.Information.WriteLine("Failed to mark {0} as executable".Yellow(), dnxPath); } } }
private void GenerateBashScripts() { string relativeAppBase; if (NoSource) { relativeAppBase = string.Format("{0}/{1}/{2}/{3}/{4}", AppRootName, "packages", _project.Name, _project.Version.ToString(), "root"); } else { relativeAppBase = string.Format("{0}/{1}/{2}", AppRootName, "src", _project.Name); } const string template = @"#!/usr/bin/env bash 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 DIR=""$( cd -P ""$( dirname ""$SOURCE"" )"" && pwd )"" export SET {0}=""$DIR/{1}"" exec ""{2}{3}"" --appbase ""${0}"" Microsoft.Dnx.ApplicationHost --configuration {4} {5} ""$@"""; foreach (var commandName in _project.Commands.Keys) { var runtimeFolder = string.Empty; if (Runtimes.Any()) { runtimeFolder = string.Format(@"$DIR/{0}/runtimes/{1}/bin/", AppRootName, Runtimes.First().Name); } var scriptPath = Path.Combine(OutputPath, commandName); File.WriteAllText(scriptPath, string.Format(template, EnvironmentNames.AppBase, relativeAppBase, runtimeFolder, Runtime.Constants.BootstrapperExeName, Configuration, commandName).Replace("\r\n", "\n")); if (!RuntimeEnvironmentHelper.IsWindows) { if (!FileOperationUtils.MarkExecutable(scriptPath)) { Reports.Information.WriteLine("Failed to mark {0} as executable".Yellow(), scriptPath); } } } }
private void GenerateBashScripts() { string relativeAppBase; if (NoSource) { relativeAppBase = $"packages/{_project.Name}/{_project.Version}/root"; } else { relativeAppBase = $"src/{_project.Name}"; } foreach (var commandName in _project.Commands.Keys) { var runtimeFolder = string.Empty; if (Runtimes.Any()) { var runtime = Runtimes.First().Name; runtimeFolder = $@"$DIR/runtimes/{runtime}/bin/"; } var scriptPath = Path.Combine(OutputPath, AppRootName, commandName); var scriptContents = $@"#!/usr/bin/env bash 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 DIR=""$( cd -P ""$( dirname ""$SOURCE"" )"" && pwd )"" exec ""{runtimeFolder}{Runtime.Constants.BootstrapperExeName}"" --project ""$DIR/{relativeAppBase}"" --configuration {Configuration} {commandName} ""$@"""; File.WriteAllText(scriptPath, scriptContents.Replace("\r\n", "\n")); if (!RuntimeEnvironmentHelper.IsWindows) { if (!FileOperationUtils.MarkExecutable(scriptPath)) { Reports.Information.WriteLine("Failed to mark {0} as executable".Yellow(), scriptPath); } } } }
public void DnuRestore_ExecutesScripts(string flavor, string os, string architecture) { bool isWindows = TestUtils.CurrentRuntimeEnvironment.OperatingSystem == "Windows"; var environment = new Dictionary <string, string> { { "DNX_TRACE", "0" }, }; var expectedPreContent = @"""one"" ""two"" "">three"" ""four"" "; var expectedPostContent = @"""five"" ""six"" ""argument seven"" ""argument eight"" "; string projectJsonContent; string scriptContent; string scriptName; if (isWindows) { projectJsonContent = @"{ ""frameworks"": { ""dnx451"": { } }, ""scripts"": { ""prerestore"": [ ""script.cmd one two > pre"", ""script.cmd ^>three >> pre && script.cmd ^ four >> pre"" ], ""postrestore"": [ ""\""%project:Directory%/script.cmd\"" five six > post"", ""\""%project:Directory%/script.cmd\"" \""argument seven\"" \""argument eight\"" >> post"" ] } }"; scriptContent = @"@echo off :argumentStart if ""%~1""=="""" goto argumentEnd echo ""%~1"" shift goto argumentStart :argumentEnd"; scriptName = "script.cmd"; } else { projectJsonContent = @"{ ""frameworks"": { ""dnx451"": { } }, ""scripts"": { ""prerestore"": [ ""script one two > pre"", ""script.sh \\>three >> pre; ./script.sh four >> pre"" ], ""postrestore"": [ ""\""%project:Directory%/script\"" five six > post"", ""\""%project:Directory%/script.sh\"" \""argument seven\"" \""argument eight\"" >> post"" ] } }"; scriptContent = @"#!/usr/bin/env bash set -o errexit for arg in ""$@""; do printf ""\""%s\""\n"" ""$arg"" done"; scriptName = "script.sh"; } var projectStructure = $@"{{ '.': ['project.json', '{ scriptName }'] }}"; var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture); using (var testEnv = new DnuTestEnvironment(runtimeHomePath, projectName: "Project Name")) { var projectPath = testEnv.ProjectPath; DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", projectJsonContent) .WithFileContents(scriptName, scriptContent) .WriteTo(projectPath); FileOperationUtils.MarkExecutable(Path.Combine(projectPath, scriptName)); string output; string error; var exitCode = DnuTestUtils.ExecDnu( runtimeHomePath, subcommand: "restore", arguments: null, stdOut: out output, stdErr: out error, environment: environment, workingDir: projectPath); Assert.Equal(0, exitCode); Assert.Empty(error); Assert.Contains("Executing script 'prerestore' in project.json", output); Assert.Contains("Executing script 'postrestore' in project.json", output); var preContent = File.ReadAllText(Path.Combine(projectPath, "pre")); Assert.Equal(expectedPreContent, preContent); var postContent = File.ReadAllText(Path.Combine(projectPath, "post")); Assert.Equal(expectedPostContent, postContent); } }