=== modified file 'stagebuilder.prolog' --- stagebuilder.prolog 2011-10-19 08:44:52 +0000 +++ stagebuilder.prolog 2011-10-18 07:25:23 +0000 @@ -4,68 +4,28 @@ gentoo_mirror("ftp://ftp.sh.cvut.cz/MIRRORS/gentoo"). concat([], []). -concat([H|T], String) :- - (atom(H) -> name(H, HS); HS = H), +concat([H|T], String) :- concat(T, Rest), - append(HS, Rest, String). - -concatn(L, N) :- concat(L, S), name(N, S). + append(H, Rest, String). join(_, [], []). -join(_, [X], X). +join(_, [X], [X]). join(Sep, [A, B|R], Result) :- concat([A, Sep, B], Start), join(Sep, [Start|R], Result). -lstrip(_, [], []). -lstrip(S, [H|T], O) :- - member(H, S) -> lstrip(S, T, O); O = [H|T]. - -rstrip(_, [], []). -rstrip(S, [H|T], O) :- - rstrip(S, T, Out), - (length(Out, 0), member(H, S) -> O = []; O = [H|Out]). - -path_join([X], X). -path_join([A, B|R], Result) :- - (atom(A) -> name(A, AS); AS = A), - (atom(B) -> name(B, BS); BS = B), - rstrip("/", AS, AP), - lstrip("/", BS, BP), - concat([AP, "/", BP], Merged), - path_join([Merged|R], Result). -path_joinn(L, N) :- path_join(L, S), name(N, S). - -site_conf_file(Name, Path) :- site_conf_dir(Dir), path_joinn([Dir, Name], Path). - escape_backslashes([], []). -escape_backslashes([UC|UR], E) :- - escape_backslashes(UR, ER), ( - member(UC, "\n") -> append("'\n'", ER, E); - member(UC, " \t()[]{}&;$#!?*=<>'\"`") -> concat(["\\", [UC], ER], E); - E = [UC|ER] - ). - -not_in(_, []). -not_in(A, [B|R]) :- A =\= B, not_in(A, R). - -escape(U, E) :- - (atom(U) -> name(U, US); US = U), - (( - member(UC, US), - member(UC, " \n\t()[]{}&;$#!?*=<>\"`"), - not_in(39, US) - ) -> - concat(["'", US, "'"], ES); - escape_backslashes(US, ES) - ), - name(E, ES). - -unpack_tarball(Tarball, Dir, [run([tar, '-xpf', Tarball, '-C', Dir])]). - -http_glob(Uri, [run_outvar([http_glob, Uri], uri)], '$uri'). - -digest_download(Uri, [run_outvar([digest_download, Uri], downloaded)], '$downloaded'). +escape_backslashes([10|U], [39, 10, 39|E]) :- escape_backslashes(U, E). +escape_backslashes([C|U], [92, C |E]) :- + member(C, " \t()[]{}&;$#!?*=<>'\"`"), + escape_backslashes(U, E). +escape_backslashes([C|U], [C|E]) :- escape_backslashes(U, E). + +unpack_tarball(Tarball, Dir, [run('tar', '-xpf', Tarball, '-C', Dir)]). + +http_glob(Uri, [run_outvar('uri', [http_glob, Uri])], '$uri') :- concat. + +digest_download(Uri, [run_outvar([digest_download, Uri])], '$downloaded'). download_gentoo_stage(Mirror, Arch, Subarch, Subdir, Commands, File) :- concat([Mirror, "/releases/", Arch, "/current-stage3/", @@ -87,23 +47,23 @@ download_gentoo_stage(Mirror, Arch, Subarch, Subdir, Commands, File). gentoo_package(portage22, [ - package_keywords('sys-apps/portage **'), - package_mask('=sys-apps/portage-9999')]). + package_keywords("sys-apps/portage **"), + package_mask("=sys-apps/portage-9999")]). gentoo_package(nopy3k, [ - package_mask('=dev-lang/python-3'), - package_mask('net-zope/zope-fixers')]). + package_mask("=dev-lang/python-3"), + package_mask("net-zope/zope-fixers")]). gentoo_package(mc, [ - package_use('app-misc/mc slang -ncurses'), - package_world('app-misc/mc')]). + package_use("app-misc/mc slang -ncurses"), + package_world("app-misc/mc")]). -gentoo_package(vim, [package_world('app-editors/vim')], [ +gentoo_package(vim, [package_world("app-editors/vim")], [ 'vim', 'vim-pager', 'vim-syntax']). gentoo_package(zsh, [ - package_world('app-shells/zsh'), - package_world('app-shells/zsh-completion') + package_world("app-shells/zsh"), + package_world("app-shells/zsh-completion") ],['zsh-completion']). gentoo_package(Name, Echos, []) :- gentoo_package(Name, Echos). @@ -126,7 +86,7 @@ echo_packages(_, [], []). echo_packages(Dir, [E|Echos], [echo_append(String, File)|Commands]) :- echo_package(E, Tail, String), - path_joinn([Dir, Tail], File), + append(Dir, Tail, File), echo_packages(Dir, Echos, Commands). disabled_uses([], []). @@ -140,7 +100,7 @@ name(U, US), enabled_uses(UR, SR). -dir_make_conf(Dir, File) :- path_joinn([Dir, "/etc/make.conf"], File). +dir_make_conf(Dir, File) :- append(Dir, "/etc/make.conf", File). configure_gentoo_packages(Dir, Packages, Commands) :- aggregate_gentoo_packages(Packages, Echos, UseE, UseD), @@ -149,27 +109,27 @@ disabled_uses(UseD, UseDS), append(UseES, UseDS, MergedUse), join(" ", MergedUse, JoinedUse), - dir_make_conf(Dir, Make_conf), - concatn(["USE=\"", JoinedUse, "\""], Use), + append(Dir, "/etc/make.conf", Make_conf), + concat(["USE=\"", JoinedUse, "\""], Use), Commands = [ echo_append(Use, Make_conf) | C1 ]. reset_make_conf(Dir, CFLAGS, CXXFLAGS, CHOST, [echo_replace(Text, Make_conf)]) :- dir_make_conf(Dir, Make_conf), - concatn([ + concat([ "Autogenerated make.conf by ProSys\n", "CFLGAGS=\"", CFLAGS, "\"\n", "CXXFLAGS=\"", CXXFLAGS, "\"\n", "CHOST=\"", CHOST, "\"\n" ], Text). -append_site_make_conf(Dir, [run_append([cat, Src], Dst)]) :- - site_conf_file("make.conf", Src), +append_site_make_conf(Dir, [run('cat ', Src, ' >>', Dst)]) :- + site_conf_dir(Conf), + append(Conf, '/make.conf', Src), dir_make_conf(Dir, Dst). -create_chroot_script(Dir, Arch, [run([cp, '-Lp', '--', Src, Dst])]) :- +create_chroot_script(Dir, Arch, [run(S)]) :- site_conf_dir(Conf), - concatn([Conf, "/chroot.sh-", Arch], Src), - path_joinn([Dir, "chroot.sh"], Dst). + concat(["cp -Lp -- ", Conf, "/chroot.sh-", Arch, " ", Dir, "/"], S). create_gentoo_builddir(Name, Dir, Commands) :- gentoo_stage(Name, _, ArchName, _), @@ -187,30 +147,16 @@ C2), append_site_make_conf(Dir, C3), configure_gentoo_packages(Dir, [portage22, nopy3k, mc, vim], C4), - C5 = [chroot(Dir, ['/root/prosys/rebuild_stage3.sh'])], + C5 = [chroot(Dir, "/root/prosys/rebuild_stage3.sh")], concat([C1, C2, C3, C4, C5], Commands). -list_escape([], []). -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), 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), - concat([[Pre], E, [")"]], T). - -cmd_tokens(echo_append(String, File), E) :- - cmd_tokens(run_append([echo, String], File), E). -cmd_tokens(echo_replace(String, File), E) :- - cmd_tokens(run_replace([echo, String], File), E). -cmd_tokens(chroot(Dir, Args), E) :- - path_joinn([Dir, "chroot.sh"], Chroot), cmd_tokens(run([Chroot|Args]), E). +run(S) :- echo_append(String, File), + concat(["echo '", String, "' >>'", File, "'"], S). + +run(S) :- echo_replace(String, File), + concat(["echo '", String, "' >'", File, "'"], S). print_cmds([]). -print_cmds([Cmd|R]) :- - cmd_tokens(Cmd, Tokens), - join(" ", Tokens, S), - name(N,S), - write(N), write('\n'), print_cmds(R). +print_cmds([run(S)|R]) :- name(N,S), write(N), write('\n'), print_cmds(R). +print_cmds([run_outvar(V,S)|R]) :- name(N,S), write(N), write('\n'), print_cmds(R). +