1 |
>>>>> On Wed, 14 Oct 2015, Michał Górny wrote: |
2 |
|
3 |
> --- |
4 |
> pkg-mgr-commands.tex | 32 ++++++++++++++++++++++++++++---- |
5 |
> 1 file changed, 28 insertions(+), 4 deletions(-) |
6 |
|
7 |
> // I'm aware this isn't perfect but I tried to keep the algorithm |
8 |
> // readable and reasonably concise. Hope it's good enough for a start |
9 |
> // though. |
10 |
|
11 |
Thanks, this will indeed serve well as a start. |
12 |
|
13 |
> diff --git a/pkg-mgr-commands.tex b/pkg-mgr-commands.tex |
14 |
> index dbdbdfd..1d57d63 100644 |
15 |
> --- a/pkg-mgr-commands.tex |
16 |
> +++ b/pkg-mgr-commands.tex |
17 |
> @@ -148,10 +148,12 @@ These commands are used during the \t{src\_prepare} phase to apply patches to th |
18 |
> Ebuilds must not run any of these commands once the current phase function has returned. |
19 |
> |
20 |
> \begin{description} |
21 |
> -\item[eapply] \featurelabel{eapply} |
22 |
> - Only available in EAPIs listed in table~\ref{tab:patch-commands} as supporting \t{eapply}. |
23 |
> +\item[eapply] \featurelabel{eapply} Takes zero or more patch(1) options, followed by one or more |
24 |
|
25 |
Should we say "GNU patch" here? We require it in ebuild-env-commands.tex. |
26 |
|
27 |
> + file or directory paths. Processes options and applies all patches found in specified locations |
28 |
> + according to Algorithm~\ref{alg:eapply}. Only available in EAPIs listed in |
29 |
> + table~\ref{tab:patch-commands} as supporting \t{eapply}. |
30 |
> |
31 |
|
32 |
> -\item[eapply\_user] \featurelabel{eapply-user} Takes no arguments. Package managers supporting it |
33 |
> +\item[eapply\_user] \featurelabel{eapply-user} Takes no arguments. Package managers supporting i |
34 |
|
35 |
Slip of fingers. |
36 |
|
37 |
> apply user-provided patches to the source tree in the current working directory. Exact behaviour |
38 |
> is implementation defined and beyond the scope of this specification. Package managers not |
39 |
> supporting it must implement the function as a no-op. Only available in EAPIs listed in |
40 |
> @@ -161,7 +163,29 @@ Ebuilds must not run any of these commands once the current phase function has r |
41 |
> \begin{algorithm} |
42 |
> \caption{eapply logic} \label{alg:eapply} |
43 |
> \begin{algorithmic}[1] |
44 |
> -\STATE \COMMENT{WORK IN PROGRESS} |
45 |
> +\STATE let options=() |
46 |
> +\STATE let infiles=FALSE |
47 |
> +\FOR{\$x in parameters} |
48 |
> + \IF{infiles is FALSE} |
49 |
> + \IF{\$x is "\t{-{}-}"} |
50 |
> + \STATE let infiles=TRUE |
51 |
> + \ELSIF{\$x starts with "\t{-}"} |
52 |
> + \STATE options+=( "\$x" ) |
53 |
> + \ELSE |
54 |
> + \STATE let infiles=TRUE |
55 |
> + \ENDIF |
56 |
> + \ENDIF |
57 |
> + |
58 |
> + \IF{infiles is TRUE} |
59 |
|
60 |
I wonder if it wouldn't be cleaner to do the whole option parsing |
61 |
first. Something along the lines of this: |
62 |
|
63 |
IF first parameter begins with a hyphen AND any parameter is equal to -- |
64 |
collect all parameters before the first -- in the options array |
65 |
collect all parameters after the first -- in the files array |
66 |
ELSIF any parameter beginning with a hyphen follows one without a hyphen |
67 |
return an error |
68 |
ELSE |
69 |
collect all parameters starting with a hyphen in the options array |
70 |
collect all parameters without a hyphen in the files array |
71 |
ENDIF |
72 |
|
73 |
FOR x in files |
74 |
... |
75 |
|
76 |
> + \IF{\$x is a directory} |
77 |
> + \FOR{\$f in all files matching \$x/*.diff and \$x/*.patch} |
78 |
> + \STATE call \t{patch -p1 -f -s "\$\{options[@]\}" "\$f"} |
79 |
|
80 |
Options "-p1 -g0 -E --no-backup-if-mismatch" are field-proven in |
81 |
eutils.eclass. This doesn't mean that we have to adhere to it |
82 |
slavishly, but I would suggest that we keep both the -g0 and the |
83 |
--no-backup-if-mismatch options (but drop -E). Also I would omit |
84 |
the -s; it is up to the PM if it wants to suppress or filter output. |
85 |
So in summary, that is: |
86 |
|
87 |
patch -p1 -f -g0 --no-backup-if-mismatch |
88 |
|
89 |
> + \ENDFOR |
90 |
> + \ELSE |
91 |
> + \STATE call \t{patch -p1 -f -s "\$\{options[@]\}" "\$x"} |
92 |
> + \ENDIF |
93 |
> + \ENDIF |
94 |
> +\ENDFOR |
95 |
> \end{algorithmic} |
96 |
> \end{algorithm} |
97 |
|
98 |
We should say something about error handling. For example, does the |
99 |
function return when it encounters the first error of a called |
100 |
patch(1)? |
101 |
|
102 |
Ulrich |