=== modified file 'stagebuilder.prolog' --- stagebuilder.prolog 2011-10-21 17:27:15 +0000 +++ stagebuilder.prolog 2011-10-21 16:00:17 +0000 @@ -1,9 +1,7 @@ -site_conf_dir('/etc/prosys'). - -gentoo_mirror('ftp://ftp.sh.cvut.cz/MIRRORS/gentoo'). - -:- op(400, yfx, +/+). +site_conf_dir("/etc/prosys"). + +gentoo_mirror("ftp://ftp.sh.cvut.cz/MIRRORS/gentoo"). concat([], []). concat([H|T], String) :- @@ -13,15 +11,11 @@ concatn(L, N) :- concat(L, S), name(N, S). -strjoin(_, [], []). -strjoin(_, [X], X). -strjoin(Sep, [A, B|R], Result) :- +join(_, [], []). +join(_, [X], X). +join(Sep, [A, B|R], Result) :- concat([A, Sep, B], Start), - strjoin(Sep, [Start|R], Result). - -join(_, [X], X). -join(Sep, [A, B|R], A + Sep + Result) :- - join(Sep, [B|R], Result). + join(Sep, [Start|R], Result). lstrip(_, [], []). lstrip(S, [H|T], O) :- @@ -42,7 +36,7 @@ path_join([Merged|R], Result). path_joinn(L, N) :- path_join(L, S), name(N, S). -site_conf_file(Name, Dir +/+ Name) :- site_conf_dir(Dir). +site_conf_file(Name, Path) :- site_conf_dir(Dir), path_joinn([Dir, Name], Path). escape_backslashes([], []). escape_backslashes([UC|UR], E) :- @@ -59,7 +53,7 @@ is_list(X) -> X = S; atom(X) -> name(X, S). -escape(U, ES) :- +escape(U, E) :- str(U, US), (( member(UC, US), @@ -68,26 +62,20 @@ ) -> concat(["'", US, "'"], ES); escape_backslashes(US, ES) - ). + ), + name(E, ES). escape(variable(Name), E) :- - concat(["${", Name, "}"], E). + concat(["${", Name, "}"], ES), + name(E, ES). escape(A+B, E) :- concat([A, B], S), escape(S, E). escape(A+B, E) :- escape(A, AE), escape(B, BE), - concat([AE, BE], E). - -escape(A +/+ B, E) :- - escape(A, AE), - escape(B, BE), - rstrip("/", AE, AP), - lstrip("/", BE, BP), - concat([AP, "/", BP], E). - -escape_n(X, N) :- escape(X, S), name(N, S). + concat([AE, BE], ES), + name(E, ES). unpack_tarball(Tarball, Dir, [run([tar, '-xpf', Tarball, '-C', Dir])]). @@ -99,8 +87,8 @@ download_gentoo_stage(Mirror, Arch, Subarch, Subdir, Commands, File) :- http_glob( - Mirror + '/releases/' + Arch + '/current-stage3/' + - Subdir +'stage3-' + Subarch + '-*.DIGESTS.asc', + Mirror + "/releases/" + Arch + "/current-stage3/" + + Subdir +"stage3-" + Subarch + "-*.DIGESTS.asc", GlobCommands, Uri), digest_download(Uri, DownloadCommands, File), append(GlobCommands, DownloadCommands, Commands). @@ -147,29 +135,30 @@ append(PkgUseE, AggUseE, MergedUseE), sort(MergedUseE, UseE), append(PkgUseD, AggUseD, MergedUseD), sort(MergedUseD, UseD). -echo_package(package_mask(String), '/etc/portage/package.mask', String). -echo_package(package_unmask(String), '/etc/portage/package.unmask', String). -echo_package(package_use(String), '/etc/portage/package.use', String). -echo_package(package_keywords(String), '/etc/portage/package.keywords', String). -echo_package(package_world(String), '/root/prosys/world', String). +echo_package(package_mask(String), "/etc/portage/package.mask", String). +echo_package(package_unmask(String), "/etc/portage/package.unmask", String). +echo_package(package_use(String), "/etc/portage/package.use", String). +echo_package(package_keywords(String), "/etc/portage/package.keywords", String). +echo_package(package_world(String), "/root/prosys/world", String). echo_packages(_, [], []). -echo_packages(Dir, [E|Echos], [echo_append(String, Dir +/+ Tail)|Commands]) :- +echo_packages(Dir, [E|Echos], [echo_append(String, File)|Commands]) :- echo_package(E, Tail, String), + path_joinn([Dir, Tail], File), echo_packages(Dir, Echos, Commands). disabled_uses([], []). disabled_uses([U|UR], [D|DR]) :- - str(U, US), + name(U, US), append("-", US, D), disabled_uses(UR, DR). enabled_uses([], []). enabled_uses([U|UR], [US|SR]) :- - str(U, US), + name(U, US), enabled_uses(UR, SR). -dir_make_conf(Dir, Dir +/+ 'etc/make.conf'). +dir_make_conf(Dir, File) :- path_joinn([Dir, "/etc/make.conf"], File). configure_gentoo_packages(Dir, Packages, Commands) :- aggregate_gentoo_packages(Packages, Echos, UseE, UseD), @@ -177,25 +166,26 @@ enabled_uses(UseE, UseES), disabled_uses(UseD, UseDS), append(UseES, UseDS, MergedUse), - join(' ', MergedUse, JoinedUse), + join(" ", MergedUse, JoinedUse), dir_make_conf(Dir, Make_conf), - Commands = [ echo_append('USE="' + JoinedUse + '"', Make_conf) | C1 ]. + Commands = [ echo_append("USE=\"" + JoinedUse + "\"", Make_conf) | C1 ]. reset_make_conf(Dir, CFLAGS, CXXFLAGS, CHOST, [echo_replace( - '#Autogenerated make.conf by ProSys\n' + - 'CFLGAGS="' + CFLAGS + '"\n' + - 'CXXFLAGS="' + CXXFLAGS + '"\n' + - 'CHOST="' + CHOST + '"\n', + "#Autogenerated make.conf by ProSys\n" + + "CFLGAGS=\"" + CFLAGS + "\"\n" + + "CXXFLAGS=\"" + CXXFLAGS + "\"\n" + + "CHOST=\"" + CHOST + "\"\n", Make_conf )]) :- dir_make_conf(Dir, Make_conf). append_site_make_conf(Dir, [run_append([cat, Src], Dst)]) :- - site_conf_file('make.conf', Src), + site_conf_file("make.conf", Src), dir_make_conf(Dir, Dst). create_chroot_script(Dir, Arch, [run([ - cp, '-Lp', '--', Conf + '/chroot.sh-' + Arch, Dir +/+ 'chroot.sh' + cp, '-Lp', '--', Conf + '/chroot.sh-' + Arch, Dst ])]) :- - site_conf_dir(Conf). + site_conf_dir(Conf), + path_joinn([Dir, "chroot.sh"], Dst). create_gentoo_builddir(Name, Dir, Commands) :- gentoo_stage(Name, _, ArchName, _), @@ -220,17 +210,8 @@ list_escape([U|UR], [E|ER]) :- escape(U, E), list_escape(UR, ER). cmd_tokens(run(L), E) :- list_escape(L, E). - -cmd_tokens(run_append(L, F), T) :- - list_escape(L, E), - escape(F, FE), - append(E, [">>", FE], T). - -cmd_tokens(run_replace(L, F), T) :- - list_escape(L, E), - escape(F, FE), - append(E, [">", FE], T). - +cmd_tokens(run_append(L, F), T) :- list_escape(L, E), append(E, [">>", F], T). +cmd_tokens(run_replace(L, F), T) :- list_escape(L, E), append(E, [">", F], T). cmd_tokens(run_outvar(L, V), T) :- list_escape(L, E), concat([V, "=$("], Pre), @@ -241,11 +222,11 @@ cmd_tokens(echo_replace(String, File), E) :- cmd_tokens(run_replace([echo, String], File), E). cmd_tokens(chroot(Dir, Args), E) :- - cmd_tokens(run([Dir +/+ 'chroot.sh'|Args]), E). + path_joinn([Dir, "chroot.sh"], Chroot), cmd_tokens(run([Chroot|Args]), E). print_cmds([]). print_cmds([Cmd|R]) :- cmd_tokens(Cmd, Tokens), - strjoin(" ", Tokens, S), + join(" ", Tokens, S), name(N,S), write(N), write('\n'), print_cmds(R).