=== modified file 'stagebuilder.prolog' --- stagebuilder.prolog 2011-11-16 17:38:01 +0000 +++ stagebuilder.prolog 2011-11-11 21:50:50 +0000 @@ -1,11 +1,5 @@ % vim: ft=prolog textwidth=80 tabstop=4 softtabstop=4 shiftwidth=4 expandtab -:- use_module(library(lists)). -:- use_module(library(ordsets)). -:- use_module(library(assoc)). -%:- use_module(library(pairs)). -%:- use_module(library(error)). - % operator definition :- op(400, yfx, +/+). @@ -283,10 +277,6 @@ ], downloaded) ]. -% -% Gentoo Packages -% - gentoo_package(portage22 ,[package_keywords('sys-apps/portage **') ,package_mask('=sys-apps/portage-9999') @@ -343,121 +333,39 @@ gentoo_package(Name, Echos, UseEnabled, []) :- gentoo_package(Name, Echos, UseEnabled). -% USE handling - -gentoo_package_use(Name, UseEnabledSet, UseDisabledSet) :- - gentoo_package(Name,_Echos, UseEnabledList, UseEnabledSet), - list_to_ord_set(UseEnabledList, UseEnabledSet), - list_to_ord_set(UseDisabledList, UseDisabledSet). - -aggregate_package_use([ ], [ ], [ ]). -aggregate_package_use([PkgName|PkgNames], UseEnabled, UseDisabled) :- - gentoo_package_use(PkgName, PkgUseEnabled, PkgUseDisabled), - aggregate_package_use(PkgNames, AggUseEnabled, AggUseDisabled), - ord_union(PkgUseEnabled, AggUseEnabled, UseEnabled), - ord_union(PkgUseDisabled, AggUseDisabled, UseDisabled). - -disabled_use(Use, '-' + Use). - -format_package_use(Packages, JoinedUse) :- - aggregate_package_use(Packages, UseEnabled, UseDisabled), - ( ord_intersection(UseEnabled, UseDisabled, Intersection) - -> throw(conflicting_use(Intersection)) - ; maplist(disabled_use, UseDisabled, UseDisabledMinus), - append(UseEnabled, UseDisabledMinus, MergedUse), - join(' ', MergedUse, JoinedUse) - ). - -% package settings handling - -echo_package(package_mask(String), - echo_append(String, '/etc/portage/package.mask') - ). -echo_package(package_unmask(String), - echo_append(String, '/etc/portage/package.unmask') - ). -echo_package(package_use(String), - echo_append(String, '/etc/portage/package.use') - ). -echo_package(package_keywords(String), - echo_append(String, '/etc/portage/package.keywords') - ). -echo_package(package_world(String), - echo_append(String, '/root/prosys/world') - ). - -extract_package_echo([ ], [ ]). -extract_package_echo([Pkg|Rest], List) :- - gentoo_package(Pkg, Echos, _, _), - append(Echos, Tail, List), - extract_package_echo(Rest, Tail). - -aggregate_package_echo(Packages, Assoc) :- - extract_package_echo(Packages, EchoPkgList), - maplist(echo_package, EchoPkgList, EchoAppendList), - empty_assoc(Empty), - aggregate_package_echo(EchoAppendList, Empty, Assoc). - -aggregate_package_echo([ ], Assoc, Assoc). -aggregate_package_echo([echo_append(String, File)|Rest], Assoc, Result) :- - ( get_assoc(File, Assoc, Prev) - -> put_assoc(File, Assoc, String - aggregate_package_echo([Rest], NewAssoc, Result). -%echo_package_dir(Dir, echo_append(String, Dir +/+ Tail), Echo) :- -% echo_package(Echo, Tail, String). -% -%extract_package_echos([], [], []). -%extract_package_echos([gentoo_package(_Name, Echos, _UE, _UD)|PkgRest] -% ,AllFiles -% ,AllStrings -% ):- -% maplist(echo_package, Echos, Files, Strings), -% extract_package_echos(PkgRest, RecFiles, RecStrings), -% append(Files, RecFiles, AllFiles), -% append(Strings, RecStrings, AllStrings). -% -%joined_echos([ ],_Keys,_Values, [ ]). -%joined_echos([Key|UniqueKeys], Keys, Values, [Echo|EchosRest]) :- -% select_rows(Key, Keys, Values, Selected), -% join('\n', Selected, Joined), -% Echo = echo. -% -%aggregate_package_echos(Packages, Echos) :- -% extract_package_echos(Packages, Files, Strings), -% sort(Files, UniqueFiles), - - -%dict_append_aux(Key -% ,AppendValue -% ,[CurrentKey|Keys] -% ,[CurrentValue|Values] -% ,[ResultValue|Results] -% ) :- -% ( Key = CurrentKey -% -> ResultValue = AppendValue + '\n' + CurrentValue -% ; ResultValue = CurrentValue -% ), -% dict_append_aux(Key, AppendValue, Keys, Values, Results). -% -%dict_append(Key, Value, Ks, Vs, RKs, RVs) :- -% ( member(Key, Keys) -% -> dict_append_aux(Key, Value, Vs, RVs), RKs = Ks -% ; RKs = [Key|Ks], RVs = [[Value]] -% ). +aggregate_gentoo_packages([ ], [ ], [ ], [ ]). +aggregate_gentoo_packages([PkgName|PkgNames], Echos, UseEnabled, UseDisabled) :- + gentoo_package(PkgName, PkgEchos, PkgUseEnabled, PkgUseDisabled), + aggregate_gentoo_packages(PkgNames, AggEchos + ,AggUseEnabled, AggUseDisabled), + append(PkgEchos, AggEchos, Echos), + append(PkgUseEnabled , AggUseEnabled , MergedUseEnabled) , + sort(MergedUseEnabled , UseEnabled ), + append(PkgUseDisabled, AggUseDisabled, MergedUseDisabled), + sort(MergedUseDisabled, UseDisabled). + +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_dir(Dir, echo_append(String, Dir +/+ Tail), Echo) :- + echo_package(Echo, Tail, String). + +dict_append(Key, AppendValue, CurrentValue, ResultValue) :- + echo_package_dir_agg([ ], Files, Strings, Files, Strings). echo_package_dir_agg([Echo|Rest], Files, Strings, AggFiles, AggStrings) :- echo_package(Echo, File, String), - dict_append(File, String, AggFiles, AggStrings, NewFiles, NewStrings), - echo_package_dir_agg(Rest, Files, Strings, NewFiles, NewStrings). - - -echo_packages(Echos, Dirs, Commands) :- - echo_package_dir_agg(Echos, Files, Strings, [], []), - - + ( member(File, AggFiles) + -> % echo_packages(Commands, Echos, Dir) :- % maplist(echo_package_dir(Dir), Commands, Echos). + +disabled_use(Use, '-' + Use). + % disabled_uses(Uses, DisabledUses) :- % maplist(disabled_use, Uses, DisabledUses). @@ -465,11 +373,14 @@ configure_gentoo_packages(Dir, Packages) --> [echo_append('USE="' + JoinedUse + '"', Make_conf)], - { format_package_use(Packages, JoinedUse), + { aggregate_gentoo_packages(Packages, Echos, UseEnabled, UseDisabled), maplist(echo_package_dir(Dir), Commands, Echos) }, prepend(Commands), - { dir_make_conf(Dir, Make_conf) + { maplist(disabled_use, UseDisabled, UseDisabledMinus), + append(UseEnabled, UseDisabledMinus, MergedUse), + join(' ', MergedUse, JoinedUse), + dir_make_conf(Dir, Make_conf) }. reset_make_conf(Dir, CFLAGS, CXXFLAGS, CHOST) -->