Exemplo n.º 1
0
        public PackageCache(Log log, UnoConfig config, bool enableTranspiler = true)
            : base(log ?? Log.Null)
        {
            if (config == null)
            {
                config = UnoConfig.Current;
            }

            _config           = config;
            _enableTranspiler = enableTranspiler;

            foreach (var src in config.GetFullPathArray("Packages.SourcePaths"))
            {
                _sourcePaths.AddOnce(Path.Combine(
                                         File.Exists(src)
                        ? Path.GetDirectoryName(src)
                        : src,
                                         "build"));
            }

            foreach (var src in config.GetFullPathArray("Packages.SearchPaths"))
            {
                _searchPaths.AddOnce(src);
            }
        }
Exemplo n.º 2
0
        public PackageCache(Log log, UnoConfig config, PackageManager pm)
            : base(log ?? Log.Null)
        {
            _pm = pm;

            if (config == null)
            {
                config = UnoConfig.Current;
            }

            foreach (var src in config.GetFullPathArray("Packages.SourcePaths"))
            {
                _sourcePaths.AddOnce(Path.Combine(src, "build"));
            }
            foreach (var src in config.GetFullPathArray("Packages.SearchPaths", "Packages.InstallDirectory"))
            {
                _searchPaths.AddOnce(src);
            }

            foreach (var file in config.GetFullPathArray("Packages.LockFiles"))
            {
                try
                {
                    Log.VeryVerbose("Package file: " + file);
                    foreach (var e in StuffObject.Load(file))
                    {
                        _locks[e.Key] = "" + e.Value;
                    }
                }
                catch (Exception e)
                {
                    Log.Trace(e);
                    Log.Warning("Failed to load " + file.Quote() + ": " + e.Message);
                }
            }
        }
Exemplo n.º 3
0
        public BackendResult Build()
        {
            if (Log.HasErrors)
            {
                return(null);
            }

            PrintRow("Packages", _input.Packages);
            PrintRow("Output dir", _env.OutputDirectory);

            _file.Delete();
            _env.Define(_target.Identifier, "TARGET_" + _target.Identifier,
                        _backend.Name, _backend.ShaderBackend.Name, _backend.ShaderBackend.Name,
                        _backend.BuildType.ToString());

            if (!string.IsNullOrEmpty(_target.FormerName))
            {
                _env.Define(_target.FormerName);
            }
            if (_options.Defines.Contains("HEADLESS"))
            {
                _env.Define("HEADLESS");
            }
            if (_options.OptimizeLevel == 0)
            {
                _options.Defines.Add("O0"); // disables native optimizations
            }
            if (_compilerOptions.Debug)
            {
                _env.Define("DEBUG");
            }
            if (_options.Configuration != BuildConfiguration.Debug)
            {
                _env.Define(_options.Configuration.ToString().ToUpperInvariant());
            }
            if (_options.Configuration == BuildConfiguration.Preview)
            {
                _env.Define("REFLECTION", "SIMULATOR", "STACKTRACE", "DesignMode");
            }
            if (Log.EnableExperimental)
            {
                _options.Defines.Add("EXPERIMENTAL");
            }
            foreach (var def in StuffFile.DefaultDefines)
            {
                _env.Define("HOST_" + def);
            }
            foreach (var def in _options.Defines)
            {
                _env.Define(def);
            }

            _target.Initialize(_env);

            foreach (var def in _options.Undefines)
            {
                _env.Undefine(def);
            }

            foreach (var p in _project.GetProperties(Log))
            {
                _env.Set("Project." + p.Key, p.Value);
            }
            foreach (var p in _config.Flatten())
            {
                _env.Set("Config." + p.Key, GetConfigValue(p.Key, p.Value));
            }
            foreach (var e in _options.Settings)
            {
                _env.Set(e.Key, GetCommandLineValue(e.Value), Disambiguation.Override);
            }

            var unoExe = _config.GetFullPath("UnoExe", false);

            if (unoExe != null)
            {
                Log.Warning(".unoconfig: 'UnoExe' is deprecated -- replace with 'Assemblies.Uno'");
            }
            else
            {
                unoExe = _config.GetFullPath("Assemblies.Uno");
            }

            _env.Set("Uno", PlatformDetection.IsWindows
                ? unoExe.QuoteSpace()
                : GetMonoPath().QuoteSpace() + " " + unoExe.QuoteSpace());

            foreach (var dll in _config.GetFullPathArray("Assemblies.Plugins"))
            {
                _compiler.Plugins.Load(dll);
            }

            if (Log.HasErrors)
            {
                return(null);
            }

            // Install NPM packages if package.json exists
            foreach (var p in _input.Packages)
            {
                if (p.IsProject && NPM.NeedsInstall(p))
                {
                    new NPM(Log).Install(p);
                }
            }

            using (Log.StartProfiler(typeof(UXProcessor)))
                UXProcessor.Build(_compiler.Disk, _input.Packages);

            if (Log.HasErrors)
            {
                return(null);
            }

            try
            {
                _compiler.Load();
            }
            finally
            {
                StopAnim();
            }

            if (Log.HasErrors)
            {
                return(null);
            }

            var defines = _compiler.Data.Extensions.Defines;
            var stuff   = GetDirtyStuff(_env, defines, _input.Packages);

            if (stuff.Count > 0)
            {
                using (Log.StartAnimation("Installing dependencies"))
                {
                    Stuff.Log.Configure(Log.IsVeryVerbose, Log.OutWriter, Log.ErrorWriter);

                    foreach (var f in stuff)
                    {
                        if (!Installer.Install(f, 0, defines))
                        {
                            Log.Error(new Source(f), null, "Failed to install dependencies");
                        }
                    }
                }
            }

            if (Log.HasErrors)
            {
                return(null);
            }

            using (Log.StartAnimation("Compiling syntax tree"))
                _compiler.Compile();

            if (Log.HasErrors)
            {
                return(null);
            }

            _anim = Log.StartAnimation("Generating code and data");

            try
            {
                return(_compiler.Generate(_target.Configure));
            }
            finally
            {
                // Add flag to avoid repeating warnings when this package is reused in following builds (uno doctor).
                _compiler.Input.Package.Flags |= SourcePackageFlags.Verified;

                _file.Product      = _env.GetString("Product");
                _file.BuildCommand = _env.GetString("Commands.Build");
                _file.RunCommand   = _env.GetString("Commands.Run");

                if (!Log.HasErrors)
                {
                    _file.Save(GetHashCode());
                    _target.DeleteOutdated(_compiler.Disk, _env);
                }

                StopAnim();
            }
        }