Ejemplo n.º 1
0
        // Create a release
        public virtual void Release(string baseOutputDir)
        {
            string srcDir = Path.Combine(baseOutputDir, this.CrossLibName + @"\src");
            string releaseFileName = Path.Combine(Paths.ReleaseDir, this.OutputFileName);
            Con.WriteLine("Generating '{0}'...", releaseFileName);

            List<string> files = new List<string>();
            string gccOptionForLink;
            string gccOptionForCompile;

            generateGccOptions(srcDir, false, false, out gccOptionForLink, out gccOptionForCompile);

            string targetName = this.Software.ToString();

            // Makefile
            StringWriter mk = GenerateMakeFileForRelease(srcDir);
            byte[] mkData = Str.NormalizeCrlf(Str.Utf8Encoding.GetBytes(mk.ToString()), new byte[] { 10 });

            TarPacker tar = new TarPacker();

            tar.AddFileSimple(targetName + @"\Makefile", mkData, 0, mkData.Length, DateTime.Now);

            // Install Script
            string isText = File.ReadAllText(Paths.UnixInstallScript);
            isText = Str.ReplaceStr(isText, "<TITLE>", TitleString, false);
            byte[] scriptData = Str.NormalizeCrlf(Str.Utf8Encoding.GetBytes(isText), new byte[] { 10 });
            tar.AddFileSimple(targetName + @"\.install.sh", scriptData, 0, scriptData.Length, DateTime.Now);

            // EULA
            Encoding enc = Str.Utf8Encoding;

            if (true)
            {
                string srcData = File.ReadAllText(Path.Combine(Paths.BinDirName, @"hamcore\eula.txt"),
                    enc);

                byte[] destData = enc.GetBytes(srcData);

                tar.AddFileSimple(targetName + @"\" + "ReadMeFirst_License.txt", destData, 0, destData.Length, DateTime.Now);
            }

            if (true)
            {
                string srcData = File.ReadAllText(Path.Combine(Paths.BinDirName, @"hamcore\warning_ja.txt"),
                    enc);

                byte[] destData = enc.GetBytes(srcData);

                tar.AddFileSimple(targetName + @"\" + "ReadMeFirst_Important_Notices_ja.txt", destData, 0, destData.Length, DateTime.Now);
            }

            if (true)
            {
                string srcData = File.ReadAllText(Path.Combine(Paths.BinDirName, @"hamcore\warning_en.txt"),
                    enc);

                byte[] destData = enc.GetBytes(srcData);

                tar.AddFileSimple(targetName + @"\" + "ReadMeFirst_Important_Notices_en.txt", destData, 0, destData.Length, DateTime.Now);
            }

            // Codes
            string[] dirs =
            {
                Path.Combine(srcDir, "code"),
                Path.Combine(srcDir, "lib"),
            };

            foreach (string dir in dirs)
            {
                string[] fileList = Directory.GetFiles(dir, "*.a", SearchOption.TopDirectoryOnly);

                if (Path.GetFileName(dir).Equals("code", StringComparison.InvariantCultureIgnoreCase))
                {
                    fileList = new string[]
                    {
                        Path.Combine(dir, string.Format("{0}.a", this.Software.ToString())),
                        Path.Combine(dir, "vpncmd.a"),
                    };
                }

                foreach (string fileName in fileList)
                {
                    if (Str.StrCmpi(Path.GetFileName(fileName), "libpcap.a") == false)
                    {
                        // Libpcap.a is not included in the release
                        byte[] fileData = File.ReadAllBytes(fileName);

                        tar.AddFileSimple(targetName + @"\" + IO.GetRelativeFileName(fileName, srcDir),
                            fileData, 0, fileData.Length, DateTime.Now);
                    }
                }
            }

            // License file
            byte[] lsFileData = File.ReadAllBytes(Path.Combine(CrossLibBaseDir, @"License.txt"));
            tar.AddFileSimple(targetName + @"\lib\License.txt", lsFileData, 0, lsFileData.Length, DateTime.Now);

            // HamCore
            byte[] hcData = File.ReadAllBytes(Path.Combine(Paths.BaseDirName, string.Format(@"bin\BuiltHamcoreFiles\hamcore_unix\hamcore.se2")));
            tar.AddFileSimple(targetName + @"\hamcore.se2", hcData, 0, hcData.Length, DateTime.Now);

            // Generate a tar
            tar.Finish();
            byte[] tarData = tar.CompressToGZip();

            File.WriteAllBytes(releaseFileName, tarData);

            Con.WriteLine("Finished.");
        }
Ejemplo n.º 2
0
        public static byte[] PackFiles(PackerFileFormat format, string[] srcFileNameList, string[] relativeNameList, ProgressDelegate proc)
        {
            if (srcFileNameList.Length != relativeNameList.Length)
            {
                throw new ApplicationException("srcFileNameList.Length != relativeNameList.Length");
            }

            int num = srcFileNameList.Length;
            int i;

            ZipPacker zip = new ZipPacker();
            TarPacker tar = new TarPacker();

            for (i = 0; i < num; i++)
            {
                if (proc != null)
                {
                    bool ret = proc(srcFileNameList[i], relativeNameList[i], i, num);

                    if (ret == false)
                    {
                        continue;
                    }
                }

                byte[]   srcData = File.ReadAllBytes(srcFileNameList[i]);
                DateTime date    = File.GetLastWriteTime(srcFileNameList[i]);

                switch (format)
                {
                case PackerFileFormat.Tar:
                case PackerFileFormat.TarGZip:
                    tar.AddFileSimple(relativeNameList[i], srcData, 0, srcData.Length, date);
                    break;

                case PackerFileFormat.ZipRaw:
                case PackerFileFormat.ZipCompressed:
                    zip.AddFileSimple(relativeNameList[i], date, FileAttributes.Normal, srcData, (format == PackerFileFormat.ZipCompressed));
                    break;
                }
            }

            switch (format)
            {
            case PackerFileFormat.Tar:
                tar.Finish();
                return(tar.GeneratedData.Read());

            case PackerFileFormat.TarGZip:
                tar.Finish();
                return(tar.CompressToGZip());

            case PackerFileFormat.ZipCompressed:
            case PackerFileFormat.ZipRaw:
                zip.Finish();
                return(zip.GeneratedData.Read());

            default:
                throw new ApplicationException("format");
            }
        }
Ejemplo n.º 3
0
        // Build SrcKit
        public virtual bool BuildSrcKit(string baseOutputDir, bool debugMode)
        {
            // Generate an Output directory name
            string outDir = Path.Combine(baseOutputDir, this.CrossLibName);
            string outSrcDir = Path.Combine(outDir, "src");
            Con.WriteLine("BuildSrcKit for '{0}'...", this.IDString);
            Con.WriteLine("CrossLib Name: '{0}'.", this.CrossLibName);
            Con.WriteLine("BuildSrcKit Output Dir = '{0}'.", outDir);

            string tsFile = Path.Combine(outDir, "TimeStamp.txt");
            string timeStamp = Str.DateTimeToStrShort(BuildSoftwareList.ListCreatedDateTime);
            Con.WriteLine("timestamp={0}", timeStamp);

            if (Directory.Exists(outDir))
            {
                bool ok = false;
                // See TimeStamp.txt file if the directory already exists
                try
                {
                    string[] ts = File.ReadAllLines(tsFile);
                    if (ts[0] == timeStamp)
                    {
                        ok = true;
                    }
                }
                catch
                {
                }

                if (ok)
                {
                    Con.WriteLine("Skipped for '{0}'.", this.IDString);
                    return false;
                }
            }
            else
            {
                Directory.CreateDirectory(outDir);
            }

            // Copy the source code
            foreach (string srcDirName in SrcDirNameList)
            {
                string srcFullPath = Path.Combine(Paths.BaseDirName, srcDirName);
                string destFullPath = Path.Combine(outSrcDir, srcDirName);
                bool delete_bom = true;

                if (Str.InStr(srcDirName, "\\hamcore"))
                {
                    delete_bom = false;
                }

                IO.CopyDir(srcFullPath, destFullPath, new IO.CopyDirPreCopyDelegate(CopySrcFilesDelegate), false, true, true, delete_bom);
            }
            IO.FileCopy(Path.Combine(Paths.BaseDirName, "CurrentBuild.txt"), Path.Combine(outSrcDir, "CurrentBuild.txt"), true, false);
            IO.FileCopy(Path.Combine(Paths.BaseDirName, "GlobalConst.h"), Path.Combine(outSrcDir, "GlobalConst.h"), true, false);
            IO.FileCopy(Path.Combine(Paths.BaseDirName, @"DebugFiles\Replace.h"), Path.Combine(outSrcDir, "Replace.h"), true, false);
            IO.FileCopy(Path.Combine(Paths.BaseDirName, @"bin\BuiltHamcoreFiles\hamcore_unix\hamcore.se2"),
                Path.Combine(outSrcDir, @"bin\hamcore.se2"), true, false);

            // Copy Crosslibs
            IO.CopyDir(Path.Combine(this.CrossLibBaseDir, this.CrossLibName), Path.Combine(outSrcDir, @"lib"),
                delegate(FileInfo fi)
                {
                    if (fi.DirectoryName.IndexOf(@".svn", StringComparison.InvariantCultureIgnoreCase) != -1)
                    {
                        return false;
                    }
                    return true;
                }, false, true, true, false);

            // Generate Makefile for compilation
            byte[] makeFileDataForCross = Str.NormalizeCrlf(Str.Utf8Encoding.GetBytes(GenerateMakeFileForCompile(outSrcDir, debugMode, true).ToString()), new byte[] { 10, });
            byte[] makeFileDataForSelf = Str.NormalizeCrlf(Str.Utf8Encoding.GetBytes(GenerateMakeFileForCompile(outSrcDir, debugMode, false).ToString()), new byte[] { 10, });

            string makeFileName = Path.Combine(outSrcDir, "Makefile");
            File.WriteAllBytes(makeFileName, makeFileDataForCross);

            // TimeStamp.txt
            File.WriteAllText(tsFile, timeStamp);

            // Create a tar.gz
            string tarGzFileName = Path.Combine(outSrcDir, this.SrcKitFileName);
            Con.WriteLine("Creating '{0}'...", tarGzFileName);
            List<string> files = new List<string>();

            foreach (string srcDirName in Util.CombineArray<string>(SrcDirNameList, new string[] { "lib" }))
            {
                string dirFullPath = Path.Combine(outSrcDir, srcDirName);
                string[] fileList = Directory.GetFiles(dirFullPath, "*",
                    srcDirName.Equals("lib", StringComparison.InvariantCultureIgnoreCase) ? SearchOption.TopDirectoryOnly : SearchOption.AllDirectories);
                foreach (string fileName in fileList)
                {
                    files.Add(fileName);
                }
            }
            files.Add(Path.Combine(outSrcDir, @"CurrentBuild.txt"));
            files.Add(Path.Combine(outSrcDir, @"bin\hamcore.se2"));
            files.Add(Path.Combine(outSrcDir, @"Replace.h"));
            files.Add(Path.Combine(outSrcDir, @"GlobalConst.h"));

            files.Sort();
            TarPacker tar = new TarPacker();
            foreach (string file in files)
            {
                byte[] fileData = File.ReadAllBytes(file);
                tar.AddFileSimple(@"src\" + IO.GetRelativeFileName(file, outSrcDir),
                    fileData,
                    0, fileData.Length, File.GetLastWriteTime(file), "0000750", "0000640");
            }
            tar.AddFileSimple(@"src\Makefile", makeFileDataForSelf, 0, makeFileDataForSelf.Length, DateTime.Now, "0000750", "0000640");
            tar.Finish();
            byte[] tarGzData = tar.CompressToGZip();
            File.WriteAllBytes(tarGzFileName, tarGzData);

            IO.MakeDir(Paths.ReleaseSrckitDir);
            File.WriteAllBytes(Path.Combine(Paths.ReleaseSrckitDir, this.SrcKitFileName), tarGzData);

            Con.WriteLine("Completed.");

            return true;
        }
Ejemplo n.º 4
0
        public static byte[] PackFiles(PackerFileFormat format, string[] srcFileNameList, string[] relativeNameList, ProgressDelegate proc)
        {
            if (srcFileNameList.Length != relativeNameList.Length)
            {
                throw new ApplicationException("srcFileNameList.Length != relativeNameList.Length");
            }

            int num = srcFileNameList.Length;
            int i;

            ZipPacker zip = new ZipPacker();
            TarPacker tar = new TarPacker();

            for (i = 0; i < num; i++)
            {
                if (proc != null)
                {
                    bool ret = proc(srcFileNameList[i], relativeNameList[i], i, num);

                    if (ret == false)
                    {
                        continue;
                    }
                }

                byte[] srcData = File.ReadAllBytes(srcFileNameList[i]);
                DateTime date = File.GetLastWriteTime(srcFileNameList[i]);

                switch (format)
                {
                    case PackerFileFormat.Tar:
                    case PackerFileFormat.TarGZip:
                        tar.AddFileSimple(relativeNameList[i], srcData, 0, srcData.Length, date);
                        break;

                    case PackerFileFormat.ZipRaw:
                    case PackerFileFormat.ZipCompressed:
                        zip.AddFileSimple(relativeNameList[i], date, FileAttributes.Normal, srcData, (format == PackerFileFormat.ZipCompressed));
                        break;
                }
            }

            switch (format)
            {
                case PackerFileFormat.Tar:
                    tar.Finish();
                    return tar.GeneratedData.Read();

                case PackerFileFormat.TarGZip:
                    tar.Finish();
                    return tar.CompressToGZip();

                case PackerFileFormat.ZipCompressed:
                case PackerFileFormat.ZipRaw:
                    zip.Finish();
                    return zip.GeneratedData.Read();

                default:
                    throw new ApplicationException("format");
            }
        }