From 5f0194ba83727df2cea55f0af67633e8f02b5982 Mon Sep 17 00:00:00 2001 From: Adarsh Sanjeev Date: Sun, 3 Jan 2016 16:02:25 +0500 Subject: String support for Chmod added --- src/engine/SCons/Defaults.py | 56 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index c1bd902..0fbd097 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -169,15 +169,65 @@ def get_paths_str(dest): else: return '"' + str(dest) + '"' +permission_dic = { + 'u':{ + 'r':stat.S_IRUSR, + 'w':stat.S_IWUSR, + 'x':stat.S_IXUSR + }, + 'g':{ + 'r':stat.S_IRGRP, + 'w':stat.S_IWGRP, + 'x':stat.S_IXGRP + }, + 'o':{ + 'r':stat.S_IROTH, + 'w':stat.S_IWOTH, + 'x':stat.S_IXOTH + } +} + def chmod_func(dest, mode): SCons.Node.FS.invalidate_node_memos(dest) if not SCons.Util.is_List(dest): dest = [dest] - for element in dest: - os.chmod(str(element), mode) + if str(mode).isdigit(): + for element in dest: + os.chmod(str(element), mode) + else: + mode = str(mode) + for operation in mode.split(","): + if "=" in operation: + operator = "=" + elif "+" in operation: + operator = "+" + elif "-" in operation: + operator = "-" + else: + raise SyntaxError("Could not find +, - or =") + user = operation.split(operator)[0].strip().replace("a", "ugo") + permission = operation.split(operator)[1].strip() + new_perm = 0 + for u in user: + for p in permission: + try: + new_perm = new_perm | permission_dic[u][p] + except KeyError: + raise SyntaxError("Unrecognized user or permission format") + for element in dest: + curr_perm = os.stat(str(element)).st_mode + if operator == "=": + os.chmod(str(element), new_perm) + elif operator == "+": + os.chmod(str(element), curr_perm | new_perm) + elif operator == "-": + os.chmod(str(element), curr_perm & ~new_perm) def chmod_strfunc(dest, mode): - return 'Chmod(%s, 0%o)' % (get_paths_str(dest), mode) + if str(mode).isdigit(): + return 'Chmod(%s, 0%o)' % (get_paths_str(dest), mode) + else: + return 'Chmod(%s, "%s")' % (get_paths_str(dest), str(mode)) Chmod = ActionFactory(chmod_func, chmod_strfunc) -- cgit v0.12 From 9ee508ee318cb51f3ff7194a0385a2ba74dcedd9 Mon Sep 17 00:00:00 2001 From: Adarsh Sanjeev Date: Sun, 3 Jan 2016 16:05:58 +0500 Subject: Tests for Chmod updated --- test/Chmod.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/Chmod.py b/test/Chmod.py index c00aea0..762d286 100644 --- a/test/Chmod.py +++ b/test/Chmod.py @@ -64,6 +64,11 @@ env.Command('f7.out', 'f7.in', [Cat, env = Environment(FILE = 'f9') env.Command('f8.out', 'f8.in', [Chmod(['$FILE', File('f10')], 0666), Cat]) Execute(Chmod(['d11', Dir('d12')], 0777)) +Execute(Chmod('f13', "go=rw")) +Execute(Chmod('f14', "u-r")) +Execute(Chmod('f15', "a+x")) +Execute(Chmod('d16', "uo=x")) +Execute(Chmod(['d17', 'd18'], "o-wx")) """) test.write('f1', "f1\n") @@ -86,6 +91,12 @@ test.write('f9', "f9\n") test.write('f10', "f10\n") test.subdir('d11') test.subdir('d12') +test.write('f13', "f13\n") +test.write('f14', "f14\n") +test.write('f15', "f15\n") +test.subdir('d16') +test.subdir('d17') +test.subdir('d18') os.chmod(test.workpath('f1'), 0444) os.chmod(test.workpath('f1-File'), 0444) @@ -100,6 +111,12 @@ os.chmod(test.workpath('f9'), 0444) os.chmod(test.workpath('f10'), 0444) os.chmod(test.workpath('d11'), 0555) os.chmod(test.workpath('d12'), 0555) +os.chmod(test.workpath('f13'), 0444) +os.chmod(test.workpath('f14'), 0444) +os.chmod(test.workpath('f15'), 0444) +os.chmod(test.workpath('d16'), 0555) +os.chmod(test.workpath('d17'), 0555) +os.chmod(test.workpath('d18'), 0555) expect = test.wrap_stdout(read_str = """\ Chmod("f1", 0666) @@ -107,6 +124,11 @@ Chmod("f1-File", 0666) Chmod("d2", 0777) Chmod("d2-Dir", 0777) Chmod(["d11", "d12"], 0777) +Chmod("f13", "go=rw") +Chmod("f14", "u-r") +Chmod("f15", "a+x") +Chmod("d16", "uo=x") +Chmod(["d17", "d18"], "o-wx") """, build_str = """\ cat(["bar.out"], ["bar.in"]) @@ -152,6 +174,18 @@ s = stat.S_IMODE(os.stat(test.workpath('d11'))[stat.ST_MODE]) test.fail_test(s != 0555) s = stat.S_IMODE(os.stat(test.workpath('d12'))[stat.ST_MODE]) test.fail_test(s != 0555) +s = stat.S_IMODE(os.stat(test.workpath('f13'))[stat.ST_MODE]) +test.fail_test(s != 0444) +s = stat.S_IMODE(os.stat(test.workpath('f14'))[stat.ST_MODE]) +test.fail_test(s != 0444) +s = stat.S_IMODE(os.stat(test.workpath('f15'))[stat.ST_MODE]) +test.fail_test(s != 0444) +s = stat.S_IMODE(os.stat(test.workpath('d16'))[stat.ST_MODE]) +test.fail_test(s != 0555) +s = stat.S_IMODE(os.stat(test.workpath('d17'))[stat.ST_MODE]) +test.fail_test(s != 0555) +s = stat.S_IMODE(os.stat(test.workpath('d18'))[stat.ST_MODE]) +test.fail_test(s != 0555) test.run() @@ -185,6 +219,18 @@ s = stat.S_IMODE(os.stat(test.workpath('d11'))[stat.ST_MODE]) test.fail_test(s != 0777) s = stat.S_IMODE(os.stat(test.workpath('d12'))[stat.ST_MODE]) test.fail_test(s != 0777) +s = stat.S_IMODE(os.stat(test.workpath('f13'))[stat.ST_MODE]) +test.fail_test(s != 0066) +s = stat.S_IMODE(os.stat(test.workpath('f14'))[stat.ST_MODE]) +test.fail_test(s != 0044) +s = stat.S_IMODE(os.stat(test.workpath('f15'))[stat.ST_MODE]) +test.fail_test(s != 0555) +s = stat.S_IMODE(os.stat(test.workpath('d16'))[stat.ST_MODE]) +test.fail_test(s != 0101) +s = stat.S_IMODE(os.stat(test.workpath('d17'))[stat.ST_MODE]) +test.fail_test(s != 0554) +s = stat.S_IMODE(os.stat(test.workpath('d18'))[stat.ST_MODE]) +test.fail_test(s != 0554) test.pass_test() -- cgit v0.12 From ea232cd3c7b8af29de3fa2619a20e7a24886cdcb Mon Sep 17 00:00:00 2001 From: Adarsh Sanjeev Date: Mon, 4 Jan 2016 22:50:59 +0500 Subject: Changed as per review --- src/engine/SCons/Defaults.py | 16 ++++++++++++---- test/Chmod.py | 32 ++++++++++++++++---------------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index 0fbd097..6344975 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -188,10 +188,14 @@ permission_dic = { } def chmod_func(dest, mode): + import SCons.Util + from string import digits SCons.Node.FS.invalidate_node_memos(dest) if not SCons.Util.is_List(dest): dest = [dest] - if str(mode).isdigit(): + if SCons.Util.is_String(mode) and not 0 in [i in digits for i in mode]: + mode = int(mode, 8) + if not SCons.Util.is_String(mode): for element in dest: os.chmod(str(element), mode) else: @@ -205,8 +209,11 @@ def chmod_func(dest, mode): operator = "-" else: raise SyntaxError("Could not find +, - or =") - user = operation.split(operator)[0].strip().replace("a", "ugo") - permission = operation.split(operator)[1].strip() + operation_list = operation.split(operator) + if len(operation_list) is not 2: + raise SyntaxError("More than one operator found") + user = operation_list[0].strip().replace("a", "ugo") + permission = operation_list[1].strip() new_perm = 0 for u in user: for p in permission: @@ -224,7 +231,8 @@ def chmod_func(dest, mode): os.chmod(str(element), curr_perm & ~new_perm) def chmod_strfunc(dest, mode): - if str(mode).isdigit(): + import SCons.Util + if not SCons.Util.is_String(mode): return 'Chmod(%s, 0%o)' % (get_paths_str(dest), mode) else: return 'Chmod(%s, "%s")' % (get_paths_str(dest), str(mode)) diff --git a/test/Chmod.py b/test/Chmod.py index 762d286..c5b2a8d 100644 --- a/test/Chmod.py +++ b/test/Chmod.py @@ -64,11 +64,11 @@ env.Command('f7.out', 'f7.in', [Cat, env = Environment(FILE = 'f9') env.Command('f8.out', 'f8.in', [Chmod(['$FILE', File('f10')], 0666), Cat]) Execute(Chmod(['d11', Dir('d12')], 0777)) -Execute(Chmod('f13', "go=rw")) -Execute(Chmod('f14', "u-r")) -Execute(Chmod('f15', "a+x")) -Execute(Chmod('d16', "uo=x")) -Execute(Chmod(['d17', 'd18'], "o-wx")) +Execute(Chmod('f13', "a=r")) +Execute(Chmod('f14', "ogu+w")) +Execute(Chmod('f15', "ug=rw, go+ rw")) +Execute(Chmod('d16', "0777")) +Execute(Chmod(['d17', 'd18'], "ogu = rwx")) """) test.write('f1', "f1\n") @@ -124,11 +124,11 @@ Chmod("f1-File", 0666) Chmod("d2", 0777) Chmod("d2-Dir", 0777) Chmod(["d11", "d12"], 0777) -Chmod("f13", "go=rw") -Chmod("f14", "u-r") -Chmod("f15", "a+x") -Chmod("d16", "uo=x") -Chmod(["d17", "d18"], "o-wx") +Chmod("f13", "a=r") +Chmod("f14", "ogu+w") +Chmod("f15", "ug=rw, go+ rw") +Chmod("d16", "0777") +Chmod(["d17", "d18"], "ogu = rwx") """, build_str = """\ cat(["bar.out"], ["bar.in"]) @@ -220,17 +220,17 @@ test.fail_test(s != 0777) s = stat.S_IMODE(os.stat(test.workpath('d12'))[stat.ST_MODE]) test.fail_test(s != 0777) s = stat.S_IMODE(os.stat(test.workpath('f13'))[stat.ST_MODE]) -test.fail_test(s != 0066) +test.fail_test(s != 0444) s = stat.S_IMODE(os.stat(test.workpath('f14'))[stat.ST_MODE]) -test.fail_test(s != 0044) +test.fail_test(s != 0666) s = stat.S_IMODE(os.stat(test.workpath('f15'))[stat.ST_MODE]) -test.fail_test(s != 0555) +test.fail_test(s != 0666) s = stat.S_IMODE(os.stat(test.workpath('d16'))[stat.ST_MODE]) -test.fail_test(s != 0101) +test.fail_test(s != 0777) s = stat.S_IMODE(os.stat(test.workpath('d17'))[stat.ST_MODE]) -test.fail_test(s != 0554) +test.fail_test(s != 0777) s = stat.S_IMODE(os.stat(test.workpath('d18'))[stat.ST_MODE]) -test.fail_test(s != 0554) +test.fail_test(s != 0777) test.pass_test() -- cgit v0.12 From 3909c2e02d5497858dcb509f09fe5766a9aa0b4d Mon Sep 17 00:00:00 2001 From: Adarsh Sanjeev Date: Tue, 5 Jan 2016 00:37:04 +0500 Subject: Updated documentation --- doc/generated/examples/caching_ex-random_1.xml | 4 +-- doc/generated/examples/tasks_ex1_1.xml | 2 +- doc/generated/examples/troubleshoot_Dump_1.xml | 2 +- doc/generated/examples/troubleshoot_Dump_2.xml | 2 +- doc/generated/examples/troubleshoot_explain1_3.xml | 2 +- .../examples/troubleshoot_stacktrace_2.xml | 4 +-- doc/generated/tools.gen | 12 +++---- doc/generated/tools.mod | 4 +-- doc/generated/variables.gen | 40 +++++++++++----------- doc/man/scons.xml | 9 ++++- src/CHANGES.txt | 2 ++ 11 files changed, 46 insertions(+), 37 deletions(-) diff --git a/doc/generated/examples/caching_ex-random_1.xml b/doc/generated/examples/caching_ex-random_1.xml index 6a0337b..cb14259 100644 --- a/doc/generated/examples/caching_ex-random_1.xml +++ b/doc/generated/examples/caching_ex-random_1.xml @@ -1,9 +1,9 @@ % scons -Q -cc -o f2.o -c f2.c cc -o f1.o -c f1.c +cc -o f4.o -c f4.c cc -o f5.o -c f5.c cc -o f3.o -c f3.c -cc -o f4.o -c f4.c +cc -o f2.o -c f2.c cc -o prog f1.o f2.o f3.o f4.o f5.o diff --git a/doc/generated/examples/tasks_ex1_1.xml b/doc/generated/examples/tasks_ex1_1.xml index 5760a45..4885fde 100644 --- a/doc/generated/examples/tasks_ex1_1.xml +++ b/doc/generated/examples/tasks_ex1_1.xml @@ -1,7 +1,7 @@ % scons -Q +cat < test.bar > test.h cc -o app main.cpp cat < foo.bar2 > foo.cpp cc -o app2 main2.cpp foo.cpp -cat < test.bar > test.h diff --git a/doc/generated/examples/troubleshoot_Dump_1.xml b/doc/generated/examples/troubleshoot_Dump_1.xml index bf141a0..99d1399 100644 --- a/doc/generated/examples/troubleshoot_Dump_1.xml +++ b/doc/generated/examples/troubleshoot_Dump_1.xml @@ -47,7 +47,7 @@ scons: Reading SConscript files ... 'PROGSUFFIX': '', 'PSPAWN': <function piped_env_spawn at 0x700000&gt;, 'RDirs': <SCons.Defaults.Variable_Method_Caller object at 0x700000&gt;, - 'SCANNERS': [], + 'SCANNERS': [<SCons.Scanner.Base object at 0x700000&gt;], 'SHELL': 'sh', 'SHLIBPREFIX': '$LIBPREFIX', 'SHLIBSUFFIX': '.so', diff --git a/doc/generated/examples/troubleshoot_Dump_2.xml b/doc/generated/examples/troubleshoot_Dump_2.xml index 0ae8fe1..a621422 100644 --- a/doc/generated/examples/troubleshoot_Dump_2.xml +++ b/doc/generated/examples/troubleshoot_Dump_2.xml @@ -71,7 +71,7 @@ scons: Reading SConscript files ... 'RCFLAGS': [], 'RCSUFFIXES': ['.rc', '.rc2'], 'RDirs': <SCons.Defaults.Variable_Method_Caller object at 0x700000&gt;, - 'SCANNERS': [], + 'SCANNERS': [<SCons.Scanner.Base object at 0x700000&gt;], 'SHCC': '$CC', 'SHCCCOM': <SCons.Action.FunctionAction object at 0x700000&gt;, 'SHCCFLAGS': ['$CCFLAGS'], diff --git a/doc/generated/examples/troubleshoot_explain1_3.xml b/doc/generated/examples/troubleshoot_explain1_3.xml index 3d8592d..7e495ea 100644 --- a/doc/generated/examples/troubleshoot_explain1_3.xml +++ b/doc/generated/examples/troubleshoot_explain1_3.xml @@ -3,5 +3,5 @@ cp file.in file.oout scons: warning: Cannot find target file.out after building -File "/scons/as_scons/bootstrap/src/script/scons.py", line 199, in <module> +File "/home/ghost/projects/scons/bootstrap/src/script/scons.py", line 199, in <module> diff --git a/doc/generated/examples/troubleshoot_stacktrace_2.xml b/doc/generated/examples/troubleshoot_stacktrace_2.xml index add59ff..1de0dcf 100644 --- a/doc/generated/examples/troubleshoot_stacktrace_2.xml +++ b/doc/generated/examples/troubleshoot_stacktrace_2.xml @@ -4,10 +4,10 @@ scons: *** [prog.o] Source `prog.c' not found, needed by target `prog.o'. scons: internal stack trace: File "bootstrap/src/engine/SCons/Job.py", line 199, in start task.prepare() - File "bootstrap/src/engine/SCons/Script/Main.py", line 173, in prepare + File "bootstrap/src/engine/SCons/Script/Main.py", line 164, in prepare return SCons.Taskmaster.OutOfDateTask.prepare(self) File "bootstrap/src/engine/SCons/Taskmaster.py", line 191, in prepare executor.prepare() - File "bootstrap/src/engine/SCons/Executor.py", line 430, in prepare + File "bootstrap/src/engine/SCons/Executor.py", line 427, in prepare raise SCons.Errors.StopError(msg % (s, self.batches[0].targets[0])) diff --git a/doc/generated/tools.gen b/doc/generated/tools.gen index ba12966..fcb7587 100644 --- a/doc/generated/tools.gen +++ b/doc/generated/tools.gen @@ -780,19 +780,19 @@ Sets construction variables for the Sets: &cv-link-AS;, &cv-link-ASCOM;, &cv-link-ASFLAGS;, &cv-link-ASPPCOM;, &cv-link-ASPPFLAGS;.Uses: &cv-link-ASCOMSTR;, &cv-link-ASPPCOMSTR;. - - Packaging + + packaging -Sets construction variables for the Package Builder. +A framework for building binary and source packages. - - packaging + + Packaging -A framework for building binary and source packages. +Sets construction variables for the Package Builder. diff --git a/doc/generated/tools.mod b/doc/generated/tools.mod index 2ee2270..1191e6a 100644 --- a/doc/generated/tools.mod +++ b/doc/generated/tools.mod @@ -78,8 +78,8 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. mwcc"> mwld"> nasm"> -Packaging"> packaging"> +Packaging"> pdf"> pdflatex"> pdftex"> @@ -189,8 +189,8 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. mwcc"> mwld"> nasm"> -Packaging"> packaging"> +Packaging"> pdf"> pdflatex"> pdftex"> diff --git a/doc/generated/variables.gen b/doc/generated/variables.gen index b377102..b64eb5a 100644 --- a/doc/generated/variables.gen +++ b/doc/generated/variables.gen @@ -2838,15 +2838,6 @@ is -dNOPAUSE -dBATCH -sDEVICE=pdfwrite HOST_ARCH - The name of the host hardware architecture used to create the Environment. - If a platform is specified when creating the Environment, then - that Platform's logic will handle setting this value. - This value is immutable, and should not be changed by the user after - the Environment is initialized. - Currently only set for Win32. - - - Sets the host architecture for Visual Studio compiler. If not set, default to the detected host architecture: note that this may depend on the python you are using. @@ -2862,7 +2853,16 @@ Valid values are the same as for This is currently only used on Windows, but in the future it will be used on other OSes as well. - + + + The name of the host hardware architecture used to create the Environment. + If a platform is specified when creating the Environment, then + that Platform's logic will handle setting this value. + This value is immutable, and should not be changed by the user after + the Environment is initialized. + Currently only set for Win32. + + HOST_OS @@ -3104,7 +3104,7 @@ The command line used to call the Java archive tool. The string displayed when the Java archive tool is called -If this is not set, then $JARCOM (the command line) is displayed. +If this is not set, then $JARCOM (the command line) is displayed. @@ -3114,7 +3114,7 @@ env = Environment(JARCOMSTR = "JARchiving $SOURCES into $TARGET") The string displayed when the Java archive tool is called -If this is not set, then $JARCOM (the command line) is displayed. +If this is not set, then $JARCOM (the command line) is displayed. @@ -7038,13 +7038,6 @@ that may not be set or used in a construction environment. TARGET_ARCH - The name of the target hardware architecture for the compiled objects - created by this Environment. - This defaults to the value of HOST_ARCH, and the user can override it. - Currently only set for Win32. - - - Sets the target architecture for Visual Studio compiler (i.e. the arch of the binaries generated by the compiler). If not set, default to $HOST_ARCH, or, if that is unset, to the architecture of the @@ -7069,7 +7062,14 @@ and ia64 (Itanium). For example, if you want to compile 64-bit binaries, you would set TARGET_ARCH='x86_64' in your SCons environment. - + + + The name of the target hardware architecture for the compiled objects + created by this Environment. + This defaults to the value of HOST_ARCH, and the user can override it. + Currently only set for Win32. + + TARGET_OS diff --git a/doc/man/scons.xml b/doc/man/scons.xml index 5c832c2..c72178e 100644 --- a/doc/man/scons.xml +++ b/doc/man/scons.xml @@ -5630,7 +5630,8 @@ env.Command('foo.out', 'foo.in', changes the permissions on the specified dest file or directory to the specified -mode. +mode +which can be octal or string, similar to the bash command. Examples: @@ -5639,6 +5640,12 @@ Execute(Chmod('file', 0755)) env.Command('foo.out', 'foo.in', [Copy('$TARGET', '$SOURCE'), Chmod('$TARGET', 0755)]) + +Execute(Chmod('file', "ugo+w")) + +env.Command('foo.out', 'foo.in', + [Copy('$TARGET', '$SOURCE'), + Chmod('$TARGET', "ugo+w")]) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 9e335f9..1a3ee63 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -19,6 +19,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER Also fixed the default arguments for the print_tree and render_tree methods. (PR #284, too) + From Adarsh Sanjeev: + - Fix for issue #2494: Added string support for Chmod function. RELEASE 2.4.1 - Mon, 07 Nov 2015 10:37:21 -0700 -- cgit v0.12