Beispiel #1
0
        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 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());
                }
            }
        }
Beispiel #3
0
        private EvaluationResult GetSharedOpaqueSubDirectory(Context context, ModuleLiteral env, EvaluationStackFrame args)
        {
            var          directory                   = Converter.ExpectSharedOpaqueDirectory(args[0]).Root;
            AbsolutePath subDirectoryPath            = Args.AsPath(args, 1, false);
            var          optionalFilterObj           = Args.AsObjectLiteralOptional(args, 2);
            SealDirectoryContentFilter?contentFilter = GetContentFilterHelper(optionalFilterObj);

            if (!context.GetPipConstructionHelper().TryComposeSharedOpaqueDirectory(subDirectoryPath, new[] { directory }, SealDirectoryCompositionActionKind.NarrowDirectoryCone, contentFilter, description: null, tags: null, out var compositeSharedOpaque))
            {
                // Error should have been logged
                return(EvaluationResult.Error);
            }

            var result = new StaticDirectory(root: compositeSharedOpaque, kind: SealDirectoryKind.SharedOpaque, s_emptySealContents.WithCompatibleComparer(OrdinalPathOnlyFileArtifactComparer.Instance));

            return(new EvaluationResult(result));
        }