[build-path-prefix-map-spec] 02/03: Swap around the target, source pairs as suggested by Ian

Ximin Luo infinity0 at debian.org
Tue Mar 14 19:29:53 UTC 2017


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository build-path-prefix-map-spec.

commit cc496234133eeacebcf359328a55b91347303b82
Author: Ximin Luo <infinity0 at debian.org>
Date:   Tue Mar 14 20:06:00 2017 +0100

    Swap around the target, source pairs as suggested by Ian
---
 consume/pecsplit.js                            |  4 ++--
 consume/pecsplit.py                            |  4 ++--
 consume/pecsplit.rs                            |  8 ++++----
 consume/prefix_map.h                           |  2 +-
 consume/testcases/0.basic.pecsplit.env         |  2 +-
 consume/testcases/0.ordering.pecsplit.env      |  2 +-
 consume/testcases/pecsplit.0.allbytes-ok.env   |  2 +-
 consume/testcases/pecsplit.0.empty-ok.env      |  2 +-
 consume/testcases/pecsplit.0.non-utf8.env      |  2 +-
 consume/testcases/pecsplit.1.long-pc-1.env     |  2 +-
 consume/testcases/pecsplit.1.long-pc-2.env     |  2 +-
 consume/testcases/pecsplit.1.long-pc-3.env     |  2 +-
 consume/testcases/pecsplit.1.long-pc-4.env     |  2 +-
 consume/testcases/pecsplit.1.long-pc-5.env     |  2 +-
 consume/testcases/pecsplit.1.many-=-not-ok.env |  2 +-
 consume/testcases/pecsplit.1.plain-pc-1.env    |  2 +-
 consume/testcases/pecsplit.1.plain-pc-2.env    |  2 +-
 consume/testcases/pecsplit.1.plain-pc-3.env    |  2 +-
 consume/testcases/pecsplit.1.plain-pc-4.env    |  2 +-
 consume/testcases/pecsplit.1.plain-pc-5.env    |  2 +-
 consume/testcases/pecsplit.1.short-pc-2.env    |  2 +-
 consume/testcases/pecsplit.1.short-pc-4.env    |  2 +-
 consume/testcases/pecsplit.1.short-pc-5.env    |  2 +-
 consume/testcases/pecsplit.1.zero-=-not-ok.env |  2 +-
 produce/pecsplit.mk                            |  4 ++--
 produce/pecsplit.pl                            |  4 ++--
 produce/test-all.sh                            |  4 ++--
 spec.in.rst                                    | 23 +++++++++++++++--------
 28 files changed, 50 insertions(+), 43 deletions(-)

diff --git a/consume/pecsplit.js b/consume/pecsplit.js
index cd9642e..d8f2ca7 100755
--- a/consume/pecsplit.js
+++ b/consume/pecsplit.js
@@ -21,8 +21,8 @@ var parse_prefix_map = function(x) {
 
 var map_prefix = function(string, pm) {
   for (var i = pm.length - 1; i >= 0; --i) {;
-    var src = pm[i][0];
-    var dst = pm[i][1];
+    var dst = pm[i][0];
+    var src = pm[i][1];
     if (string.indexOf(src) === 0) {
       return dst + string.substr(src.length);
     }
diff --git a/consume/pecsplit.py b/consume/pecsplit.py
index 5c7fe6e..fb792cd 100755
--- a/consume/pecsplit.py
+++ b/consume/pecsplit.py
@@ -14,12 +14,12 @@ def _dequote(part):
 def decode(prefix_str):
   tuples = (part.split("=") for part in prefix_str.split(":") if part)
   # Will raise if any tuple can't be destructured into a pair
-  return [(_dequote(src), _dequote(dst)) for src, dst in tuples]
+  return [(_dequote(dst), _dequote(src)) for dst, src in tuples]
 
 # Applying the variable
 
 def map_prefix(string, pm):
-  for src, dst in reversed(pm):
+  for dst, src in reversed(pm):
     if string.startswith(src):
       return dst + string[len(src):]
   return string
diff --git a/consume/pecsplit.rs b/consume/pecsplit.rs
index 2d1bb18..846e7ce 100644
--- a/consume/pecsplit.rs
+++ b/consume/pecsplit.rs
@@ -54,9 +54,9 @@ fn decode(prefix_str: Option<OsString>) -> Result<Vec<(PathBuf, PathBuf)>, &'sta
         Err("either too few or too many '='")
       } else {
         // TODO: windows
-        let src = OsString::from_vec(try!(dequote(tuple[0])));
-        let dst = OsString::from_vec(try!(dequote(tuple[1])));
-        Ok((PathBuf::from(src), PathBuf::from(dst)))
+        let dst = OsString::from_vec(try!(dequote(tuple[0])));
+        let src = OsString::from_vec(try!(dequote(tuple[1])));
+        Ok((PathBuf::from(dst), PathBuf::from(src)))
       }
     })
     .collect::<Result<Vec<_>, _>>()
@@ -66,7 +66,7 @@ fn decode(prefix_str: Option<OsString>) -> Result<Vec<(PathBuf, PathBuf)>, &'sta
 
 fn map_prefix(path: PathBuf, pm: &Vec<(PathBuf, PathBuf)>) -> PathBuf {
   for pair in pm.iter().rev() {
-    let (ref src, ref dst) = *pair;
+    let (ref dst, ref src) = *pair;
     if path.starts_with(src) {
       /* FIXME: this is different from what our other language examples do;
        * rust's [PathBuf.starts_with] only matches whole components. however
diff --git a/consume/prefix_map.h b/consume/prefix_map.h
index 1149189..cf1b577 100644
--- a/consume/prefix_map.h
+++ b/consume/prefix_map.h
@@ -43,7 +43,7 @@ struct prefix_maps
  * Returns 0 on failure and 1 on success.
  */
 int
-add_prefix_map (const char *old_prefix, const char *new_prefix,
+add_prefix_map (const char *new_prefix, const char *old_prefix,
 		struct prefix_maps *maps)
 {
   struct prefix_map *map = XNEW (struct prefix_map);
diff --git a/consume/testcases/0.basic.pecsplit.env b/consume/testcases/0.basic.pecsplit.env
index 2655c72..946f327 100644
--- a/consume/testcases/0.basic.pecsplit.env
+++ b/consume/testcases/0.basic.pecsplit.env
@@ -1 +1 @@
-/a/zzz=ERROR:/a=lol:/b/1234=ERROR:/b=foo:/a/yyy=bar
+ERROR=/a/zzz:lol=/a:ERROR=/b/1234:foo=/b:bar=/a/yyy
diff --git a/consume/testcases/0.ordering.pecsplit.env b/consume/testcases/0.ordering.pecsplit.env
index 685a938..ea9057d 100644
--- a/consume/testcases/0.ordering.pecsplit.env
+++ b/consume/testcases/0.ordering.pecsplit.env
@@ -1 +1 @@
-/a/b%+yyy=ERROR:/a=lol:/b/1234=ERROR:/b=foo:/a/b%+yyy=libbar-3-bison++_41%.10.5-3~rc1pre3+dfsg1.1-3nmu1+b4
+ERROR=/a/b%+yyy:lol=/a:ERROR=/b/1234:foo=/b:libbar-3-bison++_41%.10.5-3~rc1pre3+dfsg1.1-3nmu1+b4=/a/b%+yyy
diff --git a/consume/testcases/pecsplit.0.allbytes-ok.env b/consume/testcases/pecsplit.0.allbytes-ok.env
index 70e3333..111e1b2 100644
--- a/consume/testcases/pecsplit.0.allbytes-ok.env
+++ b/consume/testcases/pecsplit.0.allbytes-ok.env
@@ -1 +1 @@
-	





 !"#$&'()*+,-./0123456789;<>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~�������������������������������������������������������������������������������������������������������������������������������=
+=	





 !"#$&'()*+,-./0123456789;<>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~�������������������������������������������������������������������������������������������������������������������������������
diff --git a/consume/testcases/pecsplit.0.empty-ok.env b/consume/testcases/pecsplit.0.empty-ok.env
index 8b4ea22..3e5a406 100644
--- a/consume/testcases/pecsplit.0.empty-ok.env
+++ b/consume/testcases/pecsplit.0.empty-ok.env
@@ -1 +1 @@
-:/a/b%+yyy=ERROR:/a=lol::/b=foo:/a/b%+yyy=libbar-3-bison++_41%.10.5-3~rc1pre3+dfsg1.1-3nmu1+b4:
+:ERROR=/a/b%+yyy:lol=/a::foo=/b:libbar-3-bison++_41%.10.5-3~rc1pre3+dfsg1.1-3nmu1+b4=/a/b%+yyy:
diff --git a/consume/testcases/pecsplit.0.non-utf8.env b/consume/testcases/pecsplit.0.non-utf8.env
index d7693b8..fefb8af 100644
--- a/consume/testcases/pecsplit.0.non-utf8.env
+++ b/consume/testcases/pecsplit.0.non-utf8.env
@@ -1 +1 @@
-/a/b%+yyy=result�:/a=lol%#%#:/b%#=foo%#%#:/a/b%+yyy=result�:/a/b%+yyy�=sec%.reteh
+result�=/a/b%+yyy:lol%#%#=/a:foo%#%#=/b%#:result�=/a/b%+yyy:sec%.reteh=/a/b%+yyy�
diff --git a/consume/testcases/pecsplit.1.long-pc-1.env b/consume/testcases/pecsplit.1.long-pc-1.env
index b7c0bf6..31cd734 100644
--- a/consume/testcases/pecsplit.1.long-pc-1.env
+++ b/consume/testcases/pecsplit.1.long-pc-1.env
@@ -1 +1 @@
-%%#/a/zzz=ERROR:/a=lol:/b/1234=ERROR:/b=foo:/a/yyy=bar
+%%#ERROR=/a/zzz:lol=/a:ERROR=/b/1234:foo=/b:bar=/a/yyy
diff --git a/consume/testcases/pecsplit.1.long-pc-2.env b/consume/testcases/pecsplit.1.long-pc-2.env
index 9c04704..89a4ddd 100644
--- a/consume/testcases/pecsplit.1.long-pc-2.env
+++ b/consume/testcases/pecsplit.1.long-pc-2.env
@@ -1 +1 @@
-/a/zzz%%#=ERROR:/a=lol:/b/1234=ERROR:/b=foo:/a/yyy=bar
+ERROR%%#=/a/zzz:lol=/a:ERROR=/b/1234:foo=/b:bar=/a/yyy
diff --git a/consume/testcases/pecsplit.1.long-pc-3.env b/consume/testcases/pecsplit.1.long-pc-3.env
index 5b128af..c8f7cd4 100644
--- a/consume/testcases/pecsplit.1.long-pc-3.env
+++ b/consume/testcases/pecsplit.1.long-pc-3.env
@@ -1 +1 @@
-/a/zzz=ERROR:/a=%%#lol:/b/1234=ERROR:/b=foo:/a/yyy=bar
+ERROR=/a/zzz:lol=%%#/a:ERROR=/b/1234:foo=/b:bar=/a/yyy
diff --git a/consume/testcases/pecsplit.1.long-pc-4.env b/consume/testcases/pecsplit.1.long-pc-4.env
index d6521be..434bcfa 100644
--- a/consume/testcases/pecsplit.1.long-pc-4.env
+++ b/consume/testcases/pecsplit.1.long-pc-4.env
@@ -1 +1 @@
-/a/zzz=ERROR:/a=lol:/b/1234=ERROR:/b=foo%%#:/a/yyy=bar
+ERROR=/a/zzz:lol=/a:ERROR=/b/1234:foo=/b%%#:bar=/a/yyy
diff --git a/consume/testcases/pecsplit.1.long-pc-5.env b/consume/testcases/pecsplit.1.long-pc-5.env
index b7026cd..b8dcd7f 100644
--- a/consume/testcases/pecsplit.1.long-pc-5.env
+++ b/consume/testcases/pecsplit.1.long-pc-5.env
@@ -1 +1 @@
-/a/zzz=ERROR:/a=lol:/b/1234=ERROR:/b=foo:/a/yyy=bar%%#
+ERROR=/a/zzz:lol=/a:ERROR=/b/1234:foo=/b:bar=/a/yyy%%#
diff --git a/consume/testcases/pecsplit.1.many-=-not-ok.env b/consume/testcases/pecsplit.1.many-=-not-ok.env
index 6622f25..a2809ee 100644
--- a/consume/testcases/pecsplit.1.many-=-not-ok.env
+++ b/consume/testcases/pecsplit.1.many-=-not-ok.env
@@ -1 +1 @@
-/a/b=yyy=ERROR:/a=lol:/b=foo:/a/byyy=bar
+ERROR=/a/b=yyy:lol=/a:foo=/b:bar=/a/byyy
diff --git a/consume/testcases/pecsplit.1.plain-pc-1.env b/consume/testcases/pecsplit.1.plain-pc-1.env
index 96878de..e3716c8 100644
--- a/consume/testcases/pecsplit.1.plain-pc-1.env
+++ b/consume/testcases/pecsplit.1.plain-pc-1.env
@@ -1 +1 @@
-%s/a/zzz=ERROR:/a=lol:/b/1234=ERROR:/b=foo:/a/yyy=bar
+%sERROR=/a/zzz:lol=/a:ERROR=/b/1234:foo=/b:bar=/a/yyy
diff --git a/consume/testcases/pecsplit.1.plain-pc-2.env b/consume/testcases/pecsplit.1.plain-pc-2.env
index 662bc27..3718ccc 100644
--- a/consume/testcases/pecsplit.1.plain-pc-2.env
+++ b/consume/testcases/pecsplit.1.plain-pc-2.env
@@ -1 +1 @@
-/a/zzz%s=ERROR:/a=lol:/b/1234=ERROR:/b=foo:/a/yyy=bar
+ERROR%s=/a/zzz:lol=/a:ERROR=/b/1234:foo=/b:bar=/a/yyy
diff --git a/consume/testcases/pecsplit.1.plain-pc-3.env b/consume/testcases/pecsplit.1.plain-pc-3.env
index 0445b2b..043a878 100644
--- a/consume/testcases/pecsplit.1.plain-pc-3.env
+++ b/consume/testcases/pecsplit.1.plain-pc-3.env
@@ -1 +1 @@
-/a/zzz=ERROR:/a=%slol:/b/1234=ERROR:/b=foo:/a/yyy=bar
+ERROR=/a/zzz:lol=%s/a:ERROR=/b/1234:foo=/b:bar=/a/yyy
diff --git a/consume/testcases/pecsplit.1.plain-pc-4.env b/consume/testcases/pecsplit.1.plain-pc-4.env
index 857db17..af04565 100644
--- a/consume/testcases/pecsplit.1.plain-pc-4.env
+++ b/consume/testcases/pecsplit.1.plain-pc-4.env
@@ -1 +1 @@
-/a/zzz=ERROR:/a=lol:/b/1234=ERROR:/b=foo%s:/a/yyy=bar
+ERROR=/a/zzz:lol=/a:ERROR=/b/1234:foo=/b%s:bar=/a/yyy
diff --git a/consume/testcases/pecsplit.1.plain-pc-5.env b/consume/testcases/pecsplit.1.plain-pc-5.env
index be65c2d..9070d4c 100644
--- a/consume/testcases/pecsplit.1.plain-pc-5.env
+++ b/consume/testcases/pecsplit.1.plain-pc-5.env
@@ -1 +1 @@
-/a/zzz=ERROR:/a=lol:/b/1234=ERROR:/b=foo:/a/yyy=bar%s
+ERROR=/a/zzz:lol=/a:ERROR=/b/1234:foo=/b:bar=/a/yyy%s
diff --git a/consume/testcases/pecsplit.1.short-pc-2.env b/consume/testcases/pecsplit.1.short-pc-2.env
index a67f3a9..430e362 100644
--- a/consume/testcases/pecsplit.1.short-pc-2.env
+++ b/consume/testcases/pecsplit.1.short-pc-2.env
@@ -1 +1 @@
-/a/zzz%=ERROR:/a=lol:/b/1234=ERROR:/b=foo:/a/yyy=bar
+ERROR%=/a/zzz:lol=/a:ERROR=/b/1234:foo=/b:bar=/a/yyy
diff --git a/consume/testcases/pecsplit.1.short-pc-4.env b/consume/testcases/pecsplit.1.short-pc-4.env
index f0428f4..ab29aa0 100644
--- a/consume/testcases/pecsplit.1.short-pc-4.env
+++ b/consume/testcases/pecsplit.1.short-pc-4.env
@@ -1 +1 @@
-/a/zzz=ERROR:/a=lol:/b/1234=ERROR:/b=foo%:/a/yyy=bar
+ERROR=/a/zzz:lol=/a:ERROR=/b/1234:foo=/b%:bar=/a/yyy
diff --git a/consume/testcases/pecsplit.1.short-pc-5.env b/consume/testcases/pecsplit.1.short-pc-5.env
index 57b60b4..210947d 100644
--- a/consume/testcases/pecsplit.1.short-pc-5.env
+++ b/consume/testcases/pecsplit.1.short-pc-5.env
@@ -1 +1 @@
-/a/zzz=ERROR:/a=lol:/b/1234=ERROR:/b=foo:/a/yyy=bar%
+ERROR=/a/zzz:lol=/a:ERROR=/b/1234:foo=/b:bar=/a/yyy%
diff --git a/consume/testcases/pecsplit.1.zero-=-not-ok.env b/consume/testcases/pecsplit.1.zero-=-not-ok.env
index 0603429..87fa54d 100644
--- a/consume/testcases/pecsplit.1.zero-=-not-ok.env
+++ b/consume/testcases/pecsplit.1.zero-=-not-ok.env
@@ -1 +1 @@
-/a/byyyERROR:/a=lol:/b=foo:/a/byyy=bar
+/a/byyyERROR:lol=/a:foo=/b:bar=/a/byyy
diff --git a/produce/pecsplit.mk b/produce/pecsplit.mk
index 700aba2..65c0ce1 100755
--- a/produce/pecsplit.mk
+++ b/produce/pecsplit.mk
@@ -5,8 +5,8 @@
 pfmap_enquote = $(subst :,%.,$(subst =,%+,$(subst %,%\#,$(1))))
 
 export override BUILD_PATH_PREFIX_MAP := $(BUILD_PATH_PREFIX_MAP):$(call\
-pfmap_enquote,$(NEWSRC))=$(call\
-pfmap_enquote,$(NEWDST))
+pfmap_enquote,$(NEWDST))=$(call\
+pfmap_enquote,$(NEWSRC))
 
 .PHONY: print.sh
 print.sh:
diff --git a/produce/pecsplit.pl b/produce/pecsplit.pl
index f277383..229b078 100755
--- a/produce/pecsplit.pl
+++ b/produce/pecsplit.pl
@@ -14,7 +14,7 @@ sub pfmap_enquote {
 
 $ENV{"BUILD_PATH_PREFIX_MAP"} = sprintf("%s:%s=%s",
 	$ENV{"BUILD_PATH_PREFIX_MAP"},
-	pfmap_enquote($ENV{"NEWSRC"}),
-	pfmap_enquote($ENV{"NEWDST"}));
+	pfmap_enquote($ENV{"NEWDST"}),
+	pfmap_enquote($ENV{"NEWSRC"}));
 
 exec @ARGV;
diff --git a/produce/test-all.sh b/produce/test-all.sh
index 3b3c606..50f97c5 100755
--- a/produce/test-all.sh
+++ b/produce/test-all.sh
@@ -22,7 +22,7 @@ test_mapping() {
 }
 
 test_mapping 'foo' 'bar' \
-	'foo=bar'
+	'bar=foo'
 
 test_mapping '/a/b=yyy' 'libbar-3-bison++_41:10.5-3~rc1pre3+dfsg1.1-3nmu1+b4' \
-	'/a/b%+yyy=libbar-3-bison++_41%.10.5-3~rc1pre3+dfsg1.1-3nmu1+b4'
+	'libbar-3-bison++_41%.10.5-3~rc1pre3+dfsg1.1-3nmu1+b4=/a/b%+yyy'
diff --git a/spec.in.rst b/spec.in.rst
index 0148789..1658b93 100644
--- a/spec.in.rst
+++ b/spec.in.rst
@@ -55,9 +55,9 @@ Overview
 --------
 
 The environment variable ``BUILD_PATH_PREFIX_MAP`` represents an ordered map
-that associates path prefixes that exist on the build-time filesystem, with
-path prefixes that should replace them in the build output. We use the
-following terms:
+that associates reproducible path prefixes that may appear in the build output,
+with path prefixes that exist on the build-time filesystem that must not appear
+in the build output. We use the following terms:
 
 A *producer* is a program that knows how to determine appropriate values for
 the map, and can pass this information to lower-level build tools. For example,
@@ -166,6 +166,9 @@ Setting the encoded value
 Producers SHOULD NOT overwrite existing values; instead they should append
 their new mappings onto the right of any existing value.
 
+Each individual mapping has the reproducible *target* path prefix on the left,
+and the unreproducible *source* path prefix on the right.
+
 Producers who build *general software* that uses this variable, MUST NOT expect
 any special contracts on the output emitted by *general consumers* based on
 this variable ― only that their output be reproducible when the build path
@@ -180,7 +183,7 @@ See also the requirements for consumers in the next part for guidance.
 Applying the decoded structure
 ------------------------------
 
-Consumers MUST ensure that, at minimum: for all (*source*, *target*) prefix
+Consumers MUST ensure that, at minimum: for all (*target*, *source*) prefix
 pairs in the parsed list, with rightmost pairs taking priority: strings in the
 final build output, that represent build-time paths derived from *source*,
 instead appear to represent potential run-time paths derived from *target*.
@@ -193,10 +196,10 @@ for different consumers (languages, buildsystems, etc), and a more specific
 definition might conflict with their idea of what that means. Generally,
 consumers SHOULD implement one of the following algorithms:
 
-1. For each (source, target) prefix pair in the list-of-pairs, going from right
-   to left: if the subject path starts with the source prefix, then replace
-   this occurence with the target prefix, and return this new path, ignoring
-   any pairs further left in the list.
+1. For each (*target*, *source*) prefix pair in the list-of-pairs, going from
+   right to left: if the subject path starts with the source prefix, then
+   replace this occurence with the target prefix, and return this new path,
+   ignoring any pairs further left in the list.
 
 2. As in (1) but with "starts with" replaced by "starts with, restricted to
    whole-path components". So for example,
@@ -206,6 +209,10 @@ consumers SHOULD implement one of the following algorithms:
 
    This has more robust semantics but is slightly more complex to implement.
 
+Consumers MAY for historical reasons internally store the map with the prefix
+pairs flipped as in (*source*, *target*), instead of (*target*, *source*) as
+described above. New code should prefer the latter representation.
+
 
 Notes and links
 ===============

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/build-path-prefix-map-spec.git



More information about the Reproducible-commits mailing list