private static EvaluationResult Write(Context context, ModuleLiteral env, EvaluationStackFrame args) { var outputFilePath = Args.AsPath(args, 0); var obj = Args.AsObjectLiteral(args, 1); // Options don't have any settings yet, just here for future convenience var tags = Args.AsStringArrayOptional(args, 3); var description = Args.AsStringOptional(args, 4); using (var pipDataBuilderWrapper = context.FrontEndContext.GetPipDataBuilder()) { var pipData = CreatePipData(context.StringTable, obj, pipDataBuilderWrapper.Instance); if (!pipData.IsValid) { return(EvaluationResult.Error); } FileArtifact result; if (!context.GetPipConstructionHelper().TryWriteFile(outputFilePath, pipData, WriteFileEncoding.Utf8, tags, description, out result)) { // Error has been logged return(EvaluationResult.Error); } return(new EvaluationResult(result)); } }
private static EvaluationResult Write(Context context, ModuleLiteral env, EvaluationStackFrame args) { var outputFilePath = Args.AsPath(args, 0); var obj = Args.AsObjectLiteral(args, 1); var quoteChar = Args.AsStringOptional(args, 2) ?? "\'"; var tags = Args.AsStringArrayOptional(args, 3); var description = Args.AsStringOptional(args, 4); var additionalOptions = GetAdditionalOptions(context.FrontEndContext, Args.AsObjectLiteralOptional(args, 5)); using (var pipDataBuilderWrapper = context.FrontEndContext.GetPipDataBuilder()) { var pipData = CreatePipData(context.StringTable, obj, quoteChar, pipDataBuilderWrapper.Instance); if (!pipData.IsValid) { return(EvaluationResult.Error); } FileArtifact result; if (!context.GetPipConstructionHelper().TryWriteFile(outputFilePath, pipData, WriteFileEncoding.Utf8, tags, description, out result, GetWriteFileOption(additionalOptions))) { // Error has been logged return(EvaluationResult.Error); } return(new EvaluationResult(result)); } }
private EvaluationResult SetMountPoint(Context context, ModuleLiteral env, EvaluationStackFrame args) { var obj = Args.AsObjectLiteral(args, 0); var name = Converter.ExtractPathAtom(obj, m_testingSetMountPointName); var path = Converter.ExtractPathLike(obj, m_testingSetMountPointPath); var trackSourceFileChanges = Converter.ExtractOptionalBoolean(obj, m_testingSetMountPointTrackSourceFileChanges) ?? false; var isWritable = Converter.ExtractOptionalBoolean(obj, m_testingSetMountPointIsWritable) ?? false; var isReadable = Converter.ExtractOptionalBoolean(obj, m_testingSetMountPointIsReadable) ?? false; var isSystem = Converter.ExtractOptionalBoolean(obj, m_testingSetMountPointIsSystem) ?? false; var isScrubbable = Converter.ExtractOptionalBoolean(obj, m_testingSetMountPointIsScrubbable) ?? false; var mount = new Mount { Name = name, Path = path, TrackSourceFileChanges = trackSourceFileChanges, IsWritable = isWritable, IsReadable = isReadable, IsSystem = isSystem, IsScrubbable = isScrubbable, }; m_engineAbstraction.SetMountPoint(mount); return(EvaluationResult.Undefined); }
private EvaluationResult SealSourceDirectory(Context context, ModuleLiteral env, EvaluationStackFrame args) { AbsolutePath path; SealDirectoryKind sealDirectoryKind; string[] tags; string description; string[] patterns; if (args.Length > 0 && args[0].Value is ObjectLiteral) { var obj = Args.AsObjectLiteral(args, 0); var directory = Converter.ExtractDirectory(obj, m_sealRoot, allowUndefined: false); path = directory.Path; var include = Converter.ExtractStringLiteral(obj, m_sealInclude, s_includeMap.Keys, allowUndefined: true); sealDirectoryKind = include != null ? s_includeMap[include] : SealDirectoryKind.SourceTopDirectoryOnly; tags = Converter.ExtractStringArray(obj, m_sealTags, allowUndefined: true); description = Converter.ExtractString(obj, m_sealDescription, allowUndefined: true); patterns = Converter.ExtractStringArray(obj, m_sealPatterns, allowUndefined: true); } else { path = Args.AsPath(args, 0, false); var optionAsEnumValue = Args.AsNumberOrEnumValueOptional(args, 1); var option = optionAsEnumValue.HasValue ? (SealSourceDirectoryOption)optionAsEnumValue.Value : SealSourceDirectoryOption.TopDirectoryOnly; sealDirectoryKind = option == SealSourceDirectoryOption.AllDirectories ? SealDirectoryKind.SourceAllDirectories : SealDirectoryKind.SourceTopDirectoryOnly; tags = Args.AsStringArrayOptional(args, 2); description = Args.AsStringOptional(args, 3); patterns = Args.AsStringArrayOptional(args, 4); } DirectoryArtifact sealedDirectoryArtifact; if (!context.GetPipConstructionHelper().TrySealDirectory( directoryRoot: path, contents: s_emptySealContents, outputDirectorycontents: s_emptyOutputDirectoryContents, kind: sealDirectoryKind, tags: tags, description: description, patterns: patterns, sealedDirectory: out sealedDirectoryArtifact)) { // Error has been logged return(EvaluationResult.Error); } var result = new StaticDirectory(sealedDirectoryArtifact, sealDirectoryKind, s_emptySealContents.WithCompatibleComparer(OrdinalPathOnlyFileArtifactComparer.Instance)); return(new EvaluationResult(result)); }
private EvaluationResult ComposeSharedOpaqueDirectories(Context context, ModuleLiteral env, EvaluationStackFrame args) { AbsolutePath root; ArrayLiteral contents; SealDirectoryContentFilter?contentFilter; if (args.Length > 0 && args[0].Value is ObjectLiteral) { var obj = Args.AsObjectLiteral(args, 0); var directory = Converter.ExtractDirectory(obj, m_sealRoot, allowUndefined: false); root = directory.Path; contents = Converter.ExtractArrayLiteral(obj, m_sealDirectories, allowUndefined: false); var filterObj = Converter.ExtractObjectLiteral(obj, m_sealDirectoryContentFilter, allowUndefined: true); extractContentFilter(filterObj, out contentFilter); } else { root = Args.AsPath(args, 0, false); contents = Args.AsArrayLiteral(args, 1); var filterObj = Args.AsObjectLiteralOptional(args, 2); extractContentFilter(filterObj, out contentFilter); } var directories = new DirectoryArtifact[contents.Length]; for (int i = 0; i < contents.Length; ++i) { directories[i] = Converter.ExpectSharedOpaqueDirectory(contents[i], context: new ConversionContext(pos: i, objectCtx: contents)).Root; } if (!context.GetPipConstructionHelper().TryComposeSharedOpaqueDirectory(root, directories, contentFilter, description: null, tags: null, out var compositeSharedOpaque)) { // Error should have been logged return(EvaluationResult.Error); } var result = new StaticDirectory(compositeSharedOpaque, SealDirectoryKind.SharedOpaque, s_emptySealContents.WithCompatibleComparer(OrdinalPathOnlyFileArtifactComparer.Instance)); return(new EvaluationResult(result)); void extractContentFilter(ObjectLiteral obj, out SealDirectoryContentFilter?filter) { filter = null; if (obj != null) { var regex = Converter.ExtractRegex(obj, m_sealDirectoryContentFilterRegex, allowUndefined: false); var kindAsString = Converter.ExtractString(obj, m_sealDirectoryContentFilterKind, allowUndefined: false); filter = new SealDirectoryContentFilter( (SealDirectoryContentFilter.ContentFilterKind)Enum.Parse(typeof(SealDirectoryContentFilter.ContentFilterKind), kindAsString), regex.ToString()); } } }
private EvaluationResult SealDirectoryHelper(Context context, ModuleLiteral env, EvaluationStackFrame args, SealDirectoryKind sealDirectoryKind) { AbsolutePath path; ArrayLiteral contents; string[] tags; string description; bool scrub; if (args.Length > 0 && args[0].Value is ObjectLiteral) { var obj = Args.AsObjectLiteral(args, 0); var directory = Converter.ExtractDirectory(obj, m_sealRoot, allowUndefined: false); path = directory.Path; contents = Converter.ExtractArrayLiteral(obj, m_sealFiles, allowUndefined: false); tags = Converter.ExtractStringArray(obj, m_sealTags, allowUndefined: true); description = Converter.ExtractString(obj, m_sealDescription, allowUndefined: true); scrub = sealDirectoryKind.IsFull() ? Converter.ExtractOptionalBoolean(obj, m_sealScrub) ?? false : false; } else { path = Args.AsPath(args, 0, false); contents = Args.AsArrayLiteral(args, 1); tags = Args.AsStringArrayOptional(args, 2); description = Args.AsStringOptional(args, 3); // Only do scrub for fully seal directory scrub = sealDirectoryKind.IsFull() ? Args.AsBoolOptional(args, 4) : false; } var fileContents = new FileArtifact[contents.Length]; for (int i = 0; i < contents.Length; ++i) { fileContents[i] = Converter.ExpectFile(contents[i], strict: false, context: new ConversionContext(pos: i, objectCtx: contents)); } var sortedFileContents = SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> .CloneAndSort(fileContents, OrdinalFileArtifactComparer.Instance); DirectoryArtifact sealedDirectoryArtifact; if (!context.GetPipConstructionHelper().TrySealDirectory(path, sortedFileContents, sealDirectoryKind, tags, description, null, out sealedDirectoryArtifact, scrub)) { // Error has been logged return(EvaluationResult.Error); } var result = new StaticDirectory(sealedDirectoryArtifact, sealDirectoryKind, sortedFileContents.WithCompatibleComparer(OrdinalPathOnlyFileArtifactComparer.Instance)); return(new EvaluationResult(result)); }
private EvaluationResult IpcSend(Context context, ModuleLiteral env, EvaluationStackFrame args) { var obj = Args.AsObjectLiteral(args, 0); if (!TryScheduleIpcPip(context, obj, allowUndefinedTargetService: false, isServiceFinalization: false, out var outputFile, out _)) { // Error has been logged return(EvaluationResult.Error); } // create and return result var result = ObjectLiteral.Create( new List <Binding> { new Binding(m_ipcSendResultOutputFile, outputFile, location: default(LineInfo)), }, context.TopStack.InvocationLocation, context.TopStack.Path); return(EvaluationResult.Create(result)); }
private EvaluationResult WriteFileHelper(Context context, ModuleLiteral env, EvaluationStackFrame args, WriteFileMode mode) { AbsolutePath path; string[] tags; string description; PipData pipData; if (args.Length > 0 && args[0].Value is ObjectLiteral) { var obj = Args.AsObjectLiteral(args, 0); path = Converter.ExtractPath(obj, m_writeOutputPath, allowUndefined: false); tags = Converter.ExtractStringArray(obj, m_writeTags, allowUndefined: true); description = Converter.ExtractString(obj, m_writeDescription, allowUndefined: true); switch (mode) { case WriteFileMode.WriteData: var data = obj[m_writeContents]; pipData = ProcessData(context, data, new ConversionContext(pos: 1)); break; case WriteFileMode.WriteAllLines: var lines = Converter.ExtractArrayLiteral(obj, m_writeLines); var entry = context.TopStack; var newData = ObjectLiteral.Create( new List <Binding> { new Binding(m_dataSeparator, Environment.NewLine, entry.InvocationLocation), new Binding(m_dataContents, lines, entry.InvocationLocation), }, lines.Location, entry.Path); pipData = ProcessData(context, EvaluationResult.Create(newData), new ConversionContext(pos: 1)); break; case WriteFileMode.WriteAllText: var text = Converter.ExtractString(obj, m_writeText); pipData = ProcessData(context, EvaluationResult.Create(text), new ConversionContext(pos: 1)); break; default: throw Contract.AssertFailure("Unknown WriteFileMode."); } } else { path = Args.AsPath(args, 0, false); tags = Args.AsStringArrayOptional(args, 2); description = Args.AsStringOptional(args, 3); switch (mode) { case WriteFileMode.WriteFile: var fileContent = Args.AsIs(args, 1); // WriteFile has a separator argument with default newline var separator = Args.AsStringOptional(args, 3) ?? Environment.NewLine; description = Args.AsStringOptional(args, 4); pipData = CreatePipDataForWriteFile(context, fileContent, separator); break; case WriteFileMode.WriteData: var data = Args.AsIs(args, 1); pipData = ProcessData(context, EvaluationResult.Create(data), new ConversionContext(pos: 1)); break; case WriteFileMode.WriteAllLines: var lines = Args.AsArrayLiteral(args, 1); var entry = context.TopStack; var newData = ObjectLiteral.Create( new List <Binding> { new Binding(m_dataSeparator, Environment.NewLine, entry.InvocationLocation), new Binding(m_dataContents, lines, entry.InvocationLocation), }, lines.Location, entry.Path); pipData = ProcessData(context, EvaluationResult.Create(newData), new ConversionContext(pos: 1)); break; case WriteFileMode.WriteAllText: var text = Args.AsString(args, 1); pipData = ProcessData(context, EvaluationResult.Create(text), new ConversionContext(pos: 1)); break; default: throw Contract.AssertFailure("Unknown WriteFileMode."); } } FileArtifact result; if (!context.GetPipConstructionHelper().TryWriteFile(path, pipData, WriteFileEncoding.Utf8, tags, description, out result)) { // Error has been logged return(EvaluationResult.Error); } return(new EvaluationResult(result)); }