Mercurial > projects > doodle
comparison builder.d @ 123:0d427170a805
Move to 64-bit
author | David Bryant <bagnose@gmail.com> |
---|---|
date | Wed, 04 May 2011 22:19:44 +0930 |
parents | 85589f7a3a28 |
children | 1da160a2c373 |
comparison
equal
deleted
inserted
replaced
122:403c34305a39 | 123:0d427170a805 |
---|---|
5 import std.stdio; | 5 import std.stdio; |
6 import std.string; | 6 import std.string; |
7 import std.process; | 7 import std.process; |
8 import std.file; | 8 import std.file; |
9 import std.path; | 9 import std.path; |
10 import std.date; | 10 import std.datetime; |
11 import std.array; | |
12 import core.vararg; | |
11 } | 13 } |
12 | 14 |
13 | 15 |
14 // | 16 // |
15 // builder is a build tool for D code. It is intended for use during development, | 17 // builder is a build tool for D code. It is intended for use during development, |
116 | 118 |
117 | 119 |
118 // | 120 // |
119 // return the modification time of the file at path | 121 // return the modification time of the file at path |
120 // | 122 // |
121 d_time modified_time(string path) { | 123 long modified_time(string path) { |
122 d_time creation_time, access_time, modified_time; | 124 SysTime fileStatusChangeTime, fileAccessTime, fileModificationTime; |
123 if (!exists(path)) { | 125 if (!exists(path)) { |
124 return 0; | 126 return 0; |
125 } | 127 } |
126 getTimes(path, creation_time, access_time, modified_time); | 128 getTimesPosix(path, fileStatusChangeTime, fileAccessTime, fileModificationTime); |
127 return modified_time; | 129 return fileStatusChangeTime.stdTime; |
128 } | 130 } |
129 | 131 |
130 | 132 |
131 // | 133 // |
132 // A string formatter that allows progressive composition | 134 // A string formatter that allows progressive composition |
511 // an object file is built from its source | 513 // an object file is built from its source |
512 override void build() { | 514 override void build() { |
513 writefln("Object %s", mPath); | 515 writefln("Object %s", mPath); |
514 scope cmd = new StringFormatter; | 516 scope cmd = new StringFormatter; |
515 | 517 |
516 cmd.format("dmd -c"); | 518 cmd.format("dmd -m64 -c"); |
517 foreach (path; Global.bundlePaths) { | 519 foreach (path; Global.bundlePaths) { |
518 cmd.format(" -I%s", path); | 520 cmd.format(" -I%s", path); |
519 } | 521 } |
520 cmd.format(" -od%s %s", dirname(mPath), mSource.mPath); | 522 cmd.format(" -od%s %s", dirname(mPath), mSource.mPath); |
521 cmd.format(" @%s", Global.optionsPath); | 523 cmd.format(" @%s", Global.optionsPath); |
597 // the object needs, transitively | 599 // the object needs, transitively |
598 override void build() { | 600 override void build() { |
599 writefln("Program %s", mPath); | 601 writefln("Program %s", mPath); |
600 scope cmd = new StringFormatter(); | 602 scope cmd = new StringFormatter(); |
601 | 603 |
602 cmd.format("dmd -L-L%s", join(Global.buildPath, "lib")); | 604 cmd.format("dmd -m64 -L-L%s", std.path.join(Global.buildPath, "lib")); |
603 cmd.format(" -of%s %s", mPath, mObject.mPath); | 605 cmd.format(" -of%s %s", mPath, mObject.mPath); |
604 | 606 |
605 // add the libraries we need | 607 // add the libraries we need |
606 LibraryItem[] libs; | 608 LibraryItem[] libs; |
607 foreach (item; mDepends) { | 609 foreach (item; mDepends) { |
741 ObjectItem mObject; | 743 ObjectItem mObject; |
742 FileItem mClump; // library or program item this module contributes to | 744 FileItem mClump; // library or program item this module contributes to |
743 | 745 |
744 this(string name, string path, Node parent, GroupItem group) { | 746 this(string name, string path, Node parent, GroupItem group) { |
745 super(name, parent); | 747 super(name, parent); |
746 string obj_path = join(Global.buildPath, "obj", mSlashName ~ ".o"); | 748 string obj_path = std.path.join(Global.buildPath, "obj", mSlashName ~ ".o"); |
747 mSource = new SourceItem(path, group); | 749 mSource = new SourceItem(path, group); |
748 mObject = new ObjectItem(obj_path, mSource, group); | 750 mObject = new ObjectItem(obj_path, mSource, group); |
749 mSource.set_object(mObject); | 751 mSource.set_object(mObject); |
750 //writefln("loaded Module %s from %s", mDotName, mSource.mPath); | 752 //writefln("loaded Module %s from %s", mDotName, mSource.mPath); |
751 } | 753 } |
808 ResultItem mResult; | 810 ResultItem mResult; |
809 | 811 |
810 this(string name, string path, Node parent, bool test, GroupItem group) { | 812 this(string name, string path, Node parent, bool test, GroupItem group) { |
811 super(name, path, parent, group); | 813 super(name, path, parent, group); |
812 if (test) { | 814 if (test) { |
813 mProgram = new ProgramItem(join(Global.buildPath, "test", mSlashName), mObject, group); | 815 mProgram = new ProgramItem(std.path.join(Global.buildPath, "test", mSlashName), mObject, group); |
814 mResult = new ResultItem(join(Global.buildPath, "test", mSlashName ~ ".result"), mProgram, group); | 816 mResult = new ResultItem(std.path.join(Global.buildPath, "test", mSlashName ~ ".result"), mProgram, group); |
815 } | 817 } |
816 else { | 818 else { |
817 mProgram = new ProgramItem(join(Global.buildPath, "bin", mName), mObject, group); | 819 mProgram = new ProgramItem(std.path.join(Global.buildPath, "bin", mName), mObject, group); |
818 } | 820 } |
819 setClump(mProgram); | 821 setClump(mProgram); |
820 //writefln("loaded Program %s", mProgram.mPath); | 822 //writefln("loaded Program %s", mProgram.mPath); |
821 } | 823 } |
822 } | 824 } |
836 | 838 |
837 string lib_name = replace(mDotName, ".", "_"); | 839 string lib_name = replace(mDotName, ".", "_"); |
838 | 840 |
839 // examine all the children of the package's directory | 841 // examine all the children of the package's directory |
840 foreach (string child; listdir(path)) { | 842 foreach (string child; listdir(path)) { |
841 string p = join(path, child); | 843 string p = std.path.join(path, child); |
842 if (child[0] != '.') { | 844 if (child[0] != '.') { |
843 | 845 |
844 if (isfile(p)) { | 846 if (isfile(p)) { |
845 | 847 |
846 if (child.length > 2 && child[$-2..$] == ".d") { | 848 if (child.length > 2 && child[$-2..$] == ".d") { |
847 // a library module | 849 // a library module |
848 if (!mLibrary) { | 850 if (!mLibrary) { |
849 mLibrary = new LibraryItem(join(Global.buildPath, "lib", "lib" ~ lib_name ~ ".a"), | 851 mLibrary = new LibraryItem(std.path.join(Global.buildPath, "lib", "lib" ~ lib_name ~ ".a"), |
850 lib_name, mGroup); | 852 lib_name, mGroup); |
851 } | 853 } |
852 Module m = new Module(getName(child), p, this, mGroup); | 854 Module m = new Module(getName(child), p, this, mGroup); |
853 m.setClump(mLibrary); | 855 m.setClump(mLibrary); |
854 } | 856 } |
866 // TODO | 868 // TODO |
867 } | 869 } |
868 else if (child == "test") { | 870 else if (child == "test") { |
869 // test programs | 871 // test programs |
870 foreach (string grandchild; listdir(p)) { | 872 foreach (string grandchild; listdir(p)) { |
871 string p2 = join(p, grandchild); | 873 string p2 = std.path.join(p, grandchild); |
872 if (grandchild[0] != '.' && | 874 if (grandchild[0] != '.' && |
873 isfile(p2) && | 875 isfile(p2) && |
874 grandchild.length > 2 && | 876 grandchild.length > 2 && |
875 grandchild[$-2..$] == ".d") | 877 grandchild[$-2..$] == ".d") |
876 { | 878 { |
879 } | 881 } |
880 } | 882 } |
881 else if (child == "prog") { | 883 else if (child == "prog") { |
882 // deliverable programs | 884 // deliverable programs |
883 foreach (string grandchild; listdir(p)) { | 885 foreach (string grandchild; listdir(p)) { |
884 string p2 = join(p, grandchild); | 886 string p2 = std.path.join(p, grandchild); |
885 if (child[0] != '.' && | 887 if (child[0] != '.' && |
886 isfile(p2) && | 888 isfile(p2) && |
887 grandchild.length > 2 && | 889 grandchild.length > 2 && |
888 grandchild[$-2..$] == ".d") | 890 grandchild[$-2..$] == ".d") |
889 { | 891 { |
946 void load(string path) { | 948 void load(string path) { |
947 //writefln("loading bundle from %s", path); | 949 //writefln("loading bundle from %s", path); |
948 | 950 |
949 // add path to Global for use when compiling | 951 // add path to Global for use when compiling |
950 Global.bundlePaths ~= path; | 952 Global.bundlePaths ~= path; |
951 Global.optionsPath = path.join("options"); | 953 Global.optionsPath = std.path.join(path, "options"); |
952 | 954 |
953 // | 955 // |
954 // load bundles specified in the uses file - lines are bundle paths relative to path | 956 // load bundles specified in the uses file - lines are bundle paths relative to path |
955 // | 957 // |
956 string uses_path = join(path, "uses"); | 958 string uses_path = std.path.join(path, "uses"); |
957 if (exists(uses_path) && isfile(uses_path)) { | 959 if (exists(uses_path) && isfile(uses_path)) { |
958 //writefln("reading uses file: %s", uses_path); | 960 //writefln("reading uses file: %s", uses_path); |
959 scope file = new BufferedFile(uses_path); | 961 scope file = new BufferedFile(uses_path); |
960 foreach (char[] line; file) { | 962 foreach (char[] line; file) { |
961 load(join(path, line.idup)); | 963 load(std.path.join(path, line.idup)); |
962 } | 964 } |
963 } | 965 } |
964 | 966 |
965 // | 967 // |
966 // load local products | 968 // load local products |
967 // | 969 // |
968 foreach (string name; listdir(path)) { | 970 foreach (string name; listdir(path)) { |
969 if (name[0] != '.' && name != "nobuild") { | 971 if (name[0] != '.' && name != "nobuild") { |
970 string p = join(path, name); | 972 string p = std.path.join(path, name); |
971 if (isdir(p)) { | 973 if (isdir(p)) { |
972 foreach (node; mChildren) { | 974 foreach (node; mChildren) { |
973 Product existing = cast(Product)node; | 975 Product existing = cast(Product)node; |
974 if (existing && existing.mName == name) { | 976 if (existing && existing.mName == name) { |
975 error(format("product %s has two paths: %s and %s", | 977 error(format("product %s has two paths: %s and %s", |