Beispiel #1
0
        /// <summary>编译源文件</summary>
        /// <param name="cmd"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        public Int32 Compile(String cmd, String file)
        {
            var objName = GetObjPath(file);

            // 如果文件太新,则不参与编译
            var obj = (objName + ".o").AsFile();

            if (!Check(file, obj))
            {
                return(-2);
            }

            obj.DirectoryName.EnsureDirectory(false);

            var sb = new StringBuilder();

            sb.Append(cmd);

            foreach (var item in Includes)
            {
                sb.AppendFormat(" -I{0}", item);
            }

            var rs = OnCompile(file);

            if (!rs.IsNullOrEmpty())
            {
                sb.AppendFormat(" {0}", rs);
            }

            // 加上内置编译时宏定义
            sb.AppendFormat(DefineFormat + "={1}", "__BUILD_DATE__", (Int32)(DateTime.Now - new DateTime(2000, 1, 1)).TotalDays);
            sb.AppendFormat(DefineFormat + "={1}", "__BUILD_TIME__", (Int32)(DateTime.Now - new DateTime(1970, 1, 1)).TotalSeconds);
            sb.AppendFormat(DefineFormat + "=\"\\\"{1}\\\"\"", "__BUILD_STIME__", DateTime.Now.ToFullString());
            sb.AppendFormat(DefineFormat + "=\"\\\"{1}\\\"\"", "__BUILD_SDATE__", DateTime.Now.ToString("yyMMdd"));
            sb.AppendFormat(DefineFormat + "={1}", "__BUILD_ITIME__", DateTime.Now.ToString("HHmmss"));
            sb.AppendFormat(DefineFormat + "={1}", "__BUILD_IDATE__", DateTime.Now.ToString("yyMMdd"));
            var user = $"{Environment.MachineName}_{Environment.UserName}";

            if (user.Length > 15)
            {
                user = Environment.MachineName;
            }
            if (user.Length > 15)
            {
                user = user.Substring(0, 15);
            }
            sb.AppendFormat(DefineFormat + "=\"\\\"{1}\\\"\"", "__BUILD_USER__", user);

            // 先删除目标文件
            if (obj.Exists)
            {
                obj.Delete();
            }

            return(Complier.Run(sb.ToString(), 100, WriteLog));
        }
Beispiel #2
0
        /// <summary>编译源文件</summary>
        /// <param name="cmd"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        public Int32 Compile(String cmd, String file)
        {
            var objName = GetObjPath(file);

            // 如果文件太新,则不参与编译
            var obj = (objName + ".o").AsFile();

            if (!Check(file, obj))
            {
                return(-2);
            }

            obj.DirectoryName.EnsureDirectory(false);

            var sb = new StringBuilder();

            sb.Append(cmd);

            foreach (var item in Includes)
            {
                sb.AppendFormat(" -I{0}", item);
            }

            var rs = OnCompile(file);

            if (!rs.IsNullOrEmpty())
            {
                sb.AppendFormat(" {0}", rs);
            }

            // 先删除目标文件
            if (obj.Exists)
            {
                obj.Delete();
            }

            return(Complier.Run(sb.ToString(), 100, WriteLog));
        }