Ejemplo n.º 1
0
    public static void BuildAndRunDllCmd(Taskman tm, string name, string[] sources, string extra_mcs_args, IList <string> args)
    {
        var dll_path = $"{BHL_ROOT}/bhl_cmd_{name}.dll";

        MCSBuild(tm,
                 sources.ToArray(),
                 dll_path,
                 extra_mcs_args + " -debug -target:library"
                 );

        var cmd_assembly = System.Reflection.Assembly.LoadFrom(dll_path);
        var cmd_class    = cmd_assembly.GetTypes()[0];
        var cmd          = System.Activator.CreateInstance(cmd_class, null);

        if (cmd == null)
        {
            throw new Exception("Could not create instance of: " + cmd_class.Name);
        }
        var cmd_method = cmd.GetType().GetMethod("Run");

        if (cmd_method == null)
        {
            throw new Exception("No Run method in class: " + cmd_class.Name);
        }
        cmd_method.Invoke(cmd, new object[] { args.ToArray() });
    }
Ejemplo n.º 2
0
    public static void clean(Taskman tm, string[] args)
    {
        tm.Rm($"{BHL_ROOT}/src/autogen.cs");

        foreach (var dll in tm.Glob($"{BHL_ROOT}/*.dll"))
        {
            if (!dll.StartsWith("bhl_"))
            {
                continue;
            }
            tm.Rm(dll);
            tm.Rm($"{dll}.mdb");
        }

        foreach (var exe in tm.Glob($"{BHL_ROOT}/*.exe"))
        {
            //NOTE: when removing itself under Windows we can get an exception, so let's force its staleness
            if (exe.EndsWith("bhlb.exe"))
            {
                tm.Touch(exe, new DateTime(1970, 3, 1, 7, 0, 0) /*some random date in the past*/);
                continue;
            }

            tm.Rm(exe);
            tm.Rm($"{exe}.mdb");
        }
    }
Ejemplo n.º 3
0
    public static void compile(Taskman tm, string[] args)
    {
        List <string> postproc_sources;
        List <string> user_sources;
        var           runtime_args = ExtractBinArgs(args, out user_sources, out postproc_sources);

        BuildAndRunCompiler(tm, user_sources, postproc_sources, ref runtime_args);
    }
Ejemplo n.º 4
0
    public static void geng(Taskman tm, string[] args)
    {
        tm.Mkdir($"{BHL_ROOT}/tmp");

        tm.Copy($"{BHL_ROOT}/bhl.g", $"{BHL_ROOT}/tmp/bhl.g");
        tm.Copy($"{BHL_ROOT}/util/g4sharp", $"{BHL_ROOT}/tmp/g4sharp");

        tm.Shell("sh", $"-c 'cd {BHL_ROOT}/tmp && sh g4sharp bhl.g && cp bhl*.cs ../src/g/' ");
    }
Ejemplo n.º 5
0
 public static void build_lsp_dll(Taskman tm, string[] args)
 {
     MCSBuild(tm,
              new string[] {
         $"{BHL_ROOT}/src/lsp/*.cs",
         $"{BHL_ROOT}/bhl_front.dll",
         $"{BHL_ROOT}/deps/Antlr4.Runtime.Standard.dll",
         $"{BHL_ROOT}/deps/Newtonsoft.Json.dll"
     },
              $"{BHL_ROOT}/bhl_lsp.dll",
              "-target:library -define:BHLSP_DEBUG"
              );
 }
Ejemplo n.º 6
0
    public static void MCSBuild(Taskman tm, string[] srcs, string result, string opts = "", string binary = "mcs")
    {
        var files = new List <string>();

        foreach (var s in srcs)
        {
            files.AddRange(tm.Glob(s));
        }

        foreach (var f in files)
        {
            if (!File.Exists(f))
            {
                throw new Exception($"Bad file {f}");
            }
        }

        var refs = new List <string>();

        for (int i = files.Count; i-- > 0;)
        {
            if (files[i].EndsWith(".dll"))
            {
                refs.Add(files[i]);
                files.RemoveAt(i);
            }
        }

        if (files.Count == 0)
        {
            throw new Exception("No files");
        }

        string args = (refs.Count > 0 ? " -r:" + String.Join(" -r:", refs.Select(r => tm.CLIPath(r))) : "") + $" {opts} -out:{tm.CLIPath(result)} " + String.Join(" ", files.Select(f => tm.CLIPath(f)));
        string cmd  = binary + " " + args;

        uint   cmd_hash      = Hash.CRC32(cmd);
        string cmd_hash_file = $"{BHL_ROOT}/build/" + Hash.CRC32(result) + ".mhash";

        if (!File.Exists(cmd_hash_file) || File.ReadAllText(cmd_hash_file) != cmd_hash.ToString())
        {
            tm.Write(cmd_hash_file, cmd_hash.ToString());
        }

        files.Add(cmd_hash_file);

        if (tm.NeedToRegen(result, files) || tm.NeedToRegen(result, refs))
        {
            tm.Shell(binary, args);
        }
    }
Ejemplo n.º 7
0
 public static void build_front_dll(Taskman tm, string[] args)
 {
     MCSBuild(tm, new string[] {
         $"{BHL_ROOT}/deps/msgpack/Compiler/*.cs",
         $"{BHL_ROOT}/deps/msgpack/*.cs",
         $"{BHL_ROOT}/src/g/*.cs",
         $"{BHL_ROOT}/src/*.cs",
         $"{BHL_ROOT}/deps/Antlr4.Runtime.Standard.dll",
         $"{BHL_ROOT}/deps/lz4.dll",
     },
              $"{BHL_ROOT}/bhl_front.dll",
              "-define:BHL_FRONT -warnaserror -warnaserror-:3021 -nowarn:3021 -debug -target:library"
              );
 }
Ejemplo n.º 8
0
 public static void lsp(Taskman tm, string[] args)
 {
     BuildAndRunDllCmd(
         tm,
         "lsp",
         new string[] {
         $"{BHL_ROOT}/src/cmd/lsp.cs",
         $"{BHL_ROOT}/src/cmd/cmd.cs",
         $"{BHL_ROOT}/bhl_lsp.dll",
         $"{BHL_ROOT}/deps/mono_opts.dll"
     },
         "-define:BHLSP_DEBUG",
         args
         );
 }
Ejemplo n.º 9
0
    public static void test(Taskman tm, string[] args)
    {
        MCSBuild(tm,
                 new string[] {
            $"{BHL_ROOT}/tests/*.cs",
            $"{BHL_ROOT}/deps/mono_opts.dll",
            $"{BHL_ROOT}/bhl_front.dll",
            $"{BHL_ROOT}/bhl_lsp.dll",
            $"{BHL_ROOT}/deps/Antlr4.Runtime.Standard.dll"
        },
                 $"{BHL_ROOT}/test.exe",
                 "-define:BHL_FRONT -debug"
                 );

        MonoRun(tm, $"{BHL_ROOT}/test.exe", args, "--debug ");
    }
Ejemplo n.º 10
0
    public static void build_back_dll(Taskman tm, string[] args)
    {
        var mcs_bin    = args.Length > 0 ? args[0] : "/Applications/Unity/Unity.app/Contents/Frameworks/Mono/bin/gmcs";
        var dll_file   = args.Length > 1 ? args[1] : $"{BHL_ROOT}/bhl_back.dll";
        var extra_args = "";

        if (args.Length > 2)
        {
            for (int i = 2; i < args.Length; i++)
            {
                extra_args += args[i];
                if (i != args.Length - 1)
                {
                    extra_args += " ";
                }
            }
        }
        else
        {
            extra_args = "-debug";
        }

        MCSBuild(tm, new string[] {
            $"{BHL_ROOT}/deps/msgpack/Compiler/*.cs",
            $"{BHL_ROOT}/deps/msgpack/*.cs",
            $"{BHL_ROOT}/src/type.cs",
            $"{BHL_ROOT}/src/vm.cs",
            $"{BHL_ROOT}/src/error.cs",
            $"{BHL_ROOT}/src/symbol.cs",
            $"{BHL_ROOT}/src/scope.cs",
            $"{BHL_ROOT}/src/loader.cs",
            $"{BHL_ROOT}/src/storage.cs",
            $"{BHL_ROOT}/src/nodes.cs",
            $"{BHL_ROOT}/src/util.cs",
            $"{BHL_ROOT}/src/marshall.cs",
            $"{BHL_ROOT}/src/lz4.cs",
        },
                 dll_file,
                 $"{extra_args} -target:library",
                 mcs_bin
                 );
    }
Ejemplo n.º 11
0
    public static void BuildAndRunCompiler(Taskman tm, List <string> user_sources, List <string> postproc_sources, ref List <string> runtime_args)
    {
        var sources = new string[] {
            $"{BHL_ROOT}/src/cmd/compile.cs",
            $"{BHL_ROOT}/src/cmd/cmd.cs",
            $"{BHL_ROOT}/bhl_front.dll",
            $"{BHL_ROOT}/deps/mono_opts.dll",
            $"{BHL_ROOT}/deps/Antlr4.Runtime.Standard.dll",
        };

        if (user_sources.Count > 0)
        {
            user_sources.Add($"{BHL_ROOT}/bhl_front.dll");
            user_sources.Add($"{BHL_ROOT}/deps/Antlr4.Runtime.Standard.dll");
            MCSBuild(tm,
                     user_sources.ToArray(),
                     $"{BHL_ROOT}/bhl_user.dll",
                     "-define:BHL_FRONT -debug -target:library"
                     );
            runtime_args.Add($"--bindings-dll={BHL_ROOT}/bhl_user.dll");
        }

        if (postproc_sources.Count > 0)
        {
            postproc_sources.Add($"{BHL_ROOT}/bhl_front.dll");
            postproc_sources.Add($"{BHL_ROOT}/deps/Antlr4.Runtime.Standard.dll");
            MCSBuild(tm,
                     postproc_sources.ToArray(),
                     $"{BHL_ROOT}/bhl_postproc.dll",
                     "-define:BHL_FRONT -debug -target:library"
                     );
            runtime_args.Add($"--postproc-dll={BHL_ROOT}/bhl_postproc.dll");
        }

        BuildAndRunDllCmd(
            tm,
            "compile",
            sources,
            "-define:BHL_FRONT",
            runtime_args
            );
    }
Ejemplo n.º 12
0
    public static void Main(string[] args)
    {
        var tm = new Taskman(typeof(Tasks));

        try
        {
            tm.Run(args);
        }
        catch (TargetInvocationException e)
        {
            if (e.InnerException is ShellException)
            {
                System.Environment.Exit((e.InnerException as ShellException).code);
            }
            else
            {
                throw;
            }
        }
    }
Ejemplo n.º 13
0
    public static int TryMonoRun(Taskman tm, string exe, string[] args = null, string opts = "")
    {
        var mono_args = $"{opts} {exe} " + String.Join(" ", args);

        return(tm.TryShell("mono", mono_args));
    }
Ejemplo n.º 14
0
    public static void MonoRun(Taskman tm, string exe, string[] args = null, string opts = "")
    {
        var mono_args = $"{opts} {exe} " + String.Join(" ", args);

        tm.Shell("mono", mono_args);
    }
Ejemplo n.º 15
0
 public static void regen(Taskman tm, string[] args)
 {
 }