Exemple #1
0
        /// <inheritdoc />
        protected override void WriteEnd()
        {
            var environmentVariablesString = string.Join(", ", AllowedEnvironmentVariables.Select(DScriptWriterUtils.EncloseInDoubleQuotes));

            Writer.WriteLine(
                @"config({
    projects: [],
    modules: [f`package.dsc`],
    resolvers: Environment.getPathValues(""ScriptSdk"", "";"").map(path => <SourceResolver>{
        kind: ""SourceResolver"",
        root: d`${path}`
    }),");
            Writer.WriteLine("    allowedEnvironmentVariables: [{0}],", environmentVariablesString);
            Writer.WriteLine("    mounts: [");
            foreach (var mountPoint in m_mountPoints)
            {
                Writer.WriteLine("        {");
                Writer.WriteLine("            name: PathAtom.create(\"{0}\"),", mountPoint.Key);
                Writer.WriteLine("            path: {0}, ", DScriptWriterUtils.ToPath(mountPoint.Value, PathType.Path));
                Writer.WriteLine("            trackSourceFileChanges: true, ");
                Writer.WriteLine("            isReadable: true, ");
                Writer.WriteLine("            isWritable: true, ");
                Writer.WriteLine("            isSystem: false ");
                Writer.WriteLine("        },");
            }

            Writer.WriteLine("    ]");
            Writer.WriteLine(@"});");
        }
Exemple #2
0
        /// <inheritdoc />
        public override string ToRelativePathExpression(string path)
        {
            string drive = char.ToUpperInvariant(path[0]).ToString();

            WriteMount(drive, drive);
            return(DScriptWriterUtils.EncloseInQuotes(DScriptWriterUtils.GetPathFromExpression(path), "'"));
        }
Exemple #3
0
        private string GetImportVariable(string specPath)
        {
            specPath = DScriptWriterUtils.GetPathFromExpression(specPath);

            // Check whether producer of variableName is the same file or not.
            if (DScriptWriterUtils.NormalizePath(AbsolutePath).EndsWith(specPath, StringComparison.Ordinal))
            {
                return(string.Empty);
            }

            specPath = DScriptWriterUtils.RemoveFileEnding(specPath);

            string variableName;

            if (m_imports.TryGetValue(specPath, out variableName))
            {
                // return null;
                return(variableName);
            }

            variableName = "P" + m_counter++;
            m_imports.Add(specPath, variableName);
            Writer.WriteLine("import * as {1} from '{0}.dsc';", DScriptWriterUtils.NormalizePath(specPath), variableName);
            return(variableName);
        }
Exemple #4
0
        /// <inheritdoc />
        public override void AddSpec(string specRelativePath, SpecWriter specWriter)
        {
            var dsSpecWriter = specWriter as DScriptSpecWriter;

            if (dsSpecWriter != null && !m_specs.ContainsKey(specRelativePath))
            {
                var importSpec = new ImportSpec(dsSpecWriter, "P" + m_importCounter++);
                m_specs[specRelativePath] = importSpec;
                string normalizedPath = DScriptWriterUtils.NormalizePath(specRelativePath);
                string name           = normalizedPath.Replace("/", "__").Replace(".", "__").Replace("-", "_");
                Writer.WriteLine("import * as Mimic{1} from '/{0}';", normalizedPath, name);
            }
        }
Exemple #5
0
 /// <inheritdoc />
 public override void AddModule(ModuleWriter moduleWriter)
 {
     m_importedModules.Add(DScriptWriterUtils.ToRelativePath(moduleWriter.AbsolutePath, AbsolutePath));
 }
Exemple #6
0
        /// <inheritdoc />
        public override void AddMimicInvocation(
            string outputValue,
            IEnumerable <string> sealDirectoryInputs,
            IEnumerable <string> pathInputs,
            IEnumerable <MimicFileOutput> outputs,
            string observedAccessesPath,
            IEnumerable <SemaphoreInfo> semaphores,
            int runTimeInMs,
            bool isLongestProcess = false)
        {
            string mimicName = ToMimicRunnerVarName(outputValue);

            m_runners.Add(mimicName);

            m_writer.WriteLine("export const {0} = Mimic.evaluate({{", mimicName);
            m_writer.WriteLine("    processRunningTime: {0},", runTimeInMs);
            m_writer.WriteLine("    isLongestProcess: {0},", isLongestProcess.ToString().ToLower(CultureInfo.CurrentCulture));
            if (observedAccessesPath != null)
            {
                m_writer.WriteLine("    observedAccesses: {0},", DScriptWriterUtils.ToPath(observedAccessesPath, PathType.Path));
                m_writer.WriteLine("    observedAccessesRoot: {0},", "p`/RootMarker.dummy`.parent");
            }

            m_writer.WriteLine("    sealDirectoryInputs: [");
            foreach (var sealDirectory in sealDirectoryInputs)
            {
                m_writer.WriteLine("        {0},", IfStringThenToPath(sealDirectory, PathType.Directory));
            }

            m_writer.WriteLine("    ],");

            m_writer.WriteLine("    fileInputs: [");
            foreach (var pathInput in pathInputs)
            {
                m_writer.WriteLine("       {0},", IfStringThenToPath(pathInput, PathType.File));
            }

            m_writer.WriteLine("    ],");

            m_writer.WriteLine("    fileOutputs: [");

            foreach (var output in outputs)
            {
                m_writer.WriteLine("        {");
                m_writer.WriteLine("            path: {0},", IfStringThenToPath(output.Path, PathType.Path));
                m_writer.WriteLine("            repeatingContent: \"{0}\",", output.RepeatingContent);
                m_writer.WriteLine("            lengthInBytes: {0},", output.LengthInBytes);
                m_writer.WriteLine("            fileId: {0}", output.FileId);
                m_writer.WriteLine("        }, ");
            }

            m_writer.WriteLine("    ],");

            m_writer.WriteLine("    semaphores: [");

            foreach (var semaphore in semaphores)
            {
                m_writer.WriteLine("       {");
                m_writer.WriteLine("           name: {0},", semaphore.Name);
                m_writer.WriteLine("           value: \"{0}\",", semaphore.Value);
                m_writer.WriteLine("           limit: {0},", semaphore.Limit);
                m_writer.WriteLine("        }, ");
            }

            m_writer.WriteLine("   ],");

            // TODO: need to plumb this stuff through to DScript
            m_writer.WriteLine("});");
        }
Exemple #7
0
 /// <summary>
 /// If given 'expr' is quoted (<see cref="IsStringExpression"/>), the expression is converted
 /// to path (<see cref="ToPath"/>); otherwise, the expression is returned.
 /// </summary>
 private static string IfStringThenToPath(string expression, PathType type)
 {
     return(DScriptWriterUtils.IsStringExpression(expression)
         ? DScriptWriterUtils.ToPath(expression, type)
         : expression);
 }